feat: 调整登录逻辑
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
NODE_ENV = development
|
NODE_ENV = development
|
||||||
|
|
||||||
VITE_BASE_URL = https://biz.nianxx.cn
|
# 测试
|
||||||
|
VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||||
|
|
||||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
# 生产
|
||||||
|
# VITE_BASE_URL = https://biz.nianxx.cn
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
|
||||||
|
|
||||||
|
# 生产
|
||||||
|
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
NODE_ENV = production
|
NODE_ENV = production
|
||||||
|
|
||||||
VITE_BASE_URL = https://biz.nianxx.cn
|
# 测试
|
||||||
|
VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||||
|
|
||||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
# 生产
|
||||||
|
# VITE_BASE_URL = https://biz.nianxx.cn
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
|
||||||
|
|
||||||
|
# 生产
|
||||||
|
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
||||||
12
.env.staging
12
.env.staging
@@ -1,5 +1,13 @@
|
|||||||
NODE_ENV = staging
|
NODE_ENV = staging
|
||||||
|
|
||||||
VITE_BASE_URL = https://biz.nianxx.cn
|
# 测试
|
||||||
|
VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||||
|
|
||||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
# 生产
|
||||||
|
# VITE_BASE_URL = https://biz.nianxx.cn
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
ITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
|
||||||
|
|
||||||
|
# 生产
|
||||||
|
# VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
||||||
36
App.vue
36
App.vue
@@ -1,28 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onLaunch, onShow, onHide, onLoad } from "@dcloudio/uni-app";
|
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||||
import { checkPhone } from "@/manager/LoginManager";
|
|
||||||
import { goLogin } from "@/hooks/useGoLogin";
|
|
||||||
import { goHome } from "@/hooks/useGoHome";
|
|
||||||
|
|
||||||
onLaunch(async () => {
|
onLaunch(async () => {
|
||||||
console.log("App Launch");
|
console.log("App Launch");
|
||||||
|
|
||||||
const token = uni.getStorageSync("token");
|
|
||||||
|
|
||||||
// 检测是否绑定手机号和token
|
|
||||||
if (!token) {
|
|
||||||
goLogin();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
const res = await checkPhone();
|
|
||||||
|
|
||||||
if (res.data) {
|
|
||||||
goHome();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
@@ -55,4 +35,18 @@ body,
|
|||||||
.mb12 {
|
.mb12 {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重置按钮样式
|
||||||
|
.reset-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
border: none;
|
||||||
|
content: " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1 +1,33 @@
|
|||||||
|
import { loginAuth, checkPhone, bindPhone } from "@/manager/LoginManager";
|
||||||
|
|
||||||
|
// 跳转登录
|
||||||
export const goLogin = () => uni.reLaunch({ url: "/pages/login/index" });
|
export const goLogin = () => uni.reLaunch({ url: "/pages/login/index" });
|
||||||
|
|
||||||
|
// 登录逻辑
|
||||||
|
export const onLogin = (e) => {
|
||||||
|
const { code } = e.detail;
|
||||||
|
console.info("onLogin code: ", code);
|
||||||
|
|
||||||
|
loginAuth().then(async () => {
|
||||||
|
// 检测是否绑定手机号
|
||||||
|
const res = await checkPhone();
|
||||||
|
|
||||||
|
if (res.data) return;
|
||||||
|
|
||||||
|
const params = { wechatPhoneCode: code, clientId: "2" };
|
||||||
|
|
||||||
|
// 绑定手机号
|
||||||
|
bindPhone(params);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 检测token
|
||||||
|
export const checkToken = async () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const token = uni.getStorageSync("token");
|
||||||
|
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
resolve(token);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import {
|
|||||||
} from "../request/api/LoginApi";
|
} from "../request/api/LoginApi";
|
||||||
import { getWeChatAuthCode } from "./AuthManager";
|
import { getWeChatAuthCode } from "./AuthManager";
|
||||||
|
|
||||||
const loginAuth = async () => {
|
const loginAuth = () => {
|
||||||
try {
|
return new Promise(async (resolve, reject) => {
|
||||||
const openIdCode = await getWeChatAuthCode();
|
const openIdCode = await getWeChatAuthCode();
|
||||||
console.log("获取到的微信授权code:", openIdCode);
|
console.log("获取到的微信授权code:", openIdCode);
|
||||||
const response = await wxLogin({
|
const response = await wxLogin({
|
||||||
@@ -19,13 +19,12 @@ const loginAuth = async () => {
|
|||||||
|
|
||||||
if (response.access_token) {
|
if (response.access_token) {
|
||||||
uni.setStorageSync("token", response.access_token);
|
uni.setStorageSync("token", response.access_token);
|
||||||
return response;
|
|
||||||
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.message || "登录失败");
|
reject(response.message || "登录失败");
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindPhone = async (params) => {
|
const bindPhone = async (params) => {
|
||||||
|
|||||||
@@ -55,9 +55,9 @@
|
|||||||
},
|
},
|
||||||
/* 快应用特有相关 */
|
/* 快应用特有相关 */
|
||||||
"quickapp": {},
|
"quickapp": {},
|
||||||
/* 小程序特有相关 */
|
/* 小程序特有相关 朵花用:wx23f86d809ae80259 测试用:wx5e79df5996572539 */
|
||||||
"mp-weixin": {
|
"mp-weixin": {
|
||||||
"appid" : "wx23f86d809ae80259",
|
"appid": "wx5e79df5996572539",
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false
|
"urlCheck": false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -97,12 +97,18 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<ActivityListComponent
|
<ActivityListComponent
|
||||||
v-if="mainPageDataModel.activityList && mainPageDataModel.activityList.length > 0"
|
v-if="
|
||||||
|
mainPageDataModel.activityList &&
|
||||||
|
mainPageDataModel.activityList.length > 0
|
||||||
|
"
|
||||||
:activityList="mainPageDataModel.activityList"
|
:activityList="mainPageDataModel.activityList"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RecommendPostsComponent
|
<RecommendPostsComponent
|
||||||
v-if="mainPageDataModel.recommendTheme && mainPageDataModel.recommendTheme.length > 0"
|
v-if="
|
||||||
|
mainPageDataModel.recommendTheme &&
|
||||||
|
mainPageDataModel.recommendTheme.length > 0
|
||||||
|
"
|
||||||
:recommendThemeList="mainPageDataModel.recommendTheme"
|
:recommendThemeList="mainPageDataModel.recommendTheme"
|
||||||
/>
|
/>
|
||||||
</ChatCardOther>
|
</ChatCardOther>
|
||||||
@@ -165,6 +171,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
|
|||||||
import TypewriterManager from "@/utils/TypewriterManager";
|
import TypewriterManager from "@/utils/TypewriterManager";
|
||||||
import { IdUtils } from "@/utils";
|
import { IdUtils } from "@/utils";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
|
import { checkToken } from "@/hooks/useGoLogin";
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
/// 导航栏相关
|
/// 导航栏相关
|
||||||
@@ -346,14 +353,18 @@ onLoad(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(() => {
|
||||||
try {
|
try {
|
||||||
getMainPageData();
|
getMainPageData();
|
||||||
await loadRecentConversation();
|
|
||||||
loadConversationMsgList();
|
|
||||||
addNoticeListener();
|
addNoticeListener();
|
||||||
initTypewriterManager();
|
initTypewriterManager();
|
||||||
|
|
||||||
|
// 有token时,加载最近会话、最近消息、初始化socket
|
||||||
|
checkToken().then(async () => {
|
||||||
|
await loadRecentConversation();
|
||||||
|
loadConversationMsgList();
|
||||||
initWebSocket();
|
initWebSocket();
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("页面初始化错误:", error);
|
console.error("页面初始化错误:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,14 @@
|
|||||||
v-for="(item, index) in itemList"
|
v-for="(item, index) in itemList"
|
||||||
:key="index"
|
:key="index"
|
||||||
>
|
>
|
||||||
<text class="more-tips-item-title" @click="sendReply(item)">{{
|
<button
|
||||||
item
|
class="reset-btn more-tips-item-title"
|
||||||
}}</text>
|
open-type="getPhoneNumber"
|
||||||
|
@getphonenumber="onLogin"
|
||||||
|
@click="sendReply(item)"
|
||||||
|
>
|
||||||
|
{{ item }}
|
||||||
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -16,6 +21,8 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { defineProps } from "vue";
|
import { defineProps } from "vue";
|
||||||
|
import { onLogin, checkToken } from "@/hooks/useGoLogin";
|
||||||
|
|
||||||
const emits = defineEmits(["replySent"]);
|
const emits = defineEmits(["replySent"]);
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
@@ -34,7 +41,9 @@ defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sendReply = (text) => {
|
const sendReply = (text) => {
|
||||||
|
checkToken().then(() => {
|
||||||
emits("replySent", text); // 向父组件传递数据
|
emits("replySent", text); // 向父组件传递数据
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
import { getLoginUserPhone } from "@/request/api/LoginApi";
|
import { getLoginUserPhone } from "@/request/api/LoginApi";
|
||||||
|
import { checkToken } from "@/hooks/useGoLogin";
|
||||||
|
|
||||||
// 假数据
|
// 假数据
|
||||||
const userInfo = ref({
|
const userInfo = ref({
|
||||||
@@ -60,11 +61,14 @@ const menuList = ref([
|
|||||||
|
|
||||||
// 生命周期钩子
|
// 生命周期钩子
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
checkToken().then(() => {
|
||||||
getLoginUserPhoneInfo();
|
getLoginUserPhoneInfo();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const getLoginUserPhoneInfo = async () => {
|
const getLoginUserPhoneInfo = async () => {
|
||||||
const res = await getLoginUserPhone();
|
const res = await getLoginUserPhone();
|
||||||
|
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
userInfo.value.phone = res.data;
|
userInfo.value.phone = res.data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"appid": "wx23f86d809ae80259",
|
"appid": "wx5e79df5996572539",
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"libVersion": "3.8.10",
|
"libVersion": "3.8.10",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log("请求响应:" + JSON.stringify(res));
|
console.log("请求响应:" + JSON.stringify(res));
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
if (res.statusCode && res.statusCode === 424) {
|
// if (res.statusCode && res.statusCode === 424) {
|
||||||
uni.setStorageSync("token", "");
|
// uni.setStorageSync("token", "");
|
||||||
goLogin();
|
// goLogin();
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error("请求失败:", err);
|
console.error("请求失败:", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user