| | |
| | | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { useIntl, FormattedMessage } from '@umijs/max'; |
| | | import { Button, message, Modal } from 'antd'; |
| | | import { Button, message, Modal, Tag } from 'antd'; |
| | | import { |
| | | FooterToolbar, |
| | | PageContainer, |
| | |
| | | import { PlusOutlined, ExportOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | import { TextFilter, SelectFilter } from '@/components/TableSearch' |
| | | import Scope from './components/scope' |
| | | import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch' |
| | | import { statusMap } from '@/utils/enum-util' |
| | | import { repairBug } from '@/utils/common-util'; |
| | | |
| | | const TABLE_KEY = "pro-table-role"; |
| | | |
| | | const handleSave = async (val) => { |
| | | const hide = message.loading('正在添加'); |
| | | try { |
| | | const resp = await Http.doPost('api/role/save', val); |
| | | hide(); |
| | | if (resp.code === 200) { |
| | | message.success('添加成功'); |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | hide(); |
| | | message.error('添加失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | |
| | | const hide = message.loading('正在更新'); |
| | | try { |
| | | const resp = await Http.doPost('api/role/update', val); |
| | | hide(); |
| | | if (resp.code === 200) { |
| | | message.success('更新成功'); |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | hide(); |
| | | message.error('配置失败请重试!'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | |
| | | const hide = message.loading('正在删除'); |
| | | try { |
| | | const resp = await Http.doPost('api/role/remove/' + rows.map((row) => row.id).join(',')); |
| | | hide(); |
| | | if (resp.code === 200) { |
| | | message.success('删除成功'); |
| | | return true; |
| | |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | hide(); |
| | | message.error('删除失败,请重试'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const handleExport = async () => { |
| | | const hide = message.loading('正在导出'); |
| | | try { |
| | | await Http.doPost('api/role/export'); |
| | | hide(); |
| | | const resp = await Http.doPostBlob('api/role/export'); |
| | | const blob = new Blob([resp], { type: 'application/vnd.ms-excel' }); |
| | | window.location.href = window.URL.createObjectURL(blob); |
| | | message.success('导出成功'); |
| | | return true; |
| | | } catch (error) { |
| | | hide(); |
| | | message.error('导出失败,请重试'); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const handleScope = async (val) => { |
| | | const hide = message.loading('正在分配'); |
| | | try { |
| | | const resp = await Http.doPost('api/role/scope/update', 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 [currentRow, setCurrentRow] = useState(); |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | |
| | | const intl = useIntl(); |
| | | const [scopeModalVisible, setScopeModalVisible] = useState(false); |
| | | const [menuIds, setMenuIds] = useState([]); |
| | | |
| | | useEffect(() => { |
| | | |
| | |
| | | title: 'No', |
| | | dataIndex: 'index', |
| | | valueType: 'indexBorder', |
| | | width: 48, |
| | | width: 60, |
| | | }, |
| | | { |
| | | title: '姓名', |
| | | dataIndex: 'name', |
| | | valueType: 'text', |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='name' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | render: (_, record) => { |
| | | return ( |
| | | <a |
| | | onClick={() => { |
| | | Http.doGetPromise('/api/role/scope/list', { roleId: record.id }, (res) => { |
| | | if (res.data) { |
| | | setMenuIds(res.data); |
| | | } |
| | | setScopeModalVisible(true); |
| | | setCurrentRow(record); |
| | | }); |
| | | }} |
| | | > |
| | | {_} |
| | | </a> |
| | | ); |
| | | }, |
| | | }, |
| | | { |
| | | title: '标识', |
| | | dataIndex: 'code', |
| | | valueType: 'text', |
| | | copyable: true, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='code' |
| | | {...props} |
| | |
| | | />, |
| | | }, |
| | | { |
| | | title: '公司', |
| | | dataIndex: 'hostId$', |
| | | title: '修改时间', |
| | | dataIndex: 'updateTime$', |
| | | valueType: 'text', |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='updateTime' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '状态', |
| | |
| | | { label: '禁用', value: 0 }, |
| | | ]} |
| | | />, |
| | | render: (_, record) => { |
| | | const status = statusMap[record.status] |
| | | return <Tag color={status.color}>{status.text}</Tag> |
| | | }, |
| | | }, |
| | | { |
| | | title: '修改时间', |
| | | dataIndex: 'updateTime$', |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | valueType: 'text', |
| | | filterDropdown: (props) => <TextFilter |
| | | name='memo' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'option', |
| | | width: '220px', |
| | | width: 260, |
| | | valueType: 'option', |
| | | render: (_, record) => [ |
| | | <Button |
| | |
| | | }} |
| | | > |
| | | 编辑 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | | key="scope" |
| | | onClick={() => { |
| | | Http.doGetPromise('/api/role/scope/list', { roleId: record.id }, (res) => { |
| | | if (res.data) { |
| | | setMenuIds(res.data); |
| | | } |
| | | setScopeModalVisible(true); |
| | | setCurrentRow(record); |
| | | }); |
| | | }} |
| | | > |
| | | 分配权限 |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | |
| | | ]; |
| | | |
| | | return ( |
| | | <PageContainer> |
| | | <PageContainer |
| | | header={{ |
| | | breadcrumb: {}, |
| | | }} |
| | | > |
| | | <div style={{ width: '100%', float: 'right' }}> |
| | | <ProTable |
| | | key="role" |
| | |
| | | formRef={formTableRef} |
| | | columns={columns} |
| | | cardBordered |
| | | scroll={{ x: 1300 }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | search={false} |
| | | toolbar={{ |
| | | multipleLine: true, |
| | | search: { |
| | | onSearch: (value) => { |
| | | setSearchParam(prevState => ({ |
| | |
| | | } |
| | | }} |
| | | columnsState={{ |
| | | persistenceKey: 'pro-table-role', |
| | | persistenceKey: TABLE_KEY, |
| | | persistenceType: 'localStorage', |
| | | defaultValue: { |
| | | memo: { show: repairBug(TABLE_KEY, 'memo', false) }, |
| | | option: { fixed: 'right', disable: true }, |
| | | }, |
| | | onChange(value) { |
| | |
| | | <FooterToolbar |
| | | extra={ |
| | | <div> |
| | | <FormattedMessage id="pages.searchTable.chosen" defaultMessage="已选择" /> |
| | | 已选择 |
| | | <a style={{ fontWeight: 600 }}>{selectedRows.length}</a> |
| | | <FormattedMessage id="pages.searchTable.item" defaultMessage="项" /> |
| | | 项 |
| | | </div> |
| | | } |
| | | > |
| | |
| | | } |
| | | } |
| | | /> |
| | | |
| | | <Scope |
| | | open={scopeModalVisible} |
| | | values={currentRow || {}} |
| | | originMenuIds={menuIds} |
| | | onCancel={ |
| | | () => { |
| | | setScopeModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | setMenuIds([]); |
| | | } |
| | | } |
| | | onSubmit={async (values) => { |
| | | let ok = false; |
| | | if (values.id) { |
| | | ok = await handleScope({ ...values }) |
| | | } |
| | | if (ok) { |
| | | setScopeModalVisible(false); |
| | | setCurrentRow(undefined); |
| | | setMenuIds([]); |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | | } |
| | | } |
| | | }} |
| | | /> |
| | | </PageContainer> |
| | | ); |
| | | }; |