/* * Author: 黎永顺 * name: 公式列表 * Description: * Date: 2023/4/25 */ import React, { Component } from "react"; import { WeaInputSearch, WeaLocaleProvider } from "ecCom"; import { Tree } from "antd"; import cs from "classnames"; import { formualSearchField, formualSearchGroup, getFormulaDes } from "../../../apis/item"; import "../index.less"; const TreeNode = Tree.TreeNode; const getLabel = WeaLocaleProvider.getLabel; class CodeAction extends Component { constructor(props) { super(props); this.state = { disabled: false, variableText: "", funcText: "", variItemText: "", variableList: [], //变量列表 variableExpandedKeys: [], //变量展开的节点 funcList: [], //函数列表 funcExpandedKeys: [], //函数展开的节点 funcHoverItem: {} //选中的函数节点 }; } componentDidMount() { const { groupParams = {} } = this.props; this.getFormulaDes(); this.formualSearchGroup(groupParams); } componentWillReceiveProps(nextProps, nextContext) { const { isCustomFunction, isCustomFunctionClick, onChangeCustomFunction } = nextProps; if (isCustomFunction === "1" && !isCustomFunctionClick) { this.setState({ disabled: true }); } else { this.setState({ disabled: false }, () => { isCustomFunction === "1" && onChangeCustomFunction("0"); }); } } getFormulaDes = () => { getFormulaDes().then(({ data }) => { if (!_.isEmpty(data)) this.setState({ funcList: data }); }); }; formualSearchGroup = (payload) => { formualSearchGroup(payload).then(({ status, data }) => { if (status) this.setState({ variableList: _.map(data, item => ({ ...item, children: [{ name: "", fieldId: "searchInput" }] })) }); }); }; formualSearchField = (sourceId) => { const { groupParams } = this.props; const { variableList } = this.state; formualSearchField({ sourceId, extendParam: { ...groupParams } }).then(({ status, data }) => { if (status) { this.setState({ variableList: _.map(variableList, it => ({ ...it, children: sourceId === it.key ? [...it.children, ...data] : [...it.children] })) }); } }); }; handleExpandVari = (variableExpandedKeys, { expanded, node }) => { const { props: { eventKey } } = node; const { variableList } = this.state; this.setState({ variableExpandedKeys }); if (expanded) { this.formualSearchField(eventKey); } else { this.setState({ variableList: _.map(variableList, it => ({ ...it, children: eventKey === it.key ? [{ name: "", fieldId: "searchInput" }] : [...it.children] })) }); } }; handleVariNode = (selectedKeys) => { const { onVariSelect } = this.props; const { variableList } = this.state; const parentNode = _.map(variableList, it => it.key); if (selectedKeys.join() && selectedKeys.join().indexOf("searchInput") === -1 && !parentNode.includes(selectedKeys.join())) { const selectParentNodeKey = selectedKeys.join().split("_")[0]; const convertStr = _.reduce(variableList, (pre, cur) => { if (cur.key === selectParentNodeKey) { return pre + cur.value + "." + _.find(cur.children, child => child.fieldId === selectedKeys.join()).name; } return pre; }, ""); onVariSelect(convertStr); } }; render() { const { variableList, variableExpandedKeys, variableText, variItemText, funcList, funcText, funcExpandedKeys, funcHoverItem, disabled } = this.state; const { groupParams = {} } = this.props; const { referenceType } = groupParams; const variableDatalist = _.filter(variableList, it => it.value.indexOf(variableText) !== -1); const funcDatalist = _.map(funcList, it => ({ ...it, children: _.filter(it.children, child => _.lowerCase(child.name).indexOf(_.lowerCase(funcText)) !== -1) })); return (
{getLabel(33748, "变量")}
this.setState({ variableText })}/> { _.map(variableDatalist, item => { const { key, value, children = [] } = item; const itemChildren = _.filter(children.slice(1), it => it.name.indexOf(variItemText) !== -1); return { _.map([...children.slice(0, 1), ...itemChildren], (child, childIndex) => { const { name, fieldId, fieldType } = child; return ( fieldId === "searchInput" ? this.setState({ variItemText })} /> } key={fieldId + "_" + childIndex}/> : {name} { fieldType ? {fieldType === "number" ? "数字" : "文本"} : }
} key={fieldId}/> ); }) } ; }) }
{ referenceType !== "sql" &&
{getLabel(30686, "函数")}
this.setState({ funcText })}/> this.setState({ funcExpandedKeys })} > { _.map(funcDatalist, item => { const { name, dataType, children = [] } = item; return { _.map(children, (child, childIndex) => { const { name: childName, chineseName } = child; return ( this.props.onFuncSelect(childName)} onMouseEnter={() => this.setState({ funcHoverItem: child })}> {childName} {chineseName}
} key={childIndex} /> ); }) } ; }) }
{!_.isEmpty(funcHoverItem) ? funcHoverItem.name : getLabel(558, "提示")}
} ); } } export default CodeAction; const TipList = (props) => { const { tips } = props; const { paramDescs = [], formatString, description, example, result } = tips; return _.isEmpty(tips) ?
{/*
{getLabel(111, "{C:选项} 用来选择特定选项字段下的备选项")}
*/} {/*
{getLabel(111, "{U:姓名} 用来选择工作区成员")}
*/} {/*
{getLabel(111, "{D:数据} 用来选择一个部门")}
*/}
:
{getLabel(543403, "语法")}
{formatString}
{description}
{getLabel(561, "参数")}
{ _.map(paramDescs, it => { return
. {it}
; }) }
{getLabel(82159, "示例")}
{example}
{getLabel(356, "结果")}
{result}
; };