mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🎨 完善基本的加载处理
This commit is contained in:
@@ -1,29 +1,53 @@
|
|||||||
<template>
|
<template>
|
||||||
{{ data }}
|
<ToLoading v-model="loading" :empty="loadingEmpty" :title="loadingTitle" :subtitle="loadingSub" />
|
||||||
|
<div class="wc-box">
|
||||||
|
{{ data }}
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
|
|
||||||
import showSnackbar from "../../components/func/snackbar";
|
import showSnackbar from "../../components/func/snackbar";
|
||||||
|
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||||
import { getWikiData } from "../../data";
|
import { getWikiData } from "../../data";
|
||||||
|
|
||||||
|
// 路由数据
|
||||||
const id = <string>useRoute().params.id;
|
const id = <string>useRoute().params.id;
|
||||||
|
// 加载
|
||||||
|
const loading = ref<boolean>(true);
|
||||||
|
const loadingEmpty = ref<boolean>(false);
|
||||||
|
const loadingTitle = ref<string>("正在加载");
|
||||||
|
const loadingSub = ref<string>();
|
||||||
|
|
||||||
|
// 数据
|
||||||
const data = ref<TGApp.App.Character.WikiItem>();
|
const data = ref<TGApp.App.Character.WikiItem>();
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
await appWindow.show();
|
||||||
try {
|
try {
|
||||||
const res = await getWikiData("Character", id);
|
const res = await getWikiData("Character", id);
|
||||||
if (res !== undefined) {
|
if (res !== undefined) {
|
||||||
data.value = res.default;
|
data.value = res.default;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
loading.value = false;
|
||||||
console.error(e);
|
} catch (error) {
|
||||||
|
loadingEmpty.value = true;
|
||||||
|
if (error instanceof Error) {
|
||||||
|
loadingTitle.value = error.name;
|
||||||
|
loadingSub.value = error.message;
|
||||||
|
} else {
|
||||||
|
loadingTitle.value = "未知错误";
|
||||||
|
loadingSub.value = <string>error;
|
||||||
|
}
|
||||||
showSnackbar({
|
showSnackbar({
|
||||||
text: "Wiki 数据获取失败",
|
text: "Wiki 数据获取失败,即将关闭窗口",
|
||||||
color: "error",
|
color: "error",
|
||||||
});
|
});
|
||||||
history.back();
|
setTimeout(() => {
|
||||||
|
appWindow.close();
|
||||||
|
}, 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user