Просмотр исходного кода

首页登录错误添加提示

cc12458 1 год назад
Родитель
Сommit
a493d6ae85
2 измененных файлов с 22 добавлено и 10 удалено
  1. 1 0
      miniprogram/lib/logic.ts
  2. 21 10
      miniprogram/pages/home/home.ts

+ 1 - 0
miniprogram/lib/logic.ts

@@ -30,6 +30,7 @@ export async function login(force?: boolean) {
     wx.setStorageSync(TOKEN.key, TOKEN.data);
     return TOKEN.data;
   } catch (error) {
+    wx.showToast({ title: error?.errMsg ?? error?.message ?? `登录错误`, icon: 'none' });
     throw error
   } finally {
     clearTimeout(show);

+ 21 - 10
miniprogram/pages/home/home.ts

@@ -68,16 +68,27 @@ Page({
 
     _loaded: false,
   },
-  async load() {
-    await login();
-    wx.showLoading({ title: '加载中' });
-    const { patient } = await getPatients(/*this.data.patientId*/);
-    if (!patient) await toCertificationPage();
-    else {
-      this.setData({ patient });
-      this.observerPatient(patient);
-    };
-    wx.hideLoading();
+  async load(forceLogin = false) {
+    try {
+      await login(forceLogin);
+      wx.showLoading({ title: '加载中' });
+      const { patient } = await getPatients(/*this.data.patientId*/);
+      if (!patient) await toCertificationPage();
+      else {
+        this.setData({ patient });
+        this.observerPatient(patient);
+      };
+      wx.hideLoading();
+    } catch (error) {
+      await wx.showModal({
+        title: `加载失败`,
+        content: `${error?.errMsg ?? error?.message ?? ''}`,
+        showCancel: false,
+        confirmText: `重新加载`
+      }).catch(() => { });
+      this.load(true);
+      return;
+    }
 
     if (!this.data._loaded) {
       this.loadScienceList();