From 42ed9492b023319b24c9cd2bee0f35726c51aaa5 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Thu, 22 Aug 2024 16:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8B=9F=E7=89=A9=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E7=9A=AE=E8=82=A4=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=9A=AE?= =?UTF-8?q?=E8=82=A4=E8=AF=A6=E7=BB=86=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/ViewerApp.vue | 127 +++++------ frontend/src/charts/Bar1.vue | 28 +-- frontend/src/charts/Battery1.vue | 209 ++++++++++++++++++ frontend/src/charts/Circle1.vue | 86 ++----- frontend/src/charts/HealthBar1.vue | 44 ++-- frontend/src/charts/HealthBar1NoText.vue | 107 --------- frontend/src/charts/chartRoutes.ts | 62 +++++- frontend/src/charts/loading.png | Bin 799 -> 0 bytes frontend/src/charts/types.d.ts | 7 + frontend/src/charts/types/ChartParamDef.ts | 7 + frontend/src/charts/utils/transitionRef.ts | 33 +++ .../components/dialogs/GetLiveCompDialog.vue | 65 +++++- frontend/src/pages/Controller.vue | 7 +- frontend/src/style.scss | 18 ++ frontend/src/utils/request.ts | 27 +++ frontend/vite.config.ts | 5 + 16 files changed, 537 insertions(+), 295 deletions(-) create mode 100644 frontend/src/charts/Battery1.vue delete mode 100644 frontend/src/charts/HealthBar1NoText.vue delete mode 100644 frontend/src/charts/loading.png create mode 100644 frontend/src/charts/types.d.ts create mode 100644 frontend/src/charts/types/ChartParamDef.ts create mode 100644 frontend/src/charts/utils/transitionRef.ts create mode 100644 frontend/src/utils/request.ts diff --git a/frontend/src/ViewerApp.vue b/frontend/src/ViewerApp.vue index a5e094c..a2040ef 100644 --- a/frontend/src/ViewerApp.vue +++ b/frontend/src/ViewerApp.vue @@ -1,30 +1,38 @@ \ No newline at end of file diff --git a/frontend/src/charts/Bar1.vue b/frontend/src/charts/Bar1.vue index a4820bc..48f7ea7 100644 --- a/frontend/src/charts/Bar1.vue +++ b/frontend/src/charts/Bar1.vue @@ -1,4 +1,9 @@ + + + + \ No newline at end of file diff --git a/frontend/src/charts/Circle1.vue b/frontend/src/charts/Circle1.vue index c144f65..f05c372 100644 --- a/frontend/src/charts/Circle1.vue +++ b/frontend/src/charts/Circle1.vue @@ -1,6 +1,7 @@ - - - - \ No newline at end of file diff --git a/frontend/src/charts/chartRoutes.ts b/frontend/src/charts/chartRoutes.ts index 0644bb9..950b919 100644 --- a/frontend/src/charts/chartRoutes.ts +++ b/frontend/src/charts/chartRoutes.ts @@ -1,10 +1,60 @@ import { RouteRecordRaw } from 'vue-router'; export const chartRoutes: RouteRecordRaw[] = [ - { path: '/', component: () => import('./Circle1.vue'), name: '圆形1' }, - { path: '/circle1-dark', component: () => import('./Circle1.vue'), name: '圆形1 (深色)', props: { darkMode: true } }, - { path: '/bar1', component: () => import('./Bar1.vue'), name: '进度条1' }, - { path: '/health-bar1', component: () => import('./HealthBar1.vue'), name: 'HP条1' }, - { path: '/health-bar1-invert', component: () => import('./HealthBar1.vue'), name: 'HP条1 (白色文字)', props: { textInverted: true } }, - { path: '/health-bar1-notext', component: () => import('./HealthBar1.vue'), name: 'HP条1 (隐藏文字)', props: { hideText: true } }, + { + path: '/', + component: () => import('./Circle1.vue'), + name: '经典圆盘进度条', + meta: { + params: [ + { + prop: 'darkMode', + type: 'boolean', + name: '深色模式', + }, + ], + }, + }, + { + path: '/bar1', + component: () => import('./Bar1.vue'), + name: '横向胶囊进度条', + }, + { + path: '/health-bar1', + component: () => import('./HealthBar1.vue'), + name: '像素心心HP条', + meta: { + params: [ + { + prop: 'textInverted', + type: 'boolean', + name: '白色文字', + }, + { + prop: 'hideText', + type: 'boolean', + name: '隐藏文字', + }, + ], + }, + }, + { + path: '/battery1', + component: () => import('./Battery1.vue'), name: '拟物电池 (仅当前电量)', + meta: { + params: [ + { + prop: 'yellowBar', + type: 'boolean', + name: '黄色电量条', + }, + { + prop: 'hideText', + type: 'boolean', + name: '隐藏文字', + }, + ], + }, + }, ]; \ No newline at end of file diff --git a/frontend/src/charts/loading.png b/frontend/src/charts/loading.png deleted file mode 100644 index dfb39ace852a05d9bb5630f64d5bfa742d5f1abf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 799 zcmV+)1K|9LP)e!5vPjsN-U`4r~VN`JRn<-&q~F2FAge(bMCCNR1 zZ`m8Qs{YGoieB-spL8i>bGQ@iXPdj7@B8#6O<#}hFr&UC#L-!9v7i8TRwlW z%^fb}JSdU2G^1;0Bq^rbqjOL7RYsk|88&$R;CH3pPR@L;x3HUsL5dTfV@EmxUUNAj dKid8YFaSxJucJ9LoMQk0002ovPDHLkV1myhae@E< diff --git a/frontend/src/charts/types.d.ts b/frontend/src/charts/types.d.ts new file mode 100644 index 0000000..4a8efc4 --- /dev/null +++ b/frontend/src/charts/types.d.ts @@ -0,0 +1,7 @@ +import { ChartParamDef } from './types/ChartParamDef'; + +declare module 'vue-router' { + interface RouteMeta { + params: ChartParamDef[]; + } +} \ No newline at end of file diff --git a/frontend/src/charts/types/ChartParamDef.ts b/frontend/src/charts/types/ChartParamDef.ts new file mode 100644 index 0000000..e28866d --- /dev/null +++ b/frontend/src/charts/types/ChartParamDef.ts @@ -0,0 +1,7 @@ +export type ChartParamDef = { + prop: string; + type: 'boolean' | 'int' | 'float' | 'string' | 'select'; + name: string; + help?: string; + options?: { value: string, label: string }[]; +}; \ No newline at end of file diff --git a/frontend/src/charts/utils/transitionRef.ts b/frontend/src/charts/utils/transitionRef.ts new file mode 100644 index 0000000..77a1f64 --- /dev/null +++ b/frontend/src/charts/utils/transitionRef.ts @@ -0,0 +1,33 @@ +export function transitionRef(value: Ref, valuePerSec: number): Ref { + const refWithTransition = ref(value.value); + + let transitionTimer: NodeJS.Timeout | null = null; + let transitionTargetValue = value.value; + + const update = () => { + if (transitionTargetValue === refWithTransition.value && transitionTimer) { + clearInterval(transitionTimer); + transitionTimer = null; + return; + } else if (transitionTargetValue > refWithTransition.value) { + refWithTransition.value += 1; + } else { + refWithTransition.value -= 1; + } + } + + const startTransition = () => { + if (transitionTimer) { + return; + } + + transitionTimer = setInterval(update, 1000 / valuePerSec); + }; + + watch(value, (newValue) => { + transitionTargetValue = newValue; + startTransition(); + }); + + return refWithTransition; +} diff --git a/frontend/src/components/dialogs/GetLiveCompDialog.vue b/frontend/src/components/dialogs/GetLiveCompDialog.vue index 3fc177a..f6b8a8b 100644 --- a/frontend/src/components/dialogs/GetLiveCompDialog.vue +++ b/frontend/src/components/dialogs/GetLiveCompDialog.vue @@ -1,6 +1,8 @@