mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
fix(pool): 搞了个缓存
This commit is contained in:
@@ -56,17 +56,22 @@
|
|||||||
// vue
|
// vue
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
|
// store
|
||||||
|
import useHomeStore from "../store/modules/home";
|
||||||
// utils
|
// utils
|
||||||
import { createTGWindow } from "../utils/TGWindow";
|
import { createTGWindow } from "../utils/TGWindow";
|
||||||
// plugins
|
// plugins
|
||||||
import MysOper from "../plugins/Mys";
|
import MysOper from "../plugins/Mys";
|
||||||
// interface
|
// interface
|
||||||
import { GachaCard } from "../plugins/Mys/interface/gacha";
|
import { GachaCard, GachaData } from "../plugins/Mys/interface/gacha";
|
||||||
import { Map } from "../interface/Base";
|
import { Map } from "../interface/Base";
|
||||||
|
|
||||||
// vue
|
// vue
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
// store
|
||||||
|
const homeStore = useHomeStore();
|
||||||
|
|
||||||
// loading
|
// loading
|
||||||
const loading = ref(true as boolean);
|
const loading = ref(true as boolean);
|
||||||
|
|
||||||
@@ -87,7 +92,16 @@ onMounted(async () => {
|
|||||||
await console.error("获取限时祈愿数据失败");
|
await console.error("获取限时祈愿数据失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
poolCards.value = await MysOper.Gacha.card(gachaData);
|
if (!checkCover(gachaData)) {
|
||||||
|
poolCards.value = await MysOper.Gacha.card(gachaData);
|
||||||
|
let coverData: Map<string> = {};
|
||||||
|
poolCards.value.map(pool => {
|
||||||
|
coverData[pool.post_id] = pool.cover;
|
||||||
|
});
|
||||||
|
homeStore.poolCover = coverData;
|
||||||
|
} else {
|
||||||
|
poolCards.value = await MysOper.Gacha.card(gachaData, homeStore.poolCover);
|
||||||
|
}
|
||||||
poolCards.value.map(pool => {
|
poolCards.value.map(pool => {
|
||||||
poolTimeGet.value[pool.post_id] = getLastPoolTime(pool.time.end_stamp - Date.now());
|
poolTimeGet.value[pool.post_id] = getLastPoolTime(pool.time.end_stamp - Date.now());
|
||||||
poolTimePass.value[pool.post_id] = pool.time.end_stamp - Date.now();
|
poolTimePass.value[pool.post_id] = pool.time.end_stamp - Date.now();
|
||||||
@@ -102,6 +116,25 @@ onMounted(async () => {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 检测是否有新的限时祈愿
|
||||||
|
function checkCover(data: GachaData[]) {
|
||||||
|
// 如果没有缓存
|
||||||
|
if (!homeStore.poolCover || Object.keys(homeStore.poolCover).length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 获取缓存
|
||||||
|
const cover = homeStore.poolCover;
|
||||||
|
return data.every(item => {
|
||||||
|
const post_id = item.activity_url.split("/").pop();
|
||||||
|
if (!post_id || isNaN(Number(post_id))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
cover[Number(post_id)] !== undefined && cover[Number(post_id)] !== "/source/UI/empty.webp"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function toOuter(url: string, title: string) {
|
function toOuter(url: string, title: string) {
|
||||||
createTGWindow(url, "祈愿", title, 1200, 800, true);
|
createTGWindow(url, "祈愿", title, 1200, 800, true);
|
||||||
}
|
}
|
||||||
@@ -114,14 +147,12 @@ function getLastPoolTime(time: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function toPost(pool: GachaCard) {
|
async function toPost(pool: GachaCard) {
|
||||||
// 获取路由路径
|
|
||||||
const path = router.resolve({
|
const path = router.resolve({
|
||||||
name: "帖子详情",
|
name: "帖子详情",
|
||||||
params: {
|
params: {
|
||||||
post_id: pool.post_id.toString(),
|
post_id: pool.post_id.toString(),
|
||||||
},
|
},
|
||||||
}).href;
|
}).href;
|
||||||
// 打开新窗口
|
|
||||||
createTGWindow(path, "限时祈愿", pool.title, 960, 720, false);
|
createTGWindow(path, "限时祈愿", pool.title, 960, 720, false);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,27 +7,37 @@
|
|||||||
|
|
||||||
import { getPostData } from "../request/post";
|
import { getPostData } from "../request/post";
|
||||||
import { GachaCard, GachaData } from "../interface/gacha";
|
import { GachaCard, GachaData } from "../interface/gacha";
|
||||||
|
import { Map } from "../../../interface/Base";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 根据卡池信息转为渲染用的卡池信息
|
* @description 根据卡池信息转为渲染用的卡池信息
|
||||||
* @since Alpha v0.1.2
|
* @since Alpha v0.1.2
|
||||||
* @param {GachaData[]} gachaData 卡池信息
|
* @param {GachaData[]} gachaData 卡池信息
|
||||||
|
* @param {Map<string>} poolCover 卡池封面
|
||||||
* @return {Promise<GachaCard[]>}
|
* @return {Promise<GachaCard[]>}
|
||||||
*/
|
*/
|
||||||
export async function getGachaCard(gachaData: GachaData[]): Promise<GachaCard[]> {
|
export async function getGachaCard(
|
||||||
|
gachaData: GachaData[],
|
||||||
|
poolCover: Map<string> | undefined = undefined
|
||||||
|
): Promise<GachaCard[]> {
|
||||||
const gachaCard: GachaCard[] = [];
|
const gachaCard: GachaCard[] = [];
|
||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
gachaData.map(async (data: GachaData) => {
|
gachaData.map(async (data: GachaData) => {
|
||||||
|
let cover = "/source/UI/empty.webp";
|
||||||
const post_id: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
|
const post_id: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
|
||||||
if (post_id === undefined) {
|
if (post_id === undefined || isNaN(post_id)) {
|
||||||
throw new Error("无法获取帖子 ID");
|
throw new Error("无法获取帖子 ID");
|
||||||
}
|
}
|
||||||
let cover = "/source/UI/empty.webp";
|
if (poolCover !== undefined) {
|
||||||
try {
|
cover = poolCover[post_id];
|
||||||
const post = await getPostData(post_id);
|
} else {
|
||||||
cover = post.cover?.url || post.post.images[0];
|
try {
|
||||||
} catch (error) {
|
await console.log("调用 getPostData");
|
||||||
await console.error(error);
|
const post = await getPostData(post_id);
|
||||||
|
cover = post.cover?.url || post.post.images[0];
|
||||||
|
} catch (error) {
|
||||||
|
await console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return gachaCard.push({
|
return gachaCard.push({
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
import { Map } from "../../interface/Base";
|
||||||
|
|
||||||
const useHomeStore = defineStore({
|
const useHomeStore = defineStore({
|
||||||
id: "home",
|
id: "home",
|
||||||
@@ -23,6 +24,7 @@ const useHomeStore = defineStore({
|
|||||||
show: true,
|
show: true,
|
||||||
order: 2,
|
order: 2,
|
||||||
},
|
},
|
||||||
|
poolCover: {} as Map<string>,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@@ -40,6 +42,7 @@ const useHomeStore = defineStore({
|
|||||||
show: true,
|
show: true,
|
||||||
order: 2,
|
order: 2,
|
||||||
},
|
},
|
||||||
|
poolCover: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getShowItem() {
|
getShowItem() {
|
||||||
@@ -47,7 +50,6 @@ const useHomeStore = defineStore({
|
|||||||
defaultList.sort((a, b) => {
|
defaultList.sort((a, b) => {
|
||||||
return this.getItemOrder(a) - this.getItemOrder(b);
|
return this.getItemOrder(a) - this.getItemOrder(b);
|
||||||
});
|
});
|
||||||
console.info("getShowItem", defaultList);
|
|
||||||
return defaultList;
|
return defaultList;
|
||||||
},
|
},
|
||||||
getShowValue() {
|
getShowValue() {
|
||||||
|
|||||||
Reference in New Issue
Block a user