OfficeSystem/api/user.js

102 lines
2.3 KiB
JavaScript
Raw Normal View History

2025-11-07 11:18:43 +08:00
/**
* 用户相关 API
*/
/**
* 获取用户信息
* @returns {Promise} 返回用户信息
*/
export const getUserInfo = () => {
return uni.$uv.http.get('/getInfo', {
custom: {
auth: true // 启用 token 认证
}
});
};
2025-11-10 15:46:19 +08:00
/**
* 获取验证码图片
* @returns {Promise<{img: string, uuid: string, captchaEnabled: boolean}>}
*/
export const getCaptchaImage = () => {
return uni.$uv.http.get('/captchaImage', {
// 验证码无需 token
custom: {
auth: false,
toast: false
}
});
};
/**
* 登录
* @param {Object} payload 登录参数
* @param {string} payload.username 用户名
* @param {string} payload.password 密码
* @param {string} [payload.code] 验证码
* @param {string} [payload.uuid] 验证码唯一标识
* @returns {Promise<any>} 登录结果
*/
export const login = (payload) => {
return uni.$uv.http.post('/login', payload, {
custom: {
auth: false,
catch: true,
toast: false
}
});
};
2025-11-10 16:54:46 +08:00
/**
* 退出登录
* @returns {Promise<any>} 退出结果
*/
export const logout = () => {
return uni.$uv.http.post('/logout', {}, {
custom: {
auth: true,
catch: true
}
});
};
2025-11-13 14:52:54 +08:00
/**
* 获取所有用户列表
* @returns {Promise<Array>} 返回用户列表
*/
export const getUserListAll = () => {
return uni.$uv.http.get('system/user/listAll', {
custom: {
auth: true // 启用 token 认证
}
});
};
2025-11-14 15:28:48 +08:00
/**
2025-11-14 16:03:10 +08:00
* 分页获取用户列表uni-app兼容版本
2025-11-14 15:28:48 +08:00
* @param {Object} params 查询参数
2025-11-14 16:03:10 +08:00
* @param {number} params.pageNum 页码默认1
* @param {number} params.pageSize 每页数量默认100
* @param {string|number} params.status 启用状态默认0
* @param {string|number} params.delFlag 删除标记默认0
2025-11-14 15:28:48 +08:00
* @returns {Promise<Object>} 用户列表
*/
export const getUserList = (params = {}) => {
2025-11-14 16:03:10 +08:00
// 合并参数并过滤空值
const requestParams = Object.entries({
2025-11-14 15:28:48 +08:00
pageNum: 1,
pageSize: 100,
status: 0,
2025-11-14 16:03:10 +08:00
delFlag: 0,
...params
})
.filter(([_, value]) => value !== undefined && value !== null && value !== '')
.map(([key, value]) => `${key}=${encodeURIComponent(value.toString())}`)
.join('&');
2025-11-14 15:28:48 +08:00
2025-11-14 16:03:10 +08:00
const url = `/system/user/list${requestParams ? `?${requestParams}` : ''}`;
2025-11-14 15:28:48 +08:00
2025-11-14 16:03:10 +08:00
return uni.$uv.http.get(url, {
custom: { auth: true }
2025-11-14 15:28:48 +08:00
});
2025-11-14 16:03:10 +08:00
};