Files
JayuCloud/Frontend/src/api/user.ts
T

139 lines
3.9 KiB
TypeScript
Raw Normal View History

2026-02-25 09:13:45 +08:00
import api from './index'
import type { UserInfo } from './auth'
2026-02-25 11:38:31 +08:00
export interface UserVO extends UserInfo {
id: number
shopId?: number
shopName?: string
shopIds?: Array<number | string>
shopNames?: string[]
2026-02-25 11:38:31 +08:00
nickname: string
account: string
avatar: string
signature?: string
level?: string
type: number
vipId?: number
createTime: string
updateTime: string
status: number
phone?: string
}
2026-02-25 09:13:45 +08:00
export interface UpdateUserInfoRequest {
nickname?: string
avatar?: string
signature?: string
}
2026-02-25 10:37:16 +08:00
export interface ListUsersParams {
page: number
size: number
keyword?: string
shopId?: number
2026-03-10 23:23:15 +08:00
status?: number
2026-02-25 10:37:16 +08:00
}
export interface CreateUserRequest {
2026-02-25 11:38:31 +08:00
account: string
2026-02-25 10:37:16 +08:00
nickname: string
phone: string
password: string
2026-02-25 11:38:31 +08:00
type: number
shopId?: number
shopIds?: Array<number | string>
2026-02-25 10:37:16 +08:00
}
export interface UpdateUserRequest {
2026-02-25 11:38:31 +08:00
account?: string
2026-02-25 10:37:16 +08:00
nickname?: string
phone?: string
2026-02-25 11:38:31 +08:00
type?: number
shopId?: number
shopIds?: Array<number | string>
2026-02-25 10:37:16 +08:00
}
export interface UpdatePasswordRequest {
password: string
2026-03-19 20:51:07 +08:00
verificationCode: string
}
export interface BindPhoneRequest {
phone: string
verificationCode: string
}
2026-03-19 20:51:07 +08:00
export interface AvailabilityCheckResponse {
available: boolean
message: string
}
export interface LoginAccountCheckResponse {
exists: boolean
nickname?: string
message: string
}
export interface LoginShopSelectionResponse {
allowShoplessLogin: boolean
message: string
shops: Array<{
id: number | string
shopName: string
}>
}
export interface UpdatePhoneRequest {
oldPhone: string
newPhone: string
verificationCode: string
}
2026-02-25 09:13:45 +08:00
export const userApi = {
getUserInfo: async (): Promise<UserVO> => {
return await api.get<UserVO>('/user/info') as unknown as UserVO
2026-02-25 09:13:45 +08:00
},
updateUserInfo: (data: UpdateUserInfoRequest) => {
2026-03-19 20:51:07 +08:00
return api.put('/user/update', data)
},
updatePassword: (data: UpdatePasswordRequest) => {
return api.put('/user/password', data)
},
bindPhone: (data: BindPhoneRequest) => {
return api.post('/user/bind-phone', data)
},
updatePhone: (data: UpdatePhoneRequest) => {
return api.put('/user/phone', data)
},
getUserByAccount: async (account: string): Promise<UserVO> => {
return await api.get<UserVO>(`/user/get/account/${account}`) as unknown as UserVO
2026-02-28 17:09:45 +08:00
},
checkAccountAvailability: async (account: string): Promise<AvailabilityCheckResponse> => {
return await api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`) as unknown as AvailabilityCheckResponse
2026-03-19 20:51:07 +08:00
},
checkLoginAccountAvailability: async (account: string): Promise<LoginAccountCheckResponse> => {
return await api.get<LoginAccountCheckResponse>(`/user/check/login-account/${encodeURIComponent(account)}`) as unknown as LoginAccountCheckResponse
},
getLoginShopsByAccount: async (account: string): Promise<LoginShopSelectionResponse> => {
return await api.get<LoginShopSelectionResponse>(`/user/check/login-shops/account/${encodeURIComponent(account)}`) as unknown as LoginShopSelectionResponse
2026-03-19 20:51:07 +08:00
},
getLoginShopsByPhone: async (phone: string): Promise<LoginShopSelectionResponse> => {
return await api.get<LoginShopSelectionResponse>(`/user/check/login-shops/phone/${encodeURIComponent(phone)}`) as unknown as LoginShopSelectionResponse
},
checkPhoneAvailability: async (phone: string): Promise<AvailabilityCheckResponse> => {
return await api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`) as unknown as AvailabilityCheckResponse
},
listUsersByType: async (type: number): Promise<UserVO[]> => {
return await api.get<UserVO[]>(`/user/list/type/${type}`) as unknown as UserVO[]
},
sendVerificationCode: (data: { phone: string }) => {
return api.post('/user/send-verification-code', data)
},
switchShop: (shopId?: string | number) => {
return api.post('/user/switch-shop', { shopId })
},
deactivateAccount: () => {
return api.delete('/user/deactivate')
2026-02-25 09:13:45 +08:00
}
}