diff --git a/src/components/t-calendar.vue b/src/components/t-calendar.vue index 3c8c6f4d..7c875691 100644 --- a/src/components/t-calendar.vue +++ b/src/components/t-calendar.vue @@ -18,10 +18,7 @@ {{ text.text }} -
- -
-
+
{ - loadingTitle.value = "正在获取材料日历数据"; const calendarData = await MysOper.Calendar.get(); if (!calendarData) { - loadingEmpty.value = true; - loadingTitle.value = "暂无材料日历"; + await console.error("获取材料日历失败"); return; } - loadingEmpty.value = false; - loadingTitle.value = "正在渲染材料日历"; const calendarCards = MysOper.Calendar.card(calendarData); const week = new Date().getDay(); btnNow.value = week; diff --git a/src/components/t-pool.vue b/src/components/t-pool.vue index 304d3144..4544a3d6 100644 --- a/src/components/t-pool.vue +++ b/src/components/t-pool.vue @@ -5,10 +5,7 @@ wish 限时祈愿 -
- -
-
+
); const poolTimePass = ref({} as Map); +// expose +defineExpose({ + name: "限时祈愿", + loading, +}); + onMounted(async () => { - try { - loadingTitle.value = "正在获取限时祈愿数据"; - const gachaData = await MysOper.Gacha.get(); - if (!gachaData) { - loadingEmpty.value = true; - return; - } - loadingEmpty.value = false; - loadingTitle.value = "正在渲染限时祈愿"; - poolCards.value = await MysOper.Gacha.card(gachaData); + const gachaData = await MysOper.Gacha.get(); + if (!gachaData) { + await console.error("获取限时祈愿数据失败"); + return; + } + poolCards.value = await MysOper.Gacha.card(gachaData); + poolCards.value.map(pool => { + poolTimeGet.value[pool.post_id] = getLastPoolTime(pool.time.end_stamp - Date.now()); + poolTimePass.value[pool.post_id] = pool.time.end_stamp - Date.now(); + }); + await setInterval(() => { poolCards.value.map(pool => { 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()) / (pool.time.end_stamp - pool.time.start_stamp)) * 100; }); - await setInterval(() => { - poolCards.value.map(pool => { - poolTimeGet.value[pool.post_id] = getLastPoolTime(pool.time.end_stamp - Date.now()); - poolTimePass.value[pool.post_id] = - ((pool.time.end_stamp - Date.now()) / (pool.time.end_stamp - pool.time.start_stamp)) * - 100; - }); - }, 1000); - } catch (error) { - console.error(error); - return; - } finally { - loading.value = false; - } + }, 1000); + loading.value = false; }); function toOuter(url: string, title: string) { diff --git a/src/components/t-position.vue b/src/components/t-position.vue index b48f4629..4a663d3f 100644 --- a/src/components/t-position.vue +++ b/src/components/t-position.vue @@ -5,10 +5,7 @@ act 近期活动 -
- -
-
+
); const positionTimeEnd = ref({} as Map); const router = useRouter(); +// expose +defineExpose({ + name: "近期活动", + loading, +}); + onMounted(async () => { - try { - loadingTitle.value = "正在获取近期活动数据"; - const positionData = await MysOper.Position.get(); - if (!positionData) { - loadingEmpty.value = true; - loadingTitle.value = "暂无近期活动"; - return; - } - loadingEmpty.value = false; - loadingTitle.value = "正在渲染近期活动"; - positionCards.value = MysOper.Position.card(positionData); - positionCards.value.forEach(card => { - positionTimeGet.value[card.post_id] = getLastPositionTime(card.time.end_stamp - Date.now()); - positionTimeEnd.value[card.post_id] = card.time.end_stamp; - }); - await setInterval(() => { - positionCards.value.forEach(card => { - const time = card.time.end_stamp - Date.now(); - if (time <= 0) { - positionTimeGet.value[card.post_id] = "已结束"; - return; - } - positionTimeGet.value[card.post_id] = getLastPositionTime(time); - }); - }, 1000); - } catch (error) { - console.error(error); + const positionData = await MysOper.Position.get(); + if (!positionData) { + console.error("获取近期活动失败"); return; - } finally { - loading.value = false; } + positionCards.value = MysOper.Position.card(positionData); + positionCards.value.forEach(card => { + positionTimeGet.value[card.post_id] = getLastPositionTime(card.time.end_stamp - Date.now()); + positionTimeEnd.value[card.post_id] = card.time.end_stamp; + }); + await setInterval(() => { + positionCards.value.forEach(card => { + const time = card.time.end_stamp - Date.now(); + if (time <= 0) { + positionTimeGet.value[card.post_id] = "已结束"; + return; + } + positionTimeGet.value[card.post_id] = getLastPositionTime(time); + }); + }, 1000); + loading.value = false; }); function getLastPositionTime(time: number) { diff --git a/src/pages/Home.vue b/src/pages/Home.vue index a0db73df..40e2d90b 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -1,35 +1,72 @@ diff --git a/src/plugins/Mys/utils/gacha.ts b/src/plugins/Mys/utils/gacha.ts index f4a29af6..4ae1caab 100644 --- a/src/plugins/Mys/utils/gacha.ts +++ b/src/plugins/Mys/utils/gacha.ts @@ -2,16 +2,15 @@ * @file plugins Mys utils gacha.ts * @description Mys 插件抽卡工具 * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ import { getPostData } from "../request/post"; import { GachaCard, GachaData } from "../interface/gacha"; -import { PostData } from "../interface/post"; /** * @description 根据卡池信息转为渲染用的卡池信息 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @param {GachaData[]} gachaData 卡池信息 * @return {Promise} */ @@ -23,11 +22,17 @@ export async function getGachaCard(gachaData: GachaData[]): Promise if (post_id === undefined) { throw new Error("无法获取帖子 ID"); } - const post: PostData = await getPostData(post_id); + let cover = "/source/UI/empty.webp"; + try { + const post = await getPostData(post_id); + cover = post.cover?.url || post.post.images[0]; + } catch (error) { + await console.error(error); + } return gachaCard.push({ title: data.title, subtitle: data.content_before_act, - cover: post.cover?.url || post.post.images[0], + cover: cover, post_id: post_id, characters: data.pool.map(character => ({ icon: character.icon, diff --git a/src/store/modules/home.ts b/src/store/modules/home.ts index fb6f6131..fc4d4da2 100644 --- a/src/store/modules/home.ts +++ b/src/store/modules/home.ts @@ -2,7 +2,7 @@ * @file store modules home.ts * @description Home store module * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ import { defineStore } from "pinia"; @@ -43,7 +43,12 @@ const useHomeStore = defineStore({ }; }, getShowItem() { - return ["素材日历", "限时祈愿", "近期活动"]; + const defaultList = ["素材日历", "限时祈愿", "近期活动"]; + defaultList.sort((a, b) => { + return this.getItemOrder(a) - this.getItemOrder(b); + }); + console.info("getShowItem", defaultList); + return defaultList; }, getShowValue() { let showValue = []; @@ -68,29 +73,47 @@ const useHomeStore = defineStore({ } }, setShowValue(value: string[]) { + let order = 1; // 遍历 value value.forEach(item => { if (!this.getShowItem().includes(item)) { throw new Error("传入的值不在可选范围内"); } - // 获取 item 在 value 中的索引 - const index = value.indexOf(item); switch (item) { case "素材日历": - this.calendar.order = index; + this.calendar.order = order; this.calendar.show = true; + order++; break; case "限时祈愿": - this.pool.order = index; + this.pool.order = order; this.pool.show = true; + order++; break; case "近期活动": - this.position.order = index; + this.position.order = order; this.position.show = true; + order++; break; default: break; } + // 没有显示的 item + if (!value.includes("素材日历")) { + this.calendar.show = false; + this.calendar.order = order; + order++; + } + if (!value.includes("限时祈愿")) { + this.pool.show = false; + this.pool.order = order; + order++; + } + if (!value.includes("近期活动")) { + this.position.show = false; + this.position.order = order; + order++; + } }); }, },