index.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-13 15:22:48
  4. * @LastEditTime: 2022-07-28 14:49:55
  5. * @LastEditors: code4eat awesomedema@gmail.com
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/hospManage/index.tsx
  8. */
  9. import { FC } from 'react';
  10. import { menuManageModelState, ConnectProps, Loading, connect } from 'umi';
  11. import { Button, Divider, Popconfirm } from 'antd';
  12. import KCTable from '@/components/kcTable';
  13. import type { ProColumns } from '@ant-design/pro-table';
  14. import { getAllMenus } from '@/service/menu';
  15. import { TableRequestParamsType } from '@/typings';
  16. import ActModal from './modals/modal';
  17. import './style.less';
  18. import { DownOutlined, FileOutlined, RightOutlined } from '@ant-design/icons';
  19. import type { MenuItemDataType } from '@/service/menu';
  20. import { MenuTypes } from '@/constant';
  21. export enum TableActType {
  22. NOACT,
  23. ADD,
  24. DEL,
  25. EDIT,
  26. SET,
  27. MOVEANDCOPY,//复制移动
  28. }
  29. interface PageProps extends ConnectProps {
  30. menuManageModel: menuManageModelState;
  31. loading: boolean;
  32. }
  33. const MenuManage: FC<PageProps> = ({ menuManageModel: state, dispatch }) => {
  34. const { reloadTable } = state;
  35. const columns: ProColumns<MenuItemDataType>[] = [
  36. {
  37. title: 'ID',
  38. dataIndex: 'menuId',
  39. hideInTable: true,
  40. },
  41. {
  42. title: 'parentId',
  43. dataIndex: 'parentId',
  44. hideInTable: true,
  45. },
  46. {
  47. title: '菜单名称',
  48. dataIndex: 'name',
  49. hideInSearch: false,
  50. render: (text, record) => {
  51. if (record.children && record.children.length > 0) {
  52. return text;
  53. } else {
  54. //叶子节点
  55. return record.parentId != '0' ? (
  56. //非第一级
  57. <div>
  58. <FileOutlined style={{ marginRight: 10 }} />
  59. {text}
  60. </div>
  61. ) : (
  62. text
  63. );
  64. }
  65. },
  66. },
  67. {
  68. title: '类型',
  69. dataIndex: 'isHospital',
  70. render: (number, record) => {
  71. const findType = MenuTypes.filter((t) => t.value == record.type);
  72. return findType[0].label;
  73. },
  74. },
  75. // {
  76. // title: 'URL',
  77. // dataIndex: 'url',
  78. // },
  79. {
  80. title: 'Path',
  81. dataIndex: 'path',
  82. },
  83. // {
  84. // title: '变更人',
  85. // dataIndex: 'mainHospName',
  86. // },
  87. // {
  88. // title: '变更日期',
  89. // dataIndex: 'modifyTime',
  90. // },
  91. {
  92. title: '操作',
  93. width: 400,
  94. key: 'option',
  95. valueType: 'option',
  96. render: (text, record) => {
  97. return record.type == 1?[
  98. <a key="link" onClick={() => setHomePage(record)}>
  99. 设为首页
  100. </a>,
  101. <Divider key="1" type="vertical" style={{ margin: '0 1px'}} />,
  102. <a key="link0" onClick={() => editHandle(record)}>
  103. 编辑
  104. </a>,
  105. <Divider key="11" type="vertical" style={{ margin: '0 1px'}} />,
  106. <Popconfirm
  107. title="是否确定删除?"
  108. onConfirm={() => delHandle(record)}
  109. // onCancel={cancel}
  110. okText="确定"
  111. cancelText="取消"
  112. key="link2"
  113. >
  114. <a>删除</a>
  115. </Popconfirm>,
  116. <Divider key="2" type="vertical" style={{ margin: '0 1px',display:record.type != 1?'inline':'none' }} />,
  117. <a key="link3" onClick={() => addHandle(record.menuId, record)} style={{display:record.type != 1?'inline':'none'}}>
  118. 添加
  119. </a>,
  120. <Divider key="100" type="vertical" style={{ margin: '0 1px' }} />,
  121. <a key="link4" onClick={() => moveAndCopy(record)}>
  122. 复制/移动
  123. </a>,
  124. ]:[
  125. <a key="link12" onClick={() => editHandle(record)}>
  126. 编辑
  127. </a>,
  128. <Divider key="10" type="vertical" style={{ margin: '0 1px' }} />,
  129. <Popconfirm
  130. title="是否确定删除?"
  131. onConfirm={() => delHandle(record)}
  132. // onCancel={cancel}
  133. okText="确定"
  134. cancelText="取消"
  135. key="link23"
  136. >
  137. <a>删除</a>
  138. </Popconfirm>,
  139. <Divider key="2" type="vertical" style={{ margin: '0 1px' }} />,
  140. <a key="link5" onClick={() => addHandle(record.menuId, record)}>
  141. 添加
  142. </a>,
  143. ]
  144. }
  145. },
  146. ];
  147. const setHomePage = (record:MenuItemDataType)=>{
  148. dispatch &&
  149. dispatch({
  150. type: 'menuManageModel/edit',
  151. payload: {
  152. data: record,
  153. act: TableActType.SET,
  154. isShowModal: true,
  155. },
  156. });
  157. }
  158. const getData = async (params: { name?: string } & TableRequestParamsType) => {
  159. const { current = 1, pageSize = 1000, name } = params;
  160. const resp = await getAllMenus();
  161. //获取万最新数据取消重置reload
  162. dispatch &&
  163. dispatch({
  164. type: 'menuManageModel/reloadTable',
  165. payload: false,
  166. });
  167. if (name) {
  168. //搜索菜单
  169. let deeper = (data: MenuItemDataType[], keyword: string) => {
  170. let newarr:MenuItemDataType[] = [];
  171. data.forEach(element => {
  172. if (element.name.indexOf(keyword) > -1) { // 判断条件
  173. newarr.push(element);
  174. } else {
  175. if (element.children && element.children.length > 0) {
  176. let redata = deeper(element.children,keyword);
  177. if (redata && redata.length > 0) {
  178. let obj = {
  179. ...element,
  180. children: redata
  181. };
  182. newarr.push(obj);
  183. }
  184. }
  185. }
  186. });
  187. return newarr;
  188. };
  189. return {
  190. data: resp.list ? deeper(resp.list, name) : [],
  191. success: true,
  192. total: (deeper(resp.list, name)).length,
  193. };
  194. }
  195. return {
  196. data: resp.list ? resp.list : [],
  197. success: true,
  198. total: resp.totalCount,
  199. };
  200. };
  201. const moveAndCopy = (record:MenuItemDataType)=>{
  202. dispatch &&
  203. dispatch({
  204. type: 'menuManageModel/edit',
  205. payload: {
  206. act: TableActType.MOVEANDCOPY,
  207. isShowModal: true,
  208. data: record ? record : null,
  209. },
  210. });
  211. }
  212. const addHandle = (parentId?: string, record?: MenuItemDataType) => {
  213. dispatch &&
  214. dispatch({
  215. type: 'menuManageModel/add',
  216. payload: {
  217. tableAct: TableActType.ADD,
  218. isShowModal: true,
  219. parentId: parentId ? parentId : 0, //考虑新增子集菜单的情况
  220. record: record ? record : null,
  221. },
  222. });
  223. };
  224. const editHandle = (record: MenuItemDataType) => {
  225. dispatch &&
  226. dispatch({
  227. type: 'menuManageModel/edit',
  228. payload: {
  229. data: record,
  230. act: TableActType.EDIT,
  231. isShowModal: true,
  232. },
  233. });
  234. };
  235. const delHandle = (record: MenuItemDataType) => {
  236. dispatch &&
  237. dispatch({
  238. type: 'menuManageModel/delRequest',
  239. payload: [record.menuId],
  240. });
  241. };
  242. // console.log({state});
  243. return (
  244. <div className="MenuManage">
  245. <ActModal {...state} dispatch={dispatch} />
  246. <KCTable
  247. rowKey="menuId"
  248. headerTitle="查询表格"
  249. columns={columns}
  250. reload={reloadTable}
  251. toolBarRender={() => [
  252. <Button key="3" type="primary" onClick={() => addHandle()}>
  253. 新增中心
  254. </Button>,
  255. ]}
  256. request={(params) => getData(params)}
  257. expandable={{
  258. expandIcon: ({ expanded, onExpand, record }) => {
  259. // console.log({expanded, onExpand, record});
  260. return expanded
  261. ? record.children.length > 0 && (
  262. <DownOutlined onClick={(e) => onExpand(record, e)} style={{ marginRight: 10 }} />
  263. )
  264. : record.children.length > 0 && (
  265. <RightOutlined onClick={(e) => onExpand(record, e)} style={{ marginRight: 10 }} />
  266. );
  267. },
  268. }}
  269. />
  270. </div>
  271. );
  272. };
  273. export default connect(
  274. ({ menuManageModel, loading }: { menuManageModel: menuManageModelState; loading: Loading }) => {
  275. // console.log({userManageModel});
  276. return {
  277. menuManageModel,
  278. loading: loading.models.menuManageModel,
  279. };
  280. },
  281. )(MenuManage);