import useUrlState from "@ahooksjs/use-url-state"; import { Connect } from "@cqsjjb/jjb-dva-runtime"; import { Button, Form, message, Modal, Space, Tabs, Tag } from "antd"; import { useEffect, useState } from "react"; import FormBuilder from "zy-react-library/components/FormBuilder"; import AddIcon from "zy-react-library/components/Icon/AddIcon"; import Page from "zy-react-library/components/Page"; import Table from "zy-react-library/components/Table"; import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender"; import useTable from "zy-react-library/hooks/useTable"; import { getLabelName } from "zy-react-library/utils"; import { NS_APP_MENU } from "~/enumerate/namespace"; const MENU_TYPE_ENUM = [ { bianma: 1, name: "菜单" }, { bianma: 2, name: "按钮" }, ]; const MENU_ATTRIBUTION_ENUM = [ { bianma: "gwjapp", name: "港务局app" }, ]; function Menu(props) { const [currentId, setCurrentId] = useState(""); const [currentSort, setCurrentSort] = useState(0); const [addModalVisible, setAddModalVisible] = useState(false); const [parentId, setParentId] = useState(0); const [parentName, setParentName] = useState(""); const [urlState, setUrlState] = useUrlState({ menuAttribution: MENU_ATTRIBUTION_ENUM[0].bianma, }, { navigateMode: "replace", }); const { tableProps, getData } = useTable(props["appMenuListTree"], { params: { eqMenuAttribution: urlState.menuAttribution }, usePagination: false, }); const onDelete = (id) => { Modal.confirm({ title: "删除", content: "确定要删除吗?", okText: "确定", cancelText: "取消", onOk: async () => { const { success } = await props["appMenuDelete"]({ id }); if (success) { message.success("删除成功"); getData(); } }, }); }; return ( ( )} headerTitle={( ({ key: item.bianma, label: item.name }))} onChange={(event) => { setUrlState({ menuAttribution: event }); getData(); }} /> )} columns={[ { title: "名称", dataIndex: "menuName" }, { title: "路径", dataIndex: "menuUrl" }, { title: "标识", dataIndex: "menuPerms" }, { title: "类型", dataIndex: "menuType", render: (_, record) => ( {getLabelName({ list: MENU_TYPE_ENUM, status: record.menuType })} ), }, { title: "操作", width: 200, fixed: "right", render: (_, record) => ( ), }, ]} {...tableProps} /> { addModalVisible && ( { setAddModalVisible(false); setCurrentId(""); setParentId(0); setParentName(""); setCurrentSort(0); }} getData={getData} id={currentId} parentId={parentId} parentName={parentName} sort={currentSort} menuAttribution={urlState.menuAttribution} /> ) } ); } const AddModalComponent = (props) => { const [form] = Form.useForm(); const getData = async () => { const { data } = await props["appMenuInfo"]({ id: props.id }); form.setFieldsValue(data); }; useEffect(() => { if (props.id) { getData(); } }, [props.id]); const onSubmit = async (values) => { const { success } = await props[props.id ? "appMenuUpdate" : "appMenuAdd"]({ ...values, id: props.id, parentId: props.parentId, menuAttribution: props.menuAttribution, }); if (success) { message.success("保存成功"); props.onCancel(); props.getData(); } }; return ( {props.parentName || "无(此项为顶级)"}), }, { name: "menuName", label: "名称" }, { name: "menuUrl", label: "路径" }, { name: "menuPerms", label: "标识" }, { name: "menuType", label: "类型", render: FORM_ITEM_RENDER_ENUM.RADIO, items: MENU_TYPE_ENUM }, { name: "sort", label: "排序", render: FORM_ITEM_RENDER_ENUM.NUMBER, rules: [{ pattern: /^\d*$/, message: "请输入整数" }], }, ]} /> ); }; const AddModal = Connect([NS_APP_MENU], true)(AddModalComponent); export default Connect([NS_APP_MENU], true)(Menu);