添加onPageLoadInitAuth函数判断登录
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* YangXB 2021.11.24
|
||||
* */
|
||||
import { base, http } from './config';
|
||||
import { Subscribe } from './subscribe';
|
||||
import { getStorage, isArray, setStorage, toArray, toastError } from './util';
|
||||
/**
|
||||
* 请求
|
||||
@@ -44,12 +45,11 @@ const request = (url: string, options: any, config = { showLoading: true, showEr
|
||||
resolve(request.data);
|
||||
} else {
|
||||
if (config.showError != false) {
|
||||
wx.showToast({
|
||||
title: request.data.err_msg,
|
||||
icon: 'none',
|
||||
});
|
||||
wx.showToast({ title: request.data.err_msg, icon: 'none' });
|
||||
}
|
||||
if (request.data.err_code == 110000) {
|
||||
Subscribe.set('isLogin', false);
|
||||
|
||||
// const currentPage = getCurrentPage();
|
||||
// console.log(currentPage);
|
||||
// if (
|
||||
@@ -147,6 +147,7 @@ export const loginStatus = () => {
|
||||
setStorage('auth_info', res.auth_info);
|
||||
setStorage('session_id', res.session_id);
|
||||
getUsersConfigList();
|
||||
Subscribe.set('isLogin', true);
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err: any) => {
|
||||
@@ -155,7 +156,9 @@ export const loginStatus = () => {
|
||||
if (isArray(res.data)) {
|
||||
post('Applet/loginOut').then(() => {
|
||||
checkSesskey({ showLoading: false, showError: false })
|
||||
.then(() => {})
|
||||
.then(() => {
|
||||
Subscribe.set('isLogin', false);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('checkSesskey', err);
|
||||
});
|
||||
@@ -201,6 +204,7 @@ export const onPageLoadInitAuth = (
|
||||
initFun()
|
||||
.then((_res) => {
|
||||
// console.log('onPageLoadInitAuth', res);
|
||||
Subscribe.set('isLogin', true);
|
||||
that.setData({ isLogin: true, loading: false });
|
||||
that.init?.();
|
||||
})
|
||||
|
||||
@@ -9,8 +9,8 @@ function triggerEvent(key: string, data: any) {
|
||||
});
|
||||
}
|
||||
// 也可以触发一个通用的 'change' 事件
|
||||
if (listeners["change"]) {
|
||||
listeners["change"].forEach((callback: any) => {
|
||||
if (listeners['change']) {
|
||||
listeners['change'].forEach((callback: any) => {
|
||||
callback({ key, data });
|
||||
});
|
||||
}
|
||||
@@ -45,15 +45,15 @@ export const Subscribe = {
|
||||
* @param functionKey 唯一的函数key(用于取消订阅的)
|
||||
* @param callback 回调函数
|
||||
*/
|
||||
on(key: string, functionKey: string, callback: () => void) {
|
||||
on(key: string, functionKey: string, callback: (data: any) => void) {
|
||||
if (!listeners[key]) {
|
||||
listeners[key] = [];
|
||||
}
|
||||
if (typeof callback == "function") {
|
||||
(callback as IFun)["$$functionKey"] = functionKey;
|
||||
if (typeof callback == 'function') {
|
||||
(callback as IFun)['$$functionKey'] = functionKey;
|
||||
listeners[key].push(callback);
|
||||
} else {
|
||||
console.log("订阅事件 callback 必须是函数");
|
||||
console.log('订阅事件 callback 必须是函数');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user