@@ -46,11 +46,25 @@ const plugin = ref<Plugin>({
4646 installed: false ,
4747})
4848
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+
4962const { t } = useI18n ()
5063const [showMore, toggleShowMore] = useBool (false )
5164const pluginsStore = usePluginsStore ()
5265
5366const handleCancel = inject (' cancel' ) as any
67+ const handleSubmit = inject (' submit' ) as any
5468
5569const handleRestore = () => {
5670 if (official .value ) {
@@ -59,15 +73,15 @@ const handleRestore = () => {
5973 }
6074}
6175
62- const handleSubmit = async () => {
76+ const handleSave = async () => {
6377 loading .value = true
6478 try {
6579 if (props .id ) {
6680 await pluginsStore .editPlugin (props .id , plugin .value )
6781 } else {
6882 await pluginsStore .addPlugin (plugin .value )
6983 }
70- handleCancel ()
84+ await handleSubmit ()
7185 } catch (error : any ) {
7286 console .error (error )
7387 message .error (error )
@@ -91,13 +105,13 @@ const handleDelParam = (index: number) => {
91105 plugin .value .configuration .splice (index , 1 )
92106}
93107
94- const hasOption = (component : string ) => {
108+ const hasOption = (component : ComponentType ) => {
95109 return (
96110 component !== ' InputList' && [' CheckBox' , ' InputList' , ' Radio' , ' Select' ].includes (component )
97111 )
98112}
99113
100- const onComponentChange = (component : string , index : number ) => {
114+ const onComponentChange = (component : ComponentType , index : number ) => {
101115 switch (component ) {
102116 case ' CheckBox' :
103117 case ' InputList' : {
@@ -121,7 +135,7 @@ const onComponentChange = (component: string, index: number) => {
121135 break
122136 }
123137 }
124- plugin .value .configuration [index ].component = component as any
138+ plugin .value .configuration [index ].component = component
125139}
126140
127141const getOptions = (val : string []) => {
@@ -163,7 +177,7 @@ const modalSlots = {
163177 ! plugin .value .version ||
164178 ! plugin .value .path ||
165179 (plugin .value .type === ' Http' && ! plugin .value .url ),
166- onClick: handleSubmit ,
180+ onClick: handleSave ,
167181 },
168182 () => t (' common.save' ),
169183 ),
@@ -264,9 +278,12 @@ defineExpose({ modalSlots })
264278 />
265279 </div >
266280 <Divider >{{ t('plugin.configuration') }}</Divider >
267- <div v-draggable =" [plugin.configuration, { ...DraggableOptions, handle: '.drag' }]" >
281+ <div
282+ v-draggable =" [plugin.configuration, { ...DraggableOptions, handle: '.drag' }]"
283+ class =" px-8 flex flex-col gap-8"
284+ >
268285 <template v-for =" (conf , index ) in plugin .configuration " :key =" conf .id " >
269- <Card v-if =" conf.component" :title =" conf.component" class = " mb-8 " >
286+ <Card v-if =" conf.component" :title =" conf.component" >
270287 <template #title-prefix >
271288 <Icon icon =" drag" class =" drag" style =" cursor : move " />
272289 <div class =" ml-8" >{{ index + 1 }}、</div >
@@ -278,15 +295,15 @@ defineExpose({ modalSlots })
278295 </template >
279296 <div class =" form-item" >
280297 {{ t('plugin.confName') }}
281- <Input v-model =" conf.title" placeholder =" title" />
298+ <Input v-model =" conf.title" placeholder =" title" class = " min-w-[75%] " />
282299 </div >
283300 <div class =" form-item" >
284301 {{ t('plugin.confDescription') }}
285- <Input v-model =" conf.description" placeholder =" description" />
302+ <Input v-model =" conf.description" placeholder =" description" class = " min-w-[75%] " />
286303 </div >
287304 <div class =" form-item" >
288305 {{ t('plugin.confKey') }}
289- <Input v-model =" conf.key" placeholder =" key" />
306+ <Input v-model =" conf.key" placeholder =" key" class = " min-w-[75%] " />
290307 </div >
291308 <div class =" form-item" :class =" { 'flex-start': conf.value.length !== 0 }" >
292309 {{ t('plugin.confDefault') }}
@@ -295,6 +312,7 @@ defineExpose({ modalSlots })
295312 v-model =" conf.value"
296313 :options =" getOptions(conf.options)"
297314 editable
315+ :class =" conf.component === 'CodeViewer' ? 'min-w-[75%]' : ''"
298316 />
299317 </div >
300318 <div
@@ -306,28 +324,27 @@ defineExpose({ modalSlots })
306324 <InputList v-model =" conf.options" />
307325 </div >
308326 </Card >
309- <div v-else class =" form-item" >
310- <Select
311- @change =" (val: string) => onComponentChange(val, index)"
312- :options =" [
313- { label: 'CheckBox', value: 'CheckBox' },
314- { label: 'CodeViewer', value: 'CodeViewer' },
315- { label: 'Input', value: 'Input' },
316- { label: 'InputList', value: 'InputList' },
317- { label: 'KeyValueEditor', value: 'KeyValueEditor' },
318- { label: 'Radio', value: 'Radio' },
319- { label: 'Select', value: 'Select' },
320- { label: 'Switch', value: 'Switch' },
321- ]"
322- placeholder =" plugin.selectComponent"
323- />
324- <Button @click =" handleDelParam(index)" size =" small" type =" text" >
325- {{ t('common.delete') }}
326- </Button >
327- </div >
327+ <Card v-else :title =" t('plugin.selectComponent')" >
328+ <template #extra >
329+ <Button @click =" handleDelParam(index)" size =" small" type =" text" >
330+ {{ t('common.delete') }}
331+ </Button >
332+ </template >
333+ <div class =" flex grid grid-cols-4 gap-8" >
334+ <Button
335+ v-for =" item in componentList"
336+ :key =" item"
337+ @click =" onComponentChange(item, index)"
338+ >
339+ {{ item }}
340+ </Button >
341+ </div >
342+ </Card >
328343 </template >
329344 </div >
330- <Button @click =" handleAddParam" type =" primary" icon =" add" class =" w-full" />
345+ <div :class =" plugin.configuration.length !== 0 ? 'mt-8' : ''" class =" mx-8" >
346+ <Button @click =" handleAddParam" type =" primary" icon =" add" class =" w-full" />
347+ </div >
331348 </div >
332349 </div >
333350</template >
0 commit comments