From 3af5f2850d58a33749220660f1bc8f9f4474ce0b Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Sun, 14 Jun 2026 21:54:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=99=BB=E5=BD=95=E6=94=B9=E9=80=A0=EF=BC=88=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E6=8E=88=E6=9D=83=20+=20API=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E6=94=B9=E4=B8=BA/mp-api=20+=20=E9=9A=90=E7=A7=81?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=A3=80=E6=9F=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 12 +++++++++++ src/api/types.ts | 3 +++ src/api/user.ts | 6 +++--- src/config/index.ts | 6 +++--- src/pages/login/login.vue | 43 ++++++++++++++++++++++++++++++++------- src/store/user.ts | 19 +++-------------- 6 files changed, 60 insertions(+), 29 deletions(-) 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 @@