|
| 1 | +<script lang="ts"> |
| 2 | +export default { |
| 3 | + name: "chainItem", |
| 4 | +} |
| 5 | +
|
| 6 | +interface ChainItemProp { |
| 7 | + hash: string |
| 8 | + id: string |
| 9 | + img: string |
| 10 | + name: string |
| 11 | + start?: boolean |
| 12 | + lv?: string |
| 13 | + to: ChainItemProp[] | "0" |
| 14 | +} |
| 15 | +</script> |
| 16 | +<script lang="ts" setup> |
| 17 | +import { BoltIcon } from "@heroicons/vue/20/solid" |
| 18 | +import { Ref, ref, toRefs } from "vue" |
| 19 | +
|
| 20 | +import { useApi } from "../composables/useApi" |
| 21 | +import { useRouter } from "vue-router" |
| 22 | +import { useStorage } from "@vueuse/core" |
| 23 | +import { WindowCreator } from "../composables/useWindow" |
| 24 | +
|
| 25 | +const $props = defineProps<{ |
| 26 | + chainTo: ChainItemProp |
| 27 | +}>() |
| 28 | +const { chainTo } = toRefs($props) |
| 29 | +const { iconStaticURL } = useApi() |
| 30 | +const angelIconHashMap = useStorage("rocox-angel-icon-hash-map", new Map()) |
| 31 | +
|
| 32 | +const iconSrc = (hash: string, angelId: string) => { |
| 33 | + let hashedSrc = angelIconHashMap.value.get(hash) |
| 34 | + if (hashedSrc) return hashedSrc |
| 35 | +
|
| 36 | + let id = parseInt(angelId) |
| 37 | + return `${iconStaticURL}${id < 100 ? "0" : ""}${id}-.png` |
| 38 | +} |
| 39 | +
|
| 40 | +const lastLevelClass = (to: string | ChainItemProp[]) => { |
| 41 | + return to == "0" ? "last-level-in-chain" : null |
| 42 | +} |
| 43 | +
|
| 44 | +const $router = useRouter() |
| 45 | +const alwaysTargetNewWindow = useStorage("rocox-new-window-target", false) |
| 46 | +const angelPageTitle = useStorage("rocox-angel-page-title", "") |
| 47 | +const AngelWindow: Ref<WindowCreator | null> = ref(null) |
| 48 | +
|
| 49 | +function setupWindowParams(id: string, name: string, hash: string) { |
| 50 | + angelPageTitle.value = `#${id} ${name}` |
| 51 | + AngelWindow.value = new WindowCreator(id, { |
| 52 | + url: `/#/angel/${hash}`, |
| 53 | + title: angelPageTitle.value, |
| 54 | + }) |
| 55 | +
|
| 56 | + goAngelView(hash) |
| 57 | +} |
| 58 | +function goAngelView(hash: string) { |
| 59 | + if (!hash) return false |
| 60 | + if (alwaysTargetNewWindow.value) AngelWindow.value!.setup() |
| 61 | + else |
| 62 | + $router.push({ |
| 63 | + name: "Angel", |
| 64 | + params: { hash }, |
| 65 | + }) |
| 66 | +} |
| 67 | +</script> |
| 68 | + |
| 69 | +<template> |
| 70 | + <div :class="['chain-item', lastLevelClass(chainTo.to)]"> |
| 71 | + <template |
| 72 | + v-if="chainTo.start && !Array.isArray(chainTo)" |
| 73 | + class="chain-children" |
| 74 | + > |
| 75 | + <span |
| 76 | + class="angel-item" |
| 77 | + @click="setupWindowParams(chainTo.id, chainTo.name, chainTo.hash)" |
| 78 | + > |
| 79 | + <img |
| 80 | + class="angel-img" |
| 81 | + v-if="chainTo.id" |
| 82 | + :src="iconSrc(chainTo.hash, chainTo.id)" |
| 83 | + alt="Angel icon" |
| 84 | + draggable="false" |
| 85 | + loading="lazy" |
| 86 | + /> |
| 87 | + <span class="name">#{{ chainTo.id }} · {{ chainTo.name }}</span> |
| 88 | + </span> |
| 89 | + <span class="option"> |
| 90 | + <BoltIcon class="icon" /> |
| 91 | + <span class="lv" v-if="chainTo.lv">lv {{ chainTo.lv }}</span> |
| 92 | + <span class="lv" v-else>Super</span> |
| 93 | + </span> |
| 94 | + <chainItem |
| 95 | + v-if="!(typeof chainTo.to === 'string')" |
| 96 | + :chainTo="chainTo.to" |
| 97 | + /> |
| 98 | + </template> |
| 99 | + <template v-if="!chainTo.start && Array.isArray(chainTo)"> |
| 100 | + <span v-for="item of chainTo" class="chain-children"> |
| 101 | + <span |
| 102 | + class="angel-item" |
| 103 | + @click="setupWindowParams(item.id, item.name, item.hash)" |
| 104 | + > |
| 105 | + <img |
| 106 | + class="angel-img" |
| 107 | + v-if="item.id" |
| 108 | + :src="iconSrc(item.hash, item.id)" |
| 109 | + alt="Angel icon" |
| 110 | + draggable="false" |
| 111 | + loading="lazy" |
| 112 | + /> |
| 113 | + <span class="name">#{{ item.id }} · {{ item.name }}</span> |
| 114 | + </span> |
| 115 | + <span class="option" v-if="!(typeof item.to === 'string')"> |
| 116 | + <span class="lv" v-if="item.lv">Level {{ item.lv }}</span> |
| 117 | + <span class="lv" v-else>Super</span> |
| 118 | + <BoltIcon class="icon" /> |
| 119 | + </span> |
| 120 | + <chainItem v-if="!(typeof item.to === 'string')" :chainTo="item.to" /> |
| 121 | + </span> |
| 122 | + </template> |
| 123 | + </div> |
| 124 | +</template> |
| 125 | + |
| 126 | +<style lang="postcss" scoped> |
| 127 | +.chain-item { |
| 128 | + @apply w-full inline-flex flex-col justify-center items-center flex-wrap; |
| 129 | +} |
| 130 | +
|
| 131 | +.chain-item:not(:has(> .chain-item)) { |
| 132 | + @apply inline-flex flex-row items-start justify-evenly; |
| 133 | +} |
| 134 | +.chain-item:has(> .chain-item) { |
| 135 | + @apply inline-flex w-full items-center justify-between; |
| 136 | +} |
| 137 | +
|
| 138 | +.chain-children { |
| 139 | + @apply inline-flex flex-col justify-center items-center; |
| 140 | +} |
| 141 | +
|
| 142 | +.angel-item { |
| 143 | + @apply relative inline-flex items-center justify-center h-8 pr-8 pl-1 py-0.5 my-2 |
| 144 | + border-2 rounded hover:bg-slate-200 dark:hover:bg-slate-500 |
| 145 | + bg-slate-100 dark:bg-slate-600 |
| 146 | + active:bg-slate-300 dark:active:bg-slate-400 |
| 147 | + border-green-400 dark:border-green-500 |
| 148 | + cursor-pointer overflow-hidden transition-all; |
| 149 | +} |
| 150 | +.option { |
| 151 | + @apply relative inline-flex justify-center items-center; |
| 152 | +} |
| 153 | +.option .lv { |
| 154 | + @apply absolute left-full inline-flex w-fit py-px px-1 |
| 155 | + border border-slate-400 |
| 156 | + bg-slate-200 dark:bg-slate-600 |
| 157 | + translate-x-4 |
| 158 | + whitespace-nowrap rounded font-semibold font-mono text-xs; |
| 159 | +} |
| 160 | +.option .icon { |
| 161 | + @apply w-5 h-5; |
| 162 | +} |
| 163 | +.angel-img { |
| 164 | + @apply absolute right-0 inline-block w-7; |
| 165 | +} |
| 166 | +.name { |
| 167 | + @apply inline-block w-fit |
| 168 | + font-semibold text-xs; |
| 169 | +} |
| 170 | +</style> |
0 commit comments