diff --git a/src/pages/User/Characters.vue b/src/pages/User/Characters.vue index c6ff50ca..39947d11 100644 --- a/src/pages/User/Characters.vue +++ b/src/pages/User/Characters.vue @@ -43,27 +43,55 @@ @@ -126,7 +154,7 @@ import TGLogger from "@utils/TGLogger.js"; import { generateShareImg } from "@utils/TGShare.js"; import { getZhElement, timestampToDate } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; -import { computed, onMounted, ref, shallowRef, watch } from "vue"; +import { computed, nextTick, onMounted, ref, shallowRef, triggerRef, watch } from "vue"; import { AppCharacterData } from "@/data/index.js"; @@ -153,6 +181,12 @@ const showSelect = ref(false); const showMode = ref<"classic" | "card" | "dev">("dev"); const resetSelect = ref(false); const uidCur = ref(); + +// 排序 +const isLevelUp = ref(null); +const isFetterUp = ref(null); +const isConstUp = ref(null); + const uidList = shallowRef>([]); const roleOverview = shallowRef>([]); const roleList = shallowRef>([]); @@ -184,9 +218,13 @@ watch( dataVal.value = selectedList.value[0]; selectIndex.value = 0; } + isLevelUp.value = null; + isFetterUp.value = null; + isConstUp.value = null; } }, ); + watch( () => showMode.value, () => { @@ -204,6 +242,67 @@ watch( }, ); watch(() => uidCur.value, loadRole); +watch( + () => [isLevelUp.value, isLevelUp.value, isConstUp.value], + async () => { + let tmp = selectedList.value; + if (isLevelUp.value === true) { + tmp = tmp.sort((a, b) => b.avatar.level - a.avatar.level); + } else if (isLevelUp.value === false) { + tmp = tmp.sort((a, b) => a.avatar.level - b.avatar.level); + } + if (isFetterUp.value === true) { + tmp = tmp.sort((a, b) => b.avatar.fetter - a.avatar.fetter); + } else if (isFetterUp.value === false) { + tmp = tmp.sort((a, b) => a.avatar.fetter - b.avatar.fetter); + } + if (isConstUp.value === true) { + tmp = tmp.sort( + (a, b) => b.avatar.actived_constellation_num - a.avatar.actived_constellation_num, + ); + } else if (isConstUp.value === false) { + tmp = tmp.sort( + (a, b) => a.avatar.actived_constellation_num - b.avatar.actived_constellation_num, + ); + } + selectedList.value = tmp; + triggerRef(selectedList); + await nextTick(); + }, +); + +function toggleSort(value: boolean | null): boolean { + switch (value) { + case true: + return false; + case false: + return true; + case null: + return true; + } +} + +function getSortIcon(value: boolean | null): string { + switch (value) { + case true: + return "mdi-arrow-up"; + case false: + return "mdi-arrow-down"; + default: + return "mdi-sort"; + } +} + +function getSortDesc(value: boolean | null): string { + switch (value) { + case true: + return "升序"; + case false: + return "降序"; + default: + return "默认"; + } +} function getOrderedList( data: Array, @@ -455,12 +554,22 @@ function handleSwitch(next: boolean): void { } } +.uc-extension { + position: relative; + display: flex; + width: 100%; + align-items: center; + justify-content: space-between; + margin-right: 16px; + margin-bottom: 4px; + margin-left: 16px; +} + .uc-select { display: flex; align-items: center; justify-content: flex-start; - margin-bottom: 4px; - margin-left: 16px; + column-gap: 8px; } .uc-select-btn { @@ -473,6 +582,14 @@ function handleSwitch(next: boolean): void { font-size: 14px; } +.uc-sort { + position: relative; + display: flex; + align-items: center; + justify-content: center; + column-gap: 8px; +} + .uc-box { display: flex; flex-direction: column;