优化 Cookie 存储类型;更新登录状态判断逻辑;添加 Tauri 环境判断以支持版本更新处理

This commit is contained in:
2025-04-07 00:15:07 +08:00
parent eb306b66b0
commit 277497420c
4 changed files with 37 additions and 30 deletions

View File

@@ -13,7 +13,7 @@ export const isLoggedIn = computed<boolean>(() => {
}); });
const { message } = createDiscreteApi(['message']); const { message } = createDiscreteApi(['message']);
export const cookie = useLocalStorage('Cookie', {cookie: '', refreshDate: 0}, { serializer: StorageSerializers.object }); export const cookie = useLocalStorage<{ cookie: string; refreshDate: number }>('Cookie', {cookie: '', refreshDate: 0}, { serializer: StorageSerializers.object });
export async function GetSelfAccount(token?: string) { export async function GetSelfAccount(token?: string) {
if (cookie.value.cookie || token) { if (cookie.value.cookie || token) {

View File

@@ -218,7 +218,7 @@ onUnmounted(() => {
<template #header-extra> <template #header-extra>
<slot name="header-extra" /> <slot name="header-extra" />
</template> </template>
<template v-if="cookie"> <template v-if="cookie.cookie">
<NAlert type="warning"> <NAlert type="warning">
你已经登录 你已经登录
</NAlert> </NAlert>

View File

@@ -10,6 +10,8 @@ const failoverAPI = `https://failover-api.vtsuru.suki.club/`;
export const isBackendUsable = ref(true); export const isBackendUsable = ref(true);
export const isDev = import.meta.env.MODE === 'development'; export const isDev = import.meta.env.MODE === 'development';
// @ts-ignore
export const isTauri = window.__TAURI__ !== undefined || window.__TAURI_INTERNAL__ !== undefined;
export const AVATAR_URL = 'https://workers.vrp.moe/api/bilibili/avatar/'; export const AVATAR_URL = 'https://workers.vrp.moe/api/bilibili/avatar/';
export const FILE_BASE_URL = 'https://files.vtsuru.live'; export const FILE_BASE_URL = 'https://files.vtsuru.live';

View File

@@ -1,5 +1,5 @@
import { QueryGetAPI } from '@/api/query' import { QueryGetAPI } from '@/api/query'
import { apiFail, BASE_API_URL } from '@/data/constants' import { apiFail, BASE_API_URL, isTauri } from '@/data/constants'
import HyperDX from '@hyperdx/browser' import HyperDX from '@hyperdx/browser'
import EasySpeech from 'easy-speech' import EasySpeech from 'easy-speech'
import { createDiscreteApi, NButton, NFlex, NText } from 'naive-ui' import { createDiscreteApi, NButton, NFlex, NText } from 'naive-ui'
@@ -55,6 +55,10 @@ QueryGetAPI<string>(`${BASE_API_URL}vtsuru/version`)
const path = url.pathname const path = url.pathname
if (!path.startsWith('/obs')) { if (!path.startsWith('/obs')) {
if (isTauri) {
location.reload();
}
else {
const n = notification.info({ const n = notification.info({
title: '发现新的版本更新', title: '发现新的版本更新',
content: '是否现在刷新?', content: '是否现在刷新?',
@@ -84,6 +88,7 @@ QueryGetAPI<string>(`${BASE_API_URL}vtsuru/version`)
}) })
} }
} }
}
}, },
) )
}, 60 * 1000) }, 60 * 1000)