|
|
@@ -1,6 +1,6 @@
|
|
|
import { useAppStore } from "@/stores/app";
|
|
|
import { toLogin, checkLogin } from '@/libs/login'
|
|
|
-import { wxLogin, updateOpenId,getUserInfo } from "@/api/user.js";
|
|
|
+import { wxLogin, updateOpenId ,getUserInfoApi} from "@/api/user.js";
|
|
|
import { useToast } from "@/hooks/useToast";
|
|
|
import Cache from "./cache";
|
|
|
import {
|
|
|
@@ -51,6 +51,11 @@ export function uniLogin() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export function getUserInfo (e) {
|
|
|
+ const appStore = useAppStore();
|
|
|
+ if(Cache.get(TOKEN))appStore.USERINFO();
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* 统一登录方法:同时获取openid和手机号
|
|
|
* @param {Object} e - 微信获取手机号事件对象
|
|
|
@@ -211,75 +216,33 @@ async function handleLoginWithPhoneCode(phoneCode, options) {
|
|
|
// 5. 处理后端响应
|
|
|
if (res.code === 200) {
|
|
|
const appStore = useAppStore();
|
|
|
-
|
|
|
// 保存token
|
|
|
appStore.UPDATE_TOKEN(res.data.access_token || res.data);
|
|
|
|
|
|
// 获取用户信息
|
|
|
- await appStore.USERINFO();
|
|
|
-
|
|
|
- // 移除了Toast,只在页面显示
|
|
|
- // 触发登录成功事件
|
|
|
- uni.$emit('loginSuccess');
|
|
|
-
|
|
|
- // 登录成功后的处理(例如跳转)
|
|
|
- await handleAfterLoginSuccess(options);
|
|
|
-
|
|
|
- return {
|
|
|
- success: true,
|
|
|
- data: res.data,
|
|
|
- message: res.msg || '登录成功',
|
|
|
- userInfo: appStore.userInfo
|
|
|
- };
|
|
|
- } else {
|
|
|
- // 处理业务错误
|
|
|
- const error = {
|
|
|
- code: res.code,
|
|
|
- message: res.msg || res.data?.message || '登录失败',
|
|
|
- data: res.data
|
|
|
- };
|
|
|
- throw error;
|
|
|
- }
|
|
|
+ const loginResult = await getUserInfoApi();
|
|
|
+ if(loginResult.code == 200){
|
|
|
+ // 移除了Toast,只在页面显示
|
|
|
+ // 触发登录成功事件
|
|
|
+ uni.$emit('loginSuccess');
|
|
|
+ return {
|
|
|
+ success: true,
|
|
|
+ data: loginResult.user,
|
|
|
+ message: res.msg || '登录成功',
|
|
|
+ userInfo: loginResult.user
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 处理业务错误
|
|
|
+ const error = {
|
|
|
+ code: res.code,
|
|
|
+ message: res.msg || res.data?.message || '登录失败',
|
|
|
+ data: res.data
|
|
|
+ };
|
|
|
+ throw error;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * 登录成功后的处理
|
|
|
- */
|
|
|
-async function handleAfterLoginSuccess(options) {
|
|
|
- try {
|
|
|
- // 如果有回调URL,则跳转
|
|
|
- if (options.redirectUrl) {
|
|
|
- setTimeout(() => {
|
|
|
- if (options.redirectUrl.startsWith('/')) {
|
|
|
- uni.redirectTo({ url: options.redirectUrl });
|
|
|
- } else {
|
|
|
- uni.switchTab({ url: options.redirectUrl });
|
|
|
- }
|
|
|
- }, 1500);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 默认跳转逻辑
|
|
|
- const pages = getCurrentPages();
|
|
|
- const currentRoute = pages[pages.length - 1]?.route || '';
|
|
|
-
|
|
|
- // 如果当前在个人中心页面,刷新页面即可
|
|
|
- if (currentRoute.includes('mine')) {
|
|
|
- // 可以触发页面刷新
|
|
|
- const eventChannel = pages[pages.length - 1];
|
|
|
- if (eventChannel && eventChannel.onLoad) {
|
|
|
- eventChannel.onLoad();
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 其他页面跳转到个人中心
|
|
|
- setTimeout(() => {
|
|
|
- uni.switchTab({ url: '/pages/mine/mine' });
|
|
|
- }, 1500);
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('登录后处理失败:', error);
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* 快捷登录方法(适用于页面直接调用)
|
|
|
@@ -517,11 +480,8 @@ export function getSceneInfo (e) {
|
|
|
return params;
|
|
|
}
|
|
|
};
|
|
|
-//获取客户信息
|
|
|
-export function getUserInfo (e) {
|
|
|
- const appStore = useAppStore();
|
|
|
- if(Cache.get(TOKEN))appStore.USERINFO();
|
|
|
-};
|
|
|
+
|
|
|
+
|
|
|
export async function chooseImageOne(apiUrl="chat/file/imageUpload") {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
uni.chooseImage({
|