mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-12 02:21:06 +08:00
fix plugin form
This commit is contained in:
@@ -73,3 +73,12 @@ export function isContained(subArray: any[], mainArray: any[]): boolean {
|
||||
export function isIntersected(array1: any[], array2: any[]): boolean {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useToast } from 'vue-toast-notification'
|
||||
import api from '@/api'
|
||||
import type { Plugin } from '@/api/types'
|
||||
import FormRender from '@/components/render/FormRender.vue'
|
||||
import { isNullOrEmptyObject } from '@core/utils'
|
||||
|
||||
// 输入参数
|
||||
const props = defineProps({
|
||||
@@ -60,7 +61,8 @@ async function loadPluginForm() {
|
||||
const result: { [key: string]: any } = await api.get(`plugin/form/${props.plugin?.id}`)
|
||||
if (result) {
|
||||
pluginFormItems.value = result.conf
|
||||
pluginConfigForm.value = result.model
|
||||
if (result.model)
|
||||
pluginConfigForm.value = result.model
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -84,7 +86,7 @@ async function loadPluginPage() {
|
||||
async function loadPluginConf() {
|
||||
try {
|
||||
const result: { [key: string]: any } = await api.get(`plugin/${props.plugin?.id}`)
|
||||
if (result)
|
||||
if (!isNullOrEmptyObject(result))
|
||||
pluginConfigForm.value = result
|
||||
}
|
||||
catch (error) {
|
||||
@@ -116,9 +118,9 @@ function showPluginInfo() {
|
||||
}
|
||||
|
||||
// 显示插件配置
|
||||
function showPluginConfig() {
|
||||
async function showPluginConfig() {
|
||||
// 加载插件表单
|
||||
loadPluginForm()
|
||||
await loadPluginForm()
|
||||
// 加载插件配置
|
||||
loadPluginConf()
|
||||
// 加载详情数据
|
||||
@@ -203,7 +205,7 @@ const dropdownItems = ref([
|
||||
>
|
||||
<VCard :title="`插件 - ${props.plugin?.plugin_name}`">
|
||||
<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>
|
||||
<VCardActions>
|
||||
<VBtn v-if="pluginPageItems.length > 0" @click="showPluginInfo">
|
||||
|
||||
@@ -11,18 +11,28 @@ interface RenderProps {
|
||||
// 输入参数
|
||||
const elementProps = defineProps({
|
||||
config: Object as PropType<RenderProps>,
|
||||
form: Object as PropType<any>,
|
||||
})
|
||||
|
||||
// 配置表单
|
||||
// 配置元素
|
||||
const formItem = ref<RenderProps>(elementProps.config || {
|
||||
component: 'div',
|
||||
props: {},
|
||||
content: [],
|
||||
})
|
||||
|
||||
// 配置数据
|
||||
const formData = ref<any>(elementProps.form || {})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Component :is="formItem.component" v-bind="formItem.props">
|
||||
<FormRender v-for="(innerItem, innerIndex) in (formItem.content || [])" :key="innerIndex" :config="innerItem" />
|
||||
<Component :is="formItem.component" v-bind="formItem.props" v-model="formData[formItem.props?.model || '']">
|
||||
<FormRender
|
||||
v-for="(innerItem, innerIndex) in (formItem.content || [])"
|
||||
:key="innerIndex"
|
||||
v-model="formData[innerItem.props?.model || '']"
|
||||
:config="innerItem"
|
||||
:form="formData"
|
||||
/>
|
||||
</Component>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user