瀏覽代碼

登录态过期保存页面路径与启动参数,恢复登录时恢复页面

xiaohaizhao 2 年之前
父節點
當前提交
ec8c1f7908
共有 2 個文件被更改,包括 26 次插入5 次删除
  1. 17 0
      pages/tabbar/home/index.js
  2. 9 5
      utils/Http.js

+ 17 - 0
pages/tabbar/home/index.js

@@ -15,6 +15,23 @@ Page({
 		})
 		this.refreshData() //更新权限等信息
 		this.getTabBar().unReadMessageCount(); //更新信息数量
+		let history = getApp().globalData.LaunchOptions;
+		if (history && !getCurrentPages().some(v => v.__route__ == history.path)) {
+			let url = `/${history.path}?`;
+			for (const key in history.query) {
+				url += `${key}=${history.query[key]}&`
+			}
+			wx.navigateTo({
+				url,
+				success(res) {
+					wx.showToast({
+						title: '已恢复页面',
+						icon: "none"
+					});
+					getApp().globalData.LaunchOptions = null;
+				}
+			})
+		}
 	},
 	/* 更新站点信息 */
 	refreshData() {

+ 9 - 5
utils/Http.js

@@ -41,13 +41,17 @@ class HTTP {
                         icon: "none"
                     })
                 } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
-                    wx.redirectTo({
-                        url: '/pages/login/phone',
-                    });
                     wx.showToast({
-                        title: res.msg,
-                        icon: "none"
+                        title: '登陆状态已过期,请重新登陆!',
+                        icon: "none",
+                        mask: true
                     })
+                    getApp().globalData.LaunchOptions = wx.getLaunchOptionsSync();
+                    count = setTimeout(() => {
+                        wx.reLaunch({
+                            url: '/pages/login/phone',
+                        });
+                    }, 1000)
                 }
             }
         })