Skip to content

Commit ec44c2e

Browse files
committed
✨ feat: 初步实现可视化编辑 object 配置项
1 parent b7a9e50 commit ec44c2e

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

astrbot/core/config/default.py

+1
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@
695695
"temperature": {"description": "温度", "type": "float"},
696696
"top_p": {"description": "Top P值", "type": "float"},
697697
},
698+
"editable": True,
698699
},
699700
"dify_api_key": {
700701
"description": "API Key",

dashboard/src/components/shared/AstrBotConfig.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,23 @@
120120
</div>
121121
</div>
122122
</div>
123+
124+
<div v-if="metadata[metadataKey]?.editable && metadata[metadataKey]?.type === 'object'">
125+
<!-- 可编辑键值对 -->
126+
<ObjectConfigItem :object="iterable" :metadata="metadata[metadataKey].items"></ObjectConfigItem>
127+
</div>
123128
</v-card-text>
124129
</template>
125130

126131
<script>
127132
import { readonly } from 'vue';
128133
import ListConfigItem from './ListConfigItem.vue';
134+
import ObjectConfigItem from './ObjectConfigItem.vue';
129135
130136
export default {
131137
components: {
132-
ListConfigItem
138+
ListConfigItem,
139+
ObjectConfigItem
133140
},
134141
props: {
135142
metadata: Object,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<template>
2+
3+
<span :style="{ color: isAddMode ? '#000' : 'gray', 'margin-right': '8px' }" @click="toggleMode('add')">添加键</span>
4+
<span :style="{ color: !isAddMode ? '#000' : 'gray' }" @click="toggleMode('delete')">删除键</span>
5+
<div style="display: flex; margin-top: 8px; gap: 16px; align-items:center">
6+
<!-- {{ items }} -->
7+
<v-text-field v-model="newItemKey" label="键名" style="max-width: 250px;" density="compact"
8+
prepend-inner-icon="mdi-alpha-k" variant="solo-filled" flat hide-details single-line
9+
rounded="md"></v-text-field>
10+
<v-select v-if="isAddMode" hint="类型" style="max-width: 150px;" rounded="md" density="compact" v-model="newItemType" :items="typeOptions"
11+
prepend-inner-icon="mdi-alpha-t" variant="solo-filled" flat hide-details single-line>
12+
</v-select>
13+
<v-btn @click="apply" variant="tonal">
14+
确定
15+
</v-btn>
16+
<small color="error">{{ error }}</small>
17+
</div>
18+
</template>
19+
20+
<script>
21+
export default {
22+
name: 'ObjectConfigItem',
23+
props: {
24+
object: {
25+
type: Object,
26+
default: () => ({}),
27+
},
28+
metadata: {
29+
type: Object,
30+
default: () => ({}),
31+
},
32+
},
33+
data() {
34+
return {
35+
items: this.object,
36+
metadata: this.metadata,
37+
newItemKey: '',
38+
newItemType: 'string',
39+
typeOptions: [
40+
'string',
41+
'int',
42+
'float',
43+
'text',
44+
'bool',
45+
'list',
46+
'object',
47+
],
48+
error: '',
49+
isAddMode: true, // 默认模式为添加键
50+
51+
defaultValues: {
52+
string: '',
53+
int: 0,
54+
float: 0.0,
55+
text: '',
56+
bool: false,
57+
list: [],
58+
object: {},
59+
},
60+
};
61+
},
62+
methods: {
63+
toggleMode(mode) {
64+
this.isAddMode = (mode === 'add');
65+
this.newItemKey = '';
66+
this.error = '';
67+
},
68+
apply() {
69+
if (this.newItemKey === '') {
70+
this.error = '键不能为空';
71+
return;
72+
}
73+
if (this.isAddMode) {
74+
if (this.items[this.newItemKey]) {
75+
this.error = '键已存在';
76+
return;
77+
}
78+
if (!this.newItemType) {
79+
this.error = '请选择类型';
80+
return;
81+
}
82+
this.items[this.newItemKey] = this.defaultValues[this.newItemType];
83+
this.metadata[this.newItemKey] = {
84+
type: this.newItemType,
85+
description: this.newItemKey,
86+
};
87+
this.newItemType = 'string';
88+
} else {
89+
delete this.items[this.newItemKey];
90+
delete this.metadata[this.newItemKey];
91+
}
92+
this.newItemKey = '';
93+
this.error = '';
94+
},
95+
},
96+
};
97+
</script>
98+
99+
<style></style>

0 commit comments

Comments
 (0)