feat: 调整登录逻辑
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
12
.env.staging
12
.env.staging
@@ -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
36
App.vue
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
114
manifest.json
114
manifest.json
@@ -1,33 +1,33 @@
|
||||
{
|
||||
"name" : "YGTianmuCS",
|
||||
"appid" : "__UNI__BB03E8A",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
"name": "YGTianmuCS",
|
||||
"appid": "__UNI__BB03E8A",
|
||||
"description": "",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
"usingComponents" : true,
|
||||
"nvueStyleCompiler" : "uni-app",
|
||||
"compilerVersion" : 3,
|
||||
"splashscreen" : {
|
||||
"alwaysShowBeforeRender" : true,
|
||||
"waiting" : true,
|
||||
"autoclose" : true,
|
||||
"delay" : 0
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
"safearea" : {
|
||||
"bottom" : {
|
||||
"offset" : "auto" // 自动适配安全区域
|
||||
"safearea": {
|
||||
"bottom": {
|
||||
"offset": "auto" // 自动适配安全区域
|
||||
}
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {},
|
||||
"modules": {},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
"distribute": {
|
||||
/* android打包配置 */
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
@@ -46,57 +46,57 @@
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios" : {},
|
||||
"ios": {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs" : {
|
||||
"oauth" : {}
|
||||
"sdkConfigs": {
|
||||
"oauth": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp" : {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
"appid" : "wx23f86d809ae80259",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
"quickapp": {},
|
||||
/* 小程序特有相关 朵花用:wx23f86d809ae80259 测试用:wx5e79df5996572539 */
|
||||
"mp-weixin": {
|
||||
"appid": "wx5e79df5996572539",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents" : true,
|
||||
"requiredPrivateInfos" : [ "getLocation" ],
|
||||
"permission" : {
|
||||
"scope.userLocation" : {
|
||||
"desc" : "用于获取当前所在城市信息"
|
||||
"usingComponents": true,
|
||||
"requiredPrivateInfos": ["getLocation"],
|
||||
"permission": {
|
||||
"scope.userLocation": {
|
||||
"desc": "用于获取当前所在城市信息"
|
||||
}
|
||||
},
|
||||
"plugins" : {
|
||||
"WechatSI" : {
|
||||
"version" : "0.3.6",
|
||||
"provider" : "wx069ba97219f66d99"
|
||||
"plugins": {
|
||||
"WechatSI": {
|
||||
"version": "0.3.6",
|
||||
"provider": "wx069ba97219f66d99"
|
||||
}
|
||||
},
|
||||
"__usePrivacyCheck__" : true
|
||||
"__usePrivacyCheck__": true
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true,
|
||||
"usePrivacyCheck" : true
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true,
|
||||
"usePrivacyCheck": true
|
||||
},
|
||||
"uniStatistics" : {
|
||||
"enable" : false
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion" : "3",
|
||||
"h5" : {
|
||||
"router" : {
|
||||
"base" : "./",
|
||||
"mode" : "hash"
|
||||
"vueVersion": "3",
|
||||
"h5": {
|
||||
"router": {
|
||||
"base": "./",
|
||||
"mode": "hash"
|
||||
},
|
||||
"devServer" : {
|
||||
"https" : false
|
||||
"devServer": {
|
||||
"https": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"appid": "wx23f86d809ae80259",
|
||||
"appid": "wx5e79df5996572539",
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "3.8.10",
|
||||
"packOptions": {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user