index.tsx 8.5 KB

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