HomeLease/api/user/README.md
2025-08-19 14:01:32 +08:00

197 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 用户模块 API 文档
## 接口列表
### 1. 获取用户信息
```javascript
import { getUserInfo } from '@/api/user/user.js'
const response = await getUserInfo()
```
**接口地址:** `GET /app/user/info`
**响应数据:**
```javascript
{
userId: '1', // 用户ID
nickName: '超级管理员', // 用户昵称
phonenumber: '15888888888', // 手机号
avatar: 'https://...', // 头像URL
email: null, // 邮箱
sex: null, // 性别
status: '0', // 状态
createTime: null, // 创建时间
updateTime: null // 更新时间
}
```
### 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 // 已提现余额
}
```
### 3. 获取代理统计
```javascript
import { getAgentCount } from '@/api/user/user.js'
const response = await getAgentCount()
```
**接口地址:** `GET /app/order/agentCount`
**响应数据:**
```javascript
{
userNum: 4, // 名下用户数
deviceNum: 1, // 设备数量
rentAmount: 2 // 租赁数量
}
```
### 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
[
{
userId: '28', // 用户ID
nickName: '李四', // 用户昵称
avatar: '', // 头像
totalAmount: 730.00, // 总金额
deviceNum: 2, // 设备数量
orders: [ // 订单列表
{
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调用失败会自动返回模拟数据
```javascript
// 如果API调用失败会返回模拟数据
const response = await getUserInfo()
// 即使网络错误,也会返回模拟的用户信息
```
## 模拟数据
当API不可用时系统会自动使用模拟数据
- `mockUserInfo`: 用户基本信息
- `mockFinancialData`: 财务数据
- `mockAgentStats`: 代理统计数据
- `mockAgentList`: 代理用户列表数据