From 044a4b56e246e3cf82ccd818ecc6ac2c98c26c78 Mon Sep 17 00:00:00 2001 From: Dustella Date: Thu, 13 Feb 2025 19:35:12 +0800 Subject: [PATCH] feat: offline status --- auto-imports.d.ts | 4 + components.d.ts | 1 + index.html | 2 +- package.json | 2 +- src/App.vue | 301 ++----------------------------- src/CONSTANT.ts | 108 +++++++++++ src/components/DefaultLayout.vue | 190 +++++++++++++++++++ src/composables/fetch.ts | 51 +++++- 8 files changed, 368 insertions(+), 291 deletions(-) create mode 100644 src/components/DefaultLayout.vue diff --git a/auto-imports.d.ts b/auto-imports.d.ts index d1cec6a..13444c0 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -34,6 +34,7 @@ declare global { const defineComponent: typeof import('vue')['defineComponent'] const defineLoader: typeof import('vue-router/auto')['defineLoader'] const definePage: typeof import('unplugin-vue-router/runtime')['definePage'] + const doCheckOnline: typeof import('./src/composables/fetch')['doCheckOnline'] const eagerComputed: typeof import('@vueuse/core')['eagerComputed'] const effectScope: typeof import('vue')['effectScope'] const extendRef: typeof import('@vueuse/core')['extendRef'] @@ -132,6 +133,7 @@ declare global { const useAsyncQueue: typeof import('@vueuse/core')['useAsyncQueue'] const useAsyncState: typeof import('@vueuse/core')['useAsyncState'] const useAttrs: typeof import('vue')['useAttrs'] + const useBackendOnline: typeof import('./src/composables/fetch')['useBackendOnline'] const useBase64: typeof import('@vueuse/core')['useBase64'] const useBattery: typeof import('@vueuse/core')['useBattery'] const useBluetooth: typeof import('@vueuse/core')['useBluetooth'] @@ -334,6 +336,7 @@ declare module 'vue' { readonly debouncedWatch: UnwrapRef readonly defineAsyncComponent: UnwrapRef readonly defineComponent: UnwrapRef + readonly doCheckOnline: UnwrapRef readonly eagerComputed: UnwrapRef readonly effectScope: UnwrapRef readonly extendRef: UnwrapRef @@ -432,6 +435,7 @@ declare module 'vue' { readonly useAsyncQueue: UnwrapRef readonly useAsyncState: UnwrapRef readonly useAttrs: UnwrapRef + readonly useBackendOnline: UnwrapRef readonly useBase64: UnwrapRef readonly useBattery: UnwrapRef readonly useBluetooth: UnwrapRef diff --git a/components.d.ts b/components.d.ts index 6a3b3e4..0d20ac8 100644 --- a/components.d.ts +++ b/components.d.ts @@ -56,6 +56,7 @@ declare module 'vue' { CollapsibleTrigger: typeof import('./src/components/ui/collapsible/CollapsibleTrigger.vue')['default'] Day_cycle_power_wave_plot: typeof import('./src/components/dense/saber/day_cycle_power_wave_plot.vue')['default'] Day_fft_ifft_plot: typeof import('./src/components/dense/saber/day_fft_ifft_plot.vue')['default'] + DefaultLayout: typeof import('./src/components/DefaultLayout.vue')['default'] DenseFramework: typeof import('./src/components/DenseFramework.vue')['default'] Drawer: typeof import('./src/components/ui/drawer/Drawer.vue')['default'] DrawerContent: typeof import('./src/components/ui/drawer/DrawerContent.vue')['default'] diff --git a/index.html b/index.html index df53571..d1b8266 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ -
+
diff --git a/package.json b/package.json index f8be60b..e6030e3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "packageManager": "pnpm@9.14.4", "scripts": { "build": "vite build", - "dev": "vite --port 3333 --open", + "dev": "vite --port 10514 --open", "lint": "eslint .", "typecheck": "vue-tsc --noEmit", "preview": "vite preview", diff --git a/src/App.vue b/src/App.vue index 9fb48e1..c455798 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,295 +1,22 @@ diff --git a/src/CONSTANT.ts b/src/CONSTANT.ts index 0bab08c..03f36fd 100644 --- a/src/CONSTANT.ts +++ b/src/CONSTANT.ts @@ -2,3 +2,111 @@ const KURONEKO_API = 'http://100.89.232.74:18200' // export const API_BASE_URL = 'http://localhost:5000' export const API_BASE_URL = import.meta.env.PROD ? 'https://gca-api.dustella.net:8443' : KURONEKO_API // export const API_BASE_URL = 'https://gca-api.dustella.net:8443' + +export const headerData = { + user: { + name: 'shadcn', + email: 'm@example.com', + avatar: '/avatars/shadcn.jpg', + }, + navMain: [ + { + title: '流星雷达', + url: '#', + icon: 'ri-radar-fill', + isActive: true, + items: [ + { + title: '潮汐波提取', + url: '/radar/TW-single', + }, + { + title: '潮汐波统计', + url: '/radar/TW-stats', + }, + { + title: '行星波提取', + url: '/radar/PW-single', + }, + { + title: '行星波统计', + url: '/radar/PW-stats', + }, + ], + }, + { + title: 'SABER', + url: '#', + icon: 'game-icons:cracked-saber', + isActive: true, + items: [ + { + title: '重力波提取', + url: '/saber/gw/single', + }, + { + title: '重力波统计', + url: '/saber/gw/stats', + }, + ], + + }, + { + title: '探空气球', + url: '#', + icon: 'bxs:balloon', + isActive: true, + items: [ + { + title: '重力波单次', + url: '/balloon/single', + }, + { + title: '重力波统计', + url: '/balloon/year', + }, + ], + }, + { + title: 'TIDI', + url: '#', + icon: 'mdi:telescope', + isActive: true, + items: [ + { + title: '行星波振幅', + url: '/tidi/waves', + }, + { + title: '行星波月统计', + url: '/tidi/month_stats', + }, + ], + }, + { + title: 'COSMIC', + url: '#', + icon: 'mdi:telescope', + isActive: true, + items: [ + { + title: '行星波月统计', + url: '/cosmic/stats', + }, + { + title: '行星波单次', + url: '/cosmic/single', + }, + ], + }, + ], + + 关于: [ + { + name: 'Design Engineering', + url: '#', + icon: 'Frame', + }, + + ], +} as const diff --git a/src/components/DefaultLayout.vue b/src/components/DefaultLayout.vue new file mode 100644 index 0000000..8fa255a --- /dev/null +++ b/src/components/DefaultLayout.vue @@ -0,0 +1,190 @@ + + + diff --git a/src/composables/fetch.ts b/src/composables/fetch.ts index f1aeed1..055fa64 100644 --- a/src/composables/fetch.ts +++ b/src/composables/fetch.ts @@ -11,10 +11,9 @@ export const baseFetch = createFetch({ baseUrl: API_BASE_URL, options: { async beforeFetch({ options }) { - const code = '0101' options.headers = { ...options.headers, - Authorization: `${code}`, + Authorization: `${authCode.value}`, } return { options } }, @@ -25,3 +24,51 @@ export const baseFetch = createFetch({ }, }) + +export async function doCheckOnline() { + let resp = null + try { + resp = await baseFetch('/ping', { + timeout: 2000, + }) + const { error } = resp + if (error.value) + throw new Error(error.value) + const status = resp.response.value?.status + if (!status) { + return false + } + if (status === 200) { + return true + } + else if (status >= 400 && status < 500) { + return true + } + return false + } + catch (err) { + if (resp?.response.value?.status === 401) { + return true + } + console.error(err) + return false + } +} + +export const useBackendOnline = createSharedComposable(() => { + const isOnline = ref(true) + + const useCheckInterval = useIntervalFn(() => { + doCheckOnline().then((online) => { + isOnline.value = online + }) + }, 5000, { + immediate: true, + immediateCallback: true, + }) + useCheckInterval.resume() + + return { + isOnline, + } +})