From f82e8c1aa938c3383f545a507db8d68064974834 Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Tue, 19 Aug 2025 14:01:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user/README.md | 274 ++++++++++++++++++++------------------ api/user/mockData.js | 44 ++++++ api/user/user.js | 78 +++-------- pages/profile/profile.vue | 47 ++++--- pages/useList/useList.vue | 231 +++++++++++++++++++++++++++++--- 5 files changed, 448 insertions(+), 226 deletions(-) diff --git a/api/user/README.md b/api/user/README.md index 0c9b183..e6c2b84 100644 --- a/api/user/README.md +++ b/api/user/README.md @@ -1,78 +1,21 @@ -# 用户API模块 +# 用户模块 API 文档 -## 概述 - -用户API模块提供了用户信息、财务数据和统计信息的获取功能。 - -## API列表 +## 接口列表 ### 1. 获取用户信息 ```javascript import { getUserInfo } from '@/api/user/user.js' -// 获取用户基本信息 const response = await getUserInfo() -if (response.code === 200) { - const userInfo = response.data - // userInfo包含:userId, nickName, phonenumber, avatar等 -} ``` -### 2. 获取财务数据 -```javascript -import { getUserFinancialData } from '@/api/user/user.js' +**接口地址:** `GET /app/user/info` -// 获取用户财务信息 -const response = await getUserFinancialData() -if (response.code === 200) { - const financialData = response.data - // financialData包含:balance, waitBalance, withdrawBalance, withdrawedBalance等 -} -``` - -### 3. 获取代理统计 -```javascript -import { getAgentCount } from '@/api/user/user.js' - -// 获取代理统计信息 -const response = await getAgentCount() -if (response.code === 200) { - const agentStats = response.data - // agentStats包含:userNum, deviceNum, rentAmount等 -} -``` - -### 4. 获取用户列表 -```javascript -import { getUserList } from '@/api/user/user.js' - -// 获取用户列表 -const response = await getUserList() -if (response.code === 200) { - const userList = response.data - // userList包含用户列表数据 -} -``` - -### 5. 更新用户信息 -```javascript -import { updateUserInfo } from '@/api/user/user.js' - -// 更新用户信息 -const userData = { - nickName: '新昵称', - phonenumber: '13800138000' -} -const response = await updateUserInfo(userData) -``` - -## 数据结构 - -### 用户信息 (UserInfo) +**响应数据:** ```javascript { userId: '1', // 用户ID - nickName: '超级管理员', // 昵称 + nickName: '超级管理员', // 用户昵称 phonenumber: '15888888888', // 手机号 avatar: 'https://...', // 头像URL email: null, // 邮箱 @@ -83,17 +26,35 @@ const response = await updateUserInfo(userData) } ``` -### 财务数据 (FinancialData) +### 2. 获取用户财务数据 +```javascript +import { getUserFinancialData } from '@/api/user/user.js' + +const response = await getUserFinancialData() +``` + +**接口地址:** `GET /app/user/financial` + +**响应数据:** ```javascript { - balance: 10000.00, // 可提现金额 - waitBalance: 0, // 待入账金额 - withdrawBalance: 0, // 提现中金额 - withdrawedBalance: 0 // 已提现金额 + balance: 10000.00, // 余额 + waitBalance: 0, // 待结算余额 + withdrawBalance: 0, // 可提现余额 + withdrawedBalance: 0 // 已提现余额 } ``` -### 代理统计 (AgentStats) +### 3. 获取代理统计 +```javascript +import { getAgentCount } from '@/api/user/user.js' + +const response = await getAgentCount() +``` + +**接口地址:** `GET /app/order/agentCount` + +**响应数据:** ```javascript { userNum: 4, // 名下用户数 @@ -102,84 +63,135 @@ const response = await updateUserInfo(userData) } ``` -### 用户列表 (UserList) +### 4. 获取代理用户列表 +```javascript +import { getAgentList } from '@/api/user/user.js' + +const response = await getAgentList({ + beginTime: '2024-10-10 12:10:00', // 开始时间(筛选) + endTime: '2026-10-10 12:10:00', // 结束时间(筛选) + name: '李' // 用户昵称(搜索) +}) +``` + +**接口地址:** `GET /app/order/agentList` + +**请求参数:** +- `beginTime` (string, 可选): 开始时间,格式: YYYY-MM-DD HH:mm:ss +- `endTime` (string, 可选): 结束时间,格式: YYYY-MM-DD HH:mm:ss +- `name` (string, 可选): 用户昵称,支持模糊搜索 + +**响应数据:** ```javascript [ { - id: 1, // 用户ID - username: '张三', // 用户名 - totalAmount: '5000', // 总金额 - deviceCount: 2, // 设备数量 - devices: [ // 设备列表 + userId: '28', // 用户ID + nickName: '李四', // 用户昵称 + avatar: '', // 头像 + totalAmount: 730.00, // 总金额 + deviceNum: 2, // 设备数量 + orders: [ // 订单列表 { - type: '智能门锁', // 设备类型 - amount: '1000', // 金额 - rentDate: '2025.01.15', // 租赁日期 - period: '1年', // 租赁周期 - expiryDate: '2026.01.15' // 到期日期 + id: '3', // 订单ID + userId: '28', // 用户ID + name: '派大星', // 联系人姓名 + phone: '13777777777', // 联系电话 + address: '广西南宁市西乡塘区', // 地址 + detailed: '详细地址', // 详细地址 + typeName: '单头灶', // 设备类型名称 + suitName: '一年', // 套餐名称 + suitDay: '365', // 套餐天数 + amount: 365.00, // 金额 + status: '2', // 订单状态 + leaseTime: '2025-08-15 10:50:22', // 租赁时间 + expirationTime: '2025-11-15 10:50:25', // 到期时间 + orderNumber: '123456789101114' // 订单号 } ] } ] ``` +### 5. 更新用户信息 +```javascript +import { updateUserInfo } from '@/api/user/user.js' + +const response = await updateUserInfo({ + nickName: '新昵称', + email: 'new@example.com' +}) +``` + +**接口地址:** `PUT /app/user/info` + +## 使用示例 + +### 在页面中获取用户数据 +```javascript +// 在 Profile 页面中 +async fetchUserData() { + try { + const [userInfo, financial, stats] = await Promise.all([ + getUserInfo(), + getUserFinancialData(), + getAgentCount() + ]) + + this.userInfo = userInfo.data + this.financialData = financial.data + this.userStats = stats.data + } catch (error) { + console.error('获取用户数据失败:', error) + } +} +``` + +### 在用户列表页面中 +```javascript +// 在用户列表页面中 +async fetchUserList() { + try { + const params = { + beginTime: '2024-10-10 00:00:00', + endTime: '2026-10-10 23:59:59', + name: '李' + } + + const response = await getAgentList(params) + if (response.code === 200) { + // 转换数据格式 + this.users = response.data.map(user => ({ + ...user, + devices: user.orders.map(order => ({ + type: order.typeName, + amount: order.amount, + rentDate: this.formatDate(order.leaseTime), + period: order.suitName, + expiryDate: this.formatDate(order.expirationTime) + })) + })) + } + } catch (error) { + console.error('获取用户列表失败:', error) + } +} +``` + ## 错误处理 -所有API都包含错误处理机制: +所有API函数都包含错误处理机制,如果API调用失败,会自动返回模拟数据: -1. **网络错误**:自动使用模拟数据 -2. **API错误**:返回错误信息 -3. **数据验证**:确保返回数据格式正确 +```javascript +// 如果API调用失败,会返回模拟数据 +const response = await getUserInfo() +// 即使网络错误,也会返回模拟的用户信息 +``` ## 模拟数据 当API不可用时,系统会自动使用模拟数据: -- 用户信息:超级管理员 -- 财务数据:预设的金额数据 -- 用户统计:预设的统计数据 - -## 使用示例 - -在Vue组件中使用: - -```javascript -export default { - data() { - return { - userInfo: {}, - financialData: {}, - userStats: {} - } - }, - - async onLoad() { - await this.fetchUserData() - }, - - methods: { - async fetchUserData() { - try { - const [userInfo, financial, stats] = await Promise.all([ - getUserInfo(), - getUserFinancialData(), - getAgentCount() - ]) - - this.userInfo = userInfo.data - this.financialData = financial.data - this.userStats = stats.data - } catch (error) { - console.error('获取用户数据失败:', error) - } - } - } -} -``` - -## 注意事项 - -1. 所有API都需要有效的token -2. 财务数据需要用户登录后才能获取 -3. 统计数据可能有缓存,建议定期刷新 -4. 头像URL需要网络访问权限 \ No newline at end of file +- `mockUserInfo`: 用户基本信息 +- `mockFinancialData`: 财务数据 +- `mockAgentStats`: 代理统计数据 +- `mockAgentList`: 代理用户列表数据 \ No newline at end of file diff --git a/api/user/mockData.js b/api/user/mockData.js index 2e11f35..83ac5de 100644 --- a/api/user/mockData.js +++ b/api/user/mockData.js @@ -24,6 +24,50 @@ export const mockAgentStats = { rentAmount: 2, } +export const mockAgentList = [ + { + userId: '28', + nickName: '李四', + avatar: '', + totalAmount: 730.00, + deviceNum: 2, + orders: [ + { + id: '3', + userId: '28', + name: '派大星', + phone: '13777777777', + address: '广西南宁市西乡塘区', + detailed: '详细地址', + typeName: '单头灶', + suitName: '一年', + suitDay: '365', + amount: 365.00, + status: '2', + leaseTime: '2025-08-15 10:50:22', + expirationTime: '2025-11-15 10:50:25', + orderNumber: '123456789101114', + }, + { + id: '4', + userId: '28', + name: '派大星', + phone: '137777777777', + address: '测试', + detailed: '测试', + typeName: '单头灶', + suitName: '一年', + suitDay: '365', + amount: 365.00, + status: '2', + leaseTime: '2025-08-18 14:10:26', + expirationTime: '2025-10-01 14:10:29', + orderNumber: '123456789101115', + } + ] + } +] + // 模拟API响应格式 export const createMockResponse = (data, code = 200, msg = '操作成功') => { return { diff --git a/api/user/user.js b/api/user/user.js index f3a9675..60fc6a4 100644 --- a/api/user/user.js +++ b/api/user/user.js @@ -1,5 +1,5 @@ import request from '@/utils/request' -import { mockUserInfo, mockFinancialData, mockAgentStats, createMockResponse } from './mockData.js' +import { mockUserInfo, mockFinancialData, mockAgentStats, mockAgentList, createMockResponse } from './mockData.js' /** * 获取用户信息 @@ -70,75 +70,35 @@ export function getAgentCount() { } /** - * 获取用户列表 + * 获取代理用户列表 * @param {Object} params - 查询参数 - * @returns {Promise} 返回用户列表数据 + * @param {string} params.beginTime - 开始时间 + * @param {string} params.endTime - 结束时间 + * @param {string} params.name - 用户昵称搜索 + * @returns {Promise} */ -export function getUserList(params = {}) { +export function getAgentList(params = {}) { return request({ - url: '/app/user/list', + url: '/app/order/agentList', method: 'GET', params, showLoading: false, }).catch(error => { - console.warn('用户列表API调用失败,使用模拟数据:', 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', - }, - ], - }, - ]) + return createMockResponse(mockAgentList) }) } +/** + * 获取用户列表 (使用代理列表接口) + * @param {Object} params - 查询参数 + * @returns {Promise} + */ +export function getUserList(params = {}) { + return getAgentList(params) +} + /** * 更新用户信息 * @param {Object} data - 用户信息数据 diff --git a/pages/profile/profile.vue b/pages/profile/profile.vue index 0001fe0..38d20e7 100644 --- a/pages/profile/profile.vue +++ b/pages/profile/profile.vue @@ -1,7 +1,7 @@