| | |
| | | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { Button, message, Modal } from 'antd'; |
| | | import { Button, message, Modal, Tag } from 'antd'; |
| | | import { |
| | | FooterToolbar, |
| | | PageContainer, |
| | |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' |
| | | import { transformTreeData } from '@/utils/tree-util' |
| | | import { statusMap } from '@/utils/enum-util' |
| | | import { repairBug } from '@/utils/common-util'; |
| | | |
| | | const TABLE_KEY = "pro-table-dept"; |
| | | |
| | | const handleSave = async (val) => { |
| | | const hide = message.loading('正在添加'); |
| | |
| | | const [currentRow, setCurrentRow] = useState(); |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | |
| | | const [treeData, setTreeData] = useState([]); |
| | | |
| | | useEffect(() => { |
| | | |
| | | }, []); |
| | | |
| | | const columns = [ |
| | | { |
| | | title: 'No', |
| | | dataIndex: 'index', |
| | | valueType: 'indexBorder', |
| | | width: 48, |
| | | }, |
| | | { |
| | | title: '名称', |
| | | title: '部门名称', |
| | | dataIndex: 'name', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='name' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | width: 240, |
| | | // filterDropdown: (props) => <TextFilter |
| | | // name='name' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | }, |
| | | { |
| | | title: '上级部门', |
| | | dataIndex: 'parentId', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='parentId' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '上级部门名', |
| | | dataIndex: 'parentName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | hidden: true, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='parentName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径', |
| | | dataIndex: 'path', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='path' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径名', |
| | | dataIndex: 'pathName', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='pathName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='leader' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | // filterDropdown: (props) => <TextFilter |
| | | // name='leader' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | }, |
| | | { |
| | | title: '数量', |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='sort' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | // filterDropdown: (props) => <TextFilter |
| | | // name='sort' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | render: (_, record) => { |
| | | return <span style={{ fontWeight: "bold" }}>{_}</span> |
| | | } |
| | | }, |
| | | { |
| | | title: '状态', |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='status' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | data={[ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | />, |
| | | }, |
| | | { |
| | | title: '添加时间', |
| | | dataIndex: 'createTime$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='createTime' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '添加人员', |
| | | dataIndex: 'createBy$', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='createBy' |
| | | major='user' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | // filterDropdown: (props) => <SelectFilter |
| | | // name='status' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // data={[ |
| | | // { label: '正常', value: 1 }, |
| | | // { label: '禁用', value: 0 }, |
| | | // ]} |
| | | // />, |
| | | render: (_, record) => { |
| | | const status = statusMap[record.status] |
| | | return <Tag color={status.color}>{status.text}</Tag> |
| | | }, |
| | | }, |
| | | { |
| | | title: '修改时间', |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='updateTime' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | // filterDropdown: (props) => <DatetimeRangeFilter |
| | | // name='updateTime' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | }, |
| | | { |
| | | title: '修改人员', |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='updateBy' |
| | | major='user' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | // filterDropdown: (props) => <LinkFilter |
| | | // name='updateBy' |
| | | // major='user' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | }, |
| | | { |
| | | title: '备注', |
| | |
| | | ]; |
| | | |
| | | return ( |
| | | <PageContainer> |
| | | <PageContainer |
| | | header={{ |
| | | breadcrumb: {}, |
| | | }} |
| | | > |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <ProTable |
| | | key="dept" |
| | |
| | | cardBordered |
| | | scroll={{ x: 1300 }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | pagination={{ pageSize: 100 }} |
| | | search={false} |
| | | toolbar={{ |
| | | search: { |
| | |
| | | ], |
| | | }} |
| | | request={(params, sorter, filter) => |
| | | Http.doPostPromise('/api/dept/page', { ...params, ...searchParam }, (res) => { |
| | | Http.doPostPromise('/api/dept/tree', { ...params, ...searchParam }, (res) => { |
| | | const rootMenu = { id: 0, name: '根目录', value: 0, children: [] }; |
| | | rootMenu.children = res.data; |
| | | const treeData = transformTreeData([rootMenu]); |
| | | setTreeData(treeData); |
| | | |
| | | return { |
| | | data: res.data.records, |
| | | total: res.data.total, |
| | | data: res.data, |
| | | success: true, |
| | | } |
| | | }) |
| | |
| | | } |
| | | }} |
| | | columnsState={{ |
| | | persistenceKey: 'pro-table-dept', |
| | | persistenceKey: TABLE_KEY, |
| | | persistenceType: 'localStorage', |
| | | defaultValue: { |
| | | fullName: { show: repairBug(TABLE_KEY, 'fullName', false) }, |
| | | brief: { show: repairBug(TABLE_KEY, 'brief', false) }, |
| | | code: { show: repairBug(TABLE_KEY, 'code', false) }, |
| | | type: { show: repairBug(TABLE_KEY, 'type', false) }, |
| | | count: { show: repairBug(TABLE_KEY, 'count', false) }, |
| | | memo: { show: repairBug(TABLE_KEY, 'memo', false) }, |
| | | option: { fixed: 'right', disable: true }, |
| | | }, |
| | | onChange(value) { |
| | |
| | | <Edit |
| | | open={modalVisible} |
| | | values={currentRow || {}} |
| | | treeData={treeData} |
| | | onCancel={ |
| | | () => { |
| | | setModalVisible(false); |