feat: 调整登录逻辑

This commit is contained in:
duanshuwen
2025-09-12 22:20:01 +08:00
parent 07752394eb
commit c03a4200be
12 changed files with 248 additions and 175 deletions

View File

@@ -1,5 +1,13 @@
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

View File

@@ -1,5 +1,13 @@
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

View File

@@ -1,5 +1,13 @@
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
View File

@@ -1,28 +1,8 @@
<script setup>
import { onLaunch, onShow, onHide, onLoad } from "@dcloudio/uni-app";
import { checkPhone } from "@/manager/LoginManager";
import { goLogin } from "@/hooks/useGoLogin";
import { goHome } from "@/hooks/useGoHome";
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
onLaunch(async () => {
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(() => {
@@ -55,4 +35,18 @@ body,
.mb12 {
margin-bottom: 12px;
}
// 重置按钮样式
.reset-btn {
background: none;
border: none;
outline: none;
padding: 0;
margin: 0;
&::after {
border: none;
content: " ";
}
}
</style>

View File

@@ -1 +1,33 @@
import { loginAuth, checkPhone, bindPhone } from "@/manager/LoginManager";
// 跳转登录
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);
});
};

View File

@@ -5,8 +5,8 @@ import {
} from "../request/api/LoginApi";
import { getWeChatAuthCode } from "./AuthManager";
const loginAuth = async () => {
try {
const loginAuth = () => {
return new Promise(async (resolve, reject) => {
const openIdCode = await getWeChatAuthCode();
console.log("获取到的微信授权code:", openIdCode);
const response = await wxLogin({
@@ -19,13 +19,12 @@ const loginAuth = async () => {
if (response.access_token) {
uni.setStorageSync("token", response.access_token);
return response;
resolve();
} else {
throw new Error(response.message || "登录失败");
}
} catch (err) {
throw err;
reject(response.message || "登录失败");
}
});
};
const bindPhone = async (params) => {

View File

@@ -55,9 +55,9 @@
},
/* */
"quickapp": {},
/* */
/* wx23f86d809ae80259 wx5e79df5996572539 */
"mp-weixin": {
"appid" : "wx23f86d809ae80259",
"appid": "wx5e79df5996572539",
"setting": {
"urlCheck": false
},

View File

@@ -97,12 +97,18 @@
/>
<ActivityListComponent
v-if="mainPageDataModel.activityList && mainPageDataModel.activityList.length > 0"
v-if="
mainPageDataModel.activityList &&
mainPageDataModel.activityList.length > 0
"
:activityList="mainPageDataModel.activityList"
/>
<RecommendPostsComponent
v-if="mainPageDataModel.recommendTheme && mainPageDataModel.recommendTheme.length > 0"
v-if="
mainPageDataModel.recommendTheme &&
mainPageDataModel.recommendTheme.length > 0
"
:recommendThemeList="mainPageDataModel.recommendTheme"
/>
</ChatCardOther>
@@ -165,6 +171,7 @@ import WebSocketManager from "@/utils/WebSocketManager";
import TypewriterManager from "@/utils/TypewriterManager";
import { IdUtils } from "@/utils";
import { useAppStore } from "@/store";
import { checkToken } from "@/hooks/useGoLogin";
const appStore = useAppStore();
/// 导航栏相关
@@ -346,14 +353,18 @@ onLoad(() => {
});
});
onMounted(async () => {
onMounted(() => {
try {
getMainPageData();
await loadRecentConversation();
loadConversationMsgList();
addNoticeListener();
initTypewriterManager();
// 有token时加载最近会话、最近消息、初始化socket
checkToken().then(async () => {
await loadRecentConversation();
loadConversationMsgList();
initWebSocket();
});
} catch (error) {
console.error("页面初始化错误:", error);
}

View File

@@ -6,9 +6,14 @@
v-for="(item, index) in itemList"
:key="index"
>
<text class="more-tips-item-title" @click="sendReply(item)">{{
item
}}</text>
<button
class="reset-btn more-tips-item-title"
open-type="getPhoneNumber"
@getphonenumber="onLogin"
@click="sendReply(item)"
>
{{ item }}
</button>
</view>
</view>
</view>
@@ -16,6 +21,8 @@
<script setup>
import { defineProps } from "vue";
import { onLogin, checkToken } from "@/hooks/useGoLogin";
const emits = defineEmits(["replySent"]);
defineProps({
@@ -34,7 +41,9 @@ defineProps({
});
const sendReply = (text) => {
checkToken().then(() => {
emits("replySent", text); // 向父组件传递数据
});
};
</script>

View File

@@ -38,6 +38,7 @@
<script setup>
import { ref, onMounted } from "vue";
import { getLoginUserPhone } from "@/request/api/LoginApi";
import { checkToken } from "@/hooks/useGoLogin";
// 假数据
const userInfo = ref({
@@ -60,11 +61,14 @@ const menuList = ref([
// 生命周期钩子
onMounted(() => {
checkToken().then(() => {
getLoginUserPhoneInfo();
});
});
const getLoginUserPhoneInfo = async () => {
const res = await getLoginUserPhone();
if (res.code === 0) {
userInfo.value.phone = res.data;
}

View File

@@ -1,5 +1,5 @@
{
"appid": "wx23f86d809ae80259",
"appid": "wx5e79df5996572539",
"compileType": "miniprogram",
"libVersion": "3.8.10",
"packOptions": {

View File

@@ -50,10 +50,10 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
success: (res) => {
console.log("请求响应:" + JSON.stringify(res));
resolve(res.data);
if (res.statusCode && res.statusCode === 424) {
uni.setStorageSync("token", "");
goLogin();
}
// if (res.statusCode && res.statusCode === 424) {
// uni.setStorageSync("token", "");
// goLogin();
// }
},
fail: (err) => {
console.error("请求失败:", err);