Compare commits
3 Commits
ea56695099
...
fix-109
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e18c99161 | ||
|
|
6745e36a79 | ||
|
|
56ad450731 |
@@ -2,12 +2,12 @@
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { getEvnUrl } from "@/request/api/config";
|
||||
import { refreshToken } from "@/hooks/useGoLogin";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
onLaunch(async () => {
|
||||
await getEvnUrl({ versionValue: "1.0.3" });
|
||||
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
|
||||
if (token) {
|
||||
refreshToken();
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
import { appId, clientId } from "@/constant/base";
|
||||
import { currentClientType } from "@/constant/base";
|
||||
|
||||
/// 存储在本地的认证 token 键名
|
||||
export const clientAuthToken = "AUTH_TOKEN_" + clientId + "_" + appId;
|
||||
// 存储在本地的认证 token 键名
|
||||
const CLIENT_TYPE = currentClientType();
|
||||
const ACCESS_TOKEN = `${CLIENT_TYPE}_ACCESS_TOKEN`;
|
||||
const REFRESH_ACCESS_TOKEN = `${CLIENT_TYPE}_REFRESH_ACCESS_TOKEN`;
|
||||
|
||||
/// 设置本地存储的认证 token
|
||||
export const setStorageSyncToken = (token) => {
|
||||
uni.setStorageSync(clientAuthToken, token);
|
||||
// 设置本地存储的认证 token
|
||||
export const setAccessToken = (token) => {
|
||||
return uni.setStorageSync(ACCESS_TOKEN, token);
|
||||
};
|
||||
|
||||
/// 获取本地存储的认证 token
|
||||
export const getStorageSyncToken = () => {
|
||||
return uni.getStorageSync(clientAuthToken);
|
||||
// 设置本地存储的刷新 token
|
||||
export const setRefreshToken = (token) => {
|
||||
return uni.setStorageSync(REFRESH_ACCESS_TOKEN, token);
|
||||
};
|
||||
|
||||
/// 移除本地存储的认证 token
|
||||
export const removeStorageSyncToken = () => {
|
||||
uni.setStorageSync(clientAuthToken, "");
|
||||
};
|
||||
// 获取本地存储的刷新 token
|
||||
export const getRefreshToken = () => {
|
||||
return uni.getStorageSync(REFRESH_ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
// 获取本地存储的认证 token
|
||||
export const getAccessToken = () => {
|
||||
return uni.getStorageSync(ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
// 移除本地存储的认证 token
|
||||
export const removeAccessToken = () => {
|
||||
return uni.removeStorageSync(ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
export const removeRefreshToken = () => {
|
||||
return uni.removeStorageSync(REFRESH_ACCESS_TOKEN);
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { wxLogin, checkUserPhone } from "../request/api/LoginApi";
|
||||
import { wxLogin, checkUserPhone } from "@/request/api/LoginApi";
|
||||
import { loginAuth, bindPhone } from "@/manager/LoginManager";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
import { getStorageSyncToken, setStorageSyncToken } from "../constant/token";
|
||||
import { getAccessToken, setAccessToken } from "../constant/token";
|
||||
|
||||
// 跳转登录
|
||||
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
|
||||
@@ -49,7 +49,7 @@ export const onLogin = async (e) => {
|
||||
|
||||
// 检测token
|
||||
export const checkToken = () => {
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!token) {
|
||||
@@ -62,7 +62,7 @@ export const checkToken = () => {
|
||||
};
|
||||
|
||||
// 刷新token
|
||||
export const refreshToken = () => {
|
||||
export const refreshToken = (needLogin = false) => {
|
||||
return new Promise(async (resolve) => {
|
||||
uni.login({
|
||||
provider: "weixin", //使用微信登录
|
||||
@@ -78,10 +78,22 @@ export const refreshToken = () => {
|
||||
|
||||
const response = await wxLogin(params);
|
||||
|
||||
if (needLogin && response.access_token) {
|
||||
setAccessToken(response.access_token);
|
||||
}
|
||||
|
||||
if (response.access_token) {
|
||||
setStorageSyncToken(response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
const checkRes = await checkUserPhone({
|
||||
token: response.access_token,
|
||||
});
|
||||
|
||||
if (checkRes.data) {
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import {
|
||||
wxLogin,
|
||||
bindUserPhone,
|
||||
checkUserPhone,
|
||||
} from "../request/api/LoginApi";
|
||||
import { wxLogin, bindUserPhone } from "../request/api/LoginApi";
|
||||
import { getWeChatAuthCode } from "./AuthManager";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
import { removeStorageSyncToken, setStorageSyncToken } from "../constant/token";
|
||||
import { removeAccessToken, setAccessToken } from "../constant/token";
|
||||
|
||||
const loginAuth = (e) => {
|
||||
removeStorageSyncToken();
|
||||
removeAccessToken();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const openIdCode = await getWeChatAuthCode(e);
|
||||
@@ -26,7 +22,8 @@ const loginAuth = (e) => {
|
||||
|
||||
if (response.access_token) {
|
||||
console.log("进入条件");
|
||||
setStorageSyncToken(response.access_token);
|
||||
setAccessToken(response.access_token);
|
||||
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve();
|
||||
|
||||
@@ -108,7 +108,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
|
||||
import { ThrottleUtils, IdUtils } from "@/utils";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
import { getAccessToken } from "@/constant/token";
|
||||
|
||||
const appStore = useAppStore();
|
||||
/// 导航栏相关
|
||||
@@ -296,7 +296,7 @@ onLoad(() => {
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
console.log("initHandler");
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
|
||||
if (!token) return;
|
||||
loadRecentConversation();
|
||||
@@ -364,7 +364,7 @@ const initWebSocket = async () => {
|
||||
}
|
||||
|
||||
// 使用配置的WebSocket服务器地址
|
||||
const token = getStorageSyncToken();
|
||||
const token = getAccessToken();
|
||||
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
|
||||
|
||||
// 初始化WebSocket管理器
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
<template>
|
||||
<view
|
||||
class="quick-access flex flex-row ml-12 pt-8 pb-8 scroll-x whitespace-nowrap"
|
||||
>
|
||||
<view
|
||||
class="item border-box rounded-50 flex flex-row items-center"
|
||||
v-for="(item, index) in itemList"
|
||||
:key="index"
|
||||
@click="sendReply(item)"
|
||||
>
|
||||
<view class="quick-access flex flex-row ml-12 pt-8 pb-8 scroll-x whitespace-nowrap">
|
||||
<view class="item border-box rounded-50 flex flex-row items-center" v-for="(item, index) in itemList" :key="index"
|
||||
@click="sendReply(item)">
|
||||
<view class="flex items-center justify-center">
|
||||
<image v-if="item.icon" class="icon" :src="item.icon" />
|
||||
<text class="font-size-14 color-2D91FF line-height-20">
|
||||
@@ -22,6 +16,7 @@
|
||||
import { ref } from "vue";
|
||||
import { Command } from "@/model/ChatModel";
|
||||
import { SEND_MESSAGE_COMMAND_TYPE } from "@/constant/constant";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const itemList = ref([
|
||||
{
|
||||
@@ -55,7 +50,9 @@ const sendReply = (item) => {
|
||||
|
||||
// 快速预定
|
||||
if (item.type === Command.quickBooking) {
|
||||
uni.navigateTo({ url: "/pages-quick/list" });
|
||||
checkToken().then(() => {
|
||||
uni.navigateTo({ url: "/pages-quick/list" });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,12 @@
|
||||
<uni-popup ref="popup" type="bottom" :safe-area="false">
|
||||
<view class="popup-content border-box pt-12 pl-12 pr-12">
|
||||
<view class="header flex flex-items-center pb-12">
|
||||
<view
|
||||
class="title flex-full text-center font-size-17 color-000 font-500 ml-24"
|
||||
>更多服务</view
|
||||
>
|
||||
<view class="title flex-full text-center font-size-17 color-000 font-500 ml-24">更多服务</view>
|
||||
<uni-icons type="close" size="24" color="#CACFD8" @click="close" />
|
||||
</view>
|
||||
|
||||
<view class="list bg-white border-box pl-20 pr-20">
|
||||
<view
|
||||
class="item border-box border-bottom pt-20 pb-20"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
>
|
||||
<view class="item border-box border-bottom pt-20 pb-20" v-for="(item, index) in list" :key="index">
|
||||
<view class="flex flex-items-center flex-justify-center">
|
||||
<image v-if="item.icon" class="left" :src="item.icon" />
|
||||
<view class="center flex-full">
|
||||
@@ -25,10 +18,7 @@
|
||||
{{ item.content }}
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="right border-box font-size-12 color-white line-height-16"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<view class="right border-box font-size-12 color-white line-height-16" @click="handleClick(item)">
|
||||
{{ item.btnText }}
|
||||
</view>
|
||||
</view>
|
||||
@@ -42,6 +32,7 @@
|
||||
import { ref } from "vue";
|
||||
import { Command } from "@/model/ChatModel";
|
||||
import { SEND_MESSAGE_COMMAND_TYPE } from "@/constant/constant";
|
||||
import { checkToken } from "@/hooks/useGoLogin";
|
||||
|
||||
const popup = ref(null);
|
||||
|
||||
@@ -100,7 +91,10 @@ const handleClick = (item) => {
|
||||
close();
|
||||
|
||||
if (item.path) {
|
||||
uni.navigateTo({ url: item.path });
|
||||
checkToken().then(() => {
|
||||
uni.navigateTo({ url: item.path });
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,12 @@ import { ref, computed } from "vue";
|
||||
import {
|
||||
getServiceAgreement,
|
||||
getPrivacyAgreement,
|
||||
checkUserPhone
|
||||
} from "@/request/api/LoginApi";
|
||||
import { onLogin, goBack, refreshToken } from "@/hooks/useGoLogin";
|
||||
import CheckBox from "@/components/CheckBox/index.vue";
|
||||
import AgreePopup from "./components/AgreePopup/index.vue";
|
||||
import { zniconsMap } from "@/static/fonts/znicons";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { getStorageSyncToken } from "@/constant/token";
|
||||
|
||||
const needWxLogin = ref(false);
|
||||
const isAgree = ref(false);
|
||||
@@ -78,7 +76,7 @@ const handleAgreeAndGetPhone = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
refreshToken().then(() => goBack());
|
||||
refreshToken(true).then(() => goBack());
|
||||
};
|
||||
|
||||
const getPhoneNumber = (e) => {
|
||||
@@ -126,15 +124,9 @@ getPrivacyAgreementData();
|
||||
|
||||
// 页面显示时刷新token
|
||||
onShow(async () => {
|
||||
const token = getStorageSyncToken();
|
||||
const res = await refreshToken();
|
||||
|
||||
if (token) {
|
||||
const res = await checkUserPhone();
|
||||
|
||||
needWxLogin.value = res.data;
|
||||
} else {
|
||||
needWxLogin.value = true;
|
||||
}
|
||||
needWxLogin.value = res;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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