@@ -46,11 +46,25 @@ const plugin = ref<Plugin>({
46
46
installed: false ,
47
47
})
48
48
49
+ const componentList = [
50
+ ' CheckBox' ,
51
+ ' CodeViewer' ,
52
+ ' Input' ,
53
+ ' InputList' ,
54
+ ' KeyValueEditor' ,
55
+ ' Radio' ,
56
+ ' Select' ,
57
+ ' Switch' ,
58
+ ] as const
59
+
60
+ type ComponentType = (typeof componentList )[number ]
61
+
49
62
const { t } = useI18n ()
50
63
const [showMore, toggleShowMore] = useBool (false )
51
64
const pluginsStore = usePluginsStore ()
52
65
53
66
const handleCancel = inject (' cancel' ) as any
67
+ const handleSubmit = inject (' submit' ) as any
54
68
55
69
const handleRestore = () => {
56
70
if (official .value ) {
@@ -59,15 +73,15 @@ const handleRestore = () => {
59
73
}
60
74
}
61
75
62
- const handleSubmit = async () => {
76
+ const handleSave = async () => {
63
77
loading .value = true
64
78
try {
65
79
if (props .id ) {
66
80
await pluginsStore .editPlugin (props .id , plugin .value )
67
81
} else {
68
82
await pluginsStore .addPlugin (plugin .value )
69
83
}
70
- handleCancel ()
84
+ await handleSubmit ()
71
85
} catch (error : any ) {
72
86
console .error (error )
73
87
message .error (error )
@@ -91,13 +105,13 @@ const handleDelParam = (index: number) => {
91
105
plugin .value .configuration .splice (index , 1 )
92
106
}
93
107
94
- const hasOption = (component : string ) => {
108
+ const hasOption = (component : ComponentType ) => {
95
109
return (
96
110
component !== ' InputList' && [' CheckBox' , ' InputList' , ' Radio' , ' Select' ].includes (component )
97
111
)
98
112
}
99
113
100
- const onComponentChange = (component : string , index : number ) => {
114
+ const onComponentChange = (component : ComponentType , index : number ) => {
101
115
switch (component ) {
102
116
case ' CheckBox' :
103
117
case ' InputList' : {
@@ -121,7 +135,7 @@ const onComponentChange = (component: string, index: number) => {
121
135
break
122
136
}
123
137
}
124
- plugin .value .configuration [index ].component = component as any
138
+ plugin .value .configuration [index ].component = component
125
139
}
126
140
127
141
const getOptions = (val : string []) => {
@@ -163,7 +177,7 @@ const modalSlots = {
163
177
! plugin .value .version ||
164
178
! plugin .value .path ||
165
179
(plugin .value .type === ' Http' && ! plugin .value .url ),
166
- onClick: handleSubmit ,
180
+ onClick: handleSave ,
167
181
},
168
182
() => t (' common.save' ),
169
183
),
@@ -262,9 +276,12 @@ defineExpose({ modalSlots })
262
276
/>
263
277
</div >
264
278
<Divider >{{ t('plugin.configuration') }}</Divider >
265
- <div v-draggable =" [plugin.configuration, { ...DraggableOptions, handle: '.drag' }]" >
279
+ <div
280
+ v-draggable =" [plugin.configuration, { ...DraggableOptions, handle: '.drag' }]"
281
+ class =" px-8 flex flex-col gap-8"
282
+ >
266
283
<template v-for =" (conf , index ) in plugin .configuration " :key =" conf .id " >
267
- <Card v-if =" conf.component" :title =" conf.component" class = " mb-8 " >
284
+ <Card v-if =" conf.component" :title =" conf.component" >
268
285
<template #title-prefix >
269
286
<Icon icon =" drag" class =" drag" style =" cursor : move " />
270
287
<div class =" ml-8" >{{ index + 1 }}、</div >
@@ -276,15 +293,15 @@ defineExpose({ modalSlots })
276
293
</template >
277
294
<div class =" form-item" >
278
295
{{ t('plugin.confName') }}
279
- <Input v-model =" conf.title" placeholder =" title" />
296
+ <Input v-model =" conf.title" placeholder =" title" class = " min-w-[75%] " />
280
297
</div >
281
298
<div class =" form-item" >
282
299
{{ t('plugin.confDescription') }}
283
- <Input v-model =" conf.description" placeholder =" description" />
300
+ <Input v-model =" conf.description" placeholder =" description" class = " min-w-[75%] " />
284
301
</div >
285
302
<div class =" form-item" >
286
303
{{ t('plugin.confKey') }}
287
- <Input v-model =" conf.key" placeholder =" key" />
304
+ <Input v-model =" conf.key" placeholder =" key" class = " min-w-[75%] " />
288
305
</div >
289
306
<div class =" form-item" :class =" { 'items-start': conf.value.length !== 0 }" >
290
307
{{ t('plugin.confDefault') }}
@@ -293,6 +310,7 @@ defineExpose({ modalSlots })
293
310
v-model =" conf.value"
294
311
:options =" getOptions(conf.options)"
295
312
editable
313
+ :class =" conf.component === 'CodeViewer' ? 'min-w-[75%]' : ''"
296
314
/>
297
315
</div >
298
316
<div
@@ -304,28 +322,28 @@ defineExpose({ modalSlots })
304
322
<InputList v-model =" conf.options" />
305
323
</div >
306
324
</Card >
307
- <div v-else class =" form-item" >
308
- <Select
309
- @change =" (val: string) => onComponentChange(val, index)"
310
- :options =" [
311
- { label: 'CheckBox', value: 'CheckBox' },
312
- { label: 'CodeViewer', value: 'CodeViewer' },
313
- { label: 'Input', value: 'Input' },
314
- { label: 'InputList', value: 'InputList' },
315
- { label: 'KeyValueEditor', value: 'KeyValueEditor' },
316
- { label: 'Radio', value: 'Radio' },
317
- { label: 'Select', value: 'Select' },
318
- { label: 'Switch', value: 'Switch' },
319
- ]"
320
- placeholder =" plugin.selectComponent"
321
- />
322
- <Button @click =" handleDelParam(index)" size =" small" type =" text" >
323
- {{ t('common.delete') }}
324
- </Button >
325
- </div >
325
+ <Card v-else :title =" t('plugin.selectComponent')" >
326
+ <template #extra >
327
+ <Button @click =" handleDelParam(index)" size =" small" type =" text" >
328
+ {{ t('common.delete') }}
329
+ </Button >
330
+ </template >
331
+ <div class =" flex grid grid-cols-4 gap-8" >
332
+ <Button
333
+ v-for =" item in componentList"
334
+ :key =" item"
335
+ @click =" onComponentChange(item, index)"
336
+ >
337
+ {{ item }}
338
+ </Button >
339
+ </div >
340
+ </Card >
326
341
</template >
327
342
</div >
328
- <Button @click =" handleAddParam" type =" primary" icon =" add" class =" w-full" />
343
+
344
+ <div :class =" plugin.configuration.length !== 0 ? 'mt-8' : ''" class =" mx-8" >
345
+ <Button @click =" handleAddParam" type =" primary" icon =" add" class =" w-full" />
346
+ </div >
329
347
</div >
330
348
</div >
331
349
</template >
0 commit comments