From 4e34fe7ae7faeddd38c26af426584b80a43c9a5a Mon Sep 17 00:00:00 2001 From: igrowp <164761965@qq.com> Date: Wed, 2 Nov 2022 16:42:47 +0800 Subject: [PATCH] =?UTF-8?q?amis-saas-6892=20fix:=20=E9=95=BF=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E8=BE=93=E5=85=A5=E6=A1=86=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie687148b058931b26f79f93cf0b635faa0d9924d --- .../src/renderer/ExpressionFormulaControl.tsx | 116 +++++++++--------- .../src/renderer/textarea-formula/plugin.tsx | 3 + 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/packages/amis-editor/src/renderer/ExpressionFormulaControl.tsx b/packages/amis-editor/src/renderer/ExpressionFormulaControl.tsx index 78cf96c33..8cb1b97cf 100644 --- a/packages/amis-editor/src/renderer/ExpressionFormulaControl.tsx +++ b/packages/amis-editor/src/renderer/ExpressionFormulaControl.tsx @@ -6,8 +6,7 @@ import React from 'react'; import {autobind, FormControlProps} from 'amis-core'; import cx from 'classnames'; import isEqual from 'lodash/isEqual'; -import {FormItem, Button, Icon} from 'amis'; -import FormulaPicker from './textarea-formula/FormulaPicker'; +import {FormItem, Button, Icon, PickerContainer} from 'amis'; import {FormulaEditor} from 'amis-ui/lib/components/formula/Editor'; import type {VariableItem} from 'amis-ui/lib/components/formula/Editor'; import {resolveVariablesFromScope} from './textarea-formula/utils'; @@ -21,8 +20,6 @@ interface ExpressionFormulaControlProps extends FormControlProps { interface ExpressionFormulaControlState { variables: Array; - formulaPickerOpen: boolean; - formulaPickerValue: string; } @@ -40,7 +37,6 @@ export default class ExpressionFormulaControl extends React.Component< super(props); this.state = { variables: [], - formulaPickerOpen: false, formulaPickerValue: '' }; } @@ -103,21 +99,11 @@ export default class ExpressionFormulaControl extends React.Component< return []; } - @autobind - openFormulaPickerModal() { - this.setState({ - formulaPickerOpen: true - }); - } - @autobind handleConfirm(value = '') { value = value.replace(/^\$\{(.*)\}$/, (match: string, p1: string) => p1); value = value ? `\${${value}}` : ''; this.props?.onChange?.(value); - this.setState({ - formulaPickerOpen: false - }); } @autobind @@ -128,8 +114,8 @@ export default class ExpressionFormulaControl extends React.Component< } render() { - const {value, className, variableMode} = this.props; - const {formulaPickerOpen, formulaPickerValue} = this.state; + const {value, className, variableMode, header, ...rest} = this.props; + const {formulaPickerValue} = this.state; const variables = this.props.variables || this.state.variables; const highlightValue = FormulaEditor.highlightValue( @@ -139,46 +125,66 @@ export default class ExpressionFormulaControl extends React.Component< html: formulaPickerValue }; + // 自身字段 + const selfName = this.props?.data?.name; + return (
- {formulaPickerValue ? ( - - ) : ( - - )} - - {formulaPickerOpen ? ( - this.setState({formulaPickerOpen: false})} - onConfirm={this.handleConfirm} - /> - ) : null} + void; + value: any; + }) => { + return ( + + ); + }} + value={formulaPickerValue} + onConfirm={this.handleConfirm} + size="md" + > + {({onClick}: {onClick: (e: React.MouseEvent) => void}) => + formulaPickerValue ? ( + + ) : ( + + ) + } +
); } diff --git a/packages/amis-editor/src/renderer/textarea-formula/plugin.tsx b/packages/amis-editor/src/renderer/textarea-formula/plugin.tsx index 79373b65e..6bc526651 100644 --- a/packages/amis-editor/src/renderer/textarea-formula/plugin.tsx +++ b/packages/amis-editor/src/renderer/textarea-formula/plugin.tsx @@ -206,6 +206,9 @@ export class FormulaPlugin { // bca-disable-next-line popoverEl.innerHTML = highlightValue.html; popoverEl.classList.add('expression-popover'); + const arrow = document.createElement('div'); + arrow.classList.add('expression-popover-arrow'); + popoverEl.appendChild(arrow); text.appendChild(popoverEl); this.editor.markText(from, to, {