diff --git a/plugins/config/client/components/global.vue b/plugins/config/client/components/global.vue
index 1319fcb1..425151b7 100644
--- a/plugins/config/client/components/global.vue
+++ b/plugins/config/client/components/global.vue
@@ -4,7 +4,7 @@
diff --git a/plugins/config/client/components/index.vue b/plugins/config/client/components/index.vue
index 9015731d..8e96e3fb 100644
--- a/plugins/config/client/components/index.vue
+++ b/plugins/config/client/components/index.vue
@@ -1,5 +1,5 @@
-
+
@@ -38,11 +38,11 @@
-
+
确定要移除{{ current.children ? `分组 ${current.alias}` : `插件 ${current.label}` }} 吗?此操作不可撤销!
- 取消
- 确定
+ 取消
+ 确定
@@ -52,14 +52,13 @@
import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
-import { addItem, envMap, plugins, removeItem, splitPath, Tree, coreDeps } from './utils'
+import { clone, store, useAction } from '@koishijs/client'
+import { addItem, current, plugins, removeItem, showSelect, Tree } from './utils'
import GlobalSettings from './global.vue'
import GroupSettings from './group.vue'
import TreeView from './tree.vue'
import PluginSettings from './plugin.vue'
import KAlias from './alias.vue'
-import { clone, message, send, store } from '@koishijs/client'
-import { showSelect } from './utils'
const route = useRoute()
const router = useRouter()
@@ -75,95 +74,30 @@ const path = computed({
},
})
-const current = ref()
const config = ref()
-const showDialog = ref(false)
+const showRemove = ref(false)
watch(() => plugins.value.paths[path.value], (value) => {
current.value = value
config.value = clone(value.config)
}, { immediate: true })
-const name = computed(() => {
- const { label, target } = current.value
- const shortname = target || label
- if (shortname.includes('/')) {
- const [left, right] = shortname.split('/')
- return [`${left}/koishi-plugin-${right}`].find(name => name in store.packages)
- }
- return [
- `@koishijs/plugin-${shortname}`,
- `koishi-plugin-${shortname}`,
- ].find(name => name in store.packages)
+useAction('config.remove', {
+ disabled: () => !current.value.path,
+ action: () => showRemove.value = true,
})
-const type = computed(() => {
- const env = envMap.value[name.value]
- if (!env) return
- if (env.warning && current.value.disabled) return 'warning'
- for (const name in env.using) {
- if (store.services?.[name]) {
- if (env.impl.includes(name)) return 'warning'
- } else {
- if (env.using[name].required) return 'warning'
- }
- }
+useAction('config.add-plugin', {
+ disabled: () => current.value.path && !current.value.children,
+ action: () => showSelect.value = true,
})
-const menu = computed(() => {
- const isGlobal = current.value.path === ''
- const isGroup = !!current.value.children
- const isDisabled = current.value.disabled
- return [{
- icon: isDisabled ? 'play' : 'stop',
- label: isDisabled ? '启用插件' : '停用插件',
- disabled: isGroup || !name.value || coreDeps.includes(name.value),
- action: async () => {
- await execute(isDisabled ? 'reload' : 'unload')
- message.success(isDisabled ? '插件已启用。' : '插件已停用。')
- },
- }, {
- type: isDisabled ? type.value : '',
- icon: isDisabled ? 'save' : 'check',
- label: isDisabled ? '保存配置' : '重载配置',
- disabled: !isGroup && !name.value,
- async action() {
- if (isGlobal) {
- send('manager/app-reload', config.value)
- } else {
- await execute(isDisabled ? 'unload' : 'reload')
- message.success(isDisabled ? '配置已保存。' : '配置已重载。')
- }
- },
- }, {
- type: 'danger',
- icon: 'trash-can',
- label: isGroup ? '移除分组' : '移除插件',
- disabled: isGlobal,
- action: () => showDialog.value = true,
- }, {
- icon: 'add-plugin',
- label: '添加插件',
- disabled: !isGroup,
- action: () => showSelect.value = true,
- }, {
- icon: 'add-group',
- label: '添加分组',
- disabled: !isGroup,
- action: () => addItem(current.value.path, 'group', 'group'),
- }]
+useAction('config.add-group', {
+ disabled: () => current.value.path && !current.value.children,
+ action: () => addItem(current.value.path, 'group', 'group'),
})
-async function execute(event: 'unload' | 'reload') {
- await send(`manager/${event}`, current.value.path, config.value, current.value.target)
- if (current.value.target) {
- const segments = splitPath(current.value.path)
- segments[segments.length - 1] = current.value.target
- router.replace('/plugins/' + segments.join('/'))
- }
-}
-