HomeLease/api/user/README.md
2025-08-19 11:54:07 +08:00

157 lines
3.6 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模块
## 概述
用户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'
// 获取用户财务信息
const response = await getUserFinancialData()
if (response.code === 200) {
const financialData = response.data
// financialData包含withdrawable, pending, withdrawing, withdrawn等
}
```
### 3. 获取用户统计
```javascript
import { getUserStats } from '@/api/user/user.js'
// 获取用户统计信息
const response = await getUserStats()
if (response.code === 200) {
const userStats = response.data
// userStats包含users, leases, amount等
}
```
### 4. 更新用户信息
```javascript
import { updateUserInfo } from '@/api/user/user.js'
// 更新用户信息
const userData = {
nickName: '新昵称',
phonenumber: '13800138000'
}
const response = await updateUserInfo(userData)
```
## 数据结构
### 用户信息 (UserInfo)
```javascript
{
userId: '1', // 用户ID
nickName: '超级管理员', // 昵称
phonenumber: '15888888888', // 手机号
avatar: 'https://...', // 头像URL
email: null, // 邮箱
sex: null, // 性别
status: '0', // 状态
createTime: null, // 创建时间
updateTime: null // 更新时间
}
```
### 财务数据 (FinancialData)
```javascript
{
withdrawable: '18079.29', // 可提现金额
pending: '399.59', // 待入账金额
withdrawing: '9.59', // 提现中金额
withdrawn: '999.59', // 已提现金额
totalIncome: '20000.00', // 总收入
totalExpense: '1521.72' // 总支出
}
```
### 用户统计 (UserStats)
```javascript
{
users: 30, // 名下用户数
leases: 30, // 租赁数量
amount: 3000, // 租赁金额
activeUsers: 25, // 活跃用户数
totalLeases: 45, // 总租赁数
totalAmount: 5000 // 总金额
}
```
## 错误处理
所有API都包含错误处理机制
1. **网络错误**:自动使用模拟数据
2. **API错误**:返回错误信息
3. **数据验证**:确保返回数据格式正确
## 模拟数据
当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(),
getUserStats()
])
this.userInfo = userInfo.data
this.financialData = financial.data
this.userStats = stats.data
} catch (error) {
console.error('获取用户数据失败:', error)
}
}
}
}
```
## 注意事项
1. 所有API都需要有效的token
2. 财务数据需要用户登录后才能获取
3. 统计数据可能有缓存,建议定期刷新
4. 头像URL需要网络访问权限