From 4cd1040e5d9195b040a2036270566bb56712dfb0 Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Sun, 14 Jun 2026 17:21:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9A=E4=B9=89=E5=85=B1=E4=BA=AB?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=8C=E6=94=B9=E9=80=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=20API=EF=BC=88=E6=96=B0=E5=A2=9E=20wxLogin=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建 src/api/types.ts,统一定义所有业务共享类型 - 改造 src/api/user.ts,类型迁移至 types.ts,新增 wxLogin 接口 - 更新 src/api/index.ts barrel 导出(card/order 模块待后续任务创建) - 同步更新 src/store/user.ts 适配新的 WxLoginResult 返回结构 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/api/index.ts | 5 ++- src/api/types.ts | 95 +++++++++++++++++++++++++++++++++++++++++++++++ src/api/user.ts | 28 ++++++-------- src/store/user.ts | 7 ++-- 4 files changed, 114 insertions(+), 21 deletions(-) create mode 100644 src/api/types.ts diff --git a/src/api/index.ts b/src/api/index.ts index 3cd127f..46ff3a6 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,2 +1,5 @@ +export * from './types' export * from './user' -export * from './request' +export * from './card' +export * from './order' +export { get, post, put, del, getToken, setToken, removeToken } from './request' diff --git a/src/api/types.ts b/src/api/types.ts new file mode 100644 index 0000000..00f2992 --- /dev/null +++ b/src/api/types.ts @@ -0,0 +1,95 @@ +/** 用户信息 */ +export interface UserInfo { + id: number + nickname: string + avatarUrl: string + phone?: string +} + +/** 微信登录结果 */ +export interface WxLoginResult { + accessToken: string + refreshToken: string + userId: number +} + +/** 账号密码登录参数(降级方案) */ +export interface LoginParams { + username: string + password: string +} + +/** 年卡基本信息 */ +export interface CardInfo { + id: string + name: string + price: number + originalPrice: number + coverImage: string + description: string + scenicCount: number +} + +/** 年卡详情 */ +export interface CardDetail extends CardInfo { + benefits: string[] + scenicSpots: ScenicSpot[] + validDays: number + detail: string +} + +/** 景区信息 */ +export interface ScenicSpot { + id: string + name: string + image: string + address?: string +} + +/** 我的年卡 */ +export interface MyCard { + id: string + cardId: string + cardName: string + coverImage: string + userName: string + expireDate: string + status: 'active' | 'expired' | 'inactive' +} + +/** 激活年卡参数 */ +export interface ActivateParams { + realName: string + idCard: string + phone: string +} + +/** 入园码信息 */ +export interface QrCodeInfo { + qrCode: string + expireTime: string + cardName: string + userName: string + expireDate: string +} + +/** 订单信息 */ +export interface OrderInfo { + id: string + cardId: string + cardName: string + price: number + status: 'pending' | 'paid' | 'cancelled' + createTime: string +} + +/** 创建订单参数 */ +export interface CreateOrderParams { + cardId: string +} + +/** 模拟支付结果 */ +export interface MockPayResult { + success: boolean + orderId: string +} diff --git a/src/api/user.ts b/src/api/user.ts index 2afd7b0..0cf58a3 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,25 +1,19 @@ import { get, post } from './request' +import type { UserInfo, WxLoginResult, LoginParams } from './types' -export interface UserInfo { - id: number - nickname: string - avatarUrl: string +/** 微信授权登录 */ +export function wxLogin(code: string): Promise { + return post('/auth/wx-login', { code }, false) } -export interface LoginParams { - username: string - password: string -} - -export interface LoginResult { - token: string - userInfo: UserInfo -} - -export function login(params: LoginParams): Promise { - return post('/api/login', params, false) +/** 账号密码登录(降级方案) */ +export function login(params: LoginParams): Promise { + return post('/auth/login', params, false) } +/** 获取当前用户信息 */ export function getUserInfo(): Promise { - return get('/api/user/info') + return get('/user/info') } + +export type { UserInfo, WxLoginResult, LoginParams } diff --git a/src/store/user.ts b/src/store/user.ts index 0e0bb00..ad2f7a5 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -11,9 +11,10 @@ export const useUserStore = defineStore('user', () => { async function login(params: LoginParams) { const result = await apiLogin(params) - token.value = result.token - userInfo.value = result.userInfo - setToken(result.token) + token.value = result.accessToken + setToken(result.accessToken) + // 登录成功后获取用户信息 + await fetchUserInfo() return result }