mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-20 04:39:45 +08:00
🎨 优化链接识别
This commit is contained in:
@@ -112,53 +112,20 @@ async function toNav(item: TGApp.BBS.Navigator.Navigator): Promise<void> {
|
||||
// 处理 protocol
|
||||
async function toBBS(link: URL): Promise<void> {
|
||||
if (link.protocol == "mihoyobbs:") {
|
||||
if (link.pathname.startsWith("//article")) {
|
||||
if (link.hostname === "article") {
|
||||
const postId = link.pathname.split("/").pop();
|
||||
await createPost(<string>postId);
|
||||
return;
|
||||
}
|
||||
if (link.pathname.startsWith("//forum")) {
|
||||
if (link.hostname === "forum") {
|
||||
const forumId = link.pathname.split("/").pop();
|
||||
const localPath = getLocalPath(forumId);
|
||||
if (localPath === "") {
|
||||
showSnackbar.warn(`不支持的链接:${link.href}`);
|
||||
return;
|
||||
}
|
||||
const localPath = `/posts/forum/${props.modelValue}/${forumId}`;
|
||||
await emit("active_deep_link", `router?path=${localPath}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
showSnackbar.warn(`不支持的链接:${link.href}`);
|
||||
}
|
||||
|
||||
// todo 动态获取版块列表
|
||||
function getLocalPath(forum?: string): string {
|
||||
if (!forum) return "";
|
||||
const forumLocalMap: Record<string, string> = {
|
||||
"31": "/news/3", // 崩坏2 官方
|
||||
"6": "/news/1", // 崩坏3 官方
|
||||
"28": "/news/2", // 原神官方
|
||||
"33": "/news/4", // 未定官方
|
||||
"58": "/news/8", // 绝区零官方
|
||||
"36": "/news/5", // 大别野公告
|
||||
};
|
||||
if (forumLocalMap[forum]) return forumLocalMap[forum];
|
||||
const ysForums = ["26", "43", "29", "49", "50"];
|
||||
const srForums = ["52", "61", "56", "62"];
|
||||
const bh3Forums = ["1", "14", "4", "41"];
|
||||
const bh2Forums = ["30", "51", "40"];
|
||||
const wdForums = ["37", "60", "42", "38"];
|
||||
const zzzForums = ["57", "59", "64", "65"];
|
||||
const dbyForums = ["54", "35", "34", "39", "47", "48", "55", "36"];
|
||||
if (ysForums.includes(forum)) return `/posts/forum/2/${forum}`;
|
||||
if (srForums.includes(forum)) return `/posts/forum/6/${forum}`;
|
||||
if (bh3Forums.includes(forum)) return `/posts/forum/1/${forum}`;
|
||||
if (bh2Forums.includes(forum)) return `/posts/forum/3/${forum}`;
|
||||
if (wdForums.includes(forum)) return `/posts/forum/4/${forum}`;
|
||||
if (zzzForums.includes(forum)) return `/posts/forum/8/${forum}`;
|
||||
if (dbyForums.includes(forum)) return `/posts/forum/5/${forum}`;
|
||||
return "";
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.tgn-container {
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
</template>
|
||||
<template #prepend>
|
||||
<div class="tolc-icon">
|
||||
<TMiImg :src="item.img" v-if="item.img !== ''" alt="award" />
|
||||
<img v-else src="/source/UI/empty.webp" alt="empty" />
|
||||
<img v-if="item.img === ''" src="/source/UI/empty.webp" alt="empty" />
|
||||
<TMiImg :src="item.img" v-else alt="award" />
|
||||
</div>
|
||||
</template>
|
||||
<template #append>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<v-select
|
||||
v-model="selectedForum"
|
||||
class="post-switch-item"
|
||||
:items="getGameForums(curGid)"
|
||||
:items="curForums"
|
||||
variant="outlined"
|
||||
label="版块"
|
||||
:disabled="isReq"
|
||||
@@ -130,7 +130,7 @@ import TPostCard from "@comp/app/t-postcard.vue";
|
||||
import showLoading from "@comp/func/loading.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue";
|
||||
import { onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
@@ -160,6 +160,12 @@ const selectedForum = shallowRef<SortSelect>();
|
||||
const sortGameList = shallowRef<Array<SortSelectGame>>([]);
|
||||
const postRaw = shallowRef<PostRaw>({ isLast: false, lastId: "", total: 0 });
|
||||
const posts = shallowRef<Array<TGApp.BBS.Post.FullData>>([]);
|
||||
const curGame = computed<SortSelectGame | undefined>(() => {
|
||||
return sortGameList.value.find((item) => item.gid === curGid.value);
|
||||
});
|
||||
const curForums = computed<Array<SortSelect>>(() => {
|
||||
return curGame.value?.forum ?? [];
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await showLoading.start("正在加载帖子数据");
|
||||
@@ -169,11 +175,11 @@ onMounted(async () => {
|
||||
if (!forum) forum = route.params.forum;
|
||||
if (gid && typeof gid === "string") curGid.value = Number(gid);
|
||||
if (forum && typeof forum === "string") {
|
||||
selectedForum.value = getForum(curGid.value, Number(forum));
|
||||
selectedForum.value = getForum(Number(forum));
|
||||
} else {
|
||||
selectedForum.value = getGameForums(curGid.value)[0];
|
||||
selectedForum.value = curForums.value[0];
|
||||
}
|
||||
const gameLabel = getGameLabel(curGid.value);
|
||||
const gameLabel = curGame.value?.text ?? "";
|
||||
await TGLogger.Info(`[Posts][${gameLabel}][onMounted][${selectedForum.value.text}] 打开帖子列表`);
|
||||
await freshPostData();
|
||||
firstLoad.value = true;
|
||||
@@ -182,11 +188,10 @@ watch(
|
||||
() => curGid.value,
|
||||
() => {
|
||||
if (!selectedForum.value) return;
|
||||
const forums = getGameForums(curGid.value);
|
||||
const forumFind = forums.find((item) => item.text === selectedForum.value?.text);
|
||||
const forumFind = curForums.value.find((item) => item.text === selectedForum.value?.text);
|
||||
if (!firstLoad.value) return;
|
||||
selectedForum.value = forumFind ?? forums[0];
|
||||
showSnackbar.success(`已将分区切换到 ${getGameLabel(curGid.value)}`);
|
||||
selectedForum.value = forumFind ?? curForums.value[0];
|
||||
showSnackbar.success(`已将分区切换到 ${curGame.value?.text}`);
|
||||
},
|
||||
);
|
||||
watch(
|
||||
@@ -227,22 +232,9 @@ async function loadForums(): Promise<void> {
|
||||
sortGameList.value = gameList;
|
||||
}
|
||||
|
||||
function getGameForums(gid: number): SortSelect[] {
|
||||
const game = sortGameList.value.find((item) => item.gid === gid);
|
||||
if (game) return game.forum;
|
||||
return [];
|
||||
}
|
||||
|
||||
function getGameLabel(gid: number): string {
|
||||
const game = sortGameList.value.find((item) => item.gid === gid);
|
||||
if (game) return game.text;
|
||||
return "";
|
||||
}
|
||||
|
||||
function getForum(gid: number, forum: number): SortSelect {
|
||||
const forums = getGameForums(gid);
|
||||
const forumItem = forums.find((item) => item.value === forum);
|
||||
return forumItem ? forumItem : forums[0];
|
||||
function getForum(forum: number): SortSelect {
|
||||
const forumItem = curForums.value.find((item) => item.value === forum);
|
||||
return forumItem ? forumItem : curForums.value[0];
|
||||
}
|
||||
|
||||
function getSortLabel(value: number): string {
|
||||
@@ -282,9 +274,9 @@ async function freshPostData(): Promise<void> {
|
||||
query: { gid: curGid.value, forum: selectedForum.value.value },
|
||||
});
|
||||
isReq.value = true;
|
||||
await showLoading.start(`正在刷新${getGameLabel(curGid.value)}帖子`);
|
||||
const gameLabel = getGameLabel(curGid.value);
|
||||
const forumLabel = getForum(curGid.value, selectedForum.value.value).text;
|
||||
const gameLabel = curGame.value?.text ?? "";
|
||||
await showLoading.start(`正在刷新${gameLabel}帖子`);
|
||||
const forumLabel = getForum(selectedForum.value.value).text;
|
||||
const sortLabel = getSortLabel(curSortType.value);
|
||||
await TGLogger.Info(
|
||||
`[Posts][${gameLabel}][freshPostData][${forumLabel}][${sortLabel}] 刷新帖子列表`,
|
||||
@@ -314,7 +306,7 @@ async function loadMore(): Promise<void> {
|
||||
}
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
await showLoading.start("正在加载更多帖子数据", `游戏:${getGameLabel(curGid.value)}`);
|
||||
await showLoading.start("正在加载更多帖子数据", `游戏:${curGame.value?.text}`);
|
||||
const postsGet = await getCurrentPosts(true, selectedForum.value.value);
|
||||
await showLoading.update(
|
||||
`版块:${selectedForum.value.text},排序:${getSortLabel(curSortType.value)},数量:${postsGet.list.length}`,
|
||||
|
||||
Reference in New Issue
Block a user