import request from '@/utils/request' import { mockUserInfo, mockFinancialData, mockAgentStats, mockAgentList, createMockResponse } from './mockData.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} userId - 用户ID * @returns {Promise} 返回头像URL */ export function getUserAvatar(userId) { return request({ url: '/app/user/avatar', method: 'GET', params: { userId }, showLoading: false, }) }