huangye-parking/miniapp/api/user.js
2026-03-03 23:31:28 +08:00

57 lines
1.2 KiB
JavaScript

/**
* 用户相关 API
*/
import { get, put } from '@/utils/request'
/**
* 获取用户信息
*/
export function getProfile() {
return get('/api/user/profile')
}
/**
* 更新用户信息(头像、昵称)
* @param {Object} data
* @param {string} [data.nickname] - 昵称
* @param {string} [data.avatar] - 头像URL
*/
export function updateProfile(data) {
return put('/api/user/profile', data)
}
/**
* 上传图片到 COS
* @param {string} filePath - 本地文件路径
* @returns {Promise<string>} 图片URL
*/
export function uploadImage(filePath) {
return new Promise((resolve, reject) => {
const token = uni.getStorageSync('token')
uni.uploadFile({
url: 'http://localhost:5030/api/upload/image',
filePath,
name: 'file',
header: {
'Authorization': `Bearer ${token}`
},
success: (res) => {
if (res.statusCode === 200) {
const data = JSON.parse(res.data)
if (data.success) {
resolve(data.data.url)
} else {
reject(new Error(data.message || '上传失败'))
}
} else {
reject(new Error('上传失败'))
}
},
fail: (err) => {
reject(err)
}
})
})
}