| | |
| | | ProTable, |
| | | LightFilter, |
| | | } from '@ant-design/pro-components'; |
| | | import { FormattedMessage, useIntl } from '@umijs/max'; |
| | | import { PlusOutlined, ExportOutlined } from '@ant-design/icons'; |
| | | import Http from '@/utils/http'; |
| | | import Edit from './components/edit' |
| | |
| | | import { transformTreeData } from '@/utils/tree-util' |
| | | import { createIcon } from '@/utils/icon-util' |
| | | import { statusMap } from '@/utils/enum-util' |
| | | import { repairBug } from '@/utils/common-util'; |
| | | |
| | | const TABLE_KEY = "pro-table-menu"; |
| | | |
| | | const typeMap = { |
| | | 0: { |
| | | color: 'blue', |
| | | color: 'success', |
| | | text: '菜单', |
| | | }, |
| | | 1: { |
| | | color: '', |
| | | color: 'default', |
| | | text: '按钮', |
| | | }, |
| | | }; |
| | | |
| | | const handleSave = async (val) => { |
| | | const hide = message.loading('正在添加'); |
| | | const handleSave = async (val, intl) => { |
| | | const hide = message.loading(intl.formatMessage({ id: 'page.adding', defaultMessage: '正在添加' })); |
| | | try { |
| | | const resp = await Http.doPost('api/menu/save', val); |
| | | if (resp.code === 200) { |
| | | message.success('添加成功'); |
| | | message.success(intl.formatMessage({ id: 'page.add.success', defaultMessage: '添加成功' })); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('添加失败请重试!'); |
| | | message.error(intl.formatMessage({ id: 'page.add.fail', defaultMessage: '添加失败请重试!' })); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const handleUpdate = async (val) => { |
| | | const hide = message.loading('正在更新'); |
| | | const handleUpdate = async (val, intl) => { |
| | | const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '正在更新' })); |
| | | try { |
| | | const resp = await Http.doPost('api/menu/update', val); |
| | | if (resp.code === 200) { |
| | | message.success('更新成功'); |
| | | message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '更新成功' })); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('配置失败请重试!'); |
| | | message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '更新失败请重试!' })); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const handleRemove = async (rows) => { |
| | | const handleRemove = async (rows, intl) => { |
| | | if (!rows) return true; |
| | | const hide = message.loading('正在删除'); |
| | | const hide = message.loading(intl.formatMessage({ id: 'page.deleting', defaultMessage: '正在删除' })); |
| | | try { |
| | | const resp = await Http.doPost('api/menu/remove/' + rows.map((row) => row.id).join(',')); |
| | | if (resp.code === 200) { |
| | | message.success('删除成功'); |
| | | message.success(intl.formatMessage({ id: 'page.delete.success', defaultMessage: '删除成功' })); |
| | | return true; |
| | | } else { |
| | | message.error(resp.msg); |
| | | return false; |
| | | } |
| | | } catch (error) { |
| | | message.error('删除失败,请重试'); |
| | | message.error(intl.formatMessage({ id: 'page.delete.fail', defaultMessage: '删除失败,请重试!' })); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | | } |
| | | }; |
| | | |
| | | const handleExport = async () => { |
| | | const hide = message.loading('正在导出'); |
| | | const handleExport = async (intl) => { |
| | | const hide = message.loading(intl.formatMessage({ id: 'page.exporting', defaultMessage: '正在导出' })); |
| | | try { |
| | | const resp = await Http.doPostBlob('api/menu/export'); |
| | | const blob = new Blob([resp], { type: 'application/vnd.ms-excel' }); |
| | | window.location.href = window.URL.createObjectURL(blob); |
| | | message.success('导出成功'); |
| | | message.success(intl.formatMessage({ id: 'page.export.success', defaultMessage: '导出成功' })); |
| | | return true; |
| | | } catch (error) { |
| | | message.error('导出失败,请重试'); |
| | | message.error(intl.formatMessage({ id: 'page.export.fail', defaultMessage: '导出失败,请重试' })); |
| | | return false; |
| | | } finally { |
| | | hide(); |
| | |
| | | |
| | | |
| | | const Main = () => { |
| | | const intl = useIntl(); |
| | | const formTableRef = useRef(); |
| | | const actionRef = useRef(); |
| | | const [selectedRows, setSelectedRows] = useState([]); |
| | |
| | | />, |
| | | }, |
| | | { |
| | | title: '上级菜单名', |
| | | dataIndex: 'parentName', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='parentName' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径', |
| | | dataIndex: 'path', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='path' |
| | | {...props} |
| | | actionRef={actionRef} |
| | | setSearchParam={setSearchParam} |
| | | />, |
| | | }, |
| | | { |
| | | title: '关联路径名', |
| | | dataIndex: 'pathName', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='pathName' |
| | |
| | | title: '页面组件', |
| | | dataIndex: 'component', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='component' |
| | |
| | | title: '简述', |
| | | dataIndex: 'brief', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='brief' |
| | |
| | | title: '标识', |
| | | dataIndex: 'code', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='code' |
| | |
| | | title: '元信息', |
| | | dataIndex: 'meta', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='meta' |
| | |
| | | title: '添加时间', |
| | | dataIndex: 'createTime$', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <DatetimeRangeFilter |
| | | name='createTime' |
| | |
| | | title: '添加人员', |
| | | dataIndex: 'createBy$', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <LinkFilter |
| | | name='createBy' |
| | |
| | | title: '备注', |
| | | dataIndex: 'memo', |
| | | valueType: 'text', |
| | | hidden: true, |
| | | hidden: false, |
| | | width: 140, |
| | | filterDropdown: (props) => <TextFilter |
| | | name='memo' |
| | |
| | | setCurrentRow(record); |
| | | }} |
| | | > |
| | | 编辑 |
| | | <FormattedMessage id='page.edit' defaultMessage='编辑' /> |
| | | </Button>, |
| | | <Button |
| | | type="link" |
| | |
| | | key="batchRemove" |
| | | onClick={async () => { |
| | | Modal.confirm({ |
| | | title: '删除', |
| | | content: '确定删除该项吗?', |
| | | title: intl.formatMessage({ id: 'page.delete', defaultMessage: '删除' }), |
| | | content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '确定删除该项吗?' }), |
| | | onOk: async () => { |
| | | const success = await handleRemove([record]); |
| | | const success = await handleRemove([record], intl); |
| | | if (success) { |
| | | if (actionRef.current) { |
| | | actionRef.current.reload(); |
| | |
| | | }); |
| | | }} |
| | | > |
| | | 删除 |
| | | <FormattedMessage id='page.delete' defaultMessage='删除' /> |
| | | </Button>, |
| | | ], |
| | | }, |
| | |
| | | }} |
| | | > |
| | | <PlusOutlined /> |
| | | 添加 |
| | | <FormattedMessage id='page.add' defaultMessage='添加' /> |
| | | </Button>, |
| | | <Button |
| | | key="export" |
| | | onClick={async () => { |
| | | handleExport(); |
| | | handleExport(intl); |
| | | }} |
| | | > |
| | | <ExportOutlined /> |
| | | 导出 |
| | | <FormattedMessage id='page.export' defaultMessage='导出' /> |
| | | </Button>, |
| | | ], |
| | | }} |
| | |
| | | } |
| | | }} |
| | | columnsState={{ |
| | | persistenceKey: 'pro-table-menu', |
| | | persistenceKey: TABLE_KEY, |
| | | persistenceType: 'localStorage', |
| | | defaultValue: { |
| | | pathName: { show: repairBug(TABLE_KEY, 'pathName', false) }, |
| | | component: { show: repairBug(TABLE_KEY, 'component', false) }, |
| | | brief: { show: repairBug(TABLE_KEY, 'brief', false) }, |
| | | code: { show: repairBug(TABLE_KEY, 'code', false) }, |
| | | meta: { show: repairBug(TABLE_KEY, 'meta', false) }, |
| | | createTime$: { show: repairBug(TABLE_KEY, 'createTime$', false) }, |
| | | createBy$: { show: repairBug(TABLE_KEY, 'createBy$', false) }, |
| | | memo: { show: repairBug(TABLE_KEY, 'memo', false) }, |
| | | option: { fixed: 'right', disable: true }, |
| | | }, |
| | | onChange(value) { |
| | |
| | | <FooterToolbar |
| | | extra={ |
| | | <div> |
| | | 已选择 |
| | | <a style={{ fontWeight: 600 }}>{selectedRows.length}</a> |
| | | 项 |
| | | <FormattedMessage id='page.selected' defaultMessage=' 项已选择' /> |
| | | </div> |
| | | } |
| | | > |
| | |
| | | danger |
| | | onClick={async () => { |
| | | Modal.confirm({ |
| | | title: '删除', |
| | | content: '确定删除该项吗?', |
| | | title: intl.formatMessage({ id: 'page.delete', defaultMessage: '删除' }), |
| | | content: intl.formatMessage({ id: 'page.delete.confirm', defaultMessage: '确定删除该项吗?' }), |
| | | onOk: async () => { |
| | | const success = await handleRemove(selectedRows); |
| | | const success = await handleRemove(selectedRows, intl); |
| | | if (success) { |
| | | setSelectedRows([]); |
| | | actionRef.current?.reloadAndRest?.(); |
| | |
| | | }); |
| | | }} |
| | | > |
| | | 批量删除 |
| | | <FormattedMessage id='page.delete.batch' defaultMessage='批量删除' /> |
| | | </Button> |
| | | </FooterToolbar> |
| | | )} |
| | |
| | | onSubmit={async (values) => { |
| | | let ok = false; |
| | | if (values.id) { |
| | | ok = await handleUpdate({ ...values }) |
| | | ok = await handleUpdate({ ...values }, intl) |
| | | } else { |
| | | ok = await handleSave({ ...values }) |
| | | ok = await handleSave({ ...values }, intl) |
| | | } |
| | | if (ok) { |
| | | setModalVisible(false); |