fix(editor): 数据源模板输入框输入数字索引后浏览器卡死

fix #611
This commit is contained in:
roymondchen 2024-05-29 19:57:14 +08:00
parent ee269917f8
commit a66da8de9e
2 changed files with 26 additions and 13 deletions

View File

@ -54,6 +54,7 @@ import { Coin } from '@element-plus/icons-vue';
import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
import type { FieldProps, FormItem } from '@tmagic/form';
import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
import { isNumber } from '@tmagic/utils';
import Icon from '@editor/components/Icon.vue';
import type { Services } from '@editor/type';
@ -209,7 +210,7 @@ const fieldQuerySearch = (
const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
// xx.xx.xx
const keys = dsKey.split('.');
const keys = dsKey.replaceAll(/\[(\d+)\]/g, '.$1').split('.');
// id
const dsId = keys.shift();
@ -224,6 +225,11 @@ const fieldQuerySearch = (
//
let key = keys.shift();
while (key) {
if (isNumber(key)) {
key = keys.shift();
continue;
}
for (const field of fields) {
if (field.name === key) {
fields = field.fields || [];

View File

@ -1,5 +1,6 @@
import { CascaderOption, FormConfig, FormState } from '@tmagic/form';
import { DataSchema, DataSourceFieldType, DataSourceSchema } from '@tmagic/schema';
import { isNumber } from '@tmagic/utils';
import BaseFormConfig from './formConfigs/base';
import HttpFormConfig from './formConfigs/http';
@ -165,20 +166,26 @@ export const getDisplayField = (dataSources: DataSourceSchema[], key: string) =>
let dsText = '';
let ds: DataSourceSchema | undefined;
let fields: DataSchema[] | undefined;
// 将模块解析成数据源对应的值
match[1].split('.').forEach((item, index) => {
if (index === 0) {
ds = dataSources.find((ds) => ds.id === item);
dsText += ds?.title || item;
fields = ds?.fields;
return;
}
match[1]
.replaceAll(/\[(\d+)\]/g, '.$1')
.split('.')
.forEach((item, index) => {
if (index === 0) {
ds = dataSources.find((ds) => ds.id === item);
dsText += ds?.title || item;
fields = ds?.fields;
return;
}
const field = fields?.find((field) => field.name === item);
fields = field?.fields;
dsText += `.${field?.title || item}`;
});
if (isNumber(item)) {
dsText += `[${item}]`;
} else {
const field = fields?.find((field) => field.name === item);
fields = field?.fields;
dsText += `.${field?.title || item}`;
}
});
displayState.push({
type: 'var',