添加onPageLoadInitAuth函数判断登录
This commit is contained in:
@@ -3,15 +3,7 @@
|
||||
* YangXB 2021.11.24
|
||||
* */
|
||||
import { base, http } from './config';
|
||||
import {
|
||||
getCurrentPage,
|
||||
getStorage,
|
||||
goIndexPage,
|
||||
isArray,
|
||||
setStorage,
|
||||
toArray,
|
||||
toastError,
|
||||
} from './util';
|
||||
import { getStorage, isArray, setStorage, toArray, toastError } from './util';
|
||||
/**
|
||||
* 请求
|
||||
*/
|
||||
@@ -58,15 +50,15 @@ const request = (url: string, options: any, config = { showLoading: true, showEr
|
||||
});
|
||||
}
|
||||
if (request.data.err_code == 110000) {
|
||||
const currentPage = getCurrentPage();
|
||||
console.log(currentPage);
|
||||
if (
|
||||
!['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
|
||||
currentPage.route,
|
||||
)
|
||||
) {
|
||||
goIndexPage();
|
||||
}
|
||||
// const currentPage = getCurrentPage();
|
||||
// console.log(currentPage);
|
||||
// if (
|
||||
// !['pages/index/index', 'pages/processEntry/processEntry', 'pages/my/my'].includes(
|
||||
// currentPage.route,
|
||||
// )
|
||||
// ) {
|
||||
// goIndexPage();
|
||||
// }
|
||||
}
|
||||
reject(request.data);
|
||||
}
|
||||
@@ -197,6 +189,28 @@ export const loginStatusPage = (that: WechatMiniprogram.Page.Instance<any, any>)
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 页面初始化
|
||||
*/
|
||||
export const onPageLoadInitAuth = (
|
||||
that: WechatMiniprogram.Page.Instance<any, any>,
|
||||
initFun: () => Promise<void>,
|
||||
) => {
|
||||
if (typeof initFun == 'function') {
|
||||
that.setData({ loading: true });
|
||||
initFun()
|
||||
.then((_res) => {
|
||||
// console.log('onPageLoadInitAuth', res);
|
||||
that.setData({ isLogin: true, loading: false });
|
||||
that.init?.();
|
||||
})
|
||||
.catch((_res) => {
|
||||
// console.log('onPageLoadInitAuth catch', res);
|
||||
that.setData({ isLogin: false, loading: false });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} config { showLoading: true, showError: true }
|
||||
|
||||
Reference in New Issue
Block a user