Skip to content

Commit 63f8457

Browse files
committed
feat: enhance PluginForm component with improved configuration handling and UI updates
1 parent 01ff6cc commit 63f8457

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

frontend/src/views/PluginsView/components/PluginForm.vue

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4962
const { t } = useI18n()
5063
const [showMore, toggleShowMore] = useBool(false)
5164
const pluginsStore = usePluginsStore()
5265
5366
const handleCancel = inject('cancel') as any
67+
const handleSubmit = inject('submit') as any
5468
5569
const 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
127141
const 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
),
@@ -262,9 +276,12 @@ defineExpose({ modalSlots })
262276
/>
263277
</div>
264278
<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+
>
266283
<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">
268285
<template #title-prefix>
269286
<Icon icon="drag" class="drag" style="cursor: move" />
270287
<div class="ml-8">{{ index + 1 }}、</div>
@@ -276,15 +293,15 @@ defineExpose({ modalSlots })
276293
</template>
277294
<div class="form-item">
278295
{{ t('plugin.confName') }}
279-
<Input v-model="conf.title" placeholder="title" />
296+
<Input v-model="conf.title" placeholder="title" class="min-w-[75%]" />
280297
</div>
281298
<div class="form-item">
282299
{{ t('plugin.confDescription') }}
283-
<Input v-model="conf.description" placeholder="description" />
300+
<Input v-model="conf.description" placeholder="description" class="min-w-[75%]" />
284301
</div>
285302
<div class="form-item">
286303
{{ t('plugin.confKey') }}
287-
<Input v-model="conf.key" placeholder="key" />
304+
<Input v-model="conf.key" placeholder="key" class="min-w-[75%]" />
288305
</div>
289306
<div class="form-item" :class="{ 'items-start': conf.value.length !== 0 }">
290307
{{ t('plugin.confDefault') }}
@@ -293,6 +310,7 @@ defineExpose({ modalSlots })
293310
v-model="conf.value"
294311
:options="getOptions(conf.options)"
295312
editable
313+
:class="conf.component === 'CodeViewer' ? 'min-w-[75%]' : ''"
296314
/>
297315
</div>
298316
<div
@@ -304,28 +322,28 @@ defineExpose({ modalSlots })
304322
<InputList v-model="conf.options" />
305323
</div>
306324
</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>
326341
</template>
327342
</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>
329347
</div>
330348
</div>
331349
</template>

frontend/src/views/PluginsView/components/PluginView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const modalSlots = {
131131
h(
132132
'div',
133133
{
134-
class: 'p-4 flex flex-col gap-2',
134+
class: 'p-4 flex flex-col gap-2 min-w-128',
135135
},
136136
events.map(([type, label]) =>
137137
h(

0 commit comments

Comments
 (0)