feat(frontend): 完成Skill与Plugin管理页面
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import type { Plugin } from '@/contracts'
|
||||
import { mockPlugins } from '@/services/pluginService'
|
||||
import * as pluginService from '@/services/pluginService'
|
||||
|
||||
export const usePluginStore = defineStore('plugin', () => {
|
||||
const plugins = ref<Plugin[]>(mockPlugins)
|
||||
const plugins = ref<Plugin[]>(pluginService.mockPlugins)
|
||||
const selectedPluginId = ref<string | null>(null)
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
const selectedPlugin = computed(() =>
|
||||
plugins.value.find((p) => p.plugin_id === selectedPluginId.value) || null
|
||||
@@ -19,8 +20,10 @@ export const usePluginStore = defineStore('plugin', () => {
|
||||
async function loadPlugins() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const { listPlugins } = await import('@/services/pluginService')
|
||||
plugins.value = await listPlugins()
|
||||
plugins.value = await pluginService.listPlugins()
|
||||
error.value = null
|
||||
} catch (reason) {
|
||||
error.value = reason instanceof Error ? reason.message : 'Plugin 加载失败'
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@@ -30,23 +33,34 @@ export const usePluginStore = defineStore('plugin', () => {
|
||||
selectedPluginId.value = pluginId
|
||||
}
|
||||
|
||||
async function installPlugin(packagePath: string) {
|
||||
const installed = await pluginService.installPlugin(packagePath)
|
||||
const index = plugins.value.findIndex((plugin) => plugin.plugin_id === installed.plugin_id)
|
||||
if (index >= 0) plugins.value[index] = installed
|
||||
else plugins.value.unshift(installed)
|
||||
selectedPluginId.value = installed.plugin_id
|
||||
}
|
||||
|
||||
async function grantPermissions(pluginId: string, permissions: string[]) {
|
||||
const updated = await pluginService.grantPluginPermissions(pluginId, permissions)
|
||||
const index = plugins.value.findIndex((plugin) => plugin.plugin_id === pluginId)
|
||||
if (index >= 0) plugins.value[index] = updated
|
||||
}
|
||||
|
||||
async function enablePlugin(pluginId: string) {
|
||||
const plugin = plugins.value.find((p) => p.plugin_id === pluginId)
|
||||
if (plugin) {
|
||||
plugin.enabled = true
|
||||
plugin.status = 'ready'
|
||||
}
|
||||
const updated = await pluginService.enablePlugin(pluginId)
|
||||
const index = plugins.value.findIndex((plugin) => plugin.plugin_id === pluginId)
|
||||
if (index >= 0) plugins.value[index] = updated
|
||||
}
|
||||
|
||||
async function disablePlugin(pluginId: string) {
|
||||
const plugin = plugins.value.find((p) => p.plugin_id === pluginId)
|
||||
if (plugin) {
|
||||
plugin.enabled = false
|
||||
plugin.status = 'disabled'
|
||||
}
|
||||
const updated = await pluginService.disablePlugin(pluginId)
|
||||
const index = plugins.value.findIndex((plugin) => plugin.plugin_id === pluginId)
|
||||
if (index >= 0) plugins.value[index] = updated
|
||||
}
|
||||
|
||||
async function uninstallPlugin(pluginId: string) {
|
||||
await pluginService.uninstallPlugin(pluginId)
|
||||
const idx = plugins.value.findIndex((p) => p.plugin_id === pluginId)
|
||||
if (idx > -1) plugins.value.splice(idx, 1)
|
||||
if (selectedPluginId.value === pluginId) selectedPluginId.value = null
|
||||
@@ -60,8 +74,11 @@ export const usePluginStore = defineStore('plugin', () => {
|
||||
readyPlugins,
|
||||
errorPlugins,
|
||||
isLoading,
|
||||
error,
|
||||
loadPlugins,
|
||||
selectPlugin,
|
||||
installPlugin,
|
||||
grantPermissions,
|
||||
enablePlugin,
|
||||
disablePlugin,
|
||||
uninstallPlugin,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import type { Skill } from '@/contracts'
|
||||
import { mockSkills } from '@/services/skillService'
|
||||
import * as skillService from '@/services/skillService'
|
||||
|
||||
export const useSkillStore = defineStore('skill', () => {
|
||||
const skills = ref<Skill[]>(mockSkills)
|
||||
const skills = ref<Skill[]>(skillService.mockSkills)
|
||||
const selectedSkillId = ref<string | null>(null)
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
const selectedSkill = computed(() =>
|
||||
skills.value.find((s) => s.skill_id === selectedSkillId.value) || null
|
||||
@@ -19,8 +20,10 @@ export const useSkillStore = defineStore('skill', () => {
|
||||
async function loadSkills() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const { listSkills } = await import('@/services/skillService')
|
||||
skills.value = await listSkills()
|
||||
skills.value = await skillService.listSkills()
|
||||
error.value = null
|
||||
} catch (reason) {
|
||||
error.value = reason instanceof Error ? reason.message : 'Skill 加载失败'
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@@ -30,23 +33,28 @@ export const useSkillStore = defineStore('skill', () => {
|
||||
selectedSkillId.value = skillId
|
||||
}
|
||||
|
||||
async function installSkill(packagePath: string) {
|
||||
const installed = await skillService.installSkill(packagePath)
|
||||
const index = skills.value.findIndex((skill) => skill.skill_id === installed.skill_id)
|
||||
if (index >= 0) skills.value[index] = installed
|
||||
else skills.value.unshift(installed)
|
||||
selectedSkillId.value = installed.skill_id
|
||||
}
|
||||
|
||||
async function enableSkill(skillId: string) {
|
||||
const skill = skills.value.find((s) => s.skill_id === skillId)
|
||||
if (skill) {
|
||||
skill.enabled = true
|
||||
skill.status = 'ready'
|
||||
}
|
||||
const updated = await skillService.enableSkill(skillId)
|
||||
const index = skills.value.findIndex((skill) => skill.skill_id === skillId)
|
||||
if (index >= 0) skills.value[index] = updated
|
||||
}
|
||||
|
||||
async function disableSkill(skillId: string) {
|
||||
const skill = skills.value.find((s) => s.skill_id === skillId)
|
||||
if (skill) {
|
||||
skill.enabled = false
|
||||
skill.status = 'disabled'
|
||||
}
|
||||
const updated = await skillService.disableSkill(skillId)
|
||||
const index = skills.value.findIndex((skill) => skill.skill_id === skillId)
|
||||
if (index >= 0) skills.value[index] = updated
|
||||
}
|
||||
|
||||
async function uninstallSkill(skillId: string) {
|
||||
await skillService.uninstallSkill(skillId)
|
||||
const idx = skills.value.findIndex((s) => s.skill_id === skillId)
|
||||
if (idx > -1) skills.value.splice(idx, 1)
|
||||
if (selectedSkillId.value === skillId) selectedSkillId.value = null
|
||||
@@ -60,8 +68,10 @@ export const useSkillStore = defineStore('skill', () => {
|
||||
installedSkills,
|
||||
readySkills,
|
||||
isLoading,
|
||||
error,
|
||||
loadSkills,
|
||||
selectSkill,
|
||||
installSkill,
|
||||
enableSkill,
|
||||
disableSkill,
|
||||
uninstallSkill,
|
||||
|
||||
Reference in New Issue
Block a user