import React from "react"; import { Empty } from "antd"; import { CodeSource, RouterCompProps } from "../tmpl/interface"; import DtmplEdit from "../detail/edit/dtmpl-edit"; import HcserviceV3 from "../tmpl/hcservice-v3"; import withRouter from "./withroute"; import TabActDtmplView from "../detail/view/tab-act-dtmpl-view"; export interface DtmplRouteProps extends RouterCompProps { layoutRootPath?: string; } export interface DtmplRoutePropsStat { codeSource?: CodeSource; queriedCode?: string; } class DtmplRoute extends React.Component { state = { codeSource: undefined, queriedCode: undefined, }; static defaultProps = { basePath: "", codeSource: undefined, queriedCode: undefined, }; async componentDidMount() { await this.queryCode(); } get computedLayoutPath() { const { layoutRootPath } = this.props; if (layoutRootPath !== undefined) return `/${layoutRootPath}`; return ""; } shouldComponentUpdate(prevProps, prevState) { if (!prevProps || prevProps != this.props) { this.setState({ codeSource: undefined, queriedCode: undefined }); } return true; } async componentDidUpdate(prevProps, prevState, snapshot) { if (!prevProps || prevProps != this.props) { await this.queryCode(); } } queryCode = async () => { const { params } = this.props; const { sourceId } = params; let codeSource: CodeSource = this.getCodeSource(); let queriedCode = await HcserviceV3.queryCode(sourceId, codeSource); this.setState({ codeSource, queriedCode, }); }; getMenuId = () => { const { searchParams } = this.props; //console.log("this.props.match.params",this.props); // var searchParams = new URLSearchParams( location.search); let menuId = searchParams.get("menuId"); return menuId; }; getServerKey = () => { // 获取serverKey const { searchParams } = this.props; let serverKey = searchParams.get("serverKey"); return serverKey || null; }; getCodeSource = () => { const { searchParams } = this.props; // let params=Units.transQueryStrToParams(location.search); // if('codeSource' in params){ return searchParams.get("codeSource"); // }else{ // return undefined; // } }; goBackToLtmpl = () => { //加tab页后不再支持返回列表 //this.props.navigate(-1); //this.props.navigate(); }; goNavigatel = () => { this.props.navigate(window.location.hash.replace("#/", "/")); //.reload(); }; goDtmpl = (code: string) => { const { sourceId } = this.props.params; const { basePath } = this.props; let url = `${basePath}${this.computedLayoutPath }/${sourceId}/detail-edit?menuId=${this.getMenuId()}`; if (code) { url = url + `&code=${code}`; } let mainCode = this.getMainCode(); if (mainCode) { url = url + `&mainCode=${mainCode}`; } this.props.navigate(url); }; getMainCode = () => { const { searchParams } = this.props; return searchParams.get("mainCode"); }; getCode = () => { const { codeSource, queriedCode } = this.state; const { searchParams } = this.props; //let code; if (codeSource) { return queriedCode; } else { // let params=Units.transQueryStrToParams(location.search); return searchParams.get("code"); } }; getMode = () => { const { searchParams } = this.props; // let params=Units.transQueryStrToParams(location.search); return this.getCode() ? searchParams.get("mode") : "add"; }; render() { const { location, params, searchParams } = this.props; const { sourceId } = params; const serverKey = this.getServerKey(); const { codeSource } = this.state; if (!location) { return <>; } const code = this.getCode(); if (code && code == "bad-code") { return ; } // let params=Units.transQueryStrToParams(location.search); let versionId = params["versionId"]; if (location.pathname.endsWith("detail-view")) { return ( ); } else { return ( ); } } } export default withRouter(DtmplRoute);