♻️ loading组件重构

This commit is contained in:
目棃
2024-12-16 11:13:30 +08:00
parent 1f167845a4
commit 24e3f11c4a
33 changed files with 482 additions and 428 deletions

View File

@@ -25,12 +25,12 @@ const jsonList = shallowRef<TGApp.BBS.Announcement.AnnoSingle>();
const jsonContent = shallowRef<TGApp.BBS.Announcement.ContentItem>();
onMounted(async () => {
showLoading.start("正在获取公告数据...");
await showLoading.start("正在获取公告数据");
if (!annoId) {
showLoading.empty("未找到数据");
await showLoading.empty("未找到数据");
return;
}
showLoading.update("正在获取数据...", `公告ID: ${annoId}`);
await showLoading.update(`公告ID: ${annoId}`);
const listData = await Hk4eApi.anno.list(region, lang);
for (const listItem of listData.list) {
for (const single of listItem.list) {
@@ -41,7 +41,7 @@ onMounted(async () => {
}
}
jsonContent.value = await Hk4eApi.anno.content(annoId, region, lang);
showLoading.end();
await showLoading.end();
});
</script>
<style lang="css" scoped>

View File

@@ -34,17 +34,17 @@ const appVersion = ref<string>();
const annoData = shallowRef<TGApp.BBS.Announcement.ContentItem>();
onMounted(async () => {
showLoading.start("正在加载公告数据...");
await showLoading.start("正在加载公告数据");
appVersion.value = await app.getVersion();
if (!annoId || !region) {
showLoading.empty("未找到数据", "公告不存在或解析失败");
await showLoading.empty("未找到数据", "未解析到公告ID或服务器");
await TGLogger.Error("[t-anno.vue] 未找到数据");
return;
}
showLoading.update("正在获取数据...", `公告ID:${annoId}`);
await showLoading.update("正在获取数据");
try {
annoData.value = await Hk4eApi.anno.content(annoId, region, lang);
showLoading.update("正在渲染数据...", `公告ID${annoId}`);
await showLoading.update("正在渲染数据");
await webviewWindow
.getCurrentWebviewWindow()
.setTitle(`Anno_${annoId} ${annoData.value.title}`);
@@ -52,14 +52,13 @@ onMounted(async () => {
if (error instanceof Error)
await TGLogger.Error(`[t-anno.vue][${annoId}] ${error.name}${error.message}`);
else console.error(error);
showLoading.empty("未找到数据", "公告不存在或解析失败");
await showLoading.empty("未找到数据", "公告不存在或解析失败");
await webviewWindow.getCurrentWebviewWindow().setTitle(`Anno_${annoId} Parsing Error`);
return;
}
// 打开 json
const isDev = useAppStore().devMode ?? false;
if (isDev) await createAnnoJson(annoId, region, lang);
showLoading.end();
await showLoading.end();
});
function parseText(title: string): string {

View File

@@ -24,18 +24,19 @@ const jsonData = shallowRef<TGApp.Plugins.Mys.Post.FullData>();
const parseData = shallowRef<Array<TGApp.Plugins.Mys.SctPost.Base>>();
onMounted(async () => {
showLoading.start(`正在获取帖子数据...`);
await showLoading.start(`正在获取帖子数据`);
if (!postId) {
showLoading.empty("错误的帖子ID");
await showLoading.empty("未获取到PostID");
return;
}
const resp = await Mys.Post.getPostFull(postId);
if ("retcode" in resp) {
showLoading.empty("获取数据失败", `[${resp.retcode}]${resp.message}`);
await showLoading.empty("获取数据失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}]${resp.message}`);
await TGLogger.Error(`[${postId}]获取帖子数据失败:${resp.retcode} ${resp.message}`);
return;
}
await showLoading.update("正在渲染帖子数据");
jsonData.value = resp;
try {
parseData.value = JSON.parse(jsonData.value.post.content);
@@ -48,7 +49,7 @@ onMounted(async () => {
}
console.warn(`[${postId}]解析帖子数据失败:${err}`);
}
showLoading.end();
await showLoading.end();
});
</script>
<style lang="css" scoped>

View File

@@ -122,34 +122,33 @@ function getGameIcon(gameId: number): string {
}
onMounted(async () => {
await showLoading.start(`正在加载帖子数据`);
appVersion.value = await app.getVersion();
showLoading.start(`正在加载帖子数据...`);
// 检查数据
if (!postId) {
showLoading.empty("未找到数据", "PostID 不存在");
await showLoading.empty("PostID 不存在");
await webviewWindow.getCurrentWebviewWindow().setTitle("未找到数据");
await TGLogger.Error("[t-post][onMounted] PostID 不存在");
return;
}
showLoading.update("正在获取数据...", `帖子ID: ${postId}`);
await showLoading.update(`帖子ID: ${postId}`);
const resp = await Mys.Post.getPostFull(postId);
if ("retcode" in resp) {
showLoading.empty(`[code]${resp.retcode}`, resp.message);
await showLoading.empty("数据加载失败", `[${resp.retcode}]${resp.message}`);
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
await webviewWindow.getCurrentWebviewWindow().setTitle(`Post_${postId} ${resp.message}`);
await TGLogger.Error(`[t-post][${postId}][onMounted] ${resp.retcode}: ${resp.message}`);
return;
}
postData.value = resp;
showLoading.update("正在渲染数据...", `帖子ID: ${postId}`);
await showLoading.update("正在渲染数据");
renderPost.value = getRenderPost(postData.value);
await webviewWindow
.getCurrentWebviewWindow()
.setTitle(`Post_${postId} ${postData.value.post.subject}`);
await TGLogger.Info(`[t-post][${postId}][onMounted] ${postData.value.post.subject}`);
// 打开 json
const isDev = useAppStore().devMode ?? false;
if (isDev) {
await showLoading.update("正在打开调试窗口");
await TGLogger.Info(`[t-post][${postId}][onMounted] 打开 JSON 窗口`);
await createPostJson(postId);
}
@@ -158,7 +157,7 @@ onMounted(async () => {
shareTimer = null;
}
shareTimer = setInterval(getShareTimer, 1000);
showLoading.end();
await showLoading.end();
});
function getShareTimer(): void {