123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- /*
- * @Author: your name
- * @Date: 2021-07-26 10:13:13
- * @LastEditTime: 2021-09-18 11:40:14
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
- */
- import { PlusOutlined } from '@ant-design/icons';
- import { Button, Popconfirm } from 'antd';
- import React, { useState, useRef } from 'react';
- import { PageContainer } from '@ant-design/pro-layout';
- import ProTable from '@ant-design/pro-table';
- import { ModalForm, ProFormText, ProFormSelect, ProFormDigit } from '@ant-design/pro-form';
- import UpdateForm from './updateForm';
- import { addList, editList, delList } from './service';
- import { getMenuList } from '@/pages/platformMana/menuManage/service';
- const UserMana = () => {
- const columns = [
- {
- title: '菜单名称',
- dataIndex: 'name',
- key: 'name',
- // ellipsis: true,
- },
- {
- title: '菜单Id',
- dataIndex: 'menuId',
- key: 'menuId',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: 'URL',
- dataIndex: 'url',
- key: 'url',
- ellipsis: true,
- hideInSearch: true,
- },
- {
- title: 'Path',
- dataIndex: 'path',
- key: 'path',
- ellipsis: true,
- hideInSearch: true,
- },
- {
- title: '变更人',
- dataIndex: 'modifyUserName',
- key: 'modifyUserName',
- hideInSearch: true,
- ellipsis: true,
- },
- {
- title: '变更日期',
- dataIndex: 'modifyTime',
- key: 'modifyTime',
- valueType: 'date',
- ellipsis: true,
- hideInSearch: true,
- },
- {
- title: '操作',
- dataIndex: 'option',
- valueType: 'option',
- render: (_, record) => {
- const { type } = record;
- const btnGroups = [
- <a
- key="config"
- onClick={() => {
- handleUpdateModalVisible(true);
- setCurrentRow(record);
- }}
- >
- 编辑
- </a>,
- <Popconfirm
- key="subscribeAlert"
- title="是否确定删除?"
- onConfirm={() => {
- delUserHandler(record);
- }}
- >
- <a>删除</a>
- </Popconfirm>,
- ];
- return type != 0
- ? [...btnGroups]
- : [
- <a
- key="config"
- onClick={() => {
- setIfAddZeroLevelMenu(false);
- handleModalVisible(true);
- setCurrentRow(record);
- }}
- >
- 添加
- </a>,
- ...btnGroups,
- ];
- },
- },
- ];
- const [createModalVisible, handleModalVisible] = useState(false);
- const [updateModalVisible, handleUpdateModalVisible] = useState(false);
- const actionRef = useRef();
- const [currentRow, setCurrentRow] = useState(undefined);
- const [ifAddZeroLevelMenu, setIfAddZeroLevelMenu] = useState(true);
- // const [shareParamsSetting,setShareParamsSetting] = useState(false); //是否分摊参数设置
- /**
- *
- * @param {Boolean} bool 弹窗展示状态
- */
- const updateModalVisibleChange = (bool) => {
- handleUpdateModalVisible(bool);
- if (!bool) setCurrentRow(undefined);
- };
- //获取Drawer菜单列表
- const getMenus = async (params = {}, sort, filter) => {
- const res = await getMenuList(params);
- return {
- data: res.data.list,
- total: res.data.totalCount,
- success: res.success,
- };
- };
- /**
- *
- * @param {Object} value 删除项数据
- */
- const delUserHandler = async (value) => {
- const ids = [value.menuId];
- const resp = await delList({ ids });
- if (resp.status == 200) {
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- };
- return (
- <PageContainer>
- <ProTable
- columns={columns}
- request={getMenus}
- actionRef={actionRef}
- rowKey="menuId"
- toolBarRender={() => [
- <Button
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- onClick={() => {
- setIfAddZeroLevelMenu(true);
- handleModalVisible(true);
- }}
- >
- 新增
- </Button>,
- ]}
- pagination={{
- pageSize: 10,
- }}
- search={false}
- />
- <ModalForm
- title="新增菜单"
- width="800px"
- labelCol={{ span: 5, offset: 3 }}
- layout={'horizontal'}
- modalProps={{
- destroyOnClose: true,
- }}
- visible={createModalVisible}
- onVisibleChange={handleModalVisible}
- onFinish={async (value) => {
- let id = 0;
- currentRow && (id = currentRow.menuId);
- // console.log({id});
- const resp = await addList({ ...value, parentId: id });
- const { status } = resp;
- if (status == 200) {
- if (actionRef.current) {
- actionRef.current.reload();
- }
- return true;
- }
- setCurrentRow(undefined);
- }}
- >
- <ProFormText
- label="菜单名称"
- rules={[
- {
- required: true,
- message: '角色名是必填项!',
- },
- ]}
- width="sm"
- name="name"
- placeholder="请输入菜单"
- />
- <ProFormText
- label="Path"
- rules={[
- {
- required: true,
- message: '菜单路径是必填项!',
- },
- ]}
- width="sm"
- name="path"
- />
- {/* <ProFormText
- label="权限字段"
- rules={[
- {
- required: true,
- message: '权限字段是必填项!',
- },
- ]}
- width="sm"
- name="perms"
- placeholder="请输入"
- /> */}
- <ProFormSelect
- name="type"
- label="类型"
- width="sm"
- options={[
- { label: '目录', value: 0 },
- { label: '菜单', value: 1 },
- { label: '按钮', value: 2 },
- ]}
- fieldProps={{
- optionItemRender(item) {
- return item.label + ' - ' + item.value;
- },
- }}
- placeholder="请选择类型"
- rules={[{ required: true, message: '请选择类型!' }]}
- />
- <ProFormText
- label="菜单Icon"
- rules={[
- {
- required: false,
- },
- ]}
- width="sm"
- name="icon"
- />
- <ProFormDigit
- label="菜单排序"
- rules={[
- {
- required: false,
- },
- ]}
- width="sm"
- name="orderNum"
- placeholder="请选择菜单序号"
- />
- </ModalForm>
- {/* 更新 */}
- <UpdateForm
- onSubmit={async (value) => {
- const { menuId, parentId = 0 } = currentRow;
- // console.log({currentRow});
- // console.log({'编辑':value});
- const { name, path, url, perms, type, icon = 'ww', orderNum } = value;
- const resp = await editList({
- parentId,
- name,
- path,
- url,
- perms,
- type,
- icon,
- orderNum,
- id: menuId,
- });
- const { status } = resp;
- if (status == 200) {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- if (actionRef.current) {
- actionRef.current.reload();
- }
- }
- }}
- onCancel={() => {
- handleUpdateModalVisible(false);
- setCurrentRow(undefined);
- }}
- updateModalVisible={updateModalVisible}
- updateModalVisibleChange={updateModalVisibleChange}
- values={currentRow || {}}
- />
- </PageContainer>
- );
- };
- export default UserMana;
|