mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✨ 支持角色筛选
This commit is contained in:
@@ -21,33 +21,44 @@
|
|||||||
</v-btn>
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template #extension>
|
||||||
|
<div class="uc-select">
|
||||||
|
<v-btn variant="outlined" @click="showSelect = true">筛选角色</v-btn>
|
||||||
|
<v-btn variant="outlined" @click="resetSelect = true">重置筛选</v-btn>
|
||||||
|
</div>
|
||||||
|
<!-- todo 展示模式切换 -->
|
||||||
|
</template>
|
||||||
</v-app-bar>
|
</v-app-bar>
|
||||||
<div class="uc-box">
|
<div class="uc-box">
|
||||||
<div class="uc-top">
|
<div class="uc-top">
|
||||||
<div class="uc-top-title" @click="switchOld">
|
<div class="uc-top-title">
|
||||||
<span v-if="user">
|
<span v-if="user">
|
||||||
{{ user.nickname }} UID:{{ user.gameUid }} 更新于 {{ getUpdateTime() }}
|
{{ user.nickname }} UID:{{ user.gameUid }} 更新于 {{ getUpdateTime() }}
|
||||||
|
<!-- todo 展示筛选条件 -->
|
||||||
</span>
|
</span>
|
||||||
<span v-else> 暂无数据 </span>
|
<span v-else> 暂无数据 </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="uc-grid">
|
<div class="uc-grid">
|
||||||
<TuaAvatarBox
|
<TuaAvatarBox
|
||||||
v-for="(role, index) in roleList"
|
v-for="(role, index) in selectedList"
|
||||||
:key="index"
|
:key="index"
|
||||||
:model-value="role"
|
:model-value="role"
|
||||||
@click="selectRole(role)"
|
@click="selectRole(role)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<TwoSelectC v-model="showSelect" @select-c="handleSelect" v-model:reset="resetSelect" />
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { onBeforeMount, onMounted, ref } from "vue";
|
import { onBeforeMount, onMounted, ref, watch } from "vue";
|
||||||
|
|
||||||
import showSnackbar from "../../components/func/snackbar.js";
|
import showSnackbar from "../../components/func/snackbar.js";
|
||||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||||
import TuaAvatarBox from "../../components/userAvatar/tua-avatar-box.vue";
|
import TuaAvatarBox from "../../components/userAvatar/tua-avatar-box.vue";
|
||||||
|
import TwoSelectC, { SelectedCValue } from "../../components/wiki/two-select-c.vue";
|
||||||
|
import { AppCharacterData } from "../../data/index.js";
|
||||||
import TSUserAvatar from "../../plugins/Sqlite/modules/userAvatar.js";
|
import TSUserAvatar from "../../plugins/Sqlite/modules/userAvatar.js";
|
||||||
import { useUserStore } from "../../store/modules/user.js";
|
import { useUserStore } from "../../store/modules/user.js";
|
||||||
import TGLogger from "../../utils/TGLogger.js";
|
import TGLogger from "../../utils/TGLogger.js";
|
||||||
@@ -68,17 +79,18 @@ const loadingSub = ref<string>();
|
|||||||
// data
|
// data
|
||||||
const isEmpty = ref(true);
|
const isEmpty = ref(true);
|
||||||
const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
|
const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
|
||||||
|
const selectedList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
|
||||||
|
|
||||||
// overlay
|
// overlay
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const dataVal = ref<TGApp.Sqlite.Character.UserRole>(<TGApp.Sqlite.Character.UserRole>{});
|
const dataVal = ref<TGApp.Sqlite.Character.UserRole>(<TGApp.Sqlite.Character.UserRole>{});
|
||||||
const selectIndex = ref(0);
|
const selectIndex = ref(0);
|
||||||
const detailDev = ref(true);
|
|
||||||
|
const showSelect = ref<boolean>(false);
|
||||||
|
const resetSelect = ref<boolean>(false);
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
if (userStore.account.value) {
|
if (userStore.account.value) user.value = userStore.account.value;
|
||||||
user.value = userStore.account.value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -91,29 +103,43 @@ onMounted(async () => {
|
|||||||
loadData.value = false;
|
loadData.value = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
function switchOld(): void {
|
watch(resetSelect, (val) => {
|
||||||
detailDev.value = !detailDev.value;
|
if (val) {
|
||||||
|
selectedList.value = getOrderedList(roleList.value);
|
||||||
showSnackbar({
|
showSnackbar({
|
||||||
text: `已切换到${detailDev.value ? "新" : "旧"}版角色详情页面`,
|
text: "已重置筛选条件",
|
||||||
|
color: "success",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getOrderedList(
|
||||||
|
data: TGApp.Sqlite.Character.UserRole[],
|
||||||
|
): TGApp.Sqlite.Character.UserRole[] {
|
||||||
|
return data.sort((a, b) => {
|
||||||
|
if (a.avatar.rarity !== b.avatar.rarity) return b.avatar.rarity - a.avatar.rarity;
|
||||||
|
if (a.avatar.element !== b.avatar.element) {
|
||||||
|
return a.avatar.element.localeCompare(b.avatar.element);
|
||||||
|
}
|
||||||
|
return a.cid - b.cid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load(): Promise<void> {
|
async function load(): Promise<void> {
|
||||||
if (!user.value) return;
|
if (!user.value) return;
|
||||||
const roleData = await TSUserAvatar.getAvatars(user.value.gameUid);
|
const roleData = await TSUserAvatar.getAvatars(user.value.gameUid);
|
||||||
roleData.sort((a, b) => {
|
roleList.value = getOrderedList(roleData);
|
||||||
if (a.avatar.rarity !== b.avatar.rarity) return b.avatar.rarity - a.avatar.rarity;
|
selectedList.value = roleList.value;
|
||||||
if (a.avatar.element !== b.avatar.element)
|
|
||||||
return a.avatar.element.localeCompare(b.avatar.element);
|
|
||||||
return a.cid - b.cid;
|
|
||||||
});
|
|
||||||
roleList.value = roleData;
|
|
||||||
dataVal.value = roleData[selectIndex.value];
|
dataVal.value = roleData[selectIndex.value];
|
||||||
isEmpty.value = false;
|
isEmpty.value = false;
|
||||||
await TGLogger.Info(`[Character][loadRole][${user.value.gameUid}] 成功加载角色数据`);
|
await TGLogger.Info(`[Character][loadRole][${user.value.gameUid}] 成功加载角色数据`);
|
||||||
await TGLogger.Info(
|
await TGLogger.Info(
|
||||||
`[Character][loadRole][${user.value.gameUid}] 共获取到${roleData.length}个角色`,
|
`[Character][loadRole][${user.value.gameUid}] 共获取到${roleData.length}个角色`,
|
||||||
);
|
);
|
||||||
|
showSnackbar({
|
||||||
|
text: `成功加载${roleData.length}个角色`,
|
||||||
|
color: "success",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh(): Promise<void> {
|
async function refresh(): Promise<void> {
|
||||||
@@ -210,8 +236,40 @@ function selectRole(role: TGApp.Sqlite.Character.UserRole): void {
|
|||||||
selectIndex.value = roleList.value.indexOf(role);
|
selectIndex.value = roleList.value.indexOf(role);
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSelect(val: SelectedCValue) {
|
||||||
|
showSelect.value = false;
|
||||||
|
const filterC = AppCharacterData.filter((avatar) => {
|
||||||
|
if (!roleList.value.find((role) => role.avatar.id === avatar.id)) return false;
|
||||||
|
if (!val.star.includes(avatar.star)) return false;
|
||||||
|
if (!val.weapon.includes(avatar.weapon)) return false;
|
||||||
|
if (!val.elements.includes(avatar.element)) return false;
|
||||||
|
return val.area.includes(avatar.area);
|
||||||
|
});
|
||||||
|
if (filterC.length === 0) {
|
||||||
|
showSnackbar({
|
||||||
|
text: "未找到符合条件的角色",
|
||||||
|
color: "warn",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showSnackbar({
|
||||||
|
text: `筛选出符合条件的角色 ${filterC.length} 个`,
|
||||||
|
color: "success",
|
||||||
|
});
|
||||||
|
const selectedId = filterC.map((item) => item.id);
|
||||||
|
selectedList.value = roleList.value.filter((role) => selectedId.includes(role.avatar.id));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
|
.uc-select {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
margin: 0 10px;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.uc-box {
|
.uc-box {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -241,6 +299,7 @@ function selectRole(role: TGApp.Sqlite.Character.UserRole): void {
|
|||||||
.uc-top-btns {
|
.uc-top-btns {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
|
margin: 0 10px;
|
||||||
column-gap: 10px;
|
column-gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
<div class="wc-box">
|
<div class="wc-box">
|
||||||
<div class="wc-left">
|
<div class="wc-left">
|
||||||
<div class="wc-select">
|
<div class="wc-select">
|
||||||
<v-btn @click="showSelect = true">
|
<v-btn @click="showSelect = true">筛选角色</v-btn>
|
||||||
<span>筛选角色</span>
|
|
||||||
</v-btn>
|
|
||||||
<v-btn @click="resetSelect = true">重置筛选</v-btn>
|
<v-btn @click="resetSelect = true">重置筛选</v-btn>
|
||||||
</div>
|
</div>
|
||||||
<div class="wc-list">
|
<div class="wc-list">
|
||||||
@@ -93,6 +91,7 @@ function handleSelect(val: SelectedCValue) {
|
|||||||
}
|
}
|
||||||
showSnackbar({
|
showSnackbar({
|
||||||
text: `筛选出符合条件的角色 ${filterC.length} 个`,
|
text: `筛选出符合条件的角色 ${filterC.length} 个`,
|
||||||
|
color: "success",
|
||||||
});
|
});
|
||||||
cardsInfo.value = filterC;
|
cardsInfo.value = filterC;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user