OfficeSystem/api/user.js
2025-11-27 10:14:55 +08:00

103 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 用户相关 API
*/
import { buildUrl, mergeParams } from '@/utils/url'
/**
* 获取用户信息
* @returns {Promise} 返回用户信息
*/
export const getUserInfo = () => {
return uni.$uv.http.get('/getInfo', {
custom: {
auth: true // 启用 token 认证
}
});
};
/**
* 获取验证码图片
* @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
}
});
};
/**
* 退出登录
* @returns {Promise<any>} 退出结果
*/
export const logout = () => {
return uni.$uv.http.post('/logout', {}, {
custom: {
auth: true,
catch: true
}
});
};
/**
* 获取所有用户列表
* @returns {Promise<Array>} 返回用户列表
*/
export const getUserListAll = () => {
return uni.$uv.http.get('system/user/listAll', {
custom: {
auth: true // 启用 token 认证
}
});
};
/**
* 分页获取用户列表uni-app兼容版本
* @param {Object} params 查询参数
* @param {number} params.pageNum 页码默认1
* @param {number} params.pageSize 每页数量默认100
* @param {string|number} params.status 启用状态默认0
* @param {string|number} params.delFlag 删除标记默认0
* @returns {Promise<Object>} 用户列表
*/
export const getUserList = (params = {}) => {
// 设置默认参数
const defaultParams = {
pageNum: 1,
pageSize: 100,
status: 0,
delFlag: 0
};
// 合并参数
const requestParams = mergeParams(defaultParams, params);
// 使用统一URL构建工具
const url = buildUrl('/system/user/list', requestParams);
return uni.$uv.http.get(url, {
custom: { auth: true }
});
};