|
| 1 | +<script lang="ts" setup> |
| 2 | +import { CubeTransparentIcon, BugAntIcon } from "@heroicons/vue/20/solid" |
| 3 | +import { Ref, ref, toRefs, watch } from "vue" |
| 4 | +import { useApi } from "../composables/useApi" |
| 5 | +import { computedAsync, useStorage } from "@vueuse/core" |
| 6 | +import { useRouter } from "vue-router" |
| 7 | +import { WindowCreator } from "../composables/useWindow" |
| 8 | +
|
| 9 | +const $props = withDefaults( |
| 10 | + defineProps<{ |
| 11 | + id?: string |
| 12 | + search?: string |
| 13 | + feature?: string |
| 14 | + page?: number |
| 15 | + }>(), |
| 16 | + { |
| 17 | + id: "", |
| 18 | + search: "", |
| 19 | + feature: "", |
| 20 | + page: 1, |
| 21 | + } |
| 22 | +) |
| 23 | +
|
| 24 | +const { id, search, feature, page } = toRefs($props) |
| 25 | +const { getSkillList, damageTypeStaticMap, featureStaticURL } = useApi() |
| 26 | +
|
| 27 | +const listData = computedAsync(async (onCancel) => { |
| 28 | + const abortController = new AbortController() |
| 29 | +
|
| 30 | + onCancel(() => abortController.abort()) |
| 31 | + return await getSkillList( |
| 32 | + { |
| 33 | + id: id.value, |
| 34 | + search: search.value, |
| 35 | + feature: feature.value, |
| 36 | + page: page.value, |
| 37 | + }, |
| 38 | + abortController.signal |
| 39 | + ) |
| 40 | +}) |
| 41 | +
|
| 42 | +function getFeatureIconSrc(propertyIndex: string) { |
| 43 | + return `${featureStaticURL}${propertyIndex}.png` |
| 44 | +} |
| 45 | +
|
| 46 | +const isEmpty = computedAsync(() => listData.value.length === 0) |
| 47 | +const pageSize = useStorage("rocox-api-skill-list-size", 21) |
| 48 | +const totalFromID = useStorage("rocox-api-skill-max-id", 0) |
| 49 | +
|
| 50 | +const $emits = defineEmits(["update:sizes"]) |
| 51 | +
|
| 52 | +watch(listData, (val: any[]) => { |
| 53 | + if (search.value === "" && feature.value === "" && page.value === 1) { |
| 54 | + pageSize.value = val.length |
| 55 | + totalFromID.value = parseInt(val[0].id) |
| 56 | + } |
| 57 | + $emits("update:sizes", { |
| 58 | + listSize: val.length, |
| 59 | + pageSize: pageSize.value, |
| 60 | + total: totalFromID.value, |
| 61 | + }) |
| 62 | +}) |
| 63 | +
|
| 64 | +const $router = useRouter() |
| 65 | +const alwaysTargetNewWindow = useStorage("rocox-new-window-target", false) |
| 66 | +const skillPageTitle = useStorage("rocox-skill-page-title", "") |
| 67 | +const AngelWindow: Ref<WindowCreator | null> = ref(null) |
| 68 | +
|
| 69 | +function setupWindowParams(id: string, name: string, hash: string) { |
| 70 | + skillPageTitle.value = `#${id} ${name}` |
| 71 | + AngelWindow.value = new WindowCreator(id, { |
| 72 | + url: `/#/skill/${hash}`, |
| 73 | + title: skillPageTitle.value, |
| 74 | + }) |
| 75 | +
|
| 76 | + goAngelView(hash) |
| 77 | +} |
| 78 | +function goAngelView(hash: string) { |
| 79 | + if (alwaysTargetNewWindow.value) AngelWindow.value!.setup() |
| 80 | + else |
| 81 | + $router.push({ |
| 82 | + name: "Skill", |
| 83 | + params: { hash }, |
| 84 | + }) |
| 85 | +} |
| 86 | +</script> |
| 87 | + |
| 88 | +<template> |
| 89 | + <div class="skill-list-main custom-scrollbar"> |
| 90 | + <div |
| 91 | + class="skill-card" |
| 92 | + v-for="skill in listData" |
| 93 | + :key="skill.hash" |
| 94 | + @click="setupWindowParams(skill.id, skill.name, skill.hash)" |
| 95 | + > |
| 96 | + <span class="name-text"> |
| 97 | + <span class="id">#{{ skill.id }}</span> |
| 98 | + <span class="name">{{ skill.name }}</span> |
| 99 | + </span> |
| 100 | + <span class="details"> |
| 101 | + <span class="icons"> |
| 102 | + <img |
| 103 | + v-if="skill.property" |
| 104 | + class="icon property" |
| 105 | + :src="getFeatureIconSrc(skill.property)" |
| 106 | + alt="skill property" |
| 107 | + /> |
| 108 | + <img |
| 109 | + v-if="skill.power !== '--'" |
| 110 | + class="icon damage" |
| 111 | + :src="damageTypeStaticMap.get(skill.damageType)" |
| 112 | + :alt="skill.damageType === '1' ? '物理伤害' : '魔法伤害'" |
| 113 | + :title="skill.damageType === '1' ? '物理伤害' : '魔法伤害'" |
| 114 | + /> |
| 115 | + </span> |
| 116 | + <span class="text"> |
| 117 | + <span class="ppMax" title="pp总量">{{ skill.ppMax }}</span> · |
| 118 | + <span class="power" title="威力值">{{ skill.power }}</span> · |
| 119 | + <span class="speed" title="速度值">{{ skill.speed }}</span> |
| 120 | + </span> |
| 121 | + </span> |
| 122 | + </div> |
| 123 | + <Transition name="slidedown" mode="in-out" :appear="true"> |
| 124 | + <div class="empty-palceholder" v-if="isEmpty"> |
| 125 | + <span class="empty-icons"> |
| 126 | + <CubeTransparentIcon class="icon" /> · |
| 127 | + <BugAntIcon class="icon" /> |
| 128 | + </span> |
| 129 | + <span class="empty-text" |
| 130 | + >筛选结果为空,但不排除小概率因接口、网络等引起的故障。</span |
| 131 | + > |
| 132 | + </div> |
| 133 | + </Transition> |
| 134 | + </div> |
| 135 | +</template> |
| 136 | + |
| 137 | +<style lang="postcss" scoped> |
| 138 | +.skill-list-main { |
| 139 | + @apply flex flex-wrap w-full mt-8 h-[22rem] items-start justify-center content-start |
| 140 | + overflow-auto snap-y snap-mandatory; |
| 141 | +} |
| 142 | +
|
| 143 | +.skill-card { |
| 144 | + @apply flex flex-col mb-1 mr-1 |
| 145 | + border-2 border-slate-200 dark:border-slate-600 |
| 146 | + hover:bg-slate-100 active:bg-slate-200 active:border-slate-300 |
| 147 | + dark:hover:bg-slate-600 dark:active:bg-slate-800 dark:active:border-slate-600 |
| 148 | + rounded select-none transition-all snap-start cursor-pointer; |
| 149 | +} |
| 150 | +
|
| 151 | +.skill-card .name-text { |
| 152 | + @apply inline-flex items-center justify-between |
| 153 | + font-semibold text-sm; |
| 154 | +} |
| 155 | +.name-text .id { |
| 156 | + @apply inline-block ml-1 mr-2; |
| 157 | +} |
| 158 | +.name-text .name { |
| 159 | + @apply inline-block ml-2 mr-1; |
| 160 | +} |
| 161 | +
|
| 162 | +.skill-card .details { |
| 163 | + @apply inline-flex items-center justify-between; |
| 164 | +} |
| 165 | +.details .icons { |
| 166 | + @apply inline-block ml-1 mr-2; |
| 167 | +} |
| 168 | +.details .text { |
| 169 | + @apply inline-block ml-2 mr-1 |
| 170 | + font-semibold text-sm; |
| 171 | +} |
| 172 | +
|
| 173 | +.icons .icon { |
| 174 | + @apply w-6 h-6 inline-block my-1 ml-1 p-1 |
| 175 | + border rounded |
| 176 | + bg-slate-200 dark:bg-slate-600 border-slate-400 dark:border-slate-500 |
| 177 | + overflow-hidden; |
| 178 | +} |
| 179 | +.icon.damage { |
| 180 | + @apply p-0; |
| 181 | +} |
| 182 | +
|
| 183 | +.text .ppMax { |
| 184 | + @apply text-blue-700 dark:text-blue-400; |
| 185 | +} |
| 186 | +.text .power { |
| 187 | + @apply text-red-700 dark:text-red-400; |
| 188 | +} |
| 189 | +.text .speed { |
| 190 | + @apply text-sky-700 dark:text-sky-400; |
| 191 | +} |
| 192 | +
|
| 193 | +.empty-palceholder { |
| 194 | + @apply w-full h-full flex flex-col items-center justify-center |
| 195 | + select-none; |
| 196 | +} |
| 197 | +.empty-text { |
| 198 | + @apply inline-block |
| 199 | + text-sm font-bold text-center; |
| 200 | +} |
| 201 | +.empty-icons { |
| 202 | + @apply inline-flex justify-center items-center pb-4; |
| 203 | +} |
| 204 | +.empty-icons .icon { |
| 205 | + @apply w-12 h-12 inline-block m-2 |
| 206 | + animate-pulse; |
| 207 | +} |
| 208 | +</style> |
0 commit comments