From 07a02714df4ba4370f4a8cd4eaf1467db2be1069 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 14 Aug 2023 14:34:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A8=A1=E6=9D=BF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #530 --- packages/editor/src/fields/DataSourceInput.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/fields/DataSourceInput.vue b/packages/editor/src/fields/DataSourceInput.vue index d262f4cb..fd79d8c4 100644 --- a/packages/editor/src/fields/DataSourceInput.vue +++ b/packages/editor/src/fields/DataSourceInput.vue @@ -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) {