diff --git a/dashboard/src/components/shared/ObjectEditor.vue b/dashboard/src/components/shared/ObjectEditor.vue
index 055bf3310..a2f549210 100644
--- a/dashboard/src/components/shared/ObjectEditor.vue
+++ b/dashboard/src/components/shared/ObjectEditor.vue
@@ -64,6 +64,16 @@
hide-details
color="primary"
>
+
props.modelValue, (newValue) => {
function initializeLocalKeyValuePairs() {
localKeyValuePairs.value = []
for (const [key, value] of Object.entries(props.modelValue)) {
+ let _type = (typeof value) === 'object' ? 'json':(typeof value)
+ let _value = _type === 'json'?JSON.stringify(value):value
localKeyValuePairs.value.push({
key: key,
- value: value,
- type: typeof value // Store the original type
+ value: _value,
+ type: _type
})
}
}
@@ -201,6 +213,9 @@ function addKeyValuePair() {
case 'boolean':
defaultValue = false
break
+ case 'json':
+ defaultValue = "{}"
+ break
default: // string
defaultValue = ""
break
@@ -215,6 +230,15 @@ function addKeyValuePair() {
}
}
+function updateJSON(index, newValue) {
+ try {
+ JSON.parse(newValue)
+ localKeyValuePairs.value[index].jsonError = ''
+ } catch (e) {
+ localKeyValuePairs.value[index].jsonError = 'JSON 格式错误'
+ }
+}
+
function removeKeyValuePair(index) {
localKeyValuePairs.value.splice(index, 1)
}
@@ -241,6 +265,7 @@ function updateKey(index, newKey) {
function confirmDialog() {
const updatedValue = {}
for (const pair of localKeyValuePairs.value) {
+ if (pair.type === 'json' && pair.jsonError) return
let convertedValue = pair.value
// 根据声明的类型进行转换
switch (pair.type) {
@@ -256,6 +281,9 @@ function confirmDialog() {
// 这里直接赋值 pair.value 应该是安全的,因为 v-model 绑定的就是布尔值
// convertedValue = Boolean(pair.value)
break
+ case 'json':
+ convertedValue = JSON.parse(pair.value)
+ break
case 'string':
default:
// 默认转换为字符串