@ -1,18 +1,14 @@
< script lang = "ts" setup >
< script lang = "ts" setup >
/ / c o r e l i b s
/ / c o r e l i b s
import { computed , nextTick , onMounted , provide , ref , watch } from "vue" ;
import { nextTick , onMounted , provide , ref , watch } from "vue" ;
import { RouterView , useRoute , useRouter } from "vue-router" ;
import { RouterView , useRoute , useRouter } from "vue-router" ;
import { apiClient } from "@/utils/api-client" ;
import { apiClient } from "@/utils/api-client" ;
/ / l i b s
/ / l i b s
import cloneDeep from "lodash.clonedeep" ;
import cloneDeep from "lodash.clonedeep" ;
/ / h o o k s
import { useSettingForm } from "@/composables/use-setting-form" ;
/ / c o m p o n e n t s
/ / c o m p o n e n t s
import {
import {
VButton ,
VCard ,
VCard ,
VPageHeader ,
VPageHeader ,
VTabbar ,
VTabbar ,
@ -23,7 +19,7 @@ import BasicLayout from "@/layouts/BasicLayout.vue";
/ / t y p e s
/ / t y p e s
import type { Ref } from "vue" ;
import type { Ref } from "vue" ;
import type { Plugin , SettingForm } from "@halo-dev/api-client" ;
import type { Plugin , Setting , Setting Form } from "@halo-dev/api-client" ;
import { usePermission } from "@/utils/permission" ;
import { usePermission } from "@/utils/permission" ;
import { usePluginLifeCycle } from "../composables/use-plugin" ;
import { usePluginLifeCycle } from "../composables/use-plugin" ;
@ -52,22 +48,15 @@ const route = useRoute();
const router = useRouter ( ) ;
const router = useRouter ( ) ;
const plugin = ref < Plugin > ( ) ;
const plugin = ref < Plugin > ( ) ;
const setting = ref < Setting > ( ) ;
const tabs = ref < PluginTab [ ] > ( cloneDeep ( initialTabs ) ) ;
const tabs = ref < PluginTab [ ] > ( cloneDeep ( initialTabs ) ) ;
const activeTab = ref < string > ( ) ;
const activeTab = ref < string > ( ) ;
provide < Ref < Plugin | undefined > > ( "plugin" , plugin ) ;
provide < Ref < Plugin | undefined > > ( "plugin" , plugin ) ;
provide < Ref < string | undefined > > ( "activeTab" , activeTab ) ;
provide < Ref < string | undefined > > ( "activeTab" , activeTab ) ;
const settingName = computed ( ( ) => plugin . value ? . spec . settingName ) ;
const configMapName = computed ( ( ) => plugin . value ? . spec . configMapName ) ;
const { isStarted } = usePluginLifeCycle ( plugin ) ;
const { isStarted } = usePluginLifeCycle ( plugin ) ;
const { setting , handleFetchSettings } = useSettingForm (
settingName ,
configMapName
) ;
const handleFetchPlugin = async ( ) => {
const handleFetchPlugin = async ( ) => {
try {
try {
const response =
const response =
@ -80,6 +69,14 @@ const handleFetchPlugin = async () => {
}
}
} ;
} ;
const handleFetchSettings = async ( ) => {
if ( ! plugin . value ) return ;
const { data } = await apiClient . plugin . fetchPluginSetting ( {
name : plugin . value ? . metadata . name ,
} ) ;
setting . value = data ;
} ;
const handleTabChange = ( id : string ) => {
const handleTabChange = ( id : string ) => {
const tab = tabs . value . find ( ( item ) => item . id === id ) ;
const tab = tabs . value . find ( ( item ) => item . id === id ) ;
if ( tab ) {
if ( tab ) {
@ -110,7 +107,7 @@ const handleTriggerTabChange = () => {
onMounted ( async ( ) => {
onMounted ( async ( ) => {
await handleFetchPlugin ( ) ;
await handleFetchPlugin ( ) ;
if ( ! currentUserHasPermission ( [ "system:settings:view " ] ) ) {
if ( ! currentUserHasPermission ( [ "system:plugins:manage " ] ) ) {
handleTriggerTabChange ( ) ;
handleTriggerTabChange ( ) ;
return ;
return ;
}
}
@ -161,9 +158,6 @@ watch([() => route.name, () => route.params], () => {
size = "sm"
size = "sm"
/ >
/ >
< / template >
< / template >
< template # actions >
< VButton class = "opacity-0" type = "secondary" > 安装 < / VButton >
< / template >
< / VPageHeader >
< / VPageHeader >
< div class = "m-0 md:m-4" >
< div class = "m-0 md:m-4" >