index.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. // 菜单管理
  2. import { PageContainer } from '@ant-design/pro-layout';
  3. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  4. import ProTable from '@jetlinks/pro-table';
  5. import { useRef, useState } from 'react';
  6. import { useIntl } from '@@/plugin-locale/localeExports';
  7. import { Button, message, Tooltip } from 'antd';
  8. import {
  9. DeleteOutlined,
  10. PlusCircleOutlined,
  11. PlusOutlined,
  12. SearchOutlined,
  13. } from '@ant-design/icons';
  14. import { observer } from '@formily/react';
  15. import { model } from '@formily/reactive';
  16. import { useHistory } from 'umi';
  17. import SearchComponent from '@/components/SearchComponent';
  18. import Service from './service';
  19. import type { MenuItem } from './typing';
  20. import moment from 'moment';
  21. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  22. import { PermissionButton } from '@/components';
  23. export const service = new Service('menu');
  24. type ModelType = {
  25. visible: boolean;
  26. current: Partial<MenuItem>;
  27. parentId: string | undefined;
  28. };
  29. export const State = model<ModelType>({
  30. visible: false,
  31. current: {},
  32. parentId: undefined,
  33. });
  34. export default observer(() => {
  35. const actionRef = useRef<ActionType>();
  36. const intl = useIntl();
  37. const [param, setParam] = useState({});
  38. const history = useHistory();
  39. const { permission } = PermissionButton.usePermission('system/Menu');
  40. const deleteItem = async (id: string) => {
  41. const response: any = await service.remove(id);
  42. if (response.status === 200) {
  43. message.success(
  44. intl.formatMessage({
  45. id: 'pages.data.option.success',
  46. defaultMessage: '操作成功!',
  47. }),
  48. );
  49. }
  50. actionRef.current?.reload();
  51. };
  52. /**
  53. * 跳转详情页
  54. * @param id
  55. * @param pId
  56. * @param basePath
  57. */
  58. const pageJump = (id?: string, pId?: string, basePath?: string) => {
  59. // 跳转详情
  60. history.push(
  61. `${getMenuPathByParams(MENUS_CODE['system/Menu/Detail'], id)}?pId=${pId || ''}&basePath=${
  62. basePath || ''
  63. }`,
  64. );
  65. };
  66. const columns: ProColumns<MenuItem>[] = [
  67. {
  68. title: intl.formatMessage({
  69. id: 'page.system.menu.encoding',
  70. defaultMessage: '编码',
  71. }),
  72. width: 300,
  73. dataIndex: 'code',
  74. },
  75. {
  76. title: intl.formatMessage({
  77. id: 'page.system.menu.name',
  78. defaultMessage: '名称',
  79. }),
  80. width: 220,
  81. dataIndex: 'name',
  82. },
  83. {
  84. title: intl.formatMessage({
  85. id: 'page.system.menu.url',
  86. defaultMessage: '页面地址',
  87. }),
  88. dataIndex: 'url',
  89. },
  90. {
  91. title: intl.formatMessage({
  92. id: 'page.system.menu.sort',
  93. defaultMessage: '排序',
  94. }),
  95. width: 80,
  96. dataIndex: 'sortIndex',
  97. valueType: 'digit',
  98. },
  99. {
  100. title: intl.formatMessage({
  101. id: 'page.system.menu.describe',
  102. defaultMessage: '说明',
  103. }),
  104. width: 200,
  105. dataIndex: 'describe',
  106. hideInSearch: true,
  107. },
  108. {
  109. title: intl.formatMessage({
  110. id: 'pages.table.createTime',
  111. defaultMessage: '创建时间',
  112. }),
  113. width: 180,
  114. valueType: 'dateTime',
  115. dataIndex: 'createTime',
  116. render: (_, record) => {
  117. return record.createTime ? moment(record.createTime).format('YYYY-MM-DD HH:mm:ss') : '-';
  118. },
  119. },
  120. {
  121. title: intl.formatMessage({
  122. id: 'pages.data.option',
  123. defaultMessage: '操作',
  124. }),
  125. valueType: 'option',
  126. width: 240,
  127. render: (_, record) => [
  128. <Button
  129. type="link"
  130. key="view"
  131. style={{ padding: 0 }}
  132. onClick={() => {
  133. pageJump(record.id, record.parentId || '');
  134. }}
  135. >
  136. <Tooltip
  137. title={intl.formatMessage({
  138. id: 'pages.data.option.view',
  139. defaultMessage: '查看',
  140. })}
  141. >
  142. <SearchOutlined />
  143. </Tooltip>
  144. </Button>,
  145. <PermissionButton
  146. type="link"
  147. style={{ padding: 0 }}
  148. key="editable"
  149. isPermission={permission.add}
  150. tooltip={{
  151. title: intl.formatMessage({
  152. id: 'page.system.menu.table.addChildren',
  153. defaultMessage: '新增子菜单',
  154. }),
  155. }}
  156. onClick={() => {
  157. State.current = {
  158. parentId: record.id,
  159. };
  160. // State.visible = true;
  161. pageJump('', record.id, record.url);
  162. }}
  163. >
  164. <PlusCircleOutlined />
  165. </PermissionButton>,
  166. <PermissionButton
  167. key="delete"
  168. type="link"
  169. style={{ padding: 0 }}
  170. isPermission={permission.delete}
  171. popConfirm={{
  172. title: intl.formatMessage({
  173. id: 'page.system.menu.table.delete',
  174. defaultMessage: '是否删除该菜单',
  175. }),
  176. onConfirm() {
  177. deleteItem(record.id);
  178. },
  179. }}
  180. tooltip={{
  181. title: intl.formatMessage({
  182. id: 'pages.data.option.delete',
  183. defaultMessage: '删除',
  184. }),
  185. }}
  186. >
  187. <DeleteOutlined />
  188. </PermissionButton>,
  189. ],
  190. },
  191. ];
  192. /**
  193. * table 查询参数
  194. * @param data
  195. */
  196. const searchFn = (data: any) => {
  197. setParam(data);
  198. };
  199. // const modalCancel = () => {
  200. // State.current = {};
  201. // State.visible = false;
  202. // form.resetFields();
  203. // };
  204. // const saveData = async () => {
  205. // const formData = await form.validateFields();
  206. // if (formData) {
  207. // const _data = {
  208. // ...formData,
  209. // parentId: State.current.parentId,
  210. // };
  211. // const response: any = await service.save(_data);
  212. // if (response.status === 200) {
  213. // message.success('操作成功!');
  214. // modalCancel();
  215. // pageJump(response.result.id);
  216. // } else {
  217. // message.error('操作成功!');
  218. // }
  219. // }
  220. // };
  221. return (
  222. <PageContainer>
  223. <SearchComponent
  224. field={columns}
  225. target="menu"
  226. onSearch={searchFn}
  227. // onReset={() => {
  228. // // 重置分页及搜索参数
  229. // actionRef.current?.reset?.();
  230. // searchFn({});
  231. // }}
  232. />
  233. <ProTable<MenuItem>
  234. columns={columns}
  235. actionRef={actionRef}
  236. rowKey="id"
  237. pagination={false}
  238. search={false}
  239. params={param}
  240. request={async (params) => {
  241. const response = await service.queryMenuThree({ ...params, paging: false });
  242. return {
  243. code: response.message,
  244. result: {
  245. data: response.result,
  246. pageIndex: 0,
  247. pageSize: 0,
  248. total: 0,
  249. },
  250. status: response.status,
  251. };
  252. }}
  253. headerTitle={
  254. <PermissionButton
  255. isPermission={permission.add}
  256. onClick={() => {
  257. pageJump();
  258. }}
  259. key="button"
  260. icon={<PlusOutlined />}
  261. type="primary"
  262. >
  263. {intl.formatMessage({
  264. id: 'pages.data.option.add',
  265. defaultMessage: '新增',
  266. })}
  267. </PermissionButton>
  268. }
  269. />
  270. {/*<Modal*/}
  271. {/* title={intl.formatMessage({*/}
  272. {/* id: State.current.parentId*/}
  273. {/* ? 'pages.system.menu.option.addChildren'*/}
  274. {/* : 'pages.data.option.add',*/}
  275. {/* defaultMessage: '新增',*/}
  276. {/* })}*/}
  277. {/* visible={State.visible}*/}
  278. {/* width={660}*/}
  279. {/* onOk={saveData}*/}
  280. {/* onCancel={modalCancel}*/}
  281. {/*>*/}
  282. {/* <Form form={form} labelCol={{ span: 4 }} wrapperCol={{ span: 20 }}>*/}
  283. {/* <Form.Item*/}
  284. {/* name="code"*/}
  285. {/* label={intl.formatMessage({*/}
  286. {/* id: 'page.system.menu.encoding',*/}
  287. {/* defaultMessage: '编码',*/}
  288. {/* })}*/}
  289. {/* required={true}*/}
  290. {/* rules={[*/}
  291. {/* { required: true, message: '请输入编码' },*/}
  292. {/* { max: 64, message: '最多可输入64个字符' },*/}
  293. {/* {*/}
  294. {/* pattern: /^[a-zA-Z0-9`!@#$%^&*()_+\-={}|\\\]\[;':",.\/<>?]+$/,*/}
  295. {/* message: '请输入英文+数字+特殊字符(`!@#$%^&*()_+-={}|\\][;\':",./<>?)',*/}
  296. {/* },*/}
  297. {/* ]}*/}
  298. {/* >*/}
  299. {/* <Input />*/}
  300. {/* </Form.Item>*/}
  301. {/* <Form.Item*/}
  302. {/* name="name"*/}
  303. {/* label={intl.formatMessage({*/}
  304. {/* id: 'pages.table.name',*/}
  305. {/* defaultMessage: '名称',*/}
  306. {/* })}*/}
  307. {/* required={true}*/}
  308. {/* rules={[*/}
  309. {/* { required: true, message: '请输入名称' },*/}
  310. {/* { max: 64, message: '最多可输入64个字符' },*/}
  311. {/* ]}*/}
  312. {/* >*/}
  313. {/* <Input />*/}
  314. {/* </Form.Item>*/}
  315. {/* </Form>*/}
  316. {/*</Modal>*/}
  317. </PageContainer>
  318. );
  319. });