feat: 登录逻辑调整
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { removeStorageSyncToken } from "@/constant/token";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
import { removeAccessToken } from "@/constant/token";
|
||||
|
||||
/// 请求流式数据的API
|
||||
const API = "/agent/assistant/chat";
|
||||
@@ -74,7 +74,7 @@ const stopAbortTask = () => {
|
||||
|
||||
const agentChatStream = (params, onChunk) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
const requestId = Date.now().toString(); // 生成唯一请求ID
|
||||
|
||||
// 重置状态
|
||||
@@ -132,7 +132,7 @@ const agentChatStream = (params, onChunk) => {
|
||||
res.statusCode
|
||||
);
|
||||
if (res.statusCode === 424) {
|
||||
removeStorageSyncToken();
|
||||
removeAccessToken();
|
||||
goLogin();
|
||||
}
|
||||
if (onChunk) {
|
||||
@@ -146,7 +146,8 @@ const agentChatStream = (params, onChunk) => {
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
`❌ 请求 [${requestId}] ${isAborted ? "已终止" : "已过期"
|
||||
`❌ 请求 [${requestId}] ${
|
||||
isAborted ? "已终止" : "已过期"
|
||||
},忽略complete回调`
|
||||
);
|
||||
}
|
||||
@@ -241,7 +242,7 @@ const weAtob = (string) => {
|
||||
r2,
|
||||
i = 0;
|
||||
|
||||
for (; i < string.length;) {
|
||||
for (; i < string.length; ) {
|
||||
bitmap =
|
||||
(b64.indexOf(string.charAt(i++)) << 18) |
|
||||
(b64.indexOf(string.charAt(i++)) << 12) |
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
import { removeStorageSyncToken } from "@/constant/token";
|
||||
import { removeAccessToken } from "@/constant/token";
|
||||
import request from "../base/request";
|
||||
|
||||
const wxLogin = (args) => {
|
||||
const config = {
|
||||
header: {
|
||||
Authorization: "Basic Y3VzdG9tOmN1c3RvbQ==", // 可在此动态设置 token
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
};
|
||||
const config = {
|
||||
header: {
|
||||
Authorization: "Basic Y3VzdG9tOmN1c3RvbQ==", // 可在此动态设置 token
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
};
|
||||
|
||||
removeStorageSyncToken();
|
||||
removeAccessToken();
|
||||
|
||||
return request.post("/auth/oauth2/token", args, config);
|
||||
return request.post("/auth/oauth2/token", args, config);
|
||||
};
|
||||
|
||||
// 绑定用户手机号
|
||||
const bindUserPhone = (args) => {
|
||||
return request.post("/hotelBiz/user/bindUserPhone", args);
|
||||
return request.post("/hotelBiz/user/bindUserPhone", args);
|
||||
};
|
||||
|
||||
// 检测用户是否绑定手机号
|
||||
const checkUserPhone = (args) => {
|
||||
return request.get("/hotelBiz/user/checkUserHasBindPhone", args);
|
||||
const checkUserPhone = (config) => {
|
||||
return request.get("/hotelBiz/user/checkUserHasBindPhone", {}, config);
|
||||
};
|
||||
|
||||
// 获取登录用户手机号
|
||||
const getLoginUserPhone = (args) => {
|
||||
return request.get("/hotelBiz/user/getLoginUserPhone", args);
|
||||
return request.get("/hotelBiz/user/getLoginUserPhone", args);
|
||||
};
|
||||
|
||||
// 获取服务协议
|
||||
const getServiceAgreement = (args) => {
|
||||
return request.get("/hotelBiz/mainScene/serviceAgreement", args);
|
||||
return request.get("/hotelBiz/mainScene/serviceAgreement", args);
|
||||
};
|
||||
|
||||
// 获取隐私协议
|
||||
const getPrivacyAgreement = (args) => {
|
||||
return request.get("/hotelBiz/mainScene/privacyPolicy", args);
|
||||
return request.get("/hotelBiz/mainScene/privacyPolicy", args);
|
||||
};
|
||||
|
||||
export {
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
getLoginUserPhone,
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
getLoginUserPhone,
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
export const updateImageFile = (file) => {
|
||||
const { serverConfig } = useAppStore();
|
||||
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { goLogin } from "../../hooks/useGoLogin";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
const defaultConfig = {
|
||||
@@ -20,7 +20,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
url = appStore.serverConfig?.baseUrl + url;
|
||||
}
|
||||
// 动态获取 token
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
|
||||
let header = {
|
||||
...defaultConfig.header,
|
||||
@@ -31,8 +31,8 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
if (customConfig.noToken) {
|
||||
delete header.Authorization;
|
||||
} else {
|
||||
if (token) {
|
||||
header.Authorization = `Bearer ${token}`;
|
||||
if (token || customConfig.token) {
|
||||
header.Authorization = `Bearer ${token || customConfig.token}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
resolve(res.data);
|
||||
if (res.statusCode && res.statusCode === 424) {
|
||||
console.log("424错误,重新登录");
|
||||
// removeStorageSyncToken();
|
||||
// removeAccessToken();
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
// goLogin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user