InterfacePage.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. import React, {FC, useRef, useState} from 'react';
  2. import {
  3. baseFun,
  4. SDAreaTtile,
  5. SDButton,
  6. SDEditableTable,
  7. SDFormDict,
  8. SDFormText,
  9. SDModalForm,
  10. SDOperate,
  11. SDPage,
  12. SDTable,
  13. validateFun
  14. } from "@sundata/ui-frame";
  15. import {ProColumns} from "@ant-design/pro-table";
  16. import {
  17. deleteRows,
  18. getDataList,
  19. insertInterfaceService,
  20. InterfaceModel,
  21. selectDetailData, testCalc,
  22. updateInterfaceService
  23. } from "@/services/internalEvaluation/configuration/Interface";
  24. import {useModel} from '@umijs/max';
  25. import {WomanOutlined} from "@ant-design/icons";
  26. import {EditType} from "@sundata/ui-frame/lib/types";
  27. import {FormInstance} from "antd/lib/form";
  28. import {InterfaceParamModel} from "@/services/internalEvaluation/configuration/InterfaceParam";
  29. import {ActionType, EditableProTable} from "@ant-design/pro-components";
  30. import {Popconfirm} from "antd";
  31. const InterfacePage: FC = () => {
  32. const {fetchDict} = useModel('dict');
  33. const interfaceDetailsRef = useRef<FormInstance<any>>();
  34. /** 表格引用对象,刷新表格使用 */
  35. const tableRef = useRef<ActionType>();
  36. // 新增、修改、查看详细信息弹窗的显隐控制
  37. const [detailVisible, setDetailVisible] = React.useState(false);
  38. // 编辑类型
  39. const [editType, setEditType] = React.useState<EditType>('create');
  40. // 存储请求参数列表
  41. const [paramList, setParamList] = useState<InterfaceParamModel[]>([]);
  42. const [operateInterfaceId, setOperateInterfaceId] = useState<string>('');
  43. // 页面展示元素
  44. const columns: ProColumns<InterfaceModel>[] = [
  45. {
  46. title: 'id',
  47. dataIndex: 'id',
  48. search: false,
  49. hideInTable: true,
  50. },
  51. {
  52. title: '接口编号',
  53. dataIndex: 'interfaceNo',
  54. hideInTable: false,
  55. },
  56. {
  57. title: '接口名称',
  58. dataIndex: 'interfaceName',
  59. hideInTable: false,
  60. },
  61. {
  62. title: '接口类型',
  63. dataIndex: 'interfaceTypeCode',
  64. hideInTable: false,
  65. valueType: 'select',
  66. request: () => fetchDict('INTERFACE_TYPE'),
  67. fieldProps: {
  68. treeDefaultExpandAll: true,
  69. treeCheckable: true,
  70. },
  71. },
  72. {
  73. title: 'IP',
  74. dataIndex: 'interfaceIp',
  75. search: false,
  76. hideInTable: false,
  77. },
  78. {
  79. title: '端口',
  80. dataIndex: 'interfacePort',
  81. hideInTable: false,
  82. },
  83. {
  84. title: '地址',
  85. dataIndex: 'interfaceUrl',
  86. hideInTable: false,
  87. },
  88. {
  89. title: '最后修改时间',
  90. dataIndex: 'updateTime',
  91. search: false,
  92. hideInTable: false,
  93. },
  94. {
  95. title: '操作',
  96. dataIndex: 'operate',
  97. valueType: 'option',
  98. render: (_, record) => [
  99. <SDOperate
  100. key="roleCfg"
  101. icon={<WomanOutlined/>}
  102. successMessage=""
  103. onClick={
  104. () => {
  105. selectDetailDataById(record);
  106. setDetailVisible(true)
  107. setEditType("display")
  108. // console.log("查看", record)
  109. // console.log(fetchDict('INTERFACE_TYPE'))
  110. }
  111. }
  112. >
  113. 查看
  114. </SDOperate>,
  115. <SDOperate
  116. key="roleCfg"
  117. icon={<WomanOutlined/>}
  118. successMessage=""
  119. onClick={
  120. () => {
  121. console.log("修改方法", record)
  122. selectDetailDataById(record)
  123. setDetailVisible(true);
  124. setEditType('update')
  125. }}
  126. >
  127. 修改
  128. </SDOperate>,
  129. <Popconfirm
  130. title={'警告'}
  131. description={'此操作是不可逆的,确认要删除数据吗?'}
  132. onConfirm={async () => {
  133. await deleteRows(record);
  134. tableRef.current?.reload();
  135. }}
  136. >
  137. <SDOperate
  138. key="roleCfg"
  139. icon={<WomanOutlined/>}
  140. successMessage=""
  141. onClick={() => {
  142. console.log("删除方法", record)
  143. }}
  144. >
  145. 删除
  146. </SDOperate>
  147. </Popconfirm>,
  148. <SDOperate
  149. key="roleCfg"
  150. icon={<WomanOutlined/>}
  151. successMessage=""
  152. onClick={() => {
  153. console.log("测试...", record)
  154. testCalc1(record);
  155. }}
  156. >
  157. 测试接口
  158. </SDOperate>
  159. ],
  160. },
  161. ];
  162. /**
  163. * 接口请求参数列表
  164. */
  165. const paramColumns: ProColumns<InterfaceParamModel>[] = [
  166. {
  167. title: '参数对象名称',
  168. dataIndex: 'paramObjName',
  169. hideInTable: false,
  170. search: false,
  171. formItemProps: {
  172. rules: [
  173. {
  174. required: true,
  175. message: '请输入参数对象名称'
  176. }
  177. ]
  178. }
  179. },
  180. {
  181. title: '参数中文名称',
  182. dataIndex: 'paramChineseName',
  183. hideInTable: false,
  184. search: false,
  185. formItemProps: {
  186. rules: [
  187. {
  188. required: true,
  189. message: '请输入参数中文名称'
  190. }
  191. ]
  192. }
  193. },
  194. {
  195. title: '参数说明',
  196. dataIndex: 'paramDescription',
  197. hideInTable: false,
  198. search: false,
  199. },
  200. {
  201. title: '参数类型',
  202. dataIndex: 'paramTypeCode',
  203. hideInTable: false,
  204. search: false,
  205. valueType: 'select',
  206. request: () => fetchDict('INTERFACE_PARAM_TYPE'),
  207. formItemProps: {
  208. rules: [
  209. {
  210. required: true,
  211. message: '请选择参数类型'
  212. }
  213. // {
  214. // validator:(rules,value,callback) => {
  215. // if (!value) {
  216. // callback('请选择参数类型');
  217. // } else {
  218. // callback()
  219. // }
  220. // }
  221. // }
  222. ]
  223. }
  224. },
  225. {
  226. title: '是否为报文头',
  227. dataIndex: 'isHeader',
  228. hideInTable: false,
  229. search: false,
  230. valueType: 'radio',
  231. valueEnum: {
  232. true: {text: '是'},
  233. false: {text: '否'},
  234. },
  235. formItemProps: {
  236. rules: [
  237. {
  238. required: true,
  239. message: '请选择'
  240. }
  241. ]
  242. }
  243. },
  244. {
  245. title: '参数获取类型',
  246. dataIndex: 'paramRetrievalTypeCode',
  247. hideInTable: false,
  248. search: false,
  249. valueType: 'select',
  250. request: () => fetchDict('PARAM_GET_TYPE'),
  251. formItemProps: {
  252. rules: [
  253. {
  254. required: true,
  255. message: '请选择参数获取类型'
  256. }
  257. ]
  258. }
  259. },
  260. {
  261. title: '参数获取内容',
  262. dataIndex: 'paramRetrievalTypeCont',
  263. search: false,
  264. hideInTable: false,
  265. valueType: 'textarea'
  266. },
  267. ];
  268. /**
  269. * 保存 或 修改的方法
  270. * @param record InterfaceModel 实体
  271. */
  272. const saveOrUpdateInfo = async (record: InterfaceModel) => {
  273. record.paramList = paramList;
  274. record.id = operateInterfaceId;
  275. const isSuccess = editType === 'create' ? await insertInterfaceService(record) : await updateInterfaceService(record) as boolean;
  276. if (isSuccess) {
  277. handleCloseModelForm();
  278. baseFun.info('保存成功');
  279. }
  280. }
  281. /**
  282. * 根据id查询接口详情信息
  283. * @param record InterfaceModel实体
  284. */
  285. const selectDetailDataById = async (record: InterfaceModel) => {
  286. const formDatas = await selectDetailData(record);
  287. interfaceDetailsRef.current?.setFieldsValue(formDatas);
  288. setParamList(formDatas.paramList);
  289. setOperateInterfaceId(formDatas.id)
  290. }
  291. const testCalc1 = async (record: InterfaceModel)=>{
  292. console.log (await testCalc(record).then((res)=>{
  293. console.log(res)
  294. }))
  295. }
  296. /**
  297. * 关闭弹窗操作
  298. */
  299. const handleCloseModelForm = () => {
  300. setDetailVisible(false);
  301. // interfaceDetailsRef.current?.resetFields();
  302. setParamList([]);
  303. setOperateInterfaceId('');
  304. }
  305. return (
  306. <SDPage>
  307. <SDTable
  308. title={'接口配置'}
  309. rowKey={"id"}
  310. actionRef={tableRef}
  311. request={
  312. async (formdata: InterfaceModel) => {
  313. const formDatas = await getDataList(formdata);
  314. return {data: formDatas}
  315. }
  316. }
  317. toolBarRender={
  318. () => [
  319. <SDButton
  320. key="roleCfg"
  321. successMessage=""
  322. onClick={() => {
  323. setDetailVisible(true);
  324. setEditType('create');
  325. setParamList([]);
  326. }}
  327. >
  328. 新增
  329. </SDButton>,
  330. ]
  331. }
  332. columns={columns}
  333. />
  334. {detailVisible && (
  335. <SDModalForm
  336. successMessage={''}
  337. tableRef={tableRef}
  338. formRef={interfaceDetailsRef}
  339. title={(editType === 'create' ? '新增' : editType === 'update' ? '修改' : '查看') + "接口信息"}
  340. editType={editType}
  341. visible={detailVisible}
  342. doSubmit={re => saveOrUpdateInfo(re)}
  343. onVisibleChange={handleCloseModelForm}
  344. >
  345. <SDAreaTtile title={"基本信息"}/>
  346. {/*<SDFormText name="id" label="id" disabled={true} width={'md'}/>*/}
  347. <SDFormText name="interfaceNo" readonlyCond="update" label="接口编号" width={'md'} required={true}/>
  348. <SDFormText name="interfaceName" label="接口名称" width={'md'} required={true}/>
  349. <SDFormDict name="reqMethod" label="请求方式" dictKey={'INTERFACE_REQUEST_TYPE'} required={true}
  350. width={'md'}/>
  351. <SDFormDict name="interfaceTypeCode" label="接口类型" dictKey={'INTERFACE_TYPE'} required={true}
  352. width={'md'}/>
  353. {/*<SDFormText name="interfaceIp" label="IP" required={true}*/}
  354. {/* rules={[{validator: validateFun.IP, message: '请输入正确的IP地址'}]} width={'md'}/>*/}
  355. <SDFormText name="interfaceIp" label="IP" required={true} width={'md'}/>
  356. <SDFormText name="interfacePort" label="端口" width={'md'} required={true}
  357. rules={
  358. [
  359. {
  360. validator: (a, value, callback) => {
  361. if (value > 65535 || value < 1) {
  362. callback('请输入正确的端口号(1-65535)');
  363. } else {
  364. callback();
  365. }
  366. }
  367. }
  368. ]
  369. }
  370. />
  371. <SDFormText name="interfaceUrl" label="地址" width={'md'} required={true}/>
  372. <SDFormDict name="reqContentTypeCode" label="内容类型" dictKey={'INTERFACE_CONTENT_TYPE'} width={'md'}/>
  373. <SDFormDict name="respParamTypeCode" label="接收参数类型" dictKey={'RECEIVE_PARAM_TYPE'} width={'md'}/>
  374. <SDFormText name="reqBodyTemplate" label="报文体模板" type={'textarea'} width={'xl'}/>
  375. <SDFormText name="reqEncryptionLogic" label="加密逻辑" width={'xl'} type={'textarea'}/>
  376. <SDFormText name="decryptionLogic" label="解密逻辑" width={'xl'} type={'textarea'}/>
  377. <SDFormText name="processLogic" label="解密后处理逻辑" width={'xl'} type={'textarea'}/>
  378. <SDFormText name="classNameMapping" label="处理后对象映射" width={'md'}/>
  379. <SDFormText name="objNameMapping" label="映射后对象映射" width={'md'}/>
  380. {editType === 'display' && (
  381. <>
  382. <SDFormText name="createBy" label="创建人"/>
  383. <SDFormText name="createTime" label="创建时间"/>
  384. <SDFormText name="updateBy" label="最后修改人"/>
  385. <SDFormText name="updateTime" label="最后修改时间"/>
  386. </>
  387. )
  388. }
  389. <SDAreaTtile title={"请求参数"}/>
  390. <SDEditableTable<InterfaceParamModel>
  391. columns={paramColumns}
  392. value={paramList}
  393. onChange={
  394. (value) => {
  395. setParamList([...value]);
  396. }
  397. }
  398. editable={editType !== 'display'}
  399. />
  400. </SDModalForm>
  401. )}
  402. </SDPage>
  403. );
  404. };
  405. export default InterfacePage;