From 80943796ad597587fc474f84636c5ddb07ffaa10 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 11 Jun 2025 14:43:27 +0800 Subject: [PATCH] perf: TS Error --- frontend/src/components/layout/index.vue | 7 ++-- frontend/src/router/index.ts | 2 +- frontend/src/stores/user.ts | 33 ++++++++++++------- frontend/src/views/dashboard/editor/index.vue | 1 - .../views/dashboard/preview/SQPreviewShow.vue | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/layout/index.vue b/frontend/src/components/layout/index.vue index c25b4663..6e3b5cde 100644 --- a/frontend/src/components/layout/index.vue +++ b/frontend/src/components/layout/index.vue @@ -149,7 +149,6 @@ import {ref, computed, onMounted} from 'vue' import {useRouter, useRoute} from 'vue-router' import {useUserStore} from '@/stores/user' -import folder from '@/assets/svg/folder.svg' import ds from '@/assets/svg/ds.svg' import dashboard from '@/assets/svg/dashboard.svg' import chat from '@/assets/svg/chat.svg' @@ -184,12 +183,12 @@ const sysRouterList = computed(() => { const showSubmenu = computed(() => { return route.path.includes('/system') }) -const workspace = ref('1') -const options = [ +// const workspace = ref('1') +/* const options = [ {value: '1', label: 'Default workspace'}, {value: '2', label: 'Workspace 2'}, {value: '3', label: 'Workspace 3'} -] +] */ const currentPageTitle = computed(() => { if (route.path.includes('/system')) { return 'System Settings' diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 8fba4d81..51cefc81 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -8,7 +8,7 @@ import ds from "@/views/ds/index.vue"; import DashboardEditor from "@/views/dashboard/editor/index.vue"; import Dashboard from "@/views/dashboard/index.vue"; import Model from "@/views/system/model/index.vue"; -import User from "@/views/system/user/index.vue"; +// import User from "@/views/system/user/index.vue"; import { watchRouter } from "./watch"; const router = createRouter({ history: createWebHashHistory(), diff --git a/frontend/src/stores/user.ts b/frontend/src/stores/user.ts index a22a6237..e5cc79d0 100644 --- a/frontend/src/stores/user.ts +++ b/frontend/src/stores/user.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import { ref } from 'vue' +// import { ref } from 'vue' import { AuthApi } from '@/api/login' import { useCache } from '@/utils/useCache' import { i18n } from '@/i18n' @@ -17,18 +17,19 @@ interface UserState { language: string exp: number time: number + [key: string]: string | number } export const UserStore = defineStore('user', { state: (): UserState => { return { - token: null, - uid: null, - name: null, - oid: null, + token: '', + uid: '', + name: '', + oid: '', language: 'zh-CN', - exp: null, - time: null + exp: 0, + time: 0 } }, getters: { @@ -69,13 +70,23 @@ export const UserStore = defineStore('user', { const res: any = await AuthApi.info() const res_data = res || {} - const keys: string[] = ['uid', 'name', 'oid', 'language', 'exp', 'time'] - + // 指定 keys 类型为 UserState 的键 + const keys = ['uid', 'name', 'oid', 'language', 'exp', 'time'] as const + keys.forEach(key => { const dkey = key === 'uid' ? 'id' : key - this[key] = res_data[dkey] - wsCache.set('user.' + key, this[key]) + const value = res_data[dkey] + + // 使用类型守卫区分数字和字符串类型 + if (key === 'exp' || key === 'time') { + this[key] = Number(value) + wsCache.set('user.' + key, value.toString()) + } else { + this[key] = String(value) + wsCache.set('user.' + key, value) + } }) + this.setLanguage(this.language) }, setToken(token: string) { diff --git a/frontend/src/views/dashboard/editor/index.vue b/frontend/src/views/dashboard/editor/index.vue index 2861c417..4be1147b 100644 --- a/frontend/src/views/dashboard/editor/index.vue +++ b/frontend/src/views/dashboard/editor/index.vue @@ -8,7 +8,6 @@ import cloneDeep from 'lodash/cloneDeep'; import {storeToRefs} from "pinia"; import {dashboardStoreWithOut} from "@/stores/dashboard/dashboard.ts"; import router from '@/router' -import {dashboardApi} from "@/api/dashboard.ts"; import {initCanvasData} from "@/views/dashboard/utils/canvasUtils.ts"; const dashboardStore = dashboardStoreWithOut() diff --git a/frontend/src/views/dashboard/preview/SQPreviewShow.vue b/frontend/src/views/dashboard/preview/SQPreviewShow.vue index b364624c..0834c246 100644 --- a/frontend/src/views/dashboard/preview/SQPreviewShow.vue +++ b/frontend/src/views/dashboard/preview/SQPreviewShow.vue @@ -1,7 +1,7 @@