From d15cece93314b757668964868b7a0a99753328ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Fri, 6 Dec 2024 18:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20TGApp=20is=20not=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/PostNews.vue | 20 ++++++++++---------- src/store/modules/app.ts | 10 +++++++++- src/types/App/Store.d.ts | 25 ------------------------- 3 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 src/types/App/Store.d.ts diff --git a/src/pages/common/PostNews.vue b/src/pages/common/PostNews.vue index fc1d536b..4e6e1516 100644 --- a/src/pages/common/PostNews.vue +++ b/src/pages/common/PostNews.vue @@ -67,14 +67,14 @@ import showSnackbar from "../../components/func/snackbar.js"; import ToChannel from "../../components/pageNews/to-channel.vue"; import VpOverlaySearch from "../../components/viewPost/vp-overlay-search.vue"; import Mys from "../../plugins/Mys/index.js"; -import { useAppStore } from "../../store/modules/app.js"; +import { NewsType, NewsTypeEnum, useAppStore } from "../../store/modules/app.js"; import TGLogger from "../../utils/TGLogger.js"; import { createPost } from "../../utils/TGWindow.js"; import { getGameName } from "../../web/utils/tools.js"; -type PostData = { [key in TGApp.App.Store.NewsType]: TGApp.Plugins.Mys.Post.FullData[] }; +type PostData = { [key in NewsType]: TGApp.Plugins.Mys.Post.FullData[] }; type RawData = { - [key in TGApp.App.Store.NewsType]: { isLast: boolean; name: string; lastId: number }; + [key in NewsType]: { isLast: boolean; name: string; lastId: number }; }; const router = useRouter(); @@ -82,12 +82,12 @@ const appStore = useAppStore(); const gid = useRoute().params.gid; const gameName = getGameName(Number(gid)); const loading = ref(false); -const tabValues: Readonly> = ["notice", "activity", "news"]; +const tabValues: Readonly> = ["notice", "activity", "news"]; const showList = ref(false); const showSearch = ref(false); -const tab = computed({ +const tab = computed({ get: () => { - if (!(appStore.recentNewsType satisfies TGApp.App.Store.NewsType)) return "notice"; + if (!(appStore.recentNewsType satisfies NewsType)) return "notice"; return appStore.recentNewsType; }, set: (v) => (appStore.recentNewsType = v), @@ -104,7 +104,7 @@ const rawData = ref({ onMounted(async () => await firstLoad(tab.value)); -async function firstLoad(key: TGApp.App.Store.NewsType, refresh: boolean = false): Promise { +async function firstLoad(key: NewsType, refresh: boolean = false): Promise { if (rawData.value[key].lastId !== 0) { if (!refresh) return; postData.value[key] = []; @@ -112,7 +112,7 @@ async function firstLoad(key: TGApp.App.Store.NewsType, refresh: boolean = false } showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`); document.documentElement.scrollTo({ top: 0, behavior: "smooth" }); - const getData = await Mys.Painter.getNewsList(gid, TGApp.App.Store.NewsTypeEnum[key]); + const getData = await Mys.Painter.getNewsList(gid, NewsTypeEnum[key]); rawData.value[key].isLast = getData.is_last; rawData.value[key].lastId = getData.list.length; postData.value[key] = getData.list; @@ -127,7 +127,7 @@ async function switchAnno(): Promise { } // 加载更多 -async function loadMore(key: TGApp.App.Store.NewsType): Promise { +async function loadMore(key: NewsType): Promise { loading.value = true; if (rawData.value[key].isLast) { showSnackbar.warn("已经是最后一页了"); @@ -137,7 +137,7 @@ async function loadMore(key: TGApp.App.Store.NewsType): Promise { showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`); const getData = await Mys.Painter.getNewsList( gid, - TGApp.App.Store.NewsTypeEnum[key], + NewsTypeEnum[key], 20, rawData.value[key].lastId, ); diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index 323d8124..46ef3ad9 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -18,6 +18,14 @@ const dbDataPath = `${await path.appConfigDir()}${path.sep()}TeyvatGuide.db`; // 用于存放日志的路径 const logDataDir = await path.appLogDir(); +export enum NewsTypeEnum { + notice = "1", + activity = "2", + news = "3", +} + +export type NewsType = keyof typeof NewsTypeEnum; + export const useAppStore = defineStore( "app", () => { @@ -46,7 +54,7 @@ export const useAppStore = defineStore( // 语言 const lang = ref("zh-cn"); // 最近的咨讯类型 - const recentNewsType = ref("notice"); + const recentNewsType = ref("notice"); // 是否开启分辨率回正 const needResize = ref("true"); // 分享图生成默认设置,为0表示默认保存到文件,为数字表示当大小超过xMB时保存到文件,否则保存到剪贴板 diff --git a/src/types/App/Store.d.ts b/src/types/App/Store.d.ts deleted file mode 100644 index 90278c40..00000000 --- a/src/types/App/Store.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @file types/App/Store.d.ts - * @description 涉及store但是没有特定的store模块的类型定义文件 - * @since Beta v0.6.5 - */ - -declare namespace TGApp.App.Store { - /** - * @description 咨讯类型枚举 - * @since Beta v0.6.5 - * @enum {string} - */ - enum NewsTypeEnum { - notice = "1", - activity = "2", - news = "3", - } - - /** - * @description 咨讯类型枚举 - * @since Beta v0.6.5 - * @type {keyof typeof NewsTypeEnum} - */ - type NewsType = keyof typeof NewsTypeEnum; -}