|
| 1 | +<script lang="ts" setup> |
| 2 | +import { toRefs, watch } from "vue" |
| 3 | +import { useApi } from "../composables/useApi" |
| 4 | +import { computedAsync } from "@vueuse/core" |
| 5 | +
|
| 6 | +import { CubeTransparentIcon } from "@heroicons/vue/20/solid" |
| 7 | +
|
| 8 | +const $props = withDefaults( |
| 9 | + defineProps<{ |
| 10 | + id?: string |
| 11 | + search?: string |
| 12 | + feature?: string |
| 13 | + page?: number |
| 14 | + }>(), |
| 15 | + { |
| 16 | + id: "", |
| 17 | + search: "", |
| 18 | + feature: "", |
| 19 | + page: 1, |
| 20 | + } |
| 21 | +) |
| 22 | +
|
| 23 | +const { id, search, feature, page } = toRefs($props) |
| 24 | +const { getAngelList, iconStaticURL, featureStaticURL } = useApi() |
| 25 | +
|
| 26 | +const listData = computedAsync(async (onCancel) => { |
| 27 | + const abortController = new AbortController() |
| 28 | +
|
| 29 | + onCancel(() => abortController.abort()) |
| 30 | + return await getAngelList( |
| 31 | + { |
| 32 | + id: id.value, |
| 33 | + search: search.value, |
| 34 | + feature: feature.value, |
| 35 | + page: page.value, |
| 36 | + }, |
| 37 | + abortController.signal |
| 38 | + ) |
| 39 | +}) |
| 40 | +
|
| 41 | +watch(listData, (val) => { |
| 42 | + console.log(val) |
| 43 | +}) |
| 44 | +
|
| 45 | +function getFeatureIconSrc(featureIndex: string) { |
| 46 | + return `${featureStaticURL}${featureIndex}.png` |
| 47 | +} |
| 48 | +function getAngelIconSrc(iconSrc: string) { |
| 49 | + return `${iconStaticURL}${iconSrc}` |
| 50 | +} |
| 51 | +</script> |
| 52 | + |
| 53 | +<template> |
| 54 | + <div class="angel-list-main"> |
| 55 | + <div class="angel-card" v-for="angel in listData" :key="angel.hash"> |
| 56 | + <span class="details"> |
| 57 | + <span class="name-text">#{{ angel.id }} · {{ angel.name }}</span> |
| 58 | + <span class="features"> |
| 59 | + <img |
| 60 | + draggable="false" |
| 61 | + class="feature-icon icon" |
| 62 | + referrerPolicy="no-referrer" |
| 63 | + v-for="key in angel.features" |
| 64 | + :key="key" |
| 65 | + :src="getFeatureIconSrc(key)" |
| 66 | + loading="lazy" |
| 67 | + /> |
| 68 | + </span> |
| 69 | + <img |
| 70 | + draggable="false" |
| 71 | + class="angel-icon icon" |
| 72 | + v-show="angel.img" |
| 73 | + :src="getAngelIconSrc(angel.iconSrc)" |
| 74 | + alt="angel icon" |
| 75 | + referrerPolicy="no-referrer" |
| 76 | + loading="lazy" |
| 77 | + /> |
| 78 | + <CubeTransparentIcon |
| 79 | + v-show="!angel.img" |
| 80 | + draggable="false" |
| 81 | + class="icon-palceholder icon" |
| 82 | + /> |
| 83 | + </span> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | +</template> |
| 87 | + |
| 88 | +<style lang="postcss" scoped> |
| 89 | +.angel-list-main::-webkit-scrollbar { |
| 90 | + @apply w-3; |
| 91 | +} |
| 92 | +.angel-list-main::-webkit-scrollbar-track { |
| 93 | + @apply bg-slate-200 dark:bg-slate-600; |
| 94 | +} |
| 95 | +.angel-list-main::-webkit-scrollbar-thumb { |
| 96 | + @apply bg-slate-400 shadow; |
| 97 | +} |
| 98 | +.angel-list-main { |
| 99 | + @apply relative w-80 mt-8 h-80 flex flex-col items-center |
| 100 | + overflow-auto snap-y snap-mandatory; |
| 101 | +} |
| 102 | +.angel-card { |
| 103 | + @apply w-72 h-12 flex flex-col mb-1 |
| 104 | + border-2 border-slate-200 dark:border-slate-600 |
| 105 | + hover:bg-slate-100 active:bg-slate-200 active:border-slate-300 |
| 106 | + dark:hover:bg-slate-600 dark:active:bg-slate-800 dark:active:border-slate-600 |
| 107 | + rounded select-none transition-all snap-start cursor-pointer; |
| 108 | +} |
| 109 | +
|
| 110 | +.details { |
| 111 | + @apply relative w-full h-12 inline-flex items-center justify-start; |
| 112 | +} |
| 113 | +
|
| 114 | +.name-text { |
| 115 | + @apply inline-block w-36 mx-2 |
| 116 | + text-sm font-black border-r |
| 117 | + border-gray-300 dark:border-gray-500 |
| 118 | + truncate transition-all; |
| 119 | +} |
| 120 | +
|
| 121 | +.features { |
| 122 | + @apply inline-flex justify-center items-center; |
| 123 | +} |
| 124 | +.features .icon { |
| 125 | + @apply w-8 h-8 inline-block p-1.5; |
| 126 | +} |
| 127 | +
|
| 128 | +.details .angel-icon { |
| 129 | + @apply absolute right-0 w-11 h-11 inline-block |
| 130 | + rounded-r; |
| 131 | +} |
| 132 | +.icon-palceholder { |
| 133 | + @apply absolute right-0 w-11 h-11 inline-block p-2 |
| 134 | + text-slate-600 dark:text-slate-300 |
| 135 | + rounded-r transition-all; |
| 136 | +} |
| 137 | +</style> |
0 commit comments