fix(editor): 数据源字符串模板提示出错

fix #530
This commit is contained in:
roymondchen 2023-08-14 14:34:15 +08:00
parent babaadb0cf
commit 07a02714df

View File

@ -89,11 +89,13 @@ const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
const setDisplayState = () => {
displayState.value = [];
// es6
const matches = state.value.matchAll(/\$\{([\s\S]+?)\}/g);
let index = 0;
for (const match of matches) {
if (typeof match.index === 'undefined') break;
//
displayState.value.push({
type: 'text',
value: state.value.substring(index, match.index),
@ -103,6 +105,7 @@ const setDisplayState = () => {
let ds: DataSourceSchema | undefined;
let fields: DataSchema[] | undefined;
//
match[1].split('.').forEach((item, index) => {
if (index === 0) {
ds = dataSources.value.find((ds) => ds.id === item);
@ -243,17 +246,21 @@ const fieldQuerySearch = (
let result: DataSchema[] = [];
const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
// xx.xx.xx
const keys = dsKey.split('.');
// id
const ds = dataSources.value.find((ds) => ds.id === keys.shift());
const dsId = keys.shift();
const ds = dataSources.value.find((ds) => ds.id === dsId);
if (!ds) {
cb([]);
return;
}
let fields = ds.fields || [];
//
//
let key = keys.shift();
while (key) {
for (const field of fields) {