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 }