297 lines
6.4 KiB
JavaScript
297 lines
6.4 KiB
JavaScript
// 个人中心相关API接口
|
||
|
||
/**
|
||
* 获取用户信息
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const getUserInfo = (config = {}) => {
|
||
return uni.$u.http.get('/user/info', {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 更新用户信息
|
||
* @param {Object} userInfo 用户信息
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const updateUserInfo = (userInfo, config = {}) => {
|
||
return uni.$u.http.put('/user/info', userInfo, {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
loadingText: '正在更新用户信息...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户宠物列表
|
||
* @param {Object} params 查询参数
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const getUserPets = (params = {}, config = {}) => {
|
||
return uni.$u.http.get('/user/pets', {
|
||
params,
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 用户登录
|
||
* @param {Object} loginData 登录数据
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const userLogin = (loginData, config = {}) => {
|
||
return uni.$u.http.post('/auth/login', loginData, {
|
||
custom: {
|
||
auth: false,
|
||
loading: true,
|
||
loadingText: '正在登录...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 微信小程序登录
|
||
* @param {Object} wxData 微信登录数据
|
||
* @param {string} wxData.code 微信授权码(必需)
|
||
* @param {string} wxData.encryptedData 加密数据(可选,用户授权后获取)
|
||
* @param {string} wxData.iv 初始向量(可选,用户授权后获取)
|
||
* @param {string} wxData.signature 签名(可选,用户授权后获取)
|
||
* @param {Object} wxData.userInfo 用户信息(可选,用户授权后获取)
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise} 返回包含token和用户信息的Promise
|
||
*/
|
||
export const wxLogin = (wxData, config = {}) => {
|
||
// 验证必需参数
|
||
if (!wxData || !wxData.code) {
|
||
return Promise.reject(new Error('微信授权码(code)是必需的'))
|
||
}
|
||
|
||
return uni.$u.http.post('/wechat/user/mini/login', wxData, {
|
||
custom: {
|
||
auth: false,
|
||
loading: true,
|
||
loadingText: '正在登录...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 用户注册
|
||
* @param {Object} registerData 注册数据
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const userRegister = (registerData, config = {}) => {
|
||
return uni.$u.http.post('/auth/register', registerData, {
|
||
custom: {
|
||
auth: false,
|
||
loading: true,
|
||
loadingText: '正在注册...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 用户登出
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const userLogout = (config = {}) => {
|
||
return uni.$u.http.post('/auth/logout', {}, {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 刷新token
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const refreshToken = (config = {}) => {
|
||
const refreshToken = uni.getStorageSync('refreshToken')
|
||
return uni.$u.http.post('/auth/refresh', { refreshToken }, {
|
||
custom: {
|
||
loading: false,
|
||
toast: false,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 修改密码
|
||
* @param {Object} passwordData 密码数据
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const changePassword = (passwordData, config = {}) => {
|
||
return uni.$u.http.put('/user/password', passwordData, {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
loadingText: '正在修改密码...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户统计数据
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const getUserStats = (config = {}) => {
|
||
return uni.$u.http.get('/user/stats', {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户设置
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const getUserSettings = (config = {}) => {
|
||
return uni.$u.http.get('/user/settings', {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 更新用户设置
|
||
* @param {Object} settings 设置数据
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const updateUserSettings = (settings, config = {}) => {
|
||
return uni.$u.http.put('/user/settings', settings, {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
loadingText: '正在保存设置...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 绑定手机号
|
||
* @param {Object} phoneData 手机号数据
|
||
* @param {string} phoneData.encryptedData 加密数据
|
||
* @param {string} phoneData.iv 初始向量
|
||
* @param {string} phoneData.cloudID 云函数ID(可选)
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const bindPhone = (phoneData, config = {}) => {
|
||
return uni.$u.http.post('/user/bind-phone', phoneData, {
|
||
custom: {
|
||
auth: true,
|
||
loading: true,
|
||
loadingText: '正在绑定手机号...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 微信小程序登录并绑定手机号
|
||
* @param {Object} loginData 登录和手机号数据
|
||
* @param {string} loginData.code 微信授权码
|
||
* @param {string} loginData.phoneEncryptedData 手机号加密数据(可选)
|
||
* @param {string} loginData.phoneIv 手机号初始向量(可选)
|
||
* @param {string} loginData.phoneCloudID 手机号云函数ID(可选)
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const wxLoginWithPhone = (loginData, config = {}) => {
|
||
if (!loginData || !loginData.code) {
|
||
return Promise.reject(new Error('微信授权码(code)是必需的'))
|
||
}
|
||
|
||
return uni.$u.http.post('/auth/wx-login-phone', loginData, {
|
||
custom: {
|
||
auth: false,
|
||
loading: true,
|
||
loadingText: '正在登录...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取用户权限
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const getUserPermissions = (config = {}) => {
|
||
return uni.$u.http.get('/user/permissions', {
|
||
custom: {
|
||
loading: false,
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 注销账户
|
||
* @param {Object} config 自定义配置
|
||
* @returns {Promise}
|
||
*/
|
||
export const deleteAccount = (config = {}) => {
|
||
return uni.$u.http.delete('/user/account', {}, {
|
||
custom: {
|
||
loading: true,
|
||
loadingText: '正在注销账户...',
|
||
...config.custom
|
||
},
|
||
...config
|
||
})
|
||
}
|