import React, { ReactNode } from "react"; import { DtmplBaseProps, DtmplConfig, DtmplData, FieldGroupConfig, AuditData } from "../../tmpl/interface"; import RelationTable from "../../table/relation-table"; import FieldViewGroup from "./field-view-group"; import HcserviceV3 from "../../tmpl/hcservice-v3"; import "../dtmpl.css"; import Units from "../../units"; import CollapseCard from "../../controls/collapse-card"; import CqueryButtonBar from "../button/cquery-button-bar"; import TmplConfigAnalysis from "../../tmpl/tmpl-config-analysis"; import { Card, Tabs } from "antd"; import LtmplTable from "../../module/ltmpl-table"; import DtmplViewCard from "../../module/dtmpl-view-card"; import { ProgramConfig } from "../../index"; export interface DtmplViewProps extends DtmplBaseProps { versionId?: number; dtmplConfig: DtmplConfig; refreshCode?: string; parentId?: string; tabBarExtraContent?: ReactNode; isAudit?: boolean; // 是否审计 getAuditData?: (val: AuditData) => void; // 获取审计变更数据 } export interface DtmplViewStat { id?: string; loading?: boolean; dtmplData?: DtmplData; premisesTitle?: string; layout?: object; auditData?: AuditData; } class DtmplView extends React.PureComponent { static defaultProps = { showRightNav: true, maxColsOnRow: 2, isAudit: false, }; state = { loading: true, id: "dtmplView" + Units.getRandomNum(6), snapshotOpen: false, dtmplData: undefined, auditData: undefined, premisesTitle: "默认字段", layout: { labelCol: { span: 8 }, wrapperCol: { span: 16 }, }, }; async componentDidMount() { await this.loadData(); } async componentDidUpdate(prevProps) { const { sourceId, code, versionId, refreshCode } = this.props; const { code: preCode, versionId: preVersionId, refreshCode: preRefreshCode, } = prevProps; if ( code != preCode || (versionId && versionId != prevProps.versionId) || (refreshCode && refreshCode != preRefreshCode) ) { await this.loadData(); } } loadData = async () => { const { sourceId, code: propsCode, versionId, serverKey, codeSource, isAudit, getAuditData } = this.props; let code = propsCode; if (!code && codeSource) { code = await HcserviceV3.queryCode(sourceId, codeSource, serverKey); } if (code) { this.setState({ loading: true, dtmplData: undefined }); let dtmplData, auditData; if (isAudit) { // 审计查看页面 auditData = await HcserviceV3.requestViewDtmplAuditData(serverKey, sourceId, code, versionId); dtmplData = { ...(auditData?.entity || {}), sourceId: auditData?.sourceId }; getAuditData(auditData); } else { // 普通查看页面 dtmplData = await HcserviceV3.requestViewDtmplData(serverKey, sourceId, code, versionId); } this.setState({ dtmplData, auditData, loading: false }); } else { this.setState({ loading: false }); } }; fieldGroupList = () => { const { dtmplConfig, serverKey, mainCode, showRightNav, parentId, maxColsOnRow, code, isAudit } = this.props; const { dtmplData, loading, id, auditData } = this.state; const { pageLayout } = dtmplConfig; let groups: FieldGroupConfig[] = []; if (dtmplConfig) { groups = dtmplConfig.groups; } const groupElements = groups.map((item) => { if (item.type === "embed") { if (!dtmplData) { return null; } let codeSource = undefined; //code 从来源字段里面拿 let code = TmplConfigAnalysis.getFieldValueCodeOfMstrucId( dtmplConfig, dtmplData.fieldMap, item.codeSourceFieldMstrucId ); let innerSourceId = TmplConfigAnalysis.getFieldValueCodeOfMstrucId( dtmplConfig, dtmplData.fieldMap, item.pageSourceFieldMstrucId ); innerSourceId = innerSourceId ? innerSourceId : item.pointSourceId; if (!innerSourceId) { return null; } let children = null; switch (item.embedType) { case "列表": children = ; return pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : children; case "编辑": case "编辑或添加": codeSource = item.embedType === "编辑" ? "listop" : item.embedType === "编辑或添加" ? "new" : codeSource; children = ; return pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : {children} ; case "详情": codeSource = "listop"; children = ; return pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : {children} ; default: break; } } else if (item.type == "relation") { //关系 if (item.fields) { let data: DtmplData[] = undefined; if (dtmplData) { data = dtmplData.arrayMap[item.id]; } const children = ; return pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : children; } } else { //字段组 const children = ; return ( pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : {children} ); } }); if (dtmplConfig.viewRactions?.length) { // 关系查询 const viewRactions = dtmplConfig.viewRactions.map(item => { const children = ; return pageLayout === "horizontalTabs" ? { key: item.id, label: item.title, children } : {children} ; }); groupElements.push(...viewRactions); } return groupElements; }; render() { const { code, dtmplConfig, serverKey, maxColsOnRow, tabBarExtraContent } = this.props; const { premisesTitle, loading, dtmplData, id, } = this.state; const premises = dtmplConfig ? dtmplConfig.premises : undefined; if (!dtmplConfig || !dtmplData) { return ; } const { pageLayout, groups } = dtmplConfig; return (
{pageLayout === "horizontalTabs" ? : this.fieldGroupList()} {premises && premises.length > 0 ? ( {premisesTitle}} title={premisesTitle} key={premisesTitle} id={id + premises[0].id} className="hoverable" headStyle={{ background: "#f2f4f5" }} loading={loading} > ) : ( "" )} {/*因为编辑页以抽屉或模态框为主,且展示有些问题,暂时不用{showRightNav ? (*/} {/* */} {/*) : (*/} {/* ""*/} {/*)}*/}
); } } export default DtmplView;