koishi-plugin-media-luna 0.0.38 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/ConfigRenderer.vue +45 -7
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -139,6 +139,44 @@ const emit = defineEmits<{
|
|
|
139
139
|
'update:modelValue': [value: Record<string, any>]
|
|
140
140
|
}>()
|
|
141
141
|
|
|
142
|
+
// ============ 嵌套 key 辅助函数 ============
|
|
143
|
+
|
|
144
|
+
// 获取嵌套属性值(支持 'a.b.c' 格式的 key)
|
|
145
|
+
const getNestedValue = (obj: Record<string, any>, key: string): any => {
|
|
146
|
+
if (!key.includes('.')) {
|
|
147
|
+
return obj[key]
|
|
148
|
+
}
|
|
149
|
+
const parts = key.split('.')
|
|
150
|
+
let current = obj
|
|
151
|
+
for (const part of parts) {
|
|
152
|
+
if (current === undefined || current === null) {
|
|
153
|
+
return undefined
|
|
154
|
+
}
|
|
155
|
+
current = current[part]
|
|
156
|
+
}
|
|
157
|
+
return current
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 设置嵌套属性值(支持 'a.b.c' 格式的 key)
|
|
161
|
+
const setNestedValue = (obj: Record<string, any>, key: string, value: any): Record<string, any> => {
|
|
162
|
+
if (!key.includes('.')) {
|
|
163
|
+
return { ...obj, [key]: value }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const parts = key.split('.')
|
|
167
|
+
const result = { ...obj }
|
|
168
|
+
let current = result
|
|
169
|
+
|
|
170
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
171
|
+
const part = parts[i]
|
|
172
|
+
current[part] = current[part] ? { ...current[part] } : {}
|
|
173
|
+
current = current[part]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
current[parts[parts.length - 1]] = value
|
|
177
|
+
return result
|
|
178
|
+
}
|
|
179
|
+
|
|
142
180
|
// ============ 远程选项缓存 ============
|
|
143
181
|
const remoteOptionsCache = ref<Record<string, { label: string; value: any }[]>>({})
|
|
144
182
|
const remoteOptionsLoading = ref<Record<string, boolean>>({})
|
|
@@ -179,7 +217,7 @@ const fetchRemoteOptions = async (source: string, params?: Record<string, any>)
|
|
|
179
217
|
// 获取字段的参数(基于 dependsOn)
|
|
180
218
|
const getFieldParams = (field: ConfigField): Record<string, any> | undefined => {
|
|
181
219
|
if (!field.dependsOn) return undefined
|
|
182
|
-
const dependValue = props.modelValue
|
|
220
|
+
const dependValue = getNestedValue(props.modelValue, field.dependsOn)
|
|
183
221
|
if (dependValue === undefined || dependValue === null || dependValue === '') {
|
|
184
222
|
return undefined
|
|
185
223
|
}
|
|
@@ -229,8 +267,8 @@ onMounted(() => {
|
|
|
229
267
|
watch(() => props.modelValue, (newVal, oldVal) => {
|
|
230
268
|
for (const field of props.fields) {
|
|
231
269
|
if (field.type === 'select-remote' && field.dependsOn && field.optionsSource) {
|
|
232
|
-
const newDependValue = newVal
|
|
233
|
-
const oldDependValue = oldVal
|
|
270
|
+
const newDependValue = getNestedValue(newVal, field.dependsOn)
|
|
271
|
+
const oldDependValue = oldVal ? getNestedValue(oldVal, field.dependsOn) : undefined
|
|
234
272
|
|
|
235
273
|
if (newDependValue !== oldDependValue) {
|
|
236
274
|
// 依赖字段变化,重新加载选项
|
|
@@ -242,12 +280,12 @@ watch(() => props.modelValue, (newVal, oldVal) => {
|
|
|
242
280
|
|
|
243
281
|
// 获取字段值
|
|
244
282
|
const getFieldValue = (key: string) => {
|
|
245
|
-
return props.modelValue
|
|
283
|
+
return getNestedValue(props.modelValue, key)
|
|
246
284
|
}
|
|
247
285
|
|
|
248
286
|
// 设置字段值
|
|
249
287
|
const setFieldValue = (key: string, value: any) => {
|
|
250
|
-
const newValue =
|
|
288
|
+
const newValue = setNestedValue(props.modelValue, key, value)
|
|
251
289
|
emit('update:modelValue', newValue)
|
|
252
290
|
}
|
|
253
291
|
|
|
@@ -261,8 +299,8 @@ const shouldShowField = (field: ConfigField, visited = new Set<string>()): boole
|
|
|
261
299
|
if (visited.has(field.key)) return false
|
|
262
300
|
visited.add(field.key)
|
|
263
301
|
|
|
264
|
-
//
|
|
265
|
-
if (props.modelValue
|
|
302
|
+
// 检查当前条件(支持嵌套 key)
|
|
303
|
+
if (getNestedValue(props.modelValue, dependField) !== value) return false
|
|
266
304
|
|
|
267
305
|
// 递归检查依赖字段的 showWhen 条件
|
|
268
306
|
const dependentField = props.fields.find(f => f.key === dependField)
|