HomeLease/api/user/user.js

180 lines
4.3 KiB
JavaScript
Raw Normal View History

2025-08-19 11:54:07 +08:00
import request from '@/utils/request'
2025-08-19 14:22:25 +08:00
import { mockUserInfo, mockFinancialData, mockAgentStats, mockAgentList, mockWithdrawInfo, mockBanks, createMockResponse } from './mockData.js'
2025-08-19 11:54:07 +08:00
/**
* 获取用户信息
* @returns {Promise} 返回用户信息
*/
export function getUserInfo() {
return request({
url: '/app/user/getUser',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('用户信息API调用失败使用模拟数据:', error)
// 如果API调用失败返回模拟数据
return createMockResponse(mockUserInfo)
})
}
/**
* 获取用户财务数据
* @returns {Promise} 返回财务数据
*/
export function getUserFinancialData() {
return request({
url: '/app/user/getBill',
2025-08-19 11:54:07 +08:00
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('财务数据API调用失败使用模拟数据:', error)
// 如果API调用失败返回模拟数据
return createMockResponse(mockFinancialData)
})
}
/**
* 获取用户统计信息
* @returns {Promise} 返回用户统计信息
*/
export function getUserStats() {
return request({
url: '/app/user/stats',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('用户统计API调用失败使用模拟数据:', error)
// 如果API调用失败返回模拟数据
2025-08-19 12:01:17 +08:00
return createMockResponse(mockAgentStats)
})
}
/**
* 获取代理统计数据
* @returns {Promise} 返回代理统计信息
*/
export function getAgentCount() {
return request({
url: '/app/order/agentCount',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('代理统计API调用失败使用模拟数据:', error)
// 如果API调用失败返回模拟数据
return createMockResponse({
userNum: 4,
deviceNum: 1,
rentAmount: 2
})
})
}
/**
2025-08-19 14:01:32 +08:00
* 获取代理用户列表
2025-08-19 12:01:17 +08:00
* @param {Object} params - 查询参数
2025-08-19 14:01:32 +08:00
* @param {string} params.beginTime - 开始时间
* @param {string} params.endTime - 结束时间
* @param {string} params.name - 用户昵称搜索
* @returns {Promise}
2025-08-19 12:01:17 +08:00
*/
2025-08-19 14:01:32 +08:00
export function getAgentList(params = {}) {
2025-08-19 12:01:17 +08:00
return request({
2025-08-19 14:01:32 +08:00
url: '/app/order/agentList',
2025-08-19 12:01:17 +08:00
method: 'GET',
params,
showLoading: false,
}).catch(error => {
2025-08-19 14:01:32 +08:00
console.warn('代理用户列表API调用失败使用模拟数据:', error)
2025-08-19 12:01:17 +08:00
// 如果API调用失败返回模拟数据
2025-08-19 14:01:32 +08:00
return createMockResponse(mockAgentList)
2025-08-19 11:54:07 +08:00
})
}
2025-08-19 14:01:32 +08:00
/**
* 获取用户列表 (使用代理列表接口)
* @param {Object} params - 查询参数
* @returns {Promise}
*/
export function getUserList(params = {}) {
return getAgentList(params)
}
2025-08-19 11:54:07 +08:00
/**
* 更新用户信息
* @param {Object} data - 用户信息数据
* @returns {Promise} 返回更新结果
*/
export function updateUserInfo(data) {
return request({
url: '/app/user/update',
method: 'POST',
data,
})
}
2025-08-20 10:03:06 +08:00
/**
* 更新用户昵称
* @param {string} nickName - 新的昵称
* @returns {Promise} 返回更新结果
*/
export function updateNickName(nickName) {
return request({
url: '/app/user/updateNickName',
method: 'PUT',
params: { nickName },
showLoading: true,
// 强制将params作为查询参数发送
useQueryParams: true,
2025-08-20 10:03:06 +08:00
}).catch(error => {
console.warn('更新昵称API调用失败:', error)
throw error
})
}
2025-08-19 11:54:07 +08:00
/**
* 获取用户头像
* @param {string} userId - 用户ID
* @returns {Promise} 返回头像URL
*/
export function getUserAvatar(userId) {
return request({
url: '/app/user/avatar',
method: 'GET',
params: { userId },
showLoading: false,
})
2025-08-19 14:22:25 +08:00
}
/**
* 获取提现信息
* @returns {Promise} 返回提现相关信息
*/
export function getWithdrawInfo() {
return request({
url: '/app/withdraw',
method: 'GET',
showLoading: false,
}).catch(error => {
console.warn('提现信息API调用失败使用模拟数据:', error)
return createMockResponse(mockWithdrawInfo)
})
}
/**
* 提交提现申请
* @param {Object} data 提现数据
* @param {number} data.amount 提现金额
* @param {string} data.bankId 银行ID
* @returns {Promise} 返回提现申请结果
*/
export function submitWithdraw(data) {
return request({
url: '/app/withdraw',
method: 'POST',
data,
showLoading: true,
}).catch(error => {
console.warn('提现申请API调用失败:', error)
throw error
})
2025-08-19 11:54:07 +08:00
}