fix plugin form

This commit is contained in:
jxxghp
2023-07-24 12:38:32 +08:00
parent 74aca36e71
commit 7f77e181d7
3 changed files with 29 additions and 8 deletions
+9
View File
@@ -73,3 +73,12 @@ export function isContained(subArray: any[], mainArray: any[]): boolean {
export function isIntersected(array1: any[], array2: any[]): boolean { export function isIntersected(array1: any[], array2: any[]): boolean {
return array1.some(element => array2.includes(element)) return array1.some(element => array2.includes(element))
} }
export function isNullOrEmptyObject(obj: any): boolean {
// 首先判断是否为 null 或 undefined
if (obj === null || obj === undefined)
return true
// 然后判断是否为空对象
return !!(typeof obj === 'object' && Object.keys(obj).length === 0)
}
+7 -5
View File
@@ -3,6 +3,7 @@ import { useToast } from 'vue-toast-notification'
import api from '@/api' import api from '@/api'
import type { Plugin } from '@/api/types' import type { Plugin } from '@/api/types'
import FormRender from '@/components/render/FormRender.vue' import FormRender from '@/components/render/FormRender.vue'
import { isNullOrEmptyObject } from '@core/utils'
// 输入参数 // 输入参数
const props = defineProps({ const props = defineProps({
@@ -60,7 +61,8 @@ async function loadPluginForm() {
const result: { [key: string]: any } = await api.get(`plugin/form/${props.plugin?.id}`) const result: { [key: string]: any } = await api.get(`plugin/form/${props.plugin?.id}`)
if (result) { if (result) {
pluginFormItems.value = result.conf pluginFormItems.value = result.conf
pluginConfigForm.value = result.model if (result.model)
pluginConfigForm.value = result.model
} }
} }
catch (error) { catch (error) {
@@ -84,7 +86,7 @@ async function loadPluginPage() {
async function loadPluginConf() { async function loadPluginConf() {
try { try {
const result: { [key: string]: any } = await api.get(`plugin/${props.plugin?.id}`) const result: { [key: string]: any } = await api.get(`plugin/${props.plugin?.id}`)
if (result) if (!isNullOrEmptyObject(result))
pluginConfigForm.value = result pluginConfigForm.value = result
} }
catch (error) { catch (error) {
@@ -116,9 +118,9 @@ function showPluginInfo() {
} }
// 显示插件配置 // 显示插件配置
function showPluginConfig() { async function showPluginConfig() {
// 加载插件表单 // 加载插件表单
loadPluginForm() await loadPluginForm()
// 加载插件配置 // 加载插件配置
loadPluginConf() loadPluginConf()
// 加载详情数据 // 加载详情数据
@@ -203,7 +205,7 @@ const dropdownItems = ref([
> >
<VCard :title="`插件 - ${props.plugin?.plugin_name}`"> <VCard :title="`插件 - ${props.plugin?.plugin_name}`">
<VCardText> <VCardText>
<FormRender v-for="(item, index) in pluginFormItems" :key="index" :config="item" /> <FormRender v-for="(item, index) in pluginFormItems" :key="index" :config="item" :form="pluginConfigForm" />
</VCardText> </VCardText>
<VCardActions> <VCardActions>
<VBtn v-if="pluginPageItems.length > 0" @click="showPluginInfo"> <VBtn v-if="pluginPageItems.length > 0" @click="showPluginInfo">
+13 -3
View File
@@ -11,18 +11,28 @@ interface RenderProps {
// 输入参数 // 输入参数
const elementProps = defineProps({ const elementProps = defineProps({
config: Object as PropType<RenderProps>, config: Object as PropType<RenderProps>,
form: Object as PropType<any>,
}) })
// 配置表单 // 配置元素
const formItem = ref<RenderProps>(elementProps.config || { const formItem = ref<RenderProps>(elementProps.config || {
component: 'div', component: 'div',
props: {}, props: {},
content: [], content: [],
}) })
// 配置数据
const formData = ref<any>(elementProps.form || {})
</script> </script>
<template> <template>
<Component :is="formItem.component" v-bind="formItem.props"> <Component :is="formItem.component" v-bind="formItem.props" v-model="formData[formItem.props?.model || '']">
<FormRender v-for="(innerItem, innerIndex) in (formItem.content || [])" :key="innerIndex" :config="innerItem" /> <FormRender
v-for="(innerItem, innerIndex) in (formItem.content || [])"
:key="innerIndex"
v-model="formData[innerItem.props?.model || '']"
:config="innerItem"
:form="formData"
/>
</Component> </Component>
</template> </template>