1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
| <script lang="ts" setup>
| import type { TabsProps } from 'ant-design-vue';
|
| import type { Ref } from 'vue';
|
| import { onMounted, ref } from 'vue';
|
| import {
| Button,
| Form,
| FormItem,
| Input,
| message,
| Switch,
| TabPane,
| Tabs,
| } from 'ant-design-vue';
|
| import { addConfig, listConfig } from '#/api/system/configurationManage';
|
| interface ConfigItem {
| category: string;
| configName: string;
| configValue: string;
| configDict: string;
| id: string;
| }
|
| interface TabsData {
| chat: ConfigItem[];
| mail: ConfigItem[];
| pay: ConfigItem[];
| review: ConfigItem[];
| sys: ConfigItem[];
| weaviate: ConfigItem[];
| }
|
| interface ConfigResponseItem {
| category: keyof TabsData;
| configName: string;
| configValue: string;
| id: string;
| }
|
| const tabsData: Ref<TabsData> = ref({
| chat: [
| {
| category: 'chat',
| configName: 'apiKey',
| configValue: '',
| configDict: 'API 密钥',
| id: '',
| },
| {
| category: 'chat',
| configName: 'apiHost',
| configValue: '',
| configDict: 'API 地址',
| id: '',
| },
| ],
| mail: [
| {
| category: 'mail',
| configName: 'host',
| configValue: '',
| configDict: '主机地址',
| id: '',
| },
| {
| category: 'mail',
| configName: 'port',
| configValue: '',
| configDict: '主机端口',
| id: '',
| },
| {
| category: 'mail',
| configName: 'from',
| configValue: '',
| configDict: '发送方',
| id: '',
| },
| {
| category: 'mail',
| configName: 'user',
| configValue: '',
| configDict: '用户名',
| id: '',
| },
| {
| category: 'mail',
| configName: 'pass',
| configValue: '',
| configDict: '授权码',
| id: '',
| },
| {
| category: 'mail',
| configName: 'mailTitle',
| configValue: '',
| configDict: '邮箱标题',
| id: '',
| },
| {
| category: 'mail',
| configName: 'mailModel',
| configValue: '',
| configDict: '邮箱模板',
| id: '',
| },
| ],
| pay: [
| {
| category: 'pay',
| configName: 'pid',
| configValue: '',
| configDict: '商户PID',
| id: '',
| },
| {
| category: 'pay',
| configName: 'key',
| configValue: '',
| configDict: '商户密钥',
| id: '',
| },
| {
| category: 'pay',
| configName: 'payUrl',
| configValue: '',
| configDict: '支付地址',
| id: '',
| },
| {
| category: 'pay',
| configName: 'notify_url',
| configValue: '',
| configDict: '回调地址',
| id: '',
| },
| ],
| review: [
| {
| category: 'review',
| configName: 'apiKey',
| configValue: '',
| configDict: 'apiKey',
| id: '',
| },
| {
| category: 'review',
| configName: 'secretKey',
| configValue: '',
| configDict: 'secretKey',
| id: '',
| },
| {
| category: 'review',
| configName: 'enabled',
| configValue: '',
| configDict: '文本审核',
| id: '',
| },
| ],
| weaviate: [
| {
| category: 'weaviate',
| configName: 'protocol',
| configValue: '',
| configDict: '协议',
| id: '',
| },
| {
| category: 'weaviate',
| configName: 'host',
| configValue: '',
| configDict: '地址',
| id: '',
| },
| {
| category: 'weaviate',
| configName: 'classname',
| configValue: '',
| configDict: '分类名称',
| id: '',
| },
| ],
| sys: [
| {
| category: 'sys',
| configName: 'name',
| configValue: '',
| configDict: '网站名称',
| id: '',
| },
| {
| category: 'sys',
| configName: 'logoImage',
| configValue: '',
| configDict: '网站logo',
| id: '',
| },
| {
| category: 'sys',
| configName: 'copyright',
| configValue: '',
| configDict: '版权信息',
| id: '',
| },
| {
| category: 'sys',
| configName: 'customImage',
| configValue: '',
| configDict: '客服二维码',
| id: '',
| },
| ],
| });
|
| onMounted(() => {
| getConfig();
| });
|
| // 定义获取配置的方法
| async function getConfig() {
| try {
| const res: ConfigResponseItem[] = await listConfig();
| res.rows.forEach((item) => {
| if (tabsData.value[item.category]) {
| tabsData.value[item.category].forEach((items: ConfigItem) => {
| if (items.configName === item.configName) {
| items.configValue = item.configValue;
| items.id = item.id;
| }
| });
| }
| });
| handleChange(activeKey.value);
| } catch (error) {
| console.error('获取配置信息失败:', error);
| }
| }
|
| const activeKey = ref('1');
| const tabPosition = ref<TabsProps['tabPosition']>('left');
| const tabList = ref([
| {
| key: '1',
| label: '基础配置',
| data: tabsData.value.chat,
| },
| {
| key: '2',
| label: '邮箱配置',
| data: tabsData.value.mail,
| },
| {
| key: '3',
| label: '支付配置',
| data: tabsData.value.pay,
| },
| {
| key: '4',
| label: '百度配置',
| data: tabsData.value.review,
| },
| {
| key: '5',
| label: '系统配置',
| data: tabsData.value.sys,
| },
| {
| key: '6',
| label: '向量库配置',
| data: tabsData.value.weaviate,
| },
| ]);
|
| const formData = ref<Record<string, boolean | string>>({});
| const handleSubmit = () => {
| const name = getTabName();
| addConfig(tabsData.value[name]).then(() => {
| message.success('保存成功');
| });
| };
| const handleChange = (key: number | string) => {
| const currentTab = tabList.value.find((tab) => tab.key === String(key));
| if (currentTab) {
| formData.value = {}; // 清空之前的表单数据
| currentTab.data.forEach((item) => {
| formData.value[item.configName] = item.configValue;
| });
| }
| };
|
| function getTabName() {
| let name: keyof typeof tabsData.value = 'chat';
| switch (activeKey.value) {
| case '1': {
| name = 'chat';
|
| break;
| }
| case '2': {
| name = 'mail';
|
| break;
| }
| case '3': {
| name = 'pay';
|
| break;
| }
| case '4': {
| name = 'review';
|
| break;
| }
| case '5': {
| name = 'sys';
|
| break;
| }
| case '6': {
| name = 'weaviate';
|
| break;
| }
| // No default
| }
| return name;
| }
|
| const handleBlur = (item: any, value: string) => {
| const name = getTabName();
| tabsData.value[name].forEach((items: any) => {
| if (items.configName === item.configName) {
| items.configValue = value;
| }
| });
| };
| </script>
|
| <template>
| <div class="configuration-manage">
| <Tabs
| v-model:active-key="activeKey"
| :tab-position="tabPosition"
| type="card"
| @change="handleChange"
| >
| <TabPane v-for="item in tabList" :key="item.key" :tab="item.label">
| <Form :label-col="{ span: 2 }" :model="formData">
| <div>
| <FormItem
| v-for="items in item.data"
| :key="items.id"
| :label="items.configDict"
| :name="items.configName"
| >
| <template v-if="items.configName === 'enabled'">
| <Switch
| v-model:checked="formData[items.configName] as boolean"
| />
| </template>
| <template v-else>
| <Input
| v-model:value="formData[items.configName] as string"
| @blur="
| handleBlur(items, formData[items.configName] as string)
| "
| />
| </template>
| </FormItem>
| </div>
| <FormItem style="text-align: center">
| <Button type="primary" @click="handleSubmit">保存</Button>
| </FormItem>
| </Form>
| </TabPane>
| </Tabs>
| </div>
| </template>
|
| <style lang="less" scoped>
| .configuration-manage {
| padding: 10px;
| height: 100%;
| }
| </style>
|
|