257 lines
4.9 KiB
JavaScript
257 lines
4.9 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 {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const wxLogin = (wxData, config = {}) => {
|
|
return uni.$u.http.post('/auth/wx-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 {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const bindPhone = (phoneData, config = {}) => {
|
|
return uni.$u.http.post('/user/bind-phone', phoneData, {
|
|
custom: {
|
|
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
|
|
})
|
|
}
|