diff --git a/package.json b/package.json index 0aa91276..509bd4ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moviepilot", - "version": "1.8.6-2", + "version": "1.8.7", "private": true, "bin": "dist/service.js", "scripts": { diff --git a/src/api/types.ts b/src/api/types.ts index 1416d945..b279e94c 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -445,6 +445,20 @@ export interface Plugin { add_time?: number } +// 插件仪表板 +export interface PluginDashboard { + // 插件ID + id: string + // 插件名称 + name: string + // 全局配置 + attrs: { [key: string]: any } + // col列数 + cols: { [key: string]: number } + // 页面元素 + elements: { [key: string]: any }[] +} + // 种子信息 export interface TorrentInfo { // 站点ID diff --git a/src/components/render/DashboardRender.vue b/src/components/render/DashboardRender.vue new file mode 100644 index 00000000..b0a6c8a5 --- /dev/null +++ b/src/components/render/DashboardRender.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/pages/dashboard.vue b/src/pages/dashboard.vue index 817bb2af..424ce00c 100644 --- a/src/pages/dashboard.vue +++ b/src/pages/dashboard.vue @@ -9,30 +9,15 @@ import AnalyticsMemory from '@/views/dashboard/AnalyticsMemory.vue' import MediaServerLatest from '@/views/dashboard/MediaServerLatest.vue' import MediaServerLibrary from '@/views/dashboard/MediaServerLibrary.vue' import MediaServerPlaying from '@/views/dashboard/MediaServerPlaying.vue' +import DashboardRender from '@/components/render/DashboardRender.vue' import api from '@/api' import { isNullOrEmptyObject } from '@/@core/utils' import { useDisplay } from 'vuetify' +import { PluginDashboard } from '@/api/types' // 显示器宽度 const display = useDisplay() -// 仪表盘配置 -const dashboard_names = { - storage: '存储空间', - mediaStatistic: '媒体统计', - weeklyOverview: '最近入库', - speed: '实时速率', - scheduler: '后台任务', - cpu: 'CPU', - memory: '内存', - library: '我的媒体库', - playing: '继续观看', - latest: '最近添加', -} - -// 弹窗 -const dialog = ref(false) - // 从localStorage中获取数据 const default_config = { mediaStatistic: true, @@ -47,6 +32,29 @@ const default_config = { latest: true, } +// 仪表盘字典 +const dashboard_names = ref<{ [key: string]: string }>({ + storage: '存储空间', + mediaStatistic: '媒体统计', + weeklyOverview: '最近入库', + speed: '实时速率', + scheduler: '后台任务', + cpu: 'CPU', + memory: '内存', + library: '我的媒体库', + playing: '继续观看', + latest: '最近添加', +}) + +// 有仪表板的插件 +const dashboard_plugins = ref([]) + +// 插件仪表板配置 +const plugin_dashboards = ref([]) + +// 弹窗 +const dialog = ref(false) + // 初始化默认值 const config = ref(JSON.parse(localStorage.getItem('MP_DASHBOARD') || '{}')) if (isNullOrEmptyObject(config.value)) { @@ -65,52 +73,90 @@ function setDashboardConfig() { }) dialog.value = false } + +// 调用API获取有仪表板的插件 +async function getDashboardPlugins() { + try { + dashboard_plugins.value = await api.get('/plugin/dashboards') + if (!isNullOrEmptyObject(dashboard_plugins.value)) { + // 获取id和name补充到 dashboard_names 中 + dashboard_plugins.value.forEach((plugin: { [key: string]: string }) => { + dashboard_names.value[plugin.id] = plugin.name + }) + // 下载插件仪表板配置 + dashboard_plugins.value.forEach(async (plugin: { id: string }) => { + await getPluginDashboard(plugin.id) + }) + } + } catch (error) { + console.error(error) + } +} + +// 获取一个插件的仪表板配置项 +async function getPluginDashboard(id: string) { + try { + api.get(`/plugin/dashboard/${id}`).then(res => { + if (res) plugin_dashboards.value.push(res) + }) + } catch (error) { + console.error(error) + } +} + +onMounted(() => { + getDashboardPlugins() +})