diff --git a/src/App.vue b/src/App.vue index d57fcee..d0b04bc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,6 +3,18 @@ import { onLaunch } from '@dcloudio/uni-app' import { useUserStore } from './store/user' onLaunch(() => { + // #ifdef MP-WEIXIN + wx.getPrivacySetting({ + success: (res: any) => { + if (res.needAuthorization) { + uni.setStorageSync('needPrivacy', true) + } else { + uni.removeStorageSync('needPrivacy') + } + } + }) + // #endif + const userStore = useUserStore() // 如果有 token,尝试获取用户信息 if (userStore.isLogin) { diff --git a/src/api/types.ts b/src/api/types.ts index 00f2992..d56dfda 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -11,6 +11,9 @@ export interface WxLoginResult { accessToken: string refreshToken: string userId: number + openId: string + mobile: string + expiresTime: string } /** 账号密码登录参数(降级方案) */ diff --git a/src/api/user.ts b/src/api/user.ts index 0cf58a3..7b4093a 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,9 +1,9 @@ import { get, post } from './request' import type { UserInfo, WxLoginResult, LoginParams } from './types' -/** 微信授权登录 */ -export function wxLogin(code: string): Promise { - return post('/auth/wx-login', { code }, false) +/** 微信小程序登录(loginCode + phoneCode) */ +export function wxLogin(data: { loginCode: string; phoneCode: string }): Promise { + return post('/auth/wx-login', data, false) } /** 账号密码登录(降级方案) */ diff --git a/src/config/index.ts b/src/config/index.ts index a2c2638..b3c9f85 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -3,11 +3,11 @@ * 根据 Vite 环境变量读取 API 基础地址等配置 */ -/** API 基础地址(含 /manage-api 前缀) */ +/** API 基础地址(含 /mp-api 前缀) */ export const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:80' -/** API 接口前缀 */ -export const API_PREFIX = '/manage-api' +/** API 接口前缀(小程序走 MP_API 渠道) */ +export const API_PREFIX = '/mp-api' /** 完整 API 基础路径 */ export const API_BASE = `${BASE_URL}${API_PREFIX}` diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index 029122c..10bde67 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -8,7 +8,10 @@