import React, {useEffect, useRef, useState} from "react"; import {type ProColumns, type ActionType, type ProFormInstance, EditableProTable} from '@ant-design/pro-components'; import type {FormInstance} from 'antd' import { SDPage, SDFormText, SDModalForm, SDTable, SDButton, SDSubmitButton, EditType, SDAreaTtile, SDOperate, baseFun, validateFun, SDFormDict, } from "@sundata/ui-frame"; import type { DataSourcesModel, QueryLogicModel, DataItemConfigModel, InputParamModel } from '@/services/internalEvaluation/configuration/datasources'; import {WomanOutlined} from "@ant-design/icons"; import {ProductProps} from "@/sundataImport"; import { deleteRows, getDataList, selectDetailData, updateExistData, createData } from "@/services/internalEvaluation/configuration/datasources"; import {countChineseChars, firstCharIsNotNumber} from "../utils/rwacheckutils"; type widowRush = { onCancel: () => void; onChangeVisible(visible: boolean, type: string): unknown; onChangeVisdible: (visible: boolean, type ?: 'none' | 'raload') => void; } & ProductProps; const datasources: React.FC = (prop: widowRush) => { /** 编辑方式,查看、修改、新增按钮时设置,详细信息表单中使用 */ const [editType, setEditType] = useState(prop.editType || 'display'); /** 是否显示详细信息窗口 */ const [detailVisible, setDetailVisible] = useState(false); const [typeStatus, setTypeStatus] = useState(0); const [currentRow, setCurrentRow] = useState(); /** 表格引用对象,刷新表格使用 */ const actionRef = useRef(); const formRef = useRef>(); const templateRef = useRef>(); const [inputParamList, setInputParamList] = useState(); const [queryLogicList, setQueryLogicList] = useState(); const [dataItemConfigList, setDataItemConfigList] = useState(); // 页面数据 var formDataList = new Array; useEffect(() => { }, []); // 修改查询查询 const selectData = async (formdata: DataSourcesModel) => { const data = await selectDetailData(formdata); if (data.dataSourcesType === "JDBC") { setTypeStatus(1) }else if (data.dataSourcesType === "INTERFACE") { setTypeStatus(2); } else { setTypeStatus(0); } setInputParamList(data.inputParam); setQueryLogicList(data.queryLogic); setDataItemConfigList(data.dataItemConfig); formRef.current?.setFieldsValue(data); } // 删除 const delRows = async (record: any) => { baseFun.confirm('确认删除?', async () => { await deleteRows(record); baseFun.info("删除成功"); closeAndRefresh(); }); } //关闭窗口刷新父页面 const closeAndRefresh = () => { actionRef.current?.reloadAndRest?.(); } // 插入或者更新数据 const handleSave = async (data: DataSourcesModel) => { data.inputParam = inputParamList; data.queryLogic = queryLogicList; data.dataItemConfig = dataItemConfigList; if (editType == 'update') { await updateExistData(data); closeAndRefresh(); } else if (editType == 'create') { await createData(data); closeAndRefresh(); } setDetailVisible(false); setTypeStatus(0) } // 页面展示元素 const columns: ProColumns[] = [ { title: '数据来源名称', dataIndex: 'dataSourcesName', hideInTable: false, }, { title: '数据来源编号', dataIndex: 'dataSourcesNo', search: false, hideInTable: false, }, { title: '数据来源类型', dataIndex: 'dataSourcesType', search: false, hideInTable: false, }, // { // title: '数据源(请求接口)', // dataIndex: 'requestInterface', // search: false, // hideInTable: false, // }, { title: '操作', dataIndex: 'operate', valueType: 'option', render: (_, record) => [ } successMessage="" onClick={ () => { selectData(record); setDetailVisible(true); setEditType('update'); }} > 修改 , } successMessage="" onClick={() => { delRows(record) }} > 删除 , ], }, ]; // 输入参数页面展示元素 const inputParamColumns: ProColumns[] = [ { title: '数据来源编号', dataIndex: 'dataSourcesNo', search: false, hideInTable: true, }, { title: '参数编号', dataIndex: 'paramNo', hideInTable: false, }, { title: '参数名称', dataIndex: 'paramName', search: false, hideInTable: false, formItemProps: { rules: [ {required: true, message: '必填项,请输入'}, ] } }, { title: '参数说明', dataIndex: 'paramDescribe', search: false, hideInTable: false, }, { title: '参数中文名称', dataIndex: 'paramCName', search: false, hideInTable: false, formItemProps: { rules: [ {required: true, message: '必填项,请输入'}, ] } }, { title: '操作', valueType: 'option', width: 200, render: (text, record, _, action) => [ { action?.startEditable?.(record.paramNo); }} > 编辑 , { setInputParamList(...[inputParamList?.filter((item) => item.paramNo !== record.paramNo)]); console.log(inputParamList); }} > 删除 , ], }, ]; // 查询逻辑页面展示元素 const queryLogicColumns: ProColumns[] = [ { title: '数据来源编号', dataIndex: 'dataSourcesNo', search: false, hideInTable: true, }, { title: '查新逻辑编号', dataIndex: 'queryLogicNo', hideInTable: false, }, { title: 'selectSql脚本', dataIndex: 'selectSqlScript', search: false, hideInTable: false, }, { title: '脚本说明', dataIndex: 'scriptDescription', search: false, hideInTable: false, }, { title: '数据项名称', dataIndex: 'dataItemName', search: false, hideInTable: false, formItemProps: { rules: [ { validator: validateFun.account }, { validator: (rule, value, callback) => { if (firstCharIsNotNumber(value) > 0) { callback('编号不能以数字开头'); } else { callback(); } } } ] } }, { title: '数据项中文名称', dataIndex: 'dataItemCName', search: false, hideInTable: false, formItemProps: { rules: [ {required: true, message: '必填项,请输入'}, ] } }, { title: '操作', valueType: 'option', width: 200, render: (text, record, _, action) => [ { action?.startEditable?.(record.queryLogicNo); }} > 编辑 , { setQueryLogicList(queryLogicList?.filter((item) => item.queryLogicNo !== record.queryLogicNo)); }} > 删除 , ], }, ]; // 数据项配置页面展示元素 const dataItemConfigColumns: ProColumns[] = [ { title: '数据来源编号', dataIndex: 'dataSourcesNo', search: false, hideInTable: true, }, { title: '数据项编号', dataIndex: 'dataItemNo', hideInTable: false, }, { title: '数据项名称', dataIndex: 'dataItemName', search: false, hideInTable: false, }, { title: '数据项路径', dataIndex: 'dataItemRoute', search: false, hideInTable: false, }, { title: '数据项SQL', dataIndex: 'dataItemSql', search: false, hideInTable: false, }, { title: '操作', valueType: 'option', width: 200, render: (text, record, _, action) => [ { action?.startEditable?.(record.dataItemNo); }} > 编辑 , { setDataItemConfigList(dataItemConfigList?.filter((item) => item.dataItemNo !== record.dataItemNo)); }} > 删除 , ], }, ]; return ( { const formDatas = await getDataList(formdata); // 解构数组(导出用) formDataList = [...formDatas]; return {data: formDatas} }} columns={columns} actionRef={actionRef} toolBarRender={(_: any, {selectedRows}: any) => [ { setEditType('create'); setDetailVisible(true); setTypeStatus(0); setInputParamList([]); setQueryLogicList([]); setDataItemConfigList([]); }} > 新增 ]} formRef={formRef} setDetailVisible={() => { setDetailVisible(true) }} setEditType={setEditType} setCurrentRow={setCurrentRow} /> {detailVisible && ( { if (a.dataSourcesType === "JDBC"){ setTypeStatus(1); }else if (a.dataSourcesType === "INTERFACE"){ setTypeStatus(2); }else if (b.dataSourcesType === undefined){ setTypeStatus(0); } }} title={'详细信息'} editType={editType} params={currentRow} visible={detailVisible} onVisibleChange={() => { setDetailVisible(false) setTypeStatus(0) }} footer={[ 保存, { setDetailVisible(false); setTypeStatus(0) }}>关闭 ]} tableRef={actionRef} formRef={formRef} > { if (firstCharIsNotNumber(value) > 0) { callback('编号不能以数字开头'); } else { callback(); } } } ]} label="数据来源编号" readonlyCond="update"/> { typeStatus === 2 && } {typeStatus === 2 && <> rowKey="paramNo" columns={inputParamColumns} value={inputParamList} dataSource={inputParamList} onChange={(value) => { setInputParamList([...value]); }} recordCreatorProps={ { position: 'bottom', record: () => ({paramNo: (Math.random() * 1000000).toFixed(0)}) } } /> } {typeStatus === 1 && <> rowKey="queryLogicNo" columns={queryLogicColumns} value={queryLogicList} dataSource={queryLogicList} onChange={(value) => { setQueryLogicList([...value]); }} recordCreatorProps={ { position: 'bottom', record: () => ({ queryLogicNo: (Math.random() * 1000000).toFixed(0), }) } } /> } {typeStatus === 2 && <> rowKey="dataItemNo" columns={dataItemConfigColumns} value={dataItemConfigList} dataSource={dataItemConfigList} onChange={(value) => { setDataItemConfigList([...value]); }} recordCreatorProps={ { position: 'bottom', record: () => ({ dataItemNo: (Math.random() * 1000000).toFixed(0), }) } } /> } )} ); } export default datasources;