From 7c54e5d09390aeec714b82bcce274f276672e264 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 15 Apr 2025 22:53:40 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=B7=B2=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E7=9A=84=E6=8F=92=E4=BB=B6=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes: #934 --- dashboard/src/views/ExtensionPage.vue | 502 ++++++++++++++++++-------- 1 file changed, 347 insertions(+), 155 deletions(-) diff --git a/dashboard/src/views/ExtensionPage.vue b/dashboard/src/views/ExtensionPage.vue index 2f34deccf..40441c273 100644 --- a/dashboard/src/views/ExtensionPage.vue +++ b/dashboard/src/views/ExtensionPage.vue @@ -50,6 +50,11 @@ const platformEnableData = reactive({ }); const loadingPlatformData = ref(false); +// 新增变量支持列表视图 +const isListView = ref(false); +const pluginSearch = ref(""); +const loading_ = ref(false); + const plugin_handler_info_headers = [ { title: '行为类型', key: 'event_type_h' }, { title: '描述', key: 'desc', maxWidth: '250px' }, @@ -57,11 +62,36 @@ const plugin_handler_info_headers = [ { title: '触发方式', key: 'cmd' }, ]; +// 插件表格的表头定义 +const pluginHeaders = [ + { title: '名称', key: 'name', width: '200px' }, + { title: '描述', key: 'desc', maxWidth: '250px' }, + { title: '版本', key: 'version', width: '100px' }, + { title: '作者', key: 'author', width: '100px' }, + { title: '状态', key: 'status', width: '80px' }, + { title: '操作', key: 'actions', sortable: false, width: '220px' } +]; + +// 过滤要显示的插件 const filteredExtensions = computed(() => { - if (showReserved.value) { - return extension_data.data; + if (!showReserved.value) { + return extension_data?.data?.filter(ext => !ext.reserved) || []; } - return extension_data?.data?.filter(ext => !ext.reserved); + return extension_data.data || []; +}); + +// 通过搜索过滤插件 +const filteredPlugins = computed(() => { + if (!pluginSearch.value) { + return filteredExtensions.value; + } + + const search = pluginSearch.value.toLowerCase(); + return filteredExtensions.value.filter(plugin => { + return plugin.name?.toLowerCase().includes(search) || + plugin.desc?.toLowerCase().includes(search) || + plugin.author?.toLowerCase().includes(search); + }); }); // 方法 @@ -90,12 +120,15 @@ const onLoadingDialogResult = (statusCode, result, timeToClose = 2000) => { }; const getExtensions = async () => { + loading_.value = true; try { const res = await axios.get('/api/plugin/get'); Object.assign(extension_data, res.data); checkUpdate(); } catch (err) { toast(err, "error"); + } finally { + loading_.value = false; } }; @@ -118,7 +151,7 @@ const checkUpdate = () => { if (matchedPlugin) { extension.online_version = matchedPlugin.version; - extension.has_update = extension.version !== matchedPlugin.version && + extension.has_update = extension.version !== matchedPlugin.version && matchedPlugin.version !== "未知"; } else { extension.has_update = false; @@ -150,12 +183,12 @@ const updateExtension = async (extension_name) => { name: extension_name, proxy: localStorage.getItem('selectedGitHubProxy') || "" }); - + if (res.data.status === "error") { onLoadingDialogResult(2, res.data.message, -1); return; } - + Object.assign(extension_data, res.data); onLoadingDialogResult(1, res.data.message); } catch (err) { @@ -198,7 +231,7 @@ const openExtensionConfig = async (extension_name) => { const res = await axios.get('/api/config/get?plugin_name=' + extension_name); extension_config.metadata = res.data.data.metadata; extension_config.config = res.data.data.config; - + } catch (err) { toast(err, "error"); } @@ -255,11 +288,11 @@ const getPlatformEnableConfig = async () => { toast(res.data.message, "error"); return; } - + platformEnableData.platforms = res.data.data.platforms; platformEnableData.plugins = res.data.data.plugins; platformEnableData.platform_enable = res.data.data.platform_enable; - + // 如果没有平台,给出提示但仍显示对话框 if (platformEnableData.platforms.length === 0) { toast("未添加任何平台适配器,请先在平台管理中添加平台", "warning"); @@ -269,7 +302,7 @@ const getPlatformEnableConfig = async () => { if (!platformEnableData.platform_enable[platform.name]) { platformEnableData.platform_enable[platform.name] = {}; } - + // 确保每个插件在每个平台都有一个配置项 platformEnableData.plugins.forEach(plugin => { if (platformEnableData.platform_enable[platform.name][plugin.name] === undefined) { @@ -278,7 +311,7 @@ const getPlatformEnableConfig = async () => { }); }); } - + platformEnableDialog.value = true; } catch (err) { toast("获取平台插件配置失败: " + err, "error"); @@ -294,12 +327,12 @@ const savePlatformEnableConfig = async () => { const res = await axios.post('/api/plugin/platform_enable/set', { platform_enable: platformEnableData.platform_enable }); - + if (res.data.status === "error") { toast(res.data.message, "error"); return; } - + toast(res.data.message, "success"); platformEnableDialog.value = false; } catch (err) { @@ -315,7 +348,7 @@ const selectAllPluginsForPlatform = (platformName, isSelected, onlyReserved = nu if (!platformEnableData.platform_enable[platformName]) { platformEnableData.platform_enable[platformName] = {}; } - + // 为所有插件设置相同的状态 platformEnableData.plugins.forEach(plugin => { // 如果onlyReserved为null,处理所有插件 @@ -333,7 +366,7 @@ const toggleAllPluginsForPlatform = (platformName) => { if (!platformEnableData.platform_enable[platformName]) { platformEnableData.platform_enable[platformName] = {}; } - + // 对每个插件进行反选操作 platformEnableData.plugins.forEach(plugin => { const currentState = platformEnableData.platform_enable[platformName][plugin.name]; @@ -344,7 +377,7 @@ const toggleAllPluginsForPlatform = (platformName) => { // 生命周期 onMounted(async () => { await getExtensions(); - + try { const data = await commonStore.getPluginCollections(); pluginMarketData.value = data; @@ -358,147 +391,308 @@ onMounted(async () => {