| | |
| | | import { PlusOutlined, ExportOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | | 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('正在添加'); |
| | |
| | | } |
| | | }; |
| | | |
| | | 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 [modalVisible, setModalVisible] = useState(false); |
| | | const [currentRow, setCurrentRow] = useState(); |
| | | const [searchParam, setSearchParam] = useState({}); |
| | | |
| | | const [scopeModalVisible, setScopeModalVisible] = useState(false); |
| | | const [menuIds, setMenuIds] = useState([]); |
| | | |
| | | useEffect(() => { |
| | | |
| | |
| | | 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: '标识', |
| | |
| | | title: '修改时间', |
| | | dataIndex: 'updateTime$', |
| | | valueType: 'text', |
| | | width: 300, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='updateTime' |
| | | {...props} |
| | |
| | | title: '状态', |
| | | dataIndex: 'status$', |
| | | valueType: 'text', |
| | | width: 160, |
| | | filterDropdown: (props) => <SelectFilter |
| | | name='status' |
| | | {...props} |
| | |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | valueType: 'text', |
| | | hidden: false, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='memo' |
| | | {...props} |
| | |
| | | { |
| | | title: '操作', |
| | | dataIndex: 'option', |
| | | width: 140, |
| | | 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" |
| | |
| | | formRef={formTableRef} |
| | | columns={columns} |
| | | cardBordered |
| | | scroll={{ x: 1300 }} |
| | | dateFormatter="string" |
| | | pagination={{ pageSize: 20 }} |
| | | search={false} |
| | |
| | | } |
| | | }} |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | /> |
| | | |
| | | <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> |
| | | ); |
| | | }; |