From 78c413a914fd24a459b0b4d7b9b6430b4912e2b8 Mon Sep 17 00:00:00 2001 From: Seven Date: Thu, 22 Jan 2026 17:47:15 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Vant=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=BA=93=E6=94=AF=E6=8C=81=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20toast=20=E6=B6=88=E6=81=AF=E6=98=BE=E7=A4=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto-imports.d.ts | 2 ++ package.json | 2 ++ pnpm-lock.yaml | 43 +++++++++++++++++++++++++++++++++++++++ pnpm-workspace.yaml | 4 ++++ src/api/index.ts | 28 ++++++++----------------- src/views/auth/login.vue | 27 ++++++++---------------- src/views/auth/signup.vue | 25 +++++++++-------------- vite.config.ts | 5 +++-- 8 files changed, 82 insertions(+), 54 deletions(-) diff --git a/auto-imports.d.ts b/auto-imports.d.ts index edb50a1..959e51e 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -109,6 +109,7 @@ declare global { const shallowReactive: typeof import('vue').shallowReactive const shallowReadonly: typeof import('vue').shallowReadonly const shallowRef: typeof import('vue').shallowRef + const showToast: typeof import('vant/es').showToast const storeToRefs: typeof import('pinia').storeToRefs const syncRef: typeof import('@vueuse/core').syncRef const syncRefs: typeof import('@vueuse/core').syncRefs @@ -449,6 +450,7 @@ declare module 'vue' { readonly shallowReactive: UnwrapRef readonly shallowReadonly: UnwrapRef readonly shallowRef: UnwrapRef + readonly showToast: UnwrapRef readonly storeToRefs: UnwrapRef readonly syncRef: UnwrapRef readonly syncRefs: UnwrapRef diff --git a/package.json b/package.json index cb4e14f..73281cb 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "qr-scanner-wechat": "catalog:", "qrcode": "catalog:", "tailwindcss": "catalog:", + "vant": "catalog:", "vconsole": "catalog:", "vee-validate": "catalog:", "vue": "catalog:", @@ -78,6 +79,7 @@ "@ionic/cli": "catalog:", "@types/lodash-es": "catalog:", "@types/node": "catalog:", + "@vant/auto-import-resolver": "catalog:", "@vitejs/plugin-legacy": "catalog:", "@vitejs/plugin-vue": "catalog:", "@vitejs/plugin-vue-jsx": "catalog:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 443c325..fcf3a11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -114,6 +114,9 @@ catalogs: '@types/node': specifier: ^24.10.2 version: 24.10.9 + '@vant/auto-import-resolver': + specifier: ^1.3.0 + version: 1.3.0 '@vee-validate/zod': specifier: ^4.15.1 version: 4.15.1 @@ -216,6 +219,9 @@ catalogs: unplugin-vue-components: specifier: ^30.0.0 version: 30.0.0 + vant: + specifier: ^4.9.22 + version: 4.9.22 vconsole: specifier: ^3.15.1 version: 3.15.1 @@ -365,6 +371,9 @@ importers: tailwindcss: specifier: 'catalog:' version: 4.1.18 + vant: + specifier: 'catalog:' + version: 4.9.22(vue@3.5.26(typescript@5.9.3)) vconsole: specifier: 'catalog:' version: 3.15.1 @@ -435,6 +444,9 @@ importers: '@types/node': specifier: 'catalog:' version: 24.10.9 + '@vant/auto-import-resolver': + specifier: 'catalog:' + version: 1.3.0 '@vitejs/plugin-legacy': specifier: 'catalog:' version: 7.2.1(terser@5.46.0)(vite@7.3.1(@types/node@24.10.9)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.46.0)(yaml@2.8.2)) @@ -2476,6 +2488,17 @@ packages: resolution: {integrity: sha512-LZ2NqIHFhvFwxG0qZeLL9DvdNAHPGCY5dIRwBhyYeU+LfLhcStE1ImjsuTG/WaVh3XysGaeLW8Rqq7cGkPCFvw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@vant/auto-import-resolver@1.3.0': + resolution: {integrity: sha512-lJyWtCyFizR4bHZvMiNMF3w+WTFTUWAvka1eqTnPK9ticUcKTCOx6qEmHcm8JPb3g1t3GaD2W3MnHkBp/nHamw==} + + '@vant/popperjs@1.3.0': + resolution: {integrity: sha512-hB+czUG+aHtjhaEmCJDuXOep0YTZjdlRR+4MSmIFnkCQIxJaXLQdSsR90XWvAI2yvKUI7TCGqR8pQg2RtvkMHw==} + + '@vant/use@1.6.0': + resolution: {integrity: sha512-PHHxeAASgiOpSmMjceweIrv2AxDZIkWXyaczksMoWvKV2YAYEhoizRuk/xFnKF+emUIi46TsQ+rvlm/t2BBCfA==} + peerDependencies: + vue: ^3.0.0 + '@vee-validate/zod@4.15.1': resolution: {integrity: sha512-329Z4TDBE5Vx0FdbA8S4eR9iGCFFUNGbxjpQ20ff5b5wGueScjocUIx9JHPa79LTG06RnlUR4XogQsjN4tecKA==} peerDependencies: @@ -5709,6 +5732,11 @@ packages: utrie@1.0.2: resolution: {integrity: sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==} + vant@4.9.22: + resolution: {integrity: sha512-P2PDSj3oB6l3W1OpVlQpapeLmI6bXMSvPqPdrw5rutslC0Y6tSkrVB/iSD57weD7K92GsjGkvgDK0eZlOsXGqw==} + peerDependencies: + vue: ^3.0.0 + vconsole@3.15.1: resolution: {integrity: sha512-KH8XLdrq9T5YHJO/ixrjivHfmF2PC2CdVoK6RWZB4yftMykYIaXY1mxZYAic70vADM54kpMQF+dYmvl5NRNy1g==} @@ -8060,6 +8088,14 @@ snapshots: '@typescript-eslint/types': 8.53.0 eslint-visitor-keys: 4.2.1 + '@vant/auto-import-resolver@1.3.0': {} + + '@vant/popperjs@1.3.0': {} + + '@vant/use@1.6.0(vue@3.5.26(typescript@5.9.3))': + dependencies: + vue: 3.5.26(typescript@5.9.3) + '@vee-validate/zod@4.15.1(vue@3.5.26(typescript@5.9.3))(zod@3.25.76)': dependencies: type-fest: 4.41.0 @@ -11668,6 +11704,13 @@ snapshots: dependencies: base64-arraybuffer: 1.0.2 + vant@4.9.22(vue@3.5.26(typescript@5.9.3)): + dependencies: + '@vant/popperjs': 1.3.0 + '@vant/use': 1.6.0(vue@3.5.26(typescript@5.9.3)) + '@vue/shared': 3.5.26 + vue: 3.5.26(typescript@5.9.3) + vconsole@3.15.1: dependencies: '@babel/runtime': 7.28.6 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e535d4c..bb9749c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -18,6 +18,7 @@ catalog: '@capacitor/keyboard': 8.0.0 '@capacitor/share': ^8.0.0 '@capacitor/status-bar': 8.0.0 + '@capacitor/toast': ^8.0.0 '@capp/eden': http://192.168.1.2:9538/api/capp-eden-0.0.37.tgz '@cloudflare/workers-types': ^4.20260113.0 '@elysiajs/eden': ^1.4.6 @@ -40,6 +41,7 @@ catalog: '@types/lodash-es': ^4.17.12 '@types/node': ^24.10.2 '@types/qrcode': ^1.5.6 + '@vant/auto-import-resolver': ^1.3.0 '@vee-validate/zod': ^4.15.1 '@vitejs/plugin-basic-ssl': ^2.1.3 '@vitejs/plugin-legacy': ^7.2.1 @@ -77,6 +79,7 @@ catalog: unplugin-auto-import: ^20.3.0 unplugin-icons: ^22.5.0 unplugin-vue-components: ^30.0.0 + vant: ^4.9.22 vconsole: ^3.15.1 vee-validate: ^4.15.1 vite: ^7.2.7 @@ -85,6 +88,7 @@ catalog: vue: ^3.5.25 vue-i18n: ^11.2.2 vue-router: ^4.6.3 + vue-toastification: ^1.7.14 vue-tsc: ^3.1.8 workbox-window: ^7.4.0 wrangler: ^4.54.0 diff --git a/src/api/index.ts b/src/api/index.ts index afe153e..c5e1885 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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( 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; diff --git a/src/views/auth/login.vue b/src/views/auth/login.vue index 0ad43fe..2cf56ce 100644 --- a/src/views/auth/login.vue +++ b/src/views/auth/login.vue @@ -1,5 +1,4 @@