mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
Merge pull request #7217 from hsm-lv/fix-formulaeditor
fix:表达式编辑器数组高亮&限制数组成员变量操作层级
This commit is contained in:
commit
dc196fcd68
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import {themeable, ThemeProps, filterTree} from 'amis-core';
|
import {themeable, ThemeProps, filterTree, getTreeAncestors} from 'amis-core';
|
||||||
import GroupedSelection from '../GroupedSelection';
|
import GroupedSelection from '../GroupedSelection';
|
||||||
import Tabs, {Tab} from '../Tabs';
|
import Tabs, {Tab} from '../Tabs';
|
||||||
import TreeSelection from '../TreeSelection';
|
import TreeSelection from '../TreeSelection';
|
||||||
@ -87,6 +87,13 @@ function VariableList(props: VariableListProps) {
|
|||||||
props.itemRender && typeof props.itemRender === 'function'
|
props.itemRender && typeof props.itemRender === 'function'
|
||||||
? props.itemRender
|
? props.itemRender
|
||||||
: (option: Option, states: ItemRenderStates): JSX.Element => {
|
: (option: Option, states: ItemRenderStates): JSX.Element => {
|
||||||
|
// 控制只对第一层数组成员展示快捷操作入口
|
||||||
|
if (option.isMember) {
|
||||||
|
const arrs: any = getTreeAncestors(list, option as any);
|
||||||
|
option.memberDepth = arrs?.filter(
|
||||||
|
(item: Option) => item.type === 'array'
|
||||||
|
)?.length;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={cx(`${classPrefix}-item`, itemClassName)}>
|
<div className={cx(`${classPrefix}-item`, itemClassName)}>
|
||||||
@ -113,7 +120,7 @@ function VariableList(props: VariableListProps) {
|
|||||||
<label>{option.label}</label>
|
<label>{option.label}</label>
|
||||||
</TooltipWrapper>
|
</TooltipWrapper>
|
||||||
)}
|
)}
|
||||||
{option?.isMember ? (
|
{option.memberDepth < 2 ? (
|
||||||
<PopOverContainer
|
<PopOverContainer
|
||||||
popOverContainer={() => document.querySelector('body')}
|
popOverContainer={() => document.querySelector('body')}
|
||||||
popOverRender={({onClose}) => (
|
popOverRender={({onClose}) => (
|
||||||
@ -153,10 +160,14 @@ function VariableList(props: VariableListProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleMemberClick(item: any, option: any, onClose?: any) {
|
function handleMemberClick(item: any, option: any, onClose?: any) {
|
||||||
const pathArr = option.value.split('.');
|
// todo:暂时只提供一层的快捷操作
|
||||||
|
const lastPointIdx = option.value.lastIndexOf('.');
|
||||||
|
const arr = option.value.substring(0, lastPointIdx);
|
||||||
|
const member = option.value.substring(lastPointIdx + 1);
|
||||||
|
|
||||||
const value = item.value
|
const value = item.value
|
||||||
.replace('${arr}', pathArr[0])
|
.replace('${arr}', arr)
|
||||||
.replace('${member}', pathArr[1]);
|
.replace('${member}', member);
|
||||||
|
|
||||||
onClose?.();
|
onClose?.();
|
||||||
onSelect?.({
|
onSelect?.({
|
||||||
|
Loading…
Reference in New Issue
Block a user