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