From d17428e25b82248e0ff428554da25d3db30a4659 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Thu, 18 Mar 2021 12:14:54 +0800 Subject: [PATCH] feat(status): separate payload into 3 parts --- packages/plugin-status/client/index.ts | 15 ++--- packages/plugin-status/client/main.ts | 7 ++- packages/plugin-status/client/views/bots.vue | 16 +++--- .../client/views/home/group-chart.vue | 10 ++-- .../client/views/home/history-chart.vue | 12 ++-- .../client/views/home/hour-chart.vue | 14 ++--- .../plugin-status/client/views/home/index.vue | 22 ++++---- .../client/views/home/load-chart.vue | 9 +-- .../client/views/home/word-cloud.vue | 12 ++-- .../client/views/layout/index.vue | 5 +- .../client/views/plugins/index.vue | 4 +- packages/plugin-status/server/index.ts | 41 ++++---------- packages/plugin-status/server/mongo.ts | 2 +- packages/plugin-status/server/mysql.ts | 2 +- packages/plugin-status/server/profile.ts | 32 ++++++++--- packages/plugin-status/server/stats.ts | 25 ++++----- packages/plugin-status/server/webui.ts | 55 +++++++++---------- 17 files changed, 132 insertions(+), 151 deletions(-) diff --git a/packages/plugin-status/client/index.ts b/packages/plugin-status/client/index.ts index 4feb9761e6..12f09ac28a 100644 --- a/packages/plugin-status/client/index.ts +++ b/packages/plugin-status/client/index.ts @@ -2,7 +2,7 @@ import { ref, watch } from 'vue' import type { User } from 'koishi-core' -import type { Payload } from '~/server' +import type { Registry, Profile, Statistics } from '~/server' const prefix = 'koishi:' @@ -41,7 +41,9 @@ interface Config { export const user = storage.create('user') export const config = storage.create('config', { authType: 0 }) -export const status = ref(null) +export const profile = ref(null) +export const registry = ref(null) +export const stats = ref(null) export const socket = ref(null) const listeners: Record void> = {} @@ -55,11 +57,10 @@ export function start() { listeners[data.type](data.body) } } - receive('update', data => status.value = data) - receive('user', data => { - user.value = data - storage.set('user', data) - }) + receive('profile', data => profile.value = data) + receive('registry', data => registry.value = data) + receive('stats', data => stats.value = data) + receive('user', data => user.value = data) } export function send(type: string, body: any) { diff --git a/packages/plugin-status/client/main.ts b/packages/plugin-status/client/main.ts index 4e616b9aea..b95ed8a4a1 100644 --- a/packages/plugin-status/client/main.ts +++ b/packages/plugin-status/client/main.ts @@ -26,6 +26,7 @@ declare module 'vue-router' { hidden?: boolean authorize?: boolean frameless?: boolean + require?: ('stats' | 'profile' | 'registry')[] } } @@ -36,17 +37,17 @@ const router = createRouter({ routes: [{ path: '/', name: '仪表盘', - meta: { icon: 'tachometer-alt' }, + meta: { icon: 'tachometer-alt', require: ['stats', 'profile', 'registry'] }, component: () => import('./views/home/index.vue'), }, { path: '/bots', name: '机器人', - meta: { icon: 'robot' }, + meta: { icon: 'robot', require: ['stats', 'profile'] }, component: () => import('./views/bots.vue'), }, { path: '/plugins', name: '插件', - meta: { icon: 'plug' }, + meta: { icon: 'plug', require: ['registry'] }, component: () => import('./views/plugins/index.vue'), }, { path: '/sandbox', diff --git a/packages/plugin-status/client/views/bots.vue b/packages/plugin-status/client/views/bots.vue index 97e101a098..4b1b3da842 100644 --- a/packages/plugin-status/client/views/bots.vue +++ b/packages/plugin-status/client/views/bots.vue @@ -1,6 +1,6 @@