index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2022-07-12 11:14:21
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2025-03-07 16:00:03
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/indicatorMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import { ActionType, ProColumns } from '@ant-design/pro-table';
  10. import React, { useEffect, useRef, useState } from 'react';
  11. import { Button, Divider, Dropdown, Popconfirm } from 'antd';
  12. import { DownOutlined } from '@ant-design/icons';
  13. import { addIndicatorManaList, delIndicatorManaList, editIndicatorManaList, getIndicatorCateList_old, getIndicatorManaList_old, IndicatorManaItemType } from '@/service/indicator';
  14. import TreeDirectory from './TreeDirectory';
  15. import './style.less';
  16. import { getIndicatorDictionary, IndicatorDictionaryDataType } from '@/service/dictionary';
  17. import { useLocation } from 'umi';
  18. import { KCIMLeftList } from '../../components/KCIMLeftList';
  19. import KCTable from '@/components/kcTable';
  20. import { KCInput } from '@/components/KCInput';
  21. import DrawerForm from './ DrawerForm/drawer';
  22. const IndicatorMana = () => {
  23. const [reloadTable, set_reloadTable] = useState(false);
  24. const [drawerVisible, set_drawerVisible] = useState(false);
  25. const [indicateType, set_indicateType] = useState<IndicatorDictionaryDataType[]>([]);
  26. const [currentEditRowData, set_currentEditRowData] = useState<any | undefined>(undefined);
  27. const [indicatorCateTreeData, set_indicatorCateTreeData] = useState<any[]>([]);
  28. const [defaultExpandedRowKeys, set_defaultExpandedRowKeys] = useState<string[]>([]);
  29. const [tableData, set_tableData] = useState<any[]>([]);
  30. const [cateId, set_cateId] = useState<string>();
  31. const [tableDataFilterParams, set_tableDataFilterParams] = useState<{
  32. current: number;
  33. pageSize: number;
  34. name?: string;
  35. indicatorType?: string;
  36. outsideIndexes?: string[];
  37. }>({
  38. current: 1,
  39. pageSize: 10
  40. });
  41. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  42. const [currentSelectedLeft, set_currentSelectedLeft] = useState<any>(undefined);
  43. const [drawerActype, set_drawerActype] = useState<'ADD' | 'EDIT'>('ADD');
  44. const indicatorTableRef = useRef<ActionType>();
  45. const columns: ProColumns<any>[] = [
  46. {
  47. title: '指标名称',
  48. dataIndex: 'name',
  49. hideInSearch: false,
  50. ellipsis: true,
  51. },
  52. // {
  53. // title: '指标编码',
  54. // dataIndex: 'code',
  55. // ellipsis: true,
  56. // render: (text, record) => {
  57. // if (record) {
  58. // const { indicatorBoolean, code } = record;
  59. // return indicatorBoolean ? code : ''
  60. // } else {
  61. // return ''
  62. // }
  63. // }
  64. // },
  65. {
  66. title: '指标类别',
  67. dataIndex: 'indicatorType',
  68. hideInSearch: true,
  69. ellipsis: true,
  70. hideInTable: true,
  71. valueType: 'select',
  72. request: async () => {
  73. const resp = await getIndicatorDictionary();
  74. if (resp) {
  75. const data = resp.filter((t) => t.code == 'IndicatorType');
  76. if (data.length > 0) {
  77. return data[0].children.map((t) => ({ label: t.name, value: t.code }));
  78. }
  79. }
  80. return [];
  81. },
  82. render: (text, record) => {
  83. if (record) {
  84. const { indicatorBoolean, indicatorTypeList } = record;
  85. return indicatorBoolean && indicatorTypeList ? indicatorTypeList.map((t: any) => t.name).join('/') : '';
  86. } else {
  87. return '';
  88. }
  89. },
  90. },
  91. {
  92. title: '外部指标',
  93. dataIndex: 'outsideIndexes',
  94. hideInSearch: true,
  95. ellipsis: true,
  96. hideInTable: true,
  97. valueType: 'cascader',
  98. fieldProps: {
  99. fieldNames: { label: 'name', value: 'code' },
  100. placeholder: '请选择',
  101. },
  102. request: async () => {
  103. const resp = await getIndicatorDictionary();
  104. if (resp) {
  105. const data = resp.filter((t) => t.code == 'IndicatorExternal');
  106. if (data.length > 0) {
  107. return data[0].children;
  108. }
  109. }
  110. return [];
  111. },
  112. render: (text, record) => {
  113. if (record) {
  114. const { indicatorBoolean, indicatorExternalList } = record;
  115. return indicatorBoolean ? (indicatorExternalList ? indicatorExternalList.map((t: any) => t.name).join('/') : '-') : '';
  116. } else {
  117. return '';
  118. }
  119. },
  120. },
  121. {
  122. title: '指标编码',
  123. dataIndex: 'code',
  124. width: 80,
  125. hideInSearch: true,
  126. ellipsis: true,
  127. },
  128. {
  129. title: '指标定义',
  130. dataIndex: 'targetDefinition',
  131. hideInSearch: true,
  132. ellipsis: true,
  133. },
  134. {
  135. title: '操作',
  136. width: 90,
  137. key: 'option',
  138. valueType: 'option',
  139. render: (text, record) => {
  140. const items = [
  141. {
  142. key: '1',
  143. label: (
  144. <a key="linka" href={record.indicatorPath} target="_blank">
  145. 数据展示
  146. </a>
  147. ),
  148. },
  149. {
  150. key: '3',
  151. label: (
  152. <Popconfirm title="是否确定删除?" onConfirm={() => delHandle(record)} okText="确定" cancelText="取消" key="link2">
  153. <a>删除</a>
  154. </Popconfirm>
  155. ),
  156. },
  157. ];
  158. if (record && record.indicatorBoolean) {
  159. return [
  160. <a key="link3" onClick={() => actionHandle('EDIT', record)}>
  161. 管理
  162. </a>,
  163. <Dropdown menu={{ items }}>
  164. <a>
  165. <DownOutlined />
  166. </a>
  167. </Dropdown>,
  168. ];
  169. }
  170. return [];
  171. },
  172. },
  173. ];
  174. const getIndicatorDir = async () => {
  175. const resp = await getIndicatorDictionary();
  176. if (resp) {
  177. set_indicateType(resp);
  178. }
  179. };
  180. const getData = async (params: any) => {
  181. const { current = 1, pageSize = 10, name, indicatorType, outsideIndexes } = params;
  182. if (cateId) {
  183. const resp = await getIndicatorManaList_old({
  184. current,
  185. pageSize,
  186. menuCode: cateId as string,
  187. indicatorName: name,
  188. indicatorType: indicatorType,
  189. outsideIndexes: outsideIndexes && outsideIndexes.length > 0 ? outsideIndexes[outsideIndexes.length - 1] : '',
  190. });
  191. if (resp && resp[0] && resp[0].children) {
  192. const getName: any = (obj: any) => {
  193. let isArr = Array.isArray(obj);
  194. let reslut = [];
  195. if (isArr) {
  196. obj.forEach((item: any) => {
  197. reslut.push(...getName(item));
  198. });
  199. } else {
  200. reslut.push(obj.menuId);
  201. if (obj.children) {
  202. reslut.push(...getName(obj.children));
  203. }
  204. }
  205. return reslut;
  206. };
  207. set_tableData(resp[0].children as unknown as []);
  208. set_defaultExpandedRowKeys(getName(resp[0].children));
  209. return {
  210. data: resp[0].children as unknown as [],
  211. success: true,
  212. total: 1,
  213. };
  214. } else {
  215. return {
  216. data: [],
  217. success: true,
  218. total: 0,
  219. };
  220. }
  221. }
  222. return {
  223. data: [],
  224. success: false,
  225. total: 0,
  226. };
  227. };
  228. const getIndicatorCateTree = async () => {
  229. // console.log(location.search);
  230. let menuId = '';
  231. if (location.search.length > 0) {
  232. const searchArr = location.search.split('=');
  233. // console.log({ searchArr });
  234. if (searchArr[1]) {
  235. const resp = await getIndicatorCateList_old({ menuCode: searchArr[1] });
  236. if (resp) {
  237. set_indicatorCateTreeData(resp);
  238. }
  239. }
  240. }
  241. };
  242. const actionHandle = async (key: 'EDIT' | 'DEL', record: IndicatorDictionaryDataType) => {
  243. set_currentEditRowData(record);
  244. if (key == 'EDIT') {
  245. set_drawerActype('EDIT');
  246. set_drawerVisible(true);
  247. }
  248. };
  249. const addHandle = () => {
  250. set_drawerActype('ADD');
  251. set_currentEditRowData(undefined);
  252. set_drawerVisible(true);
  253. };
  254. const delHandle = async (record: IndicatorDictionaryDataType) => {
  255. const resp = await delIndicatorManaList({ id: record.id });
  256. if (resp) {
  257. indicatorTableRef.current?.reload();
  258. }
  259. };
  260. const onVisibleChangeHandle = (bool: boolean) => {
  261. if (!bool) {
  262. set_drawerVisible(false);
  263. }
  264. if (bool) {
  265. set_drawerVisible(true);
  266. }
  267. };
  268. const drawerFormCommitHanndle = async (data: any) => {
  269. // const formData = Object.assign({}, data[0].baseInfoformRef, data[1].manaInfoformRef, data[2].showSetInfoformRef, data[3].adminInfoformRef);
  270. //const _formData = {...data[0].baseInfoformRef,...data[1].manaInfoformRef,...data[2].showSetInfoformRef,...data[3].adminInfoformRef}
  271. let formData: any;
  272. data.forEach((element: any) => {
  273. if (element.baseInfoformRef) {
  274. formData = { ...formData, ...element.baseInfoformRef };
  275. }
  276. if (element.manaInfoformRef) {
  277. formData = { ...formData, ...element.manaInfoformRef };
  278. }
  279. if (element.showSetInfoformRef) {
  280. formData = { ...formData, ...element.showSetInfoformRef };
  281. }
  282. if (element.adminInfoformRef) {
  283. formData = { ...formData, ...element.adminInfoformRef };
  284. }
  285. });
  286. if (drawerActype == 'ADD') {
  287. const resp = await addIndicatorManaList({
  288. ...formData,
  289. caseBreakdown: formData.caseBreakdown ? formData.caseBreakdown.join('/') : '',
  290. dataDownload: formData.dataDownload ? formData.dataDownload.join('/') : '',
  291. drillLevel: formData.drillLevel ? formData.drillLevel.join('/') : '',
  292. dataSum: formData.dataSum ? formData.dataSum.join('/') : '',
  293. chartType: formData.chartType ? formData.chartType.join('/') : '',
  294. indicatorMenuList: formData.indicatorMenuList ? formData.indicatorMenuList : [],
  295. indicatorTypeList: formData.indicatorTypeList ? formData.indicatorTypeList : [],
  296. indicatorExternalList: formData.indicatorExternalList ? formData.indicatorExternalList : [],
  297. divisionId: `${formData.divisionId}`,
  298. });
  299. if (resp) {
  300. set_drawerVisible(false);
  301. indicatorTableRef.current?.reload();
  302. }
  303. }
  304. if (drawerActype == 'EDIT') {
  305. const resp = await editIndicatorManaList({
  306. ...currentEditRowData,
  307. ...formData,
  308. caseBreakdown: formData.caseBreakdown ? formData.caseBreakdown.join('/') : '',
  309. dataDownload: formData.dataDownload ? formData.dataDownload.join('/') : '',
  310. drillLevel: formData.drillLevel ? formData.drillLevel.join('/') : '',
  311. dataSum: formData.dataSum ? formData.dataSum.join('/') : '',
  312. chartType: formData.chartType ? formData.chartType.join('/') : '',
  313. });
  314. if (resp) {
  315. set_drawerVisible(false);
  316. indicatorTableRef.current?.reload();
  317. }
  318. }
  319. };
  320. const onSelectChangehandle = (currentSelected: any) => {
  321. set_currentSelectedLeft(currentSelected);
  322. currentSelected && set_cateId(currentSelected.code);
  323. };
  324. const handleTableChange = (pagination: any) => {
  325. set_tableDataFilterParams({
  326. ...tableDataFilterParams,
  327. current: pagination.current,
  328. pageSize: pagination.pageSize
  329. });
  330. }
  331. const tableDataSearchHandle = (paramName: string) => {
  332. set_tableDataFilterParams({
  333. ...tableDataFilterParams,
  334. current: 1,
  335. [`${paramName}`]: tableDataSearchKeywords
  336. });
  337. }
  338. useEffect(() => {
  339. if (tableData) {
  340. const keys = tableData.map((t: any) => (t ? t.code : ''));
  341. }
  342. }, [tableData]);
  343. useEffect(() => {
  344. console.log({ cateId });
  345. indicatorTableRef.current?.reload();
  346. }, [cateId]);
  347. useEffect(() => {
  348. getIndicatorCateTree();
  349. }, [location.search]);
  350. useEffect(() => {
  351. getIndicatorDir();
  352. getIndicatorCateTree();
  353. }, []);
  354. return (
  355. <div className="IndicatorMana">
  356. <DrawerForm actType={drawerActype} visible={drawerVisible} onVisibleChange={onVisibleChangeHandle} onFinish={(data) => drawerFormCommitHanndle(data)} record={currentEditRowData} />
  357. <div className="content">
  358. <div className="left">
  359. {/* <TreeDirectory data={indicatorCateTreeData} onSelectChange={(info) => onSelectChangehandle(info)} /> */}
  360. <KCIMLeftList
  361. searchKey={'name'}
  362. listType="tree"
  363. dataSource={indicatorCateTreeData}
  364. fieldNames={{ title: 'name', key: 'code' }}
  365. contentH={'100%'}
  366. onChange={(info) => onSelectChangehandle(info)}
  367. />
  368. </div>
  369. <div className="right">
  370. <div className="tableTitle">{currentSelectedLeft && currentSelectedLeft.name}</div>
  371. <div className="toolBar">
  372. <div className="filter">
  373. <div className="filterItem">
  374. <KCInput
  375. placeholder={'指标名称'}
  376. style={{ width: 240 }}
  377. search
  378. allowClear
  379. onChange={(e) => {
  380. set_tableDataSearchKeywords(e.target.value);
  381. if (e.target.value.length == 0) {
  382. set_tableDataFilterParams({
  383. ...tableDataFilterParams,
  384. current: 1,
  385. name: '',
  386. });
  387. }
  388. }}
  389. onSearch={() => tableDataSearchHandle('name')}
  390. />
  391. </div>
  392. </div>
  393. <div className="btnGroup">
  394. <span className="add" onClick={addHandle}>
  395. 新增
  396. </span>
  397. </div>
  398. </div>
  399. {cateId && (
  400. <KCTable
  401. columns={columns}
  402. scroll={{ y: `calc(100vh - 250px)` }}
  403. reload={reloadTable}
  404. rowKey="id"
  405. newVer
  406. params={{ ...tableDataFilterParams, cateId }}
  407. request={(params) => getData(params)}
  408. onChange={handleTableChange}
  409. />
  410. )}
  411. </div>
  412. </div>
  413. </div>
  414. );
  415. };
  416. export default IndicatorMana;