index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-09-18 11:40:14
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. import { PlusOutlined } from '@ant-design/icons';
  10. import { Button, Popconfirm } from 'antd';
  11. import React, { useState, useRef } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import { ModalForm, ProFormText, ProFormSelect, ProFormDigit } from '@ant-design/pro-form';
  15. import UpdateForm from './updateForm';
  16. import { addList, editList, delList } from './service';
  17. import { getMenuList } from '@/pages/platformMana/menuManage/service';
  18. const UserMana = () => {
  19. const columns = [
  20. {
  21. title: '菜单名称',
  22. dataIndex: 'name',
  23. key: 'name',
  24. // ellipsis: true,
  25. },
  26. {
  27. title: '菜单Id',
  28. dataIndex: 'menuId',
  29. key: 'menuId',
  30. hideInSearch: true,
  31. ellipsis: true,
  32. },
  33. {
  34. title: 'URL',
  35. dataIndex: 'url',
  36. key: 'url',
  37. ellipsis: true,
  38. hideInSearch: true,
  39. },
  40. {
  41. title: 'Path',
  42. dataIndex: 'path',
  43. key: 'path',
  44. ellipsis: true,
  45. hideInSearch: true,
  46. },
  47. {
  48. title: '变更人',
  49. dataIndex: 'modifyUserName',
  50. key: 'modifyUserName',
  51. hideInSearch: true,
  52. ellipsis: true,
  53. },
  54. {
  55. title: '变更日期',
  56. dataIndex: 'modifyTime',
  57. key: 'modifyTime',
  58. valueType: 'date',
  59. ellipsis: true,
  60. hideInSearch: true,
  61. },
  62. {
  63. title: '操作',
  64. dataIndex: 'option',
  65. valueType: 'option',
  66. render: (_, record) => {
  67. const { type } = record;
  68. const btnGroups = [
  69. <a
  70. key="config"
  71. onClick={() => {
  72. handleUpdateModalVisible(true);
  73. setCurrentRow(record);
  74. }}
  75. >
  76. 编辑
  77. </a>,
  78. <Popconfirm
  79. key="subscribeAlert"
  80. title="是否确定删除?"
  81. onConfirm={() => {
  82. delUserHandler(record);
  83. }}
  84. >
  85. <a>删除</a>
  86. </Popconfirm>,
  87. ];
  88. return type != 0
  89. ? [...btnGroups]
  90. : [
  91. <a
  92. key="config"
  93. onClick={() => {
  94. setIfAddZeroLevelMenu(false);
  95. handleModalVisible(true);
  96. setCurrentRow(record);
  97. }}
  98. >
  99. 添加
  100. </a>,
  101. ...btnGroups,
  102. ];
  103. },
  104. },
  105. ];
  106. const [createModalVisible, handleModalVisible] = useState(false);
  107. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  108. const actionRef = useRef();
  109. const [currentRow, setCurrentRow] = useState(undefined);
  110. const [ifAddZeroLevelMenu, setIfAddZeroLevelMenu] = useState(true);
  111. // const [shareParamsSetting,setShareParamsSetting] = useState(false); //是否分摊参数设置
  112. /**
  113. *
  114. * @param {Boolean} bool 弹窗展示状态
  115. */
  116. const updateModalVisibleChange = (bool) => {
  117. handleUpdateModalVisible(bool);
  118. if (!bool) setCurrentRow(undefined);
  119. };
  120. //获取Drawer菜单列表
  121. const getMenus = async (params = {}, sort, filter) => {
  122. const res = await getMenuList(params);
  123. return {
  124. data: res.data.list,
  125. total: res.data.totalCount,
  126. success: res.success,
  127. };
  128. };
  129. /**
  130. *
  131. * @param {Object} value 删除项数据
  132. */
  133. const delUserHandler = async (value) => {
  134. const ids = [value.menuId];
  135. const resp = await delList({ ids });
  136. if (resp.status == 200) {
  137. if (actionRef.current) {
  138. actionRef.current.reload();
  139. }
  140. }
  141. };
  142. return (
  143. <PageContainer>
  144. <ProTable
  145. columns={columns}
  146. request={getMenus}
  147. actionRef={actionRef}
  148. rowKey="menuId"
  149. toolBarRender={() => [
  150. <Button
  151. key="button"
  152. icon={<PlusOutlined />}
  153. type="primary"
  154. onClick={() => {
  155. setIfAddZeroLevelMenu(true);
  156. handleModalVisible(true);
  157. }}
  158. >
  159. 新增
  160. </Button>,
  161. ]}
  162. pagination={{
  163. pageSize: 10,
  164. }}
  165. search={false}
  166. />
  167. <ModalForm
  168. title="新增菜单"
  169. width="800px"
  170. labelCol={{ span: 5, offset: 3 }}
  171. layout={'horizontal'}
  172. modalProps={{
  173. destroyOnClose: true,
  174. }}
  175. visible={createModalVisible}
  176. onVisibleChange={handleModalVisible}
  177. onFinish={async (value) => {
  178. let id = 0;
  179. currentRow && (id = currentRow.menuId);
  180. // console.log({id});
  181. const resp = await addList({ ...value, parentId: id });
  182. const { status } = resp;
  183. if (status == 200) {
  184. if (actionRef.current) {
  185. actionRef.current.reload();
  186. }
  187. return true;
  188. }
  189. setCurrentRow(undefined);
  190. }}
  191. >
  192. <ProFormText
  193. label="菜单名称"
  194. rules={[
  195. {
  196. required: true,
  197. message: '角色名是必填项!',
  198. },
  199. ]}
  200. width="sm"
  201. name="name"
  202. placeholder="请输入菜单"
  203. />
  204. <ProFormText
  205. label="Path"
  206. rules={[
  207. {
  208. required: true,
  209. message: '菜单路径是必填项!',
  210. },
  211. ]}
  212. width="sm"
  213. name="path"
  214. />
  215. {/* <ProFormText
  216. label="权限字段"
  217. rules={[
  218. {
  219. required: true,
  220. message: '权限字段是必填项!',
  221. },
  222. ]}
  223. width="sm"
  224. name="perms"
  225. placeholder="请输入"
  226. /> */}
  227. <ProFormSelect
  228. name="type"
  229. label="类型"
  230. width="sm"
  231. options={[
  232. { label: '目录', value: 0 },
  233. { label: '菜单', value: 1 },
  234. { label: '按钮', value: 2 },
  235. ]}
  236. fieldProps={{
  237. optionItemRender(item) {
  238. return item.label + ' - ' + item.value;
  239. },
  240. }}
  241. placeholder="请选择类型"
  242. rules={[{ required: true, message: '请选择类型!' }]}
  243. />
  244. <ProFormText
  245. label="菜单Icon"
  246. rules={[
  247. {
  248. required: false,
  249. },
  250. ]}
  251. width="sm"
  252. name="icon"
  253. />
  254. <ProFormDigit
  255. label="菜单排序"
  256. rules={[
  257. {
  258. required: false,
  259. },
  260. ]}
  261. width="sm"
  262. name="orderNum"
  263. placeholder="请选择菜单序号"
  264. />
  265. </ModalForm>
  266. {/* 更新 */}
  267. <UpdateForm
  268. onSubmit={async (value) => {
  269. const { menuId, parentId = 0 } = currentRow;
  270. // console.log({currentRow});
  271. // console.log({'编辑':value});
  272. const { name, path, url, perms, type, icon = 'ww', orderNum } = value;
  273. const resp = await editList({
  274. parentId,
  275. name,
  276. path,
  277. url,
  278. perms,
  279. type,
  280. icon,
  281. orderNum,
  282. id: menuId,
  283. });
  284. const { status } = resp;
  285. if (status == 200) {
  286. handleUpdateModalVisible(false);
  287. setCurrentRow(undefined);
  288. if (actionRef.current) {
  289. actionRef.current.reload();
  290. }
  291. }
  292. }}
  293. onCancel={() => {
  294. handleUpdateModalVisible(false);
  295. setCurrentRow(undefined);
  296. }}
  297. updateModalVisible={updateModalVisible}
  298. updateModalVisibleChange={updateModalVisibleChange}
  299. values={currentRow || {}}
  300. />
  301. </PageContainer>
  302. );
  303. };
  304. export default UserMana;