|
@@ -31,15 +31,16 @@ export default class UserHelper {
|
|
|
this.cacheUserInfoToRedux(userInfo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**缓存到redux */
|
|
|
public static async cacheUserInfoToRedux(userInfo: WxLoginUsingGetResponse) {
|
|
|
ReduxUtil.dispatch(reduxActions.changeUserInfo(userInfo));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static isLogin() {
|
|
|
return !!ReduxUtil.store.getState().userInfo;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**推出登录 */
|
|
|
public static outLogin() {
|
|
|
Taro.clearStorageSync();
|
|
@@ -47,9 +48,28 @@ export default class UserHelper {
|
|
|
RouteUtil.reLaunch("/pages/bottomNavBar/index");
|
|
|
}
|
|
|
|
|
|
+ public static async UpdateOpenId () {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ Taro.login({
|
|
|
+ success: async function (login_res) {
|
|
|
+ if (login_res.code) {
|
|
|
+ await UserApi.wxUpdateOpenIdGet({
|
|
|
+ params: { jsCode: login_res.code }
|
|
|
+ })
|
|
|
+ resolve(login_res.code)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ reject(res)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
static callback?: () => Promise<any>;
|
|
|
+
|
|
|
|
|
|
- public static afterLogin<T = any>(
|
|
|
+ public static async afterLogin<T = any>(
|
|
|
options: {
|
|
|
toLoginPage?: boolean;
|
|
|
callbackBeforeRoute?: boolean;
|
|
@@ -66,10 +86,29 @@ export default class UserHelper {
|
|
|
page,
|
|
|
params,
|
|
|
} = options;
|
|
|
+ const updateOpenId = () => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ Taro.login({
|
|
|
+ success: async function (login_res) {
|
|
|
+ if (login_res.code) {
|
|
|
+ await UserApi.wxUpdateOpenIdGet({
|
|
|
+ params: { jsCode: login_res.code }
|
|
|
+ })
|
|
|
+ resolve(login_res.code)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ reject(res)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
this.callback = callback;
|
|
|
if (UserHelper.isLogin()) {
|
|
|
+ await updateOpenId()
|
|
|
callback?.();
|
|
|
} else {
|
|
|
+ await updateOpenId()
|
|
|
if (forceLogin) {
|
|
|
toLoginPage &&
|
|
|
RouteUtil.push<ILoginParms>("/pages/user/login/index", {
|