123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- import React, {FC, useRef, useState} from 'react';
- import {
- baseFun,
- SDAreaTtile,
- SDButton,
- SDEditableTable,
- SDFormDict,
- SDFormText,
- SDModalForm,
- SDOperate,
- SDPage,
- SDTable,
- validateFun
- } from "@sundata/ui-frame";
- import {ProColumns} from "@ant-design/pro-table";
- import {
- deleteRows,
- getDataList,
- insertInterfaceService,
- InterfaceModel,
- selectDetailData, testCalc,
- updateInterfaceService
- } from "@/services/internalEvaluation/configuration/Interface";
- import {useModel} from '@umijs/max';
- import {WomanOutlined} from "@ant-design/icons";
- import {EditType} from "@sundata/ui-frame/lib/types";
- import {FormInstance} from "antd/lib/form";
- import {InterfaceParamModel} from "@/services/internalEvaluation/configuration/InterfaceParam";
- import {ActionType, EditableProTable} from "@ant-design/pro-components";
- import {Popconfirm} from "antd";
- const InterfacePage: FC = () => {
- const {fetchDict} = useModel('dict');
- const interfaceDetailsRef = useRef<FormInstance<any>>();
- /** 表格引用对象,刷新表格使用 */
- const tableRef = useRef<ActionType>();
- // 新增、修改、查看详细信息弹窗的显隐控制
- const [detailVisible, setDetailVisible] = React.useState(false);
- // 编辑类型
- const [editType, setEditType] = React.useState<EditType>('create');
- // 存储请求参数列表
- const [paramList, setParamList] = useState<InterfaceParamModel[]>([]);
- const [operateInterfaceId, setOperateInterfaceId] = useState<string>('');
- // 页面展示元素
- const columns: ProColumns<InterfaceModel>[] = [
- {
- title: 'id',
- dataIndex: 'id',
- search: false,
- hideInTable: true,
- },
- {
- title: '接口编号',
- dataIndex: 'interfaceNo',
- hideInTable: false,
- },
- {
- title: '接口名称',
- dataIndex: 'interfaceName',
- hideInTable: false,
- },
- {
- title: '接口类型',
- dataIndex: 'interfaceTypeCode',
- hideInTable: false,
- valueType: 'select',
- request: () => fetchDict('INTERFACE_TYPE'),
- fieldProps: {
- treeDefaultExpandAll: true,
- treeCheckable: true,
- },
- },
- {
- title: 'IP',
- dataIndex: 'interfaceIp',
- search: false,
- hideInTable: false,
- },
- {
- title: '端口',
- dataIndex: 'interfacePort',
- hideInTable: false,
- },
- {
- title: '地址',
- dataIndex: 'interfaceUrl',
- hideInTable: false,
- },
- {
- title: '最后修改时间',
- dataIndex: 'updateTime',
- search: false,
- hideInTable: false,
- },
- {
- title: '操作',
- dataIndex: 'operate',
- valueType: 'option',
- render: (_, record) => [
- <SDOperate
- key="roleCfg"
- icon={<WomanOutlined/>}
- successMessage=""
- onClick={
- () => {
- selectDetailDataById(record);
- setDetailVisible(true)
- setEditType("display")
- // console.log("查看", record)
- // console.log(fetchDict('INTERFACE_TYPE'))
- }
- }
- >
- 查看
- </SDOperate>,
- <SDOperate
- key="roleCfg"
- icon={<WomanOutlined/>}
- successMessage=""
- onClick={
- () => {
- console.log("修改方法", record)
- selectDetailDataById(record)
- setDetailVisible(true);
- setEditType('update')
- }}
- >
- 修改
- </SDOperate>,
- <Popconfirm
- title={'警告'}
- description={'此操作是不可逆的,确认要删除数据吗?'}
- onConfirm={async () => {
- await deleteRows(record);
- tableRef.current?.reload();
- }}
- >
- <SDOperate
- key="roleCfg"
- icon={<WomanOutlined/>}
- successMessage=""
- onClick={() => {
- console.log("删除方法", record)
- }}
- >
- 删除
- </SDOperate>
- </Popconfirm>,
- <SDOperate
- key="roleCfg"
- icon={<WomanOutlined/>}
- successMessage=""
- onClick={() => {
- console.log("测试...", record)
- testCalc1(record);
- }}
- >
- 测试接口
- </SDOperate>
- ],
- },
- ];
- /**
- * 接口请求参数列表
- */
- const paramColumns: ProColumns<InterfaceParamModel>[] = [
- {
- title: '参数对象名称',
- dataIndex: 'paramObjName',
- hideInTable: false,
- search: false,
- formItemProps: {
- rules: [
- {
- required: true,
- message: '请输入参数对象名称'
- }
- ]
- }
- },
- {
- title: '参数中文名称',
- dataIndex: 'paramChineseName',
- hideInTable: false,
- search: false,
- formItemProps: {
- rules: [
- {
- required: true,
- message: '请输入参数中文名称'
- }
- ]
- }
- },
- {
- title: '参数说明',
- dataIndex: 'paramDescription',
- hideInTable: false,
- search: false,
- },
- {
- title: '参数类型',
- dataIndex: 'paramTypeCode',
- hideInTable: false,
- search: false,
- valueType: 'select',
- request: () => fetchDict('INTERFACE_PARAM_TYPE'),
- formItemProps: {
- rules: [
- {
- required: true,
- message: '请选择参数类型'
- }
- // {
- // validator:(rules,value,callback) => {
- // if (!value) {
- // callback('请选择参数类型');
- // } else {
- // callback()
- // }
- // }
- // }
- ]
- }
- },
- {
- title: '是否为报文头',
- dataIndex: 'isHeader',
- hideInTable: false,
- search: false,
- valueType: 'radio',
- valueEnum: {
- true: {text: '是'},
- false: {text: '否'},
- },
- formItemProps: {
- rules: [
- {
- required: true,
- message: '请选择'
- }
- ]
- }
- },
- {
- title: '参数获取类型',
- dataIndex: 'paramRetrievalTypeCode',
- hideInTable: false,
- search: false,
- valueType: 'select',
- request: () => fetchDict('PARAM_GET_TYPE'),
- formItemProps: {
- rules: [
- {
- required: true,
- message: '请选择参数获取类型'
- }
- ]
- }
- },
- {
- title: '参数获取内容',
- dataIndex: 'paramRetrievalTypeCont',
- search: false,
- hideInTable: false,
- valueType: 'textarea'
- },
- ];
- /**
- * 保存 或 修改的方法
- * @param record InterfaceModel 实体
- */
- const saveOrUpdateInfo = async (record: InterfaceModel) => {
- record.paramList = paramList;
- record.id = operateInterfaceId;
- const isSuccess = editType === 'create' ? await insertInterfaceService(record) : await updateInterfaceService(record) as boolean;
- if (isSuccess) {
- handleCloseModelForm();
- baseFun.info('保存成功');
- }
- }
- /**
- * 根据id查询接口详情信息
- * @param record InterfaceModel实体
- */
- const selectDetailDataById = async (record: InterfaceModel) => {
- const formDatas = await selectDetailData(record);
- interfaceDetailsRef.current?.setFieldsValue(formDatas);
- setParamList(formDatas.paramList);
- setOperateInterfaceId(formDatas.id)
- }
- const testCalc1 = async (record: InterfaceModel)=>{
- console.log (await testCalc(record).then((res)=>{
- console.log(res)
- }))
- }
- /**
- * 关闭弹窗操作
- */
- const handleCloseModelForm = () => {
- setDetailVisible(false);
- // interfaceDetailsRef.current?.resetFields();
- setParamList([]);
- setOperateInterfaceId('');
- }
- return (
- <SDPage>
- <SDTable
- title={'接口配置'}
- rowKey={"id"}
- actionRef={tableRef}
- request={
- async (formdata: InterfaceModel) => {
- const formDatas = await getDataList(formdata);
- return {data: formDatas}
- }
- }
- toolBarRender={
- () => [
- <SDButton
- key="roleCfg"
- successMessage=""
- onClick={() => {
- setDetailVisible(true);
- setEditType('create');
- setParamList([]);
- }}
- >
- 新增
- </SDButton>,
- ]
- }
- columns={columns}
- />
- {detailVisible && (
- <SDModalForm
- successMessage={''}
- tableRef={tableRef}
- formRef={interfaceDetailsRef}
- title={(editType === 'create' ? '新增' : editType === 'update' ? '修改' : '查看') + "接口信息"}
- editType={editType}
- visible={detailVisible}
- doSubmit={re => saveOrUpdateInfo(re)}
- onVisibleChange={handleCloseModelForm}
- >
- <SDAreaTtile title={"基本信息"}/>
- {/*<SDFormText name="id" label="id" disabled={true} width={'md'}/>*/}
- <SDFormText name="interfaceNo" readonlyCond="update" label="接口编号" width={'md'} required={true}/>
- <SDFormText name="interfaceName" label="接口名称" width={'md'} required={true}/>
- <SDFormDict name="reqMethod" label="请求方式" dictKey={'INTERFACE_REQUEST_TYPE'} required={true}
- width={'md'}/>
- <SDFormDict name="interfaceTypeCode" label="接口类型" dictKey={'INTERFACE_TYPE'} required={true}
- width={'md'}/>
- {/*<SDFormText name="interfaceIp" label="IP" required={true}*/}
- {/* rules={[{validator: validateFun.IP, message: '请输入正确的IP地址'}]} width={'md'}/>*/}
- <SDFormText name="interfaceIp" label="IP" required={true} width={'md'}/>
- <SDFormText name="interfacePort" label="端口" width={'md'} required={true}
- rules={
- [
- {
- validator: (a, value, callback) => {
- if (value > 65535 || value < 1) {
- callback('请输入正确的端口号(1-65535)');
- } else {
- callback();
- }
- }
- }
- ]
- }
- />
- <SDFormText name="interfaceUrl" label="地址" width={'md'} required={true}/>
- <SDFormDict name="reqContentTypeCode" label="内容类型" dictKey={'INTERFACE_CONTENT_TYPE'} width={'md'}/>
- <SDFormDict name="respParamTypeCode" label="接收参数类型" dictKey={'RECEIVE_PARAM_TYPE'} width={'md'}/>
- <SDFormText name="reqBodyTemplate" label="报文体模板" type={'textarea'} width={'xl'}/>
- <SDFormText name="reqEncryptionLogic" label="加密逻辑" width={'xl'} type={'textarea'}/>
- <SDFormText name="decryptionLogic" label="解密逻辑" width={'xl'} type={'textarea'}/>
- <SDFormText name="processLogic" label="解密后处理逻辑" width={'xl'} type={'textarea'}/>
- <SDFormText name="classNameMapping" label="处理后对象映射" width={'md'}/>
- <SDFormText name="objNameMapping" label="映射后对象映射" width={'md'}/>
- {editType === 'display' && (
- <>
- <SDFormText name="createBy" label="创建人"/>
- <SDFormText name="createTime" label="创建时间"/>
- <SDFormText name="updateBy" label="最后修改人"/>
- <SDFormText name="updateTime" label="最后修改时间"/>
- </>
- )
- }
- <SDAreaTtile title={"请求参数"}/>
- <SDEditableTable<InterfaceParamModel>
- columns={paramColumns}
- value={paramList}
- onChange={
- (value) => {
- setParamList([...value]);
- }
- }
- editable={editType !== 'display'}
- />
- </SDModalForm>
- )}
- </SDPage>
- );
- };
- export default InterfacePage;
|