Forráskód Böngészése

fix: 自定义状态码为401时,需要进行手动授权

carver 2 éve
szülő
commit
52b7472fe3

+ 1 - 1
antbuilder/core/store/actions/login.js

@@ -9,7 +9,7 @@ import {
 import request from "../../utils/request";
 import { ywtAuth } from "../../utils/ywtService";
 import { setStorage } from "../../utils";
-import { userInfoUrl, loginUrl, gwAppId } from "../../utils/constants";
+import { userInfoUrl, loginUrl } from "../../utils/constants";
 
 export default {
 	async checkUserLogin({ commit }) {

+ 20 - 1
antbuilder/core/utils/request.js

@@ -2,6 +2,7 @@ import { getIn } from "herculex/dist/utils/manipulate";
 import { host, getTicketUrl, ywtRequestUrl, terminal } from "./constants";
 import { getSilentAuthCode, getAppId, getServerTime } from "./jsapi";
 import { joinUrl } from "./format";
+import { getCurrentStore } from "../../../antbuilder/core/utils/index";
 
 function showErrorMessgage({ isShowError, error }) {
 	if (isShowError) {
@@ -235,7 +236,25 @@ export default async function request(options) {
 		return [error, null];
 	} else if (code === 401) {
 		// 手动发起请求
-		console.log("手动发起授权请求 33 ===>", res);
+		const currentStore = getCurrentStore();
+		const { dispatchGlobal } = currentStore;
+		const scopes = "auth_user";
+		/* 这里表示如果不是通过按钮触发的手机号登录,需要打开按钮弹窗 */
+		// if (currentScope !== scopes) {
+		// await dispatch.call(currentStore, "launchPhone");
+		// }
+		const success = await dispatchGlobal("doLogin", { scopes });
+		/* 登录失败 */
+		if (!success) {
+			showErrorMessgage({
+				isShowError: true,
+				error: { msg: "登录失败" },
+			});
+			my.navigateBack();
+			return;
+		}
+		const result = await request(options);
+		return result;
 	}
 	const data = res.data || null;
 	return [null, data];