amis-saas-6892 [Feature] 编辑器fx 交互优化

Change-Id: I2deff274ad0b2f572167e61b9114db7795e7680c
This commit is contained in:
jiatianqi 2022-10-27 19:39:39 +08:00
parent 5ae559a5b2
commit 3ec7647759

View File

@ -137,21 +137,13 @@ export default class FormulaControl extends React.Component<
}; };
} }
componentDidMount(): void {
this.getVariables();
}
componentDidUpdate(prevProps: FormulaControlProps) { componentDidUpdate(prevProps: FormulaControlProps) {
// 优先使用props中的变量数据 // 优先使用props中的变量数据
if (!this.props.variables) { this.getVariables();
// 从amis数据域中取变量数据
this.resolveVariablesFromScope().then(variables => {
if (Array.isArray(variables)) {
const vars = variables.filter(item => item.children?.length);
if (!this.isUnmount && !isEqual(vars, this.state.variables)) {
this.setState({
variables: vars
});
}
}
});
}
if (this.props.data !== prevProps.data) { if (this.props.data !== prevProps.data) {
this.setState({ this.setState({
variables: dataMapping(this.props.variables, this.props.data) variables: dataMapping(this.props.variables, this.props.data)
@ -196,6 +188,23 @@ export default class FormulaControl extends React.Component<
); );
} }
// 设置 variables
getVariables() {
if (!this.props.variables) {
// 从amis数据域中取变量数据
this.resolveVariablesFromScope().then(variables => {
if (Array.isArray(variables)) {
const vars = variables.filter(item => item.children?.length);
if (!this.isUnmount && !isEqual(vars, this.state.variables)) {
this.setState({
variables: vars
});
}
}
});
}
}
/** /**
* ${xx} \${xx} \${xx} * ${xx} \${xx} \${xx}
* 备注: 手动编辑时 ${xx} * 备注: 手动编辑时 ${xx}
@ -326,17 +335,10 @@ export default class FormulaControl extends React.Component<
this.props?.onChange?.(val); this.props?.onChange?.(val);
} }
handleSimpleInputChange = debounce( handleSimpleInputChange = (value: any) => {
(value: any) => { const curValue = this.replaceExpression(value);
const curValue = this.replaceExpression(value); this.props?.onChange?.(curValue);
this.props?.onChange?.(curValue); };
},
250,
{
trailing: true,
leading: false
}
);
handleInputChange = (value: any) => { handleInputChange = (value: any) => {
this.props?.onChange?.(value); this.props?.onChange?.(value);
@ -544,7 +546,7 @@ export default class FormulaControl extends React.Component<
allowInput={false} allowInput={false}
clearable={true} clearable={true}
value={value} value={value}
result={highlightValue} result={{html: '已配置表达式'}}
itemRender={this.renderFormulaValue} itemRender={this.renderFormulaValue}
onChange={this.handleInputChange} onChange={this.handleInputChange}
onResultChange={() => { onResultChange={() => {
@ -581,8 +583,12 @@ export default class FormulaControl extends React.Component<
{({onClick}: {onClick: (e: React.MouseEvent) => void}) => ( {({onClick}: {onClick: (e: React.MouseEvent) => void}) => (
<Button <Button
size="sm" size="sm"
tooltip={'点击配置表达式'} tooltip={{
tooltipPlacement="left" enterable: false,
content: '点击配置表达式',
placement: 'left',
mouseLeaveDelay: 0
}}
onClick={onClick} onClick={onClick}
// active={simple && value} // 不需要,避免 hover 时无任何反馈效果 // active={simple && value} // 不需要,避免 hover 时无任何反馈效果
> >