206 lines
5.1 KiB
JavaScript
206 lines
5.1 KiB
JavaScript
import request from '@/utils/request'
|
||
import { mockUserInfo, mockFinancialData, mockAgentStats, mockAgentList, mockWithdrawInfo, mockBanks, createMockResponse } from './mockData.js'
|
||
import { uploadFile } from '@/utils/request.js'
|
||
|
||
/**
|
||
* 获取用户信息
|
||
* @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',
|
||
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调用失败,返回模拟数据
|
||
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
|
||
})
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取代理用户列表
|
||
* @param {Object} params - 查询参数
|
||
* @param {string} params.beginTime - 开始时间
|
||
* @param {string} params.endTime - 结束时间
|
||
* @param {string} params.name - 用户昵称搜索
|
||
* @returns {Promise}
|
||
*/
|
||
export function getAgentList(params = {}) {
|
||
return request({
|
||
url: '/app/order/agentList',
|
||
method: 'GET',
|
||
params,
|
||
showLoading: false,
|
||
}).catch(error => {
|
||
console.warn('代理用户列表API调用失败,使用模拟数据:', error)
|
||
// 如果API调用失败,返回模拟数据
|
||
return createMockResponse(mockAgentList)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户列表 (使用代理列表接口)
|
||
* @param {Object} params - 查询参数
|
||
* @returns {Promise}
|
||
*/
|
||
export function getUserList(params = {}) {
|
||
return getAgentList(params)
|
||
}
|
||
|
||
/**
|
||
* 更新用户信息
|
||
* @param {Object} data - 用户信息数据
|
||
* @returns {Promise} 返回更新结果
|
||
*/
|
||
export function updateUserInfo(data) {
|
||
return request({
|
||
url: '/app/user/update',
|
||
method: 'POST',
|
||
data,
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 更新用户昵称
|
||
* @param {string} nickName - 新的昵称
|
||
* @returns {Promise} 返回更新结果
|
||
*/
|
||
export function updateNickName(nickName) {
|
||
return request({
|
||
url: '/app/user/updateNickName',
|
||
method: 'PUT',
|
||
params: { nickName },
|
||
showLoading: true,
|
||
// 强制将params作为查询参数发送
|
||
useQueryParams: true,
|
||
}).catch(error => {
|
||
console.warn('更新昵称API调用失败:', error)
|
||
throw error
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户头像
|
||
* @param {string} userId - 用户ID
|
||
* @returns {Promise} 返回头像URL
|
||
*/
|
||
export function getUserAvatar(userId) {
|
||
return request({
|
||
url: '/app/user/avatar',
|
||
method: 'GET',
|
||
params: { userId },
|
||
showLoading: false,
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取提现信息
|
||
* @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
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 上传头像
|
||
* @param {string} filePath - 文件路径
|
||
* @returns {Promise} 返回上传结果
|
||
*/
|
||
export function uploadAvatar(filePath) {
|
||
return uploadFile('/app/user/avatar', filePath, 'avatarfile', {}, {
|
||
timeout: 60000
|
||
}).then(data => {
|
||
// 上传成功后更新本地存储
|
||
const userInfo = uni.getStorageSync('userInfo') || {}
|
||
userInfo.avatar = data.data?.avatar || data.data
|
||
uni.setStorageSync('userInfo', userInfo)
|
||
|
||
// 通知其他页面更新头像
|
||
uni.$emit('avatarUpdated', userInfo.avatar)
|
||
|
||
console.log('头像上传成功,已更新本地存储:', userInfo.avatar)
|
||
return data
|
||
}).catch(error => {
|
||
console.error('头像上传失败:', error)
|
||
throw error
|
||
})
|
||
}
|