mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-11 09:08:14 +08:00
fix(home): 支持首页组件显示顺序自定义
This commit is contained in:
@@ -148,6 +148,7 @@ async function toPost(pool: GachaCard) {
|
||||
width: 100%;
|
||||
background: #546d8b;
|
||||
border-radius: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.pool-grid {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<template>
|
||||
<t-pool v-if="homeStore.pool.show" />
|
||||
<t-position v-if="homeStore.position.show" />
|
||||
<t-calendar v-if="homeStore.calendar.show" />
|
||||
<component v-for="item in components" :is="item" :key="item" />
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { shallowRef, onMounted } from "vue";
|
||||
import TPool from "../components/t-pool.vue";
|
||||
import TPosition from "../components/t-position.vue";
|
||||
import TCalendar from "../components/t-calendar.vue";
|
||||
@@ -13,4 +12,24 @@ import TCalendar from "../components/t-calendar.vue";
|
||||
import useHomeStore from "../store/modules/home";
|
||||
|
||||
const homeStore = useHomeStore();
|
||||
const showItems = homeStore.getShowValue();
|
||||
const components = shallowRef([] as any[]);
|
||||
|
||||
onMounted(() => {
|
||||
showItems.map(item => {
|
||||
switch (item) {
|
||||
case "限时祈愿":
|
||||
components.value.push(TPool);
|
||||
break;
|
||||
case "近期活动":
|
||||
components.value.push(TPosition);
|
||||
break;
|
||||
case "素材日历":
|
||||
components.value.push(TCalendar);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -50,12 +50,48 @@ const useHomeStore = defineStore({
|
||||
if (this.calendar.show) showValue.push("素材日历");
|
||||
if (this.pool.show) showValue.push("限时祈愿");
|
||||
if (this.position.show) showValue.push("近期活动");
|
||||
showValue.sort((a, b) => {
|
||||
return this.getItemOrder(a) - this.getItemOrder(b);
|
||||
});
|
||||
return showValue;
|
||||
},
|
||||
getItemOrder(item: string) {
|
||||
switch (item) {
|
||||
case "素材日历":
|
||||
return this.calendar.order;
|
||||
case "限时祈愿":
|
||||
return this.pool.order;
|
||||
case "近期活动":
|
||||
return this.position.order;
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
},
|
||||
setShowValue(value: string[]) {
|
||||
this.calendar.show = value.includes("素材日历");
|
||||
this.pool.show = value.includes("限时祈愿");
|
||||
this.position.show = value.includes("近期活动");
|
||||
// 遍历 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.show = true;
|
||||
break;
|
||||
case "限时祈愿":
|
||||
this.pool.order = index;
|
||||
this.pool.show = true;
|
||||
break;
|
||||
case "近期活动":
|
||||
this.position.order = index;
|
||||
this.position.show = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
persist: true,
|
||||
|
||||
Reference in New Issue
Block a user