import * as React from "react"; import { Select, Input } from "@alifd/next"; import { createElement } from 'react'; import { IPublicEnumTransformStage } from '@alilc/lowcode-types'; import { project } from '@alilc/lowcode-engine'; import { string } from "prop-types"; export default class AltSelbcfieldSetter extends React.Component { constructor(props) { super(props); this.state = { bcName: '', bcField: '', bcds: new Array(), bcfieldds: new Array(), bcHashtable: new Map() } } componentDidMount() { const schema = project.exportSchema(IPublicEnumTransformStage.Save); let bcHashtableEx: Map> = new Map(); if (schema.componentsTree[0].hasOwnProperty('ucmlBCList')){ const bclistinfo = schema.componentsTree[0].ucmlBCList; let bcarray = new Array(); for (let i = 0; i < bclistinfo.length; i++) { let bcobj = bclistinfo[i]; let Aobj= this.setBCSelectList(bcobj,bcarray,bcHashtableEx) bcarray.push(Aobj[0]); bcHashtableEx=new Map(Array.from(bcHashtableEx).concat(Array.from(Aobj[1]))); } this.setState({ bcds: bcarray.filter(item => !Array.isArray(item)),//给递归方法打补丁,删除不需要的对象 bcHashtable: bcHashtableEx }); } const { onChange, value } = this.props; if (value != undefined) { this.setState(value); let bcfieldcols = bcHashtableEx.get(value.bcName); let bcfarray=new Array(); for (let fieldobj of bcfieldcols) { let optex = { value: fieldobj.fieldName, label: fieldobj.caption } bcfarray.push(optex); } this.setState({ bcfieldds: bcfarray }); onChange(value); } } setBCSelectList=(source, bcarray,bcHashtableex)=> { // 遍历源对象的属性 for (let key in source) { if (source.hasOwnProperty(key)) { // 如果当前属性是children,则递归处理子节点 if (key === 'children') { for (let i = 0; i < source[key].length; i++) { let childSource = source[key][i]; this.setBCSelectList(childSource, bcarray,bcHashtableex); // 递归处理子节点 } } else { // 否则,将属性值复制到目标对象中 if(key == 'bcName'){ let opt = { value: source.bcName, label: source.bcName } bcarray.push(opt); bcHashtableex.set(source.bcName, source.columns) } } } } return [bcarray,bcHashtableex]; } // 声明 Setter 的 title static displayName = 'AltSelbcfieldSetter'; render() { const { onChange, value, t } = this.props; const bconChange = v => { let bcfieldcols = this.state.bcHashtable.get(v); let bcfieldarray=new Array(); for (let fieldobj of bcfieldcols) { let optex = { value: fieldobj.fieldName, label: fieldobj.caption } bcfieldarray.push(optex); } this.setState({ bcName: v, bcfieldds: bcfieldarray }); onChange({ bcName: v, bcField: this.state.bcField }) t.parent.setPropValue("bcName", v); t.parent.setPropValue("bcField", this.state.bcField); }; const bcfieldonChange = (v,acttype,item) => { this.setState({ bcField: v }); onChange({ bcName: this.state.bcName, bcField: v }) t.parent.setPropValue("bcName", this.state.bcName); t.parent.setPropValue("bcField", v); if(t.parent.getNode().componentName=="FormItem") { t.parent.setPropValue("name", v); t.parent.setPropValue("label", item.label); } }; return (



); } }