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

View File

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