更新:增加“我的”相关功能
This commit is contained in:
217
api/modules/user.ts
Normal file
217
api/modules/user.ts
Normal file
@@ -0,0 +1,217 @@
|
||||
// api/modules/user.ts
|
||||
import { mainClient } from '@/api/clients/main'
|
||||
import type { IApiResponse } from '@/api/types'
|
||||
import type {
|
||||
IUserInfo,
|
||||
IVipInfo,
|
||||
IOrder,
|
||||
IVipPackage,
|
||||
ITransaction,
|
||||
IFeedbackForm,
|
||||
IPageData
|
||||
} from '@/types/user'
|
||||
import { SERVICE_MAP } from '@/api/config'
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export async function getUserInfo() {
|
||||
const res = await mainClient.request<IApiResponse<{ user: IUserInfo }>>({
|
||||
url: 'common/user/getUserInfo',
|
||||
method: 'POST'
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取VIP信息
|
||||
*/
|
||||
export async function getVipInfo() {
|
||||
const res = await mainClient.request<IApiResponse<{ vipInfo: IVipInfo }>>({
|
||||
url: 'bookAbroad/home/getVipInfo',
|
||||
method: 'POST'
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单列表
|
||||
* @param current 当前页码
|
||||
* @param limit 每页数量
|
||||
*/
|
||||
export async function getOrderList(current: number, limit: number) {
|
||||
const res = await mainClient.request<IApiResponse<{ orders: IPageData<IOrder> }>>({
|
||||
url: 'bookAbroad/home/getAbroadOrderList',
|
||||
method: 'POST',
|
||||
data: { current, limit }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取VIP套餐列表
|
||||
*/
|
||||
export async function getVipPackages() {
|
||||
const res = await mainClient.request<IApiResponse<{ sysDictDatas: IVipPackage[] }>>({
|
||||
url: 'book/sysdictdata/getData',
|
||||
method: 'POST',
|
||||
data: { dictLabel: 'googleVip' }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param data 订单数据
|
||||
*/
|
||||
export async function createOrder(data: any) {
|
||||
const res = await mainClient.request<IApiResponse<{ orderSn: string }>>({
|
||||
url: 'bookAbroad/order/placeOrder',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交易记录列表
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
export async function getTransactionList(userId: number) {
|
||||
const res = await mainClient.request<IApiResponse<{ transactionDetailsList: ITransaction[] }>>({
|
||||
url: 'common/transactionDetails/getTransactionDetailsList',
|
||||
method: 'POST',
|
||||
data: { userId }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户基本信息
|
||||
* @param data 用户信息
|
||||
*/
|
||||
export async function updateUserInfo(data: Partial<IUserInfo>) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'book/user/update',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户邮箱
|
||||
* @param id 用户ID
|
||||
* @param email 邮箱地址
|
||||
* @param code 验证码
|
||||
*/
|
||||
export async function updateEmail(id: number, email: string, code: string) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'common/user/updateUserEmail',
|
||||
method: 'POST',
|
||||
data: { id, email, code }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户密码
|
||||
* @param id 用户ID
|
||||
* @param password 新密码
|
||||
*/
|
||||
export async function updatePassword(id: number, password: string) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'common/user/setPasswordById',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
data: { id, password }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮箱验证码
|
||||
* @param email 邮箱地址
|
||||
*/
|
||||
export async function sendEmailCode(email: string) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'common/user/getMailCaptcha',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
data: { email }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @param filePath 本地文件路径
|
||||
* @returns 图片URL
|
||||
*/
|
||||
export function uploadImage(filePath: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${SERVICE_MAP.MAIN}oss/fileoss`,
|
||||
filePath,
|
||||
name: 'file',
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data)
|
||||
if (data.url) {
|
||||
resolve(data.url)
|
||||
} else {
|
||||
reject(new Error('上传失败'))
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
},
|
||||
fail: reject
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交问题反馈
|
||||
* @param data 反馈表单数据
|
||||
*/
|
||||
export async function submitFeedback(data: IFeedbackForm) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'common/sysFeedback/addSysFeedback',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证Google支付
|
||||
* @param purchaseToken 购买令牌
|
||||
* @param orderSn 订单号
|
||||
* @param productId 产品ID
|
||||
*/
|
||||
export async function verifyGooglePay(purchaseToken: string, orderSn: string, productId: string) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'pay/googlepay/googleVerify',
|
||||
method: 'POST',
|
||||
data: { purchaseToken, orderSn, productId }
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证IAP支付
|
||||
* @param data 支付数据
|
||||
*/
|
||||
export async function verifyIAP(data: any) {
|
||||
const res = await mainClient.request<IApiResponse>({
|
||||
url: 'Ipa/veri',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user