+
);
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++;
+ }
});
},
},