import request from '@/utils/request' import { mockUserInfo, mockFinancialData, mockAgentStats, 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 - 查询参数 * @returns {Promise} 返回用户列表数据 */ export function getUserList(params = {}) { return request({ url: '/app/user/list', method: 'GET', params, showLoading: false, }).catch(error => { console.warn('用户列表API调用失败,使用模拟数据:', error) // 如果API调用失败,返回模拟数据 return createMockResponse([ { id: 1, username: '张三', totalAmount: '5000', deviceCount: 2, devices: [ { type: '智能门锁', amount: '1000', rentDate: '2025.01.15 12:56:08', period: '1年', expiryDate: '2026.01.15 12:56:08', }, { type: '智能摄像头', amount: '800', rentDate: '2025.02.20 10:30:00', period: '6个月', expiryDate: '2025.08.20 10:30:00', }, ], }, { id: 2, username: '李四', totalAmount: '3200', deviceCount: 3, devices: [ { type: '智能门锁', amount: '1200', rentDate: '2025.03.10 14:20:00', period: '1年', expiryDate: '2026.03.10 14:20:00', }, { type: '智能摄像头', amount: '600', rentDate: '2025.04.05 09:15:00', period: '3个月', expiryDate: '2025.07.05 09:15:00', }, { type: '智能音箱', amount: '400', rentDate: '2025.05.12 16:45:00', period: '6个月', expiryDate: '2025.11.12 16:45:00', }, ], }, ]) }) } /** * 更新用户信息 * @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, }) }