import React from 'react'; import { FormInstance} from 'antd' import {CodeSource, DtmplConfig, DtmplData, FieldGroupConfig} from "../tmpl/interface"; import DtmplForm from '../form/dtmpl-form'; import HCDataSource from "../tmpl/hc-data-source"; import Units from "../units"; import HcserviceV3 from "../tmpl/hcservice-v3"; interface EmbedDtmplEditPageProps { group?:FieldGroupConfig, code?:string, sourceId:string, serverKey?:string, mainCode?:string, codeSource?:CodeSource, onFinish: (code:string|boolean) => void, defaultDtmplData?:DtmplData, addTmplId?:string, } interface EmbedDtmplEditPageState { id?:string, dtmplConfig?: DtmplConfig, loading?: boolean; dtmplData?:DtmplData, } export default class EmbedDtmplEditPage extends React.PureComponent { formRef = React.createRef(); static defaultProps = { } state = { id:'EmbedDtmplEditPage'+Units.getRandomNum(6), dtmplConfig: undefined, loading: true, dtmplData:undefined, } async componentDidMount() { await this.loadConfigData(); } // async componentDidUpdate(prevProps) { // const { dtmplConfig} = this.state; // if(prevProps && prevProps!=this.props){ // if(prevProps.sourceId!=this.props.sourceId || dtmplConfig==null){ // await this.loadConfigData(); // }else{ // await this.loadData(dtmplConfig); // } // } // } componentWillUnmount(): void { } doSubmit = (actionId?: string) => { const {mainCode}=this.props; //if (actionId) { //actionid 直接放在表单中 this.formRef.current.setFieldsValue({'actionId': actionId}); // }; if(mainCode){ this.formRef.current.setFieldsValue({'mainCode': mainCode}); } this.formRef.current.submit(); } loadConfigData = async () => { const {code,sourceId,serverKey,group,addTmplId} = this.props; this.setState({ loading: true, }) let dtmplConfig=undefined; if(code){ dtmplConfig = await HCDataSource.requestDtmplConfig(serverKey,sourceId,code); }else{ dtmplConfig = await HCDataSource.requestAddDtmplConfig(serverKey,sourceId,addTmplId); } if(dtmplConfig?.entity && dtmplConfig?.entity?.code==code){ let dtmplData=dtmplConfig.entity; dtmplConfig.entity=undefined; this.setState({ dtmplData, id: code, loading: false, }); }else{ await this.loadData(dtmplConfig); } this.setState({ dtmplConfig, loading: false, }) } loadData = async (dtmplConfig:DtmplConfig ) => { const { sourceId, code:propsCode,defaultDtmplData,serverKey,codeSource} = this.props; let code=propsCode; if(!code && codeSource){ code=await HcserviceV3.queryCode(sourceId,codeSource,serverKey); } if (code) { this.setState({ loading: true, dtmplData:undefined, }) const dtmplData_:DtmplData=await HcserviceV3.getDtmplData(dtmplConfig,serverKey,sourceId, code); this.setState({ dtmplData:dtmplData_, id:code, loading: false, }) }else if(defaultDtmplData){ this.setState({ dtmplData:defaultDtmplData, loading: false, }) }else{ this.setState({ dtmplData:{code:undefined,title:undefined,fieldMap:{},arrayMap:{}}, loading: false, }) } } render() { const {sourceId,serverKey,mainCode,onFinish} = this.props const {dtmplConfig,id,dtmplData} = this.state; return () } }