OfficeSystem/api/user.js
2025-11-14 15:28:48 +08:00

108 lines
2.3 KiB
JavaScript

/**
* 用户相关 API
*/
/**
* 获取用户信息
* @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 认证
}
});
};
/**
* 分页获取用户列表
* @param {Object} params 查询参数
* @param {number} params.pageNum 页码
* @param {number} params.pageSize 每页数量
* @param {string|number} params.status 启用状态
* @param {string|number} params.delFlag 删除标记
* @returns {Promise<Object>} 用户列表
*/
export const getUserList = (params = {}) => {
const defaultParams = {
pageNum: 1,
pageSize: 100,
status: 0,
delFlag: 0
};
const searchParams = new URLSearchParams();
Object.entries({ ...defaultParams, ...params }).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
searchParams.append(key, value);
}
});
const queryString = searchParams.toString();
return uni.$uv.http.get(`/system/user/list${queryString ? `?${queryString}` : ''}`, {
custom: {
auth: true
}
});
};