🚸 随机loading

This commit is contained in:
BTMuli
2026-01-14 13:11:30 +08:00
parent aaf30d0df5
commit 2847042933
4 changed files with 32 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -17,8 +17,8 @@
{{ data.subtitle }} {{ data.subtitle }}
</div> </div>
<div class="loading-img"> <div class="loading-img">
<img v-if="!data.empty" alt="loading" src="/source/UI/loading.webp" /> <img v-if="data.empty" alt="loading" src="/source/UI/empty.webp" />
<img v-else alt="empty" src="/source/UI/empty.webp" /> <img v-else :src="iconUrl" alt="empty" />
</div> </div>
</div> </div>
</div> </div>
@@ -27,16 +27,22 @@
</transition> </transition>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import showSnackbar from "@comp/func/snackbar.js";
import bbsReq from "@req/bbsReq.js";
import { onMounted, ref, shallowRef, watch } from "vue"; import { onMounted, ref, shallowRef, watch } from "vue";
import { LoadingParams } from "./loading.js"; import { LoadingParams } from "./loading.js";
const defaultIcon = "/source/UI/loading.webp";
const showBox = ref<boolean>(false); const showBox = ref<boolean>(false);
const showOuter = ref<boolean>(false); const showOuter = ref<boolean>(false);
const showInner = ref<boolean>(false); const showInner = ref<boolean>(false);
const props = defineProps<LoadingParams>(); const props = defineProps<LoadingParams>();
const data = shallowRef<LoadingParams>(props); const data = shallowRef<LoadingParams>(props);
const localEmojis = shallowRef<Array<string>>([]);
const iconUrl = ref<string>(defaultIcon);
watch( watch(
() => showBox.value, () => showBox.value,
@@ -56,11 +62,27 @@ watch(
onMounted(async () => await displayBox(props)); onMounted(async () => await displayBox(props));
async function getRandomEmoji(): Promise<void> {
if (localEmojis.value.length === 0) {
const resp = await bbsReq.emojis();
if ("retcode" in resp) {
console.error(resp);
showSnackbar.error("获取表情包失败!");
iconUrl.value = defaultIcon;
return;
}
localEmojis.value = Object.values(resp);
localStorage.setItem("emojis", JSON.stringify(resp));
}
iconUrl.value = localEmojis.value[Math.floor(Math.random() * localEmojis.value.length)];
}
async function displayBox(params: LoadingParams): Promise<void> { async function displayBox(params: LoadingParams): Promise<void> {
if (!params.show) { if (!params.show) {
showBox.value = false; showBox.value = false;
await new Promise<void>((resolve) => setTimeout(resolve, 500)); await new Promise<void>((resolve) => setTimeout(resolve, 500));
data.value = { show: false, title: undefined, subtitle: undefined, empty: undefined }; data.value = { show: false, title: undefined, subtitle: undefined, empty: undefined };
await getRandomEmoji();
return; return;
} }
data.value = { data.value = {
@@ -175,14 +197,15 @@ defineExpose({ displayBox });
.loading-img { .loading-img {
display: flex; display: flex;
width: 100%; width: 100%;
height: 200px; height: 160px;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
img { img {
max-width: 100%; max-width: 100%;
max-height: 200px; max-height: 160px;
border-radius: 5px; border-radius: 4px;
aspect-ratio: 1;
} }
} }

View File

@@ -19,14 +19,12 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import useAppStore from "@store/app.js"; import showLoading from "@comp/func/loading.js";
import { tryReadGameVer } from "@utils/TGGame.js";
import { storeToRefs } from "pinia";
const { gameDir } = storeToRefs(useAppStore());
async function test() { async function test() {
await tryReadGameVer(gameDir.value); await showLoading.start("测试");
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
await showLoading.end();
} }
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>