From 993107c24cc72a92cf23df330d748c400d77831f Mon Sep 17 00:00:00 2001 From: Megghy Date: Fri, 2 May 2025 01:59:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=BF=E6=8D=A2=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E9=80=BB=E8=BE=91=E4=B8=BABiliAuth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将所有使用useAuthStore的地方替换为useBiliAuth - 删除useAuthStore文件,整合认证逻辑 - 更新相关视图和组件以适应新的认证存储 --- src/data/Initializer.ts | 4 +- src/store/{useAuthStore.ts => useBiliAuth.ts} | 2 +- src/store/usePointStore.ts | 4 +- src/views/BiliAuthView.vue | 4 +- src/views/ManageLayout.vue | 4 +- src/views/ViewerLayout.vue | 4 +- src/views/manage/point/PointManage.vue | 4 +- src/views/pointViews/PointGoodsView.vue | 4 +- src/views/pointViews/PointOrderView.vue | 4 +- src/views/pointViews/PointUserHistoryView.vue | 4 +- src/views/pointViews/PointUserLayout.vue | 4 +- src/views/pointViews/PointUserSettings.vue | 4 +- src/views/view/CheckInRankingView.vue | 40 +- src/views/view/SongListView.vue | 422 +++++++++++------- .../DefaultSongListTemplate.vue | 12 +- .../SimpleSongListTemplate.vue | 13 +- .../TraditionalSongListTemplate.vue | 27 +- .../utils/songRequestUtils.ts | 135 ++++++ 18 files changed, 477 insertions(+), 218 deletions(-) rename src/store/{useAuthStore.ts => useBiliAuth.ts} (98%) create mode 100644 src/views/view/songListTemplate/utils/songRequestUtils.ts diff --git a/src/data/Initializer.ts b/src/data/Initializer.ts index 1d2cf0b..11bc9b2 100644 --- a/src/data/Initializer.ts +++ b/src/data/Initializer.ts @@ -1,6 +1,6 @@ import { GetSelfAccount, useAccount, UpdateAccountLoop } from "@/api/account"; import { QueryGetAPI } from "@/api/query"; -import { useAuthStore } from "@/store/useAuthStore"; +import { useBiliAuth } from "@/store/useBiliAuth"; import { useNotificationStore } from "@/store/useNotificationStore"; import { createDiscreteApi, NText, NFlex, NButton } from "naive-ui"; import { BASE_API_URL, isTauri, apiFail } from "./constants"; @@ -64,7 +64,7 @@ async function InitOther() { InitTTS() await GetSelfAccount() const account = useAccount() - const useAuth = useAuthStore() + const useAuth = useBiliAuth() if (account.value.id) { if (account.value.biliUserAuthInfo && !useAuth.currentToken) { useAuth.currentToken = account.value.biliUserAuthInfo.token diff --git a/src/store/useAuthStore.ts b/src/store/useBiliAuth.ts similarity index 98% rename from src/store/useAuthStore.ts rename to src/store/useBiliAuth.ts index 3212ba0..b6bc02a 100644 --- a/src/store/useAuthStore.ts +++ b/src/store/useBiliAuth.ts @@ -6,7 +6,7 @@ import { MessageApiInjection } from 'naive-ui/es/message/src/MessageProvider' import { defineStore } from 'pinia' import { computed, ref } from 'vue' -export const useAuthStore = defineStore('BiliAuth', () => { +export const useBiliAuth = defineStore('BiliAuth', () => { const biliAuth = ref({} as BiliAuthModel) const biliTokens = useStorage< diff --git a/src/store/usePointStore.ts b/src/store/usePointStore.ts index e046006..0eddd51 100644 --- a/src/store/usePointStore.ts +++ b/src/store/usePointStore.ts @@ -3,11 +3,11 @@ import { QueryGetAPI } from "@/api/query"; import { POINT_API_URL } from "@/data/constants"; import { MessageApiInjection } from "naive-ui/es/message/src/MessageProvider"; import { defineStore } from "pinia"; -import { useAuthStore } from "./useAuthStore"; +import { useBiliAuth } from "./useBiliAuth"; import { GuidUtils } from "@/Utils"; export const usePointStore = defineStore('point', () => { - const useAuth = useAuthStore() + const useAuth = useBiliAuth() async function GetSpecificPoint(id: number) { try { diff --git a/src/views/BiliAuthView.vue b/src/views/BiliAuthView.vue index eb00c26..43c33ae 100644 --- a/src/views/BiliAuthView.vue +++ b/src/views/BiliAuthView.vue @@ -1,7 +1,7 @@ diff --git a/src/views/view/songListTemplate/DefaultSongListTemplate.vue b/src/views/view/songListTemplate/DefaultSongListTemplate.vue index 4b53199..d44bba6 100644 --- a/src/views/view/songListTemplate/DefaultSongListTemplate.vue +++ b/src/views/view/songListTemplate/DefaultSongListTemplate.vue @@ -4,11 +4,14 @@ import { SongsInfo } from '@/api/api-models' import SongList from '@/components/SongList.vue' import { SongListConfigType } from '@/data/TemplateTypes' import LiveRequestOBS from '@/views/obs/LiveRequestOBS.vue' +import { getSongRequestTooltip } from './utils/songRequestUtils' import { CloudAdd20Filled, ChevronLeft24Filled, ChevronRight24Filled } from '@vicons/fluent' import { NButton, NCard, NCollapse, NCollapseItem, NDivider, NIcon, NTooltip, useMessage } from 'naive-ui' import { h, ref, onMounted, onUnmounted } from 'vue' +import { useBiliAuth } from '@/store/useBiliAuth' const accountInfo = useAccount() +const biliAuth = useBiliAuth() //所有模板都应该有这些 const props = defineProps() @@ -75,7 +78,7 @@ const buttons = (song: SongsInfo) => [ size: 'small', circle: true, loading: isLoading.value == song.key, - disabled: !accountInfo, + disabled: !accountInfo.value, onClick: () => { isLoading.value = song.key emits('requestSong', song) @@ -86,12 +89,7 @@ const buttons = (song: SongsInfo) => [ icon: () => h(NIcon, { component: CloudAdd20Filled }), }, ), - default: () => - !props.liveRequestSettings?.allowFromWeb || song.options - ? '点歌 | 用户不允许从网页点歌, 点击后将复制点歌内容到剪切板' - : !accountInfo - ? '点歌 | 你需要登录后才能点歌' - : '点歌', + default: () => getSongRequestTooltip(song, props.liveRequestSettings) }, ) : undefined, diff --git a/src/views/view/songListTemplate/SimpleSongListTemplate.vue b/src/views/view/songListTemplate/SimpleSongListTemplate.vue index c86e825..2a669d2 100644 --- a/src/views/view/songListTemplate/SimpleSongListTemplate.vue +++ b/src/views/view/songListTemplate/SimpleSongListTemplate.vue @@ -5,9 +5,11 @@ import { FunctionTypes, SongsInfo } from '@/api/api-models' import SongPlayer from '@/components/SongPlayer.vue' import { SongListConfigType } from '@/data/TemplateTypes' import LiveRequestOBS from '@/views/obs/LiveRequestOBS.vue' +import { getSongRequestTooltip, getSongRequestButtonType } from './utils/songRequestUtils' import { CloudAdd20Filled, Play24Filled } from '@vicons/fluent' import { useWindowSize } from '@vueuse/core' import { throttle } from 'lodash' +import { useBiliAuth } from '@/store/useBiliAuth' import { NButton, NCard, @@ -36,6 +38,7 @@ const container = ref() const index = ref(20) const accountInfo = useAccount() +const biliAuth = useBiliAuth() const selectedTag = ref('') const selectedSong = ref() @@ -296,7 +299,7 @@ function loadMore() {