feat: 添加 Vant 组件库支持,优化 toast 消息显示逻辑
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user