feat: 添加 Vant 组件库支持,优化 toast 消息显示逻辑

This commit is contained in:
2026-01-22 17:47:15 +07:00
parent b8ac4bf1f2
commit 78c413a914
8 changed files with 82 additions and 54 deletions

View File

@@ -1,7 +1,6 @@
import type { App } from "@capp/eden";
import type { WatchSource } from "vue";
import { treaty } from "@elysiajs/eden";
import { toastController } from "@ionic/vue";
import { i18n } from "@/locales";
const baseURL = import.meta.env.DEV ? window.location.origin : import.meta.env.VITE_API_URL;
@@ -63,28 +62,19 @@ export function safeClient<T, E>(
if (res.error) {
if (!options.silent && res.status === 418) {
const toast = await toastController.create({
message: i18n.global.t((res.error as any).value.code, {
...(res.error as any).value.context,
}),
duration: 3000,
position: "bottom",
color: "danger",
});
await toast.present();
showToast(i18n.global.t((res.error as any).value.code, {
...(res.error as any).value.context,
}));
}
else if (res.status === 401) {
localStorage.removeItem("user-token");
window.location.reload();
setTimeout(() => {
showToast("登录状态已过期2秒后将跳转到登录页面请重新登录");
localStorage.removeItem("user-token");
window.location.reload();
}, 2000);
}
else if (!options.silent) {
const toast = await toastController.create({
message: (res.error as any).message || i18n.global.t("network_error"),
duration: 3000,
position: "bottom",
color: "danger",
});
await toast.present();
showToast((res.error as any).message || i18n.global.t("network_error"));
}
throw res.error;