| | |
| | | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { Button, message, Modal, Row, Col, Card, Tree, Input } from 'antd'; |
| | | import { Button, message, Modal, Row, Col, Card, Tree, Input, Tag } from 'antd'; |
| | | import { |
| | | FooterToolbar, |
| | | PageContainer, |
| | |
| | | import { PlusOutlined, ExportOutlined, DownOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | import Pwd from './components/pwd' |
| | | import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' |
| | | import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util' |
| | | import { statusMap } from '@/utils/enum-util' |
| | | |
| | | const handleSave = async (val) => { |
| | | const hide = message.loading('正在添加'); |
| | |
| | | } |
| | | }; |
| | | |
| | | const handlePwd = async (val) => { |
| | | const hide = message.loading('正在重置'); |
| | | try { |
| | | const resp = await Http.doPost('api/user/reset/pwd', val); |
| | | if (resp.code === 200) { |
| | | message.success('重置成功'); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('重置失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | |
| | | const Main = () => { |
| | | const formTableRef = useRef(); |
| | |
| | | const [boxHeight, setBoxHeight] = useState(); |
| | | const [deptTreeData, setDeptTreeData] = useState([]); |
| | | const [deptExpandedKeys, setDeptExpandedKeys] = useState([]); |
| | | const [pwdModalVisible, setPwdModalVisible] = useState(false); |
| | | |
| | | useEffect(() => { |
| | | const handleResize = () => setBoxHeight(window.innerHeight - 368); |
| | |
| | | width: 30, |
| | | }, |
| | | { |
| | | title: '昵称', |
| | | title: '名称', |
| | | dataIndex: 'nickname', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 100, |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='nickname' |
| | | {...props} |
| | |
| | | />, |
| | | }, |
| | | { |
| | | title: '账号', |
| | | title: '登录账号', |
| | | dataIndex: 'username', |
| | | valueType: 'text', |
| | | hidden: false, |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 100, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='deptId' |
| | | major='dept' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | render: (_, record) => { |
| | | if (_ && _ !== '-') { |
| | | return <Tag color={""}>{_}</Tag> |
| | | } else { |
| | | return '-' |
| | | } |
| | | }, |
| | | // filterDropdown: (props) => <LinkFilter |
| | | // name='deptId' |
| | | // major='dept' |
| | | // {...props} |
| | | // actionRef={actionRef} |
| | | // setSearchParam={setSearchParam} |
| | | // />, |
| | | }, |
| | | { |
| | | title: '真实姓名', |
| | |
| | | valueType: 'text', |
| | | hidden: false, |
| | | width: 80, |
| | | render: (_, record) => { |
| | | const status = statusMap[record.status] |
| | | return <Tag color={status.color}>{status.text}</Tag> |
| | | }, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='status' |
| | | {...props} |
| | |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'option', |
| | | width: 100, |
| | | width: 150, |
| | | valueType: 'option', |
| | | render: (_, record) => [ |
| | | <Button |
| | |
| | | }} |
| | | > |
| | | 编辑 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | | key="pwd" |
| | | onClick={() => { |
| | | setPwdModalVisible(true); |
| | | setCurrentRow(record); |
| | | }} |
| | | > |
| | | 重置密码 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | |
| | | blockNode |
| | | defaultExpandAll // 异步加载失效 |
| | | expandedKeys={deptExpandedKeys} |
| | | onExpand={setDeptExpandedKeys} |
| | | treeData={deptTreeData} |
| | | switcherIcon={<DownOutlined />} |
| | | onSelect={(selectedKeys, info) => { |
| | |
| | | formRef={formTableRef} |
| | | columns={columns} |
| | | cardBordered |
| | | scroll={{y: boxHeight }} |
| | | scroll={{ y: boxHeight }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | search={false} |
| | |
| | | ], |
| | | }} |
| | | request={(params, sorter, filter) => |
| | | Http.doPostPromise('/api/user/page', { ...params, ...searchParam }, (res) => { |
| | | Http.doPostPromise('/api/user/page1', { ...params, ...searchParam }, (res) => { |
| | | return { |
| | | data: res.data.records, |
| | | total: res.data.total, |
| | |
| | | <Edit |
| | | open={modalVisible} |
| | | values={currentRow || {}} |
| | | treeData={deptTreeData} |
| | | onCancel={ |
| | | () => { |
| | | setModalVisible(false); |
| | |
| | | } |
| | | } |
| | | /> |
| | | |
| | | <Pwd |
| | | open={pwdModalVisible} |
| | | values={currentRow || {}} |
| | | onCancel={ |
| | | () => { |
| | | setPwdModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | } |
| | | } |
| | | onSubmit={async (values) => { |
| | | let ok = false; |
| | | if (values.id) { |
| | | ok = await handlePwd({ ...values }) |
| | | } |
| | | if (ok) { |
| | | setPwdModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /> |
| | | </Row> |
| | | </PageContainer> |
| | | ); |