From 511b6df9d4fff237dc58c2cc2fc81331ffd4acbc Mon Sep 17 00:00:00 2001
From: miaomiao <13407923955@163.com>
Date: Wed, 25 Oct 2023 18:32:05 +0800
Subject: [PATCH] =?UTF-8?q?feat:bkvue2=E7=BB=84=E4=BB=B6,=E6=97=B6?=
=?UTF-8?q?=E9=97=B4=E8=BD=B4&=E6=A0=91=20=E7=BB=84=E4=BB=B6=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E5=AF=B9=E5=BA=94=E8=8E=B7=E5=8F=96=E5=8F=8D=E9=A6=88?=
=?UTF-8?q?key?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../render/pc/tools/lesscode-loading/index.js | 17 ++
.../materials/vue2/bk/search-select/index.js | 2 +
.../materials/vue2/bk/timeline/index.js | 4 +
.../materials/vue2/bk/tree/index.js | 15 +-
.../props/components/common/select-key.vue | 159 ++++++++++++++++++
.../props/components/render-prop.vue | 82 +++++++--
.../components/strategy/value-key-option.vue | 2 +-
lib/shared/page-code/common/modelMethods.js | 9 +-
lib/shared/page-code/index.js | 4 +-
lib/shared/page-code/script/vue2/methods.js | 14 ++
lib/shared/page-code/template/page/prop.js | 4 +-
11 files changed, 286 insertions(+), 26 deletions(-)
create mode 100644 lib/client/src/element-materials/modifier/component/props/components/common/select-key.vue
diff --git a/lib/client/src/components/render/pc/tools/lesscode-loading/index.js b/lib/client/src/components/render/pc/tools/lesscode-loading/index.js
index 1d98f42b5..4a37541ec 100644
--- a/lib/client/src/components/render/pc/tools/lesscode-loading/index.js
+++ b/lib/client/src/components/render/pc/tools/lesscode-loading/index.js
@@ -81,6 +81,18 @@ export default {
}
}
+ const processChildren = (obj, valueKeys) => {
+ if (obj.children && Array.isArray(obj.children)) {
+ obj.children = obj.children.map(child => processChildren(child, valueKeys))
+ }
+ const newObj = { ...obj }
+ for (const key in valueKeys) {
+ newObj[key] = valueKeys[key] ? obj[valueKeys[key]] : obj[key]
+ }
+
+ return newObj
+ }
+
// 监听变量的变化
const watchVariable = (data, key, staticValue) => {
const {
@@ -127,6 +139,11 @@ export default {
if (typeof val === typeof data.renderValue || typeof val === typeof data.code) {
data.renderValue = val
data.code = val
+ if (Object.keys(data.valueKeys).length > 0) {
+ const valResult = val.map(item => processChildren(item, data.valueKeys))
+ data.renderValue = valResult
+ data.code = valResult
+ }
}
})
// 更新event
diff --git a/lib/client/src/element-materials/materials/vue2/bk/search-select/index.js b/lib/client/src/element-materials/materials/vue2/bk/search-select/index.js
index 8ccf2539a..a20473764 100644
--- a/lib/client/src/element-materials/materials/vue2/bk/search-select/index.js
+++ b/lib/client/src/element-materials/materials/vue2/bk/search-select/index.js
@@ -131,11 +131,13 @@ export default {
'display-key': {
type: 'value-key-item',
dataOrigin: 'data',
+ val: 'name',
tips: '显示的字段名称'
},
'primary-key': {
type: 'value-key-item',
dataOrigin: 'data',
+ val: 'id',
tips: '应用的唯一id字段名称'
},
values: {
diff --git a/lib/client/src/element-materials/materials/vue2/bk/timeline/index.js b/lib/client/src/element-materials/materials/vue2/bk/timeline/index.js
index dff9ccd67..2fda41ef9 100644
--- a/lib/client/src/element-materials/materials/vue2/bk/timeline/index.js
+++ b/lib/client/src/element-materials/materials/vue2/bk/timeline/index.js
@@ -47,6 +47,10 @@ export default {
remoteValidate (data) {
if (!Array.isArray(data)) return '返回值需要是数组'
},
+ keys: [
+ { id: 'tag', label: '标题', tips: '选项的值,不填取 tag 字段' },
+ { id: 'content', label: '内容', tips: '选项展示的名称,不填取 content 字段' }
+ ],
val: [
{ tag: '一天前', content: '由张三上线到蓝鲸市场' },
{ tag: '16:59', content: '
diff --git a/lib/client/src/element-materials/modifier/component/props/components/strategy/value-key-option.vue b/lib/client/src/element-materials/modifier/component/props/components/strategy/value-key-option.vue
index 3f4b2b2ca..4f142b127 100644
--- a/lib/client/src/element-materials/modifier/component/props/components/strategy/value-key-option.vue
+++ b/lib/client/src/element-materials/modifier/component/props/components/strategy/value-key-option.vue
@@ -90,7 +90,7 @@
},
methods: {
trigger (value) {
- this.change(this.name, value, this.type, this.payload)
+ this.change(this.name, JSON.parse(JSON.stringify(value)), this.type, this.payload)
},
changeParams (val, key) {
this.trigger({
diff --git a/lib/shared/page-code/common/modelMethods.js b/lib/shared/page-code/common/modelMethods.js
index 5e955223e..105c190fa 100644
--- a/lib/shared/page-code/common/modelMethods.js
+++ b/lib/shared/page-code/common/modelMethods.js
@@ -39,7 +39,7 @@ export function dataTemplate (code, key, value) {
* @param { Object } payload 放置远程函数相关的信息
* @param { Boolean } isChartType 是否是图表组件相关函数
*/
-export function remoteMethodsTemplate (code, key, payload, chartType = false) {
+export function remoteMethodsTemplate (code, key, payload, chartType = false, valueKeys) {
const [method, params] = getMethodByCode(payload, code.funcGroups)
if (method.id) {
let newValue = code.remoteDataStr
@@ -48,7 +48,12 @@ export function remoteMethodsTemplate (code, key, payload, chartType = false) {
? `const ${key}Remote = await this.${method.funcName}(${getFuncParamStr(code, method, params, `${sharedI18n().t('远程函数')}【${method.funcName}】`, true)})\nthis.$set(this, '${key}', ${key}Remote)\n`
: `const ${key}Remote = await this.${method.funcName}(${getFuncParamStr(code, method, params, `${sharedI18n().t('远程函数')}【${method.funcName}】`, true)})\nObject.assign(this.${key}, ${key}Remote)\n`
} else {
- newValue += `this.${key} = await this.${method.funcName}(${getFuncParamStr(code, method, params, `${sharedI18n().t('远程函数')}【${method.funcName}】`, true)})\n`
+ if (Object.keys(valueKeys).length > 0) {
+ const valueKeysObj = JSON.stringify(valueKeys)
+ newValue += `this.${key} = (await this.${method.funcName}(${getFuncParamStr(code, method, params, `${sharedI18n().t('远程函数')}【${method.funcName}】`, true)})).map(item => this.processChildren(item, ${valueKeysObj}))\n`
+ } else {
+ newValue += `this.${key} = await this.${method.funcName}(${getFuncParamStr(code, method, params, `${sharedI18n().t('远程函数')}【${method.funcName}】`, true)})\n`
+ }
}
setProperty(code, 'remoteDataStr', newValue)
}
diff --git a/lib/shared/page-code/index.js b/lib/shared/page-code/index.js
index b12c7ea44..b05d96b7a 100644
--- a/lib/shared/page-code/index.js
+++ b/lib/shared/page-code/index.js
@@ -149,8 +149,8 @@ class NewPageCode {
* @param { Object } payload 放置远程函数相关的信息
* @param { Boolean } isChartType 是否是图表组件相关函数
*/
- remoteMethodsTemplate (key, payload, isChartType = false) {
- remoteMethodsTemplate(this, key, payload, isChartType)
+ remoteMethodsTemplate (key, payload, isChartType = false, valueKeys) {
+ remoteMethodsTemplate(this, key, payload, isChartType, valueKeys)
}
/**
diff --git a/lib/shared/page-code/script/vue2/methods.js b/lib/shared/page-code/script/vue2/methods.js
index 21643a46f..2d69c68ec 100644
--- a/lib/shared/page-code/script/vue2/methods.js
+++ b/lib/shared/page-code/script/vue2/methods.js
@@ -29,6 +29,20 @@ export default function (code) {
},
`
}
+ // 数据源字段映射处理方法
+ if (code.remoteDataStr.includes('processChildren')) {
+ methodsCon += `processChildren (obj, valueKeys) {
+ if (obj.children && Array.isArray(obj.children)) {
+ obj.children = obj.children.map(child => this.processChildren(child, valueKeys))
+ }
+ const newObj = { ...obj }
+ for (const key in valueKeys) {
+ newObj[key] = valueKeys[key] ? obj[valueKeys[key]] : obj[key]
+ }
+
+ return newObj
+ },`
+ }
// 事件描述
if (code.eventActionList?.length > 0) {
diff --git a/lib/shared/page-code/template/page/prop.js b/lib/shared/page-code/template/page/prop.js
index 17d5cf1e6..910173dd1 100644
--- a/lib/shared/page-code/template/page/prop.js
+++ b/lib/shared/page-code/template/page/prop.js
@@ -58,7 +58,7 @@ function getPropsStr (code, type, compId, props, dirProps, slots) {
compId = `${preCompId}${camelCase(i, { transform: camelCaseTransformMerge })}`
if (i === 'value') modelComId = compId
- const { valueType: type, modifiers = [], renderValue, buildInVariableType, payload = {}, directive = '' } = props[i]
+ const { valueType: type, valueKeys, modifiers = [], renderValue, buildInVariableType, payload = {}, directive = '' } = props[i]
const { sourceData = {}, customVariableCode = '' } = payload
let { format, code: val } = props[i]
@@ -140,7 +140,7 @@ function getPropsStr (code, type, compId, props, dirProps, slots) {
} else if (type === 'remote' && payload.methodCode) {
const curDir = dirProps.find((directive) => (directive.prop === i))
const key = (curDir || {}).code || propVar
- code.remoteMethodsTemplate(key, payload || {})
+ code.remoteMethodsTemplate(key, payload || {}, false, valueKeys)
if (!curDir) {
!useCustomVariable && code.dataTemplate(propVar, JSON.stringify([]))
propsStr += curPropStr