datasources.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. import React, {useEffect, useRef, useState} from "react";
  2. import {type ProColumns, type ActionType, type ProFormInstance, EditableProTable} from '@ant-design/pro-components';
  3. import type {FormInstance} from 'antd'
  4. import {
  5. SDPage,
  6. SDFormText,
  7. SDModalForm,
  8. SDTable,
  9. SDButton,
  10. SDSubmitButton,
  11. EditType,
  12. SDAreaTtile,
  13. SDOperate,
  14. baseFun,
  15. validateFun,
  16. SDFormDict,
  17. } from "@sundata/ui-frame";
  18. import type {
  19. DataSourcesModel,
  20. QueryLogicModel,
  21. DataItemConfigModel,
  22. InputParamModel
  23. } from '@/services/internalEvaluation/configuration/datasources';
  24. import {WomanOutlined} from "@ant-design/icons";
  25. import {ProductProps} from "@/sundataImport";
  26. import {
  27. deleteRows,
  28. getDataList,
  29. selectDetailData,
  30. updateExistData,
  31. createData
  32. } from "@/services/internalEvaluation/configuration/datasources";
  33. import {countChineseChars, firstCharIsNotNumber} from "../utils/rwacheckutils";
  34. type widowRush = {
  35. onCancel: () => void;
  36. onChangeVisible(visible: boolean, type: string): unknown;
  37. onChangeVisdible: (visible: boolean, type ?: 'none' | 'raload') => void;
  38. } & ProductProps;
  39. const datasources: React.FC<widowRush> = (prop: widowRush) => {
  40. /** 编辑方式,查看、修改、新增按钮时设置,详细信息表单中使用 */
  41. const [editType, setEditType] = useState<EditType>(prop.editType || 'display');
  42. /** 是否显示详细信息窗口 */
  43. const [detailVisible, setDetailVisible] = useState<boolean>(false);
  44. const [typeStatus, setTypeStatus] = useState<number>(0);
  45. const [currentRow, setCurrentRow] = useState<DataSourcesModel>();
  46. /** 表格引用对象,刷新表格使用 */
  47. const actionRef = useRef<ActionType>();
  48. const formRef = useRef<FormInstance<any>>();
  49. const templateRef = useRef<FormInstance<any>>();
  50. const [inputParamList, setInputParamList] = useState<InputParamModel[]>();
  51. const [queryLogicList, setQueryLogicList] = useState<QueryLogicModel[]>();
  52. const [dataItemConfigList, setDataItemConfigList] = useState<DataItemConfigModel[]>();
  53. // 页面数据
  54. var formDataList = new Array<DataSourcesModel>;
  55. useEffect(() => {
  56. }, []);
  57. // 修改查询查询
  58. const selectData = async (formdata: DataSourcesModel) => {
  59. const data = await selectDetailData(formdata);
  60. if (data.dataSourcesType === "JDBC") {
  61. setTypeStatus(1)
  62. }else if (data.dataSourcesType === "INTERFACE") {
  63. setTypeStatus(2);
  64. } else {
  65. setTypeStatus(0);
  66. }
  67. setInputParamList(data.inputParam);
  68. setQueryLogicList(data.queryLogic);
  69. setDataItemConfigList(data.dataItemConfig);
  70. formRef.current?.setFieldsValue(data);
  71. }
  72. // 删除
  73. const delRows = async (record: any) => {
  74. baseFun.confirm('确认删除?', async () => {
  75. await deleteRows(record);
  76. baseFun.info("删除成功");
  77. closeAndRefresh();
  78. });
  79. }
  80. //关闭窗口刷新父页面
  81. const closeAndRefresh = () => {
  82. actionRef.current?.reloadAndRest?.();
  83. }
  84. // 插入或者更新数据
  85. const handleSave = async (data: DataSourcesModel) => {
  86. data.inputParam = inputParamList;
  87. data.queryLogic = queryLogicList;
  88. data.dataItemConfig = dataItemConfigList;
  89. if (editType == 'update') {
  90. await updateExistData(data);
  91. closeAndRefresh();
  92. } else if (editType == 'create') {
  93. await createData(data);
  94. closeAndRefresh();
  95. }
  96. setDetailVisible(false);
  97. setTypeStatus(0)
  98. }
  99. // 页面展示元素
  100. const columns: ProColumns<DataSourcesModel>[] = [
  101. {
  102. title: '数据来源名称',
  103. dataIndex: 'dataSourcesName',
  104. hideInTable: false,
  105. },
  106. {
  107. title: '数据来源编号',
  108. dataIndex: 'dataSourcesNo',
  109. search: false,
  110. hideInTable: false,
  111. },
  112. {
  113. title: '数据来源类型',
  114. dataIndex: 'dataSourcesType',
  115. search: false,
  116. hideInTable: false,
  117. },
  118. // {
  119. // title: '数据源(请求接口)',
  120. // dataIndex: 'requestInterface',
  121. // search: false,
  122. // hideInTable: false,
  123. // },
  124. {
  125. title: '操作',
  126. dataIndex: 'operate',
  127. valueType: 'option',
  128. render: (_, record) => [
  129. <SDOperate
  130. key="roleCfg"
  131. icon={<WomanOutlined/>}
  132. successMessage=""
  133. onClick={
  134. () => {
  135. selectData(record);
  136. setDetailVisible(true);
  137. setEditType('update');
  138. }}
  139. >
  140. 修改
  141. </SDOperate>,
  142. <SDOperate
  143. key="roleCfg"
  144. icon={<WomanOutlined/>}
  145. successMessage=""
  146. onClick={() => {
  147. delRows(record)
  148. }}
  149. >
  150. 删除
  151. </SDOperate>,
  152. ],
  153. },
  154. ];
  155. // 输入参数页面展示元素
  156. const inputParamColumns: ProColumns<InputParamModel>[] = [
  157. {
  158. title: '数据来源编号',
  159. dataIndex: 'dataSourcesNo',
  160. search: false,
  161. hideInTable: true,
  162. },
  163. {
  164. title: '参数编号',
  165. dataIndex: 'paramNo',
  166. hideInTable: false,
  167. },
  168. {
  169. title: '参数名称',
  170. dataIndex: 'paramName',
  171. search: false,
  172. hideInTable: false,
  173. formItemProps: {
  174. rules: [
  175. {validator: validateFun.chineseRex, message: '请输入中文'},
  176. ]
  177. }
  178. },
  179. {
  180. title: '参数说明',
  181. dataIndex: 'paramDescribe',
  182. search: false,
  183. hideInTable: false,
  184. },
  185. {
  186. title: '参数中文名称',
  187. dataIndex: 'paramCName',
  188. search: false,
  189. hideInTable: false,
  190. formItemProps: {
  191. rules: [
  192. {validator: validateFun.chineseRex, message: '请输入中文'},
  193. ]
  194. }
  195. },
  196. {
  197. title: '操作',
  198. valueType: 'option',
  199. width: 200,
  200. render: (text, record, _, action) => [
  201. <a
  202. key="editable"
  203. onClick={() => {
  204. action?.startEditable?.(record.paramNo);
  205. }}
  206. >
  207. 编辑
  208. </a>,
  209. <a
  210. key="delete"
  211. onClick={() => {
  212. setInputParamList(...[inputParamList?.filter((item) => item.paramNo !== record.paramNo)]);
  213. console.log(inputParamList);
  214. }}
  215. >
  216. 删除
  217. </a>,
  218. ],
  219. },
  220. ];
  221. // 查询逻辑页面展示元素
  222. const queryLogicColumns: ProColumns<QueryLogicModel>[] = [
  223. {
  224. title: '数据来源编号',
  225. dataIndex: 'dataSourcesNo',
  226. search: false,
  227. hideInTable: true,
  228. },
  229. {
  230. title: '查新逻辑编号',
  231. dataIndex: 'queryLogicNo',
  232. hideInTable: false,
  233. },
  234. {
  235. title: 'selectSql脚本',
  236. dataIndex: 'selectSqlScript',
  237. search: false,
  238. hideInTable: false,
  239. },
  240. {
  241. title: '脚本说明',
  242. dataIndex: 'scriptDescription',
  243. search: false,
  244. hideInTable: false,
  245. },
  246. {
  247. title: '数据项名称',
  248. dataIndex: 'dataItemName',
  249. search: false,
  250. hideInTable: false,
  251. formItemProps: {
  252. rules: [
  253. {
  254. validator: validateFun.account
  255. },
  256. {
  257. validator: (rule, value, callback) => {
  258. if (firstCharIsNotNumber(value) > 0) {
  259. callback('编号不能以数字开头');
  260. } else {
  261. callback();
  262. }
  263. }
  264. }
  265. ]
  266. }
  267. },
  268. {
  269. title: '数据项中文名称',
  270. dataIndex: 'dataItemCName',
  271. search: false,
  272. hideInTable: false,
  273. formItemProps: {
  274. rules: [
  275. {validator: validateFun.chineseRex, message: '请输入中文'},
  276. ]
  277. }
  278. },
  279. {
  280. title: '操作',
  281. valueType: 'option',
  282. width: 200,
  283. render: (text, record, _, action) => [
  284. <a
  285. key="editable"
  286. onClick={() => {
  287. action?.startEditable?.(record.queryLogicNo);
  288. }}
  289. >
  290. 编辑
  291. </a>,
  292. <a
  293. key="delete"
  294. onClick={() => {
  295. setQueryLogicList(queryLogicList?.filter((item) => item.queryLogicNo !== record.queryLogicNo));
  296. }}
  297. >
  298. 删除
  299. </a>,
  300. ],
  301. },
  302. ];
  303. // 数据项配置页面展示元素
  304. const dataItemConfigColumns: ProColumns<DataItemConfigModel>[] = [
  305. {
  306. title: '数据来源编号',
  307. dataIndex: 'dataSourcesNo',
  308. search: false,
  309. hideInTable: true,
  310. },
  311. {
  312. title: '数据项编号',
  313. dataIndex: 'dataItemNo',
  314. hideInTable: false,
  315. },
  316. {
  317. title: '数据项名称',
  318. dataIndex: 'dataItemName',
  319. search: false,
  320. hideInTable: false,
  321. },
  322. {
  323. title: '数据项路径',
  324. dataIndex: 'dataItemRoute',
  325. search: false,
  326. hideInTable: false,
  327. },
  328. {
  329. title: '数据项SQL',
  330. dataIndex: 'dataItemSql',
  331. search: false,
  332. hideInTable: false,
  333. },
  334. {
  335. title: '操作',
  336. valueType: 'option',
  337. width: 200,
  338. render: (text, record, _, action) => [
  339. <a
  340. key="editable"
  341. onClick={() => {
  342. action?.startEditable?.(record.dataItemNo);
  343. }}
  344. >
  345. 编辑
  346. </a>,
  347. <a
  348. key="delete"
  349. onClick={() => {
  350. setDataItemConfigList(dataItemConfigList?.filter((item) => item.dataItemNo !== record.dataItemNo));
  351. }}
  352. >
  353. 删除
  354. </a>,
  355. ],
  356. },
  357. ];
  358. return (
  359. <SDPage>
  360. <SDTable
  361. title="查询表格"
  362. rowKey="customerName"
  363. request={async (formdata: DataSourcesModel) => {
  364. const formDatas = await getDataList(formdata);
  365. // 解构数组(导出用)
  366. formDataList = [...formDatas];
  367. return {data: formDatas}
  368. }}
  369. columns={columns}
  370. actionRef={actionRef}
  371. toolBarRender={(_: any, {selectedRows}: any) => [
  372. <SDButton
  373. successMessage=""
  374. onClick={() => {
  375. setEditType('create');
  376. setDetailVisible(true);
  377. setInputParamList([]);
  378. setQueryLogicList([]);
  379. setDataItemConfigList([]);
  380. }}
  381. >
  382. 新增
  383. </SDButton>
  384. ]}
  385. formRef={formRef}
  386. setDetailVisible={() => {
  387. setDetailVisible(true)
  388. }}
  389. setEditType={setEditType}
  390. setCurrentRow={setCurrentRow}
  391. />
  392. {detailVisible && (
  393. <SDModalForm
  394. onValuesChange={(a,b) => {
  395. if (a.dataSourcesType === "JDBC"){
  396. setTypeStatus(1);
  397. }else if (a.dataSourcesType === "INTERFACE"){
  398. setTypeStatus(2);
  399. }else if (b.dataSourcesType === undefined){
  400. setTypeStatus(0);
  401. }
  402. }}
  403. title={'详细信息'}
  404. editType={editType}
  405. params={currentRow}
  406. visible={detailVisible}
  407. onVisibleChange={() => {
  408. setDetailVisible(false)
  409. }}
  410. footer={[
  411. <SDSubmitButton editType={editType} formRef={formRef} doSubmit={handleSave}>保存</SDSubmitButton>,
  412. <SDButton
  413. key="closeUpdate"
  414. successMessage=''
  415. onClick={() => {
  416. setDetailVisible(false);
  417. setTypeStatus(0)
  418. }}>关闭</SDButton>
  419. ]}
  420. tableRef={actionRef}
  421. formRef={formRef}
  422. >
  423. <SDAreaTtile title='数据来源信息'/>
  424. <SDFormText name="dataSourcesNo" rules={[
  425. {required: true, message: '请输入编号'},
  426. {
  427. validator: validateFun.account
  428. },
  429. {
  430. validator: (rule, value, callback) => {
  431. if (firstCharIsNotNumber(value) > 0) {
  432. callback('编号不能以数字开头');
  433. } else {
  434. callback();
  435. }
  436. }
  437. }
  438. ]} label="数据来源编号" readonlyCond="update"/>
  439. <SDFormText name="dataSourcesName"
  440. rules={[{validator: validateFun.chineseRex, message: '请输入中文'}]} label="数据来源名称"/>
  441. <SDFormDict dictKey="DATASOURCETYPE" name="dataSourcesType" rules={[{required: true}]} label="数据来源类型"/>
  442. { typeStatus === 2 && <SDFormDict dictKey="@selectInterFaceData" name="requestInterfaces" rules={[{required: true}]}
  443. label="数据源(请求接口)"/> }
  444. {typeStatus === 2 && <>
  445. <SDAreaTtile title='输入参数'/>
  446. <EditableProTable<InputParamModel>
  447. rowKey="paramNo"
  448. columns={inputParamColumns}
  449. value={inputParamList}
  450. dataSource={inputParamList}
  451. onChange={(value) => {
  452. setInputParamList([...value]);
  453. }}
  454. recordCreatorProps={
  455. {
  456. position: 'bottom',
  457. record: () => ({paramNo: (Math.random() * 1000000).toFixed(0)})
  458. }
  459. }
  460. /> </>}
  461. {typeStatus === 1 && <>
  462. <SDAreaTtile title='查询逻辑'/>
  463. <EditableProTable<QueryLogicModel>
  464. rowKey="queryLogicNo"
  465. columns={queryLogicColumns}
  466. value={queryLogicList}
  467. dataSource={queryLogicList}
  468. onChange={(value) => {
  469. setQueryLogicList([...value]);
  470. }}
  471. recordCreatorProps={
  472. {
  473. position: 'bottom',
  474. record: () => ({
  475. queryLogicNo: (Math.random() * 1000000).toFixed(0),
  476. })
  477. }
  478. }
  479. /> </> }
  480. {typeStatus === 2 && <>
  481. <SDAreaTtile title='数据项配置'/>
  482. <EditableProTable<DataItemConfigModel>
  483. rowKey="dataItemNo"
  484. columns={dataItemConfigColumns}
  485. value={dataItemConfigList}
  486. dataSource={dataItemConfigList}
  487. onChange={(value) => {
  488. setDataItemConfigList([...value]);
  489. }}
  490. recordCreatorProps={
  491. {
  492. position: 'bottom',
  493. record: () => ({
  494. dataItemNo: (Math.random() * 1000000).toFixed(0),
  495. })
  496. }
  497. }
  498. /> </> }
  499. </SDModalForm>
  500. )}
  501. </SDPage>
  502. );
  503. }
  504. export default datasources;