- 用户store新增fetchUserInfo action,调用/userInfo接口获取完整用户信息 - 登录页修复:LoginResponse只有token和userId,登录成功后调用fetchUserInfo获取资料 - App.vue启动时若已登录自动刷新用户信息 - 我的页面onShow时刷新用户信息,新增下拉刷新支持 - pages.json为我的页面启用enablePullDownRefresh
68 lines
1.3 KiB
JavaScript
68 lines
1.3 KiB
JavaScript
/**
|
|
* 用户接口模块
|
|
*/
|
|
|
|
import { get, post } from './request'
|
|
|
|
/**
|
|
* 获取当前登录用户信息
|
|
* @returns {Promise<Object>} 用户信息
|
|
*/
|
|
export function getUserInfo() {
|
|
return get('/userInfo')
|
|
}
|
|
|
|
/**
|
|
* 获取用户详情
|
|
*/
|
|
export async function getUserDetail(userId) {
|
|
const response = await post('/users/detail', { userId })
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* 获取用户资料
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
export async function getProfile() {
|
|
const response = await get('/user/getProfile')
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* 更新用户资料
|
|
* @param {Object} data - 用户资料
|
|
* @param {string} [data.nickname] - 昵称
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
export async function updateProfile(data) {
|
|
const response = await post('/user/updateProfile', data)
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* 更新用户头像
|
|
* @param {string} avatar - 头像URL
|
|
* @returns {Promise<Object>}
|
|
*/
|
|
export async function updateAvatar(avatar) {
|
|
const response = await post('/user/updateAvatar', { avatar })
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* 更新用户昵称
|
|
*/
|
|
export async function updateNickname(nickname) {
|
|
const response = await post('/users/nickname', { nickname })
|
|
return response
|
|
}
|
|
|
|
export default {
|
|
getUserDetail,
|
|
getProfile,
|
|
updateProfile,
|
|
updateAvatar,
|
|
updateNickname
|
|
}
|