refactor(api): 重构API模块,实现模块化管理
* 将API按功能模块重新组织 - 新增 src/service/api/auth/ 认证相关API - 新增 src/service/api/system/ 系统管理API(用户、角色、菜单) * 删除旧的聚合API文件,避免模块间耦合 * 优化HTTP错误处理和响应拦截 * 遵循单一职责原则,提升代码可维护性 BREAKING CHANGE: API导入路径变更,需要从具体模块导入
This commit is contained in:
parent
1bb184f921
commit
792a787425
@ -1,4 +1,4 @@
|
||||
import { request } from '../http'
|
||||
import { request } from '../../http'
|
||||
|
||||
interface LoginRequest {
|
||||
loginName: string
|
||||
@ -1,181 +0,0 @@
|
||||
import { request } from '../http'
|
||||
|
||||
// 用户管理相关接口类型定义
|
||||
interface UserQuery {
|
||||
pageNo?: number
|
||||
pageSize?: number
|
||||
loginName?: string
|
||||
userName?: string
|
||||
userType?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
userStatus?: string
|
||||
beginTime?: string
|
||||
endTime?: string
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
userId?: number
|
||||
loginName: string
|
||||
userName: string
|
||||
password?: string
|
||||
userType: string
|
||||
email?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
avatar?: string
|
||||
userStatus: string
|
||||
remark?: string
|
||||
roleIds?: number[]
|
||||
}
|
||||
|
||||
interface PageResult<T> {
|
||||
records: T[]
|
||||
total: number
|
||||
size: number
|
||||
current: number
|
||||
pages: number
|
||||
}
|
||||
|
||||
interface PersonalData {
|
||||
userName: string
|
||||
email?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
avatar?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
interface PasswordUpdate {
|
||||
oldPassword: string
|
||||
newPassword: string
|
||||
confirmPassword: string
|
||||
}
|
||||
|
||||
// 获取用户动态路由信息
|
||||
export function fetchUserRoutes() {
|
||||
return request.Get<Service.ResponseResult<AppRoute.RowRoute[]>>('/coder/sysMenu/listRouters')
|
||||
}
|
||||
|
||||
// 角色数据类型
|
||||
interface RoleInfo {
|
||||
roleId: number
|
||||
roleName: string
|
||||
roleCode: string
|
||||
}
|
||||
|
||||
// 获取所有角色列表
|
||||
export function fetchRoleList() {
|
||||
return request.Get<Service.ResponseResult<RoleInfo[]>>('/coder/sysRole/list')
|
||||
}
|
||||
|
||||
// 获取角色下拉框数据
|
||||
export function fetchRoleElSelect() {
|
||||
return request.Get<Service.ResponseResult<{ label: string, value: number }[]>>('/coder/sysRole/listRoleElSelect')
|
||||
}
|
||||
|
||||
// 查询正常角色穿梭框
|
||||
export function fetchNormalRoleForUser(userId: number) {
|
||||
return request.Get<Service.ResponseResult<{ label: string, value: number, parentId: string }[]>>(`/coder/sysRole/listNormalRole/${userId}`)
|
||||
}
|
||||
|
||||
// 分配用户角色
|
||||
export function assignUserRole(userId: number, roleIds: string) {
|
||||
return request.Get<Service.ResponseResult<string>>(`/coder/sysRole/assignUserRole/${userId}/${roleIds}`)
|
||||
}
|
||||
|
||||
// 用户管理接口
|
||||
|
||||
// 分页查询用户列表
|
||||
export function fetchUserPage(params: UserQuery) {
|
||||
return request.Get<Service.ResponseResult<PageResult<UserInfo>>>('/coder/sysLoginUser/listPage', { params })
|
||||
}
|
||||
|
||||
// 查询所有用户(不分页)
|
||||
export function fetchAllUsers(params?: Omit<UserQuery, 'pageNo' | 'pageSize'>) {
|
||||
return request.Get<Service.ResponseResult<UserInfo[]>>('/coder/sysLoginUser/list', { params })
|
||||
}
|
||||
|
||||
// 根据ID查询用户
|
||||
export function fetchUserById(id: number) {
|
||||
return request.Get<Service.ResponseResult<UserInfo>>(`/coder/sysLoginUser/getById/${id}`)
|
||||
}
|
||||
|
||||
// 新增用户
|
||||
export function addUser(data: UserInfo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/add', data)
|
||||
}
|
||||
|
||||
// 修改用户信息
|
||||
export function updateUser(data: UserInfo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/update', data)
|
||||
}
|
||||
|
||||
// 删除用户
|
||||
export function deleteUser(id: number) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/deleteById/${id}`)
|
||||
}
|
||||
|
||||
// 批量删除用户
|
||||
export function batchDeleteUsers(ids: number[]) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/batchDelete', ids)
|
||||
}
|
||||
|
||||
// 修改用户状态
|
||||
export function updateUserStatus(userId: number, userStatus: string) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/updateStatus/${userId}/${userStatus}`)
|
||||
}
|
||||
|
||||
// 获取当前登录用户信息
|
||||
|
||||
// 获取个人资料
|
||||
export function fetchPersonalData() {
|
||||
return request.Get<Service.ResponseResult<PersonalData>>('/coder/sysLoginUser/getPersonalData')
|
||||
}
|
||||
|
||||
// 修改个人资料
|
||||
export function updatePersonalData(data: PersonalData) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/updateBasicData', data)
|
||||
}
|
||||
|
||||
// 修改登录密码
|
||||
export function updateUserPassword(data: PasswordUpdate) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/updateUserPwd', data)
|
||||
}
|
||||
|
||||
// 重置用户密码
|
||||
export function resetUserPassword(id: number, password: string) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/resetPwd/${id}/${password}`)
|
||||
}
|
||||
|
||||
// 下载用户导入模板
|
||||
export function downloadExcelTemplate() {
|
||||
const method = request.Get<Blob>('/coder/sysLoginUser/downloadExcelTemplate')
|
||||
method.meta = {
|
||||
isBlob: true,
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
// 导出用户数据
|
||||
export function exportExcelData(params?: UserQuery) {
|
||||
const method = request.Get<Blob>('/coder/sysLoginUser/exportExcelData', { params })
|
||||
method.meta = {
|
||||
isBlob: true,
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
// 导入用户数据
|
||||
export function importUserData(file: File, updateSupport = false) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('updateSupport', String(updateSupport))
|
||||
|
||||
return request.Post<Service.ResponseResult<{
|
||||
total: number
|
||||
success: number
|
||||
failed: number
|
||||
message: string
|
||||
}>>('/coder/sysLoginUser/importExcelData', formData)
|
||||
}
|
||||
11
src/service/api/system/menu/index.ts
Normal file
11
src/service/api/system/menu/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { request } from '../../../http'
|
||||
|
||||
// 菜单路由管理相关API
|
||||
|
||||
// 获取用户动态路由信息
|
||||
export function getUserRoutes() {
|
||||
return request.Get<Service.ResponseResult<AppRoute.RowRoute[]>>('/coder/sysMenu/listRouters')
|
||||
}
|
||||
|
||||
// 兼容性导出 - 保持原有函数名以确保向后兼容
|
||||
export const fetchUserRoutes = getUserRoutes
|
||||
40
src/service/api/system/role/index.ts
Normal file
40
src/service/api/system/role/index.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { request } from '../../../http'
|
||||
import type {
|
||||
RoleSelectVo,
|
||||
RoleTransferVo,
|
||||
RoleVo,
|
||||
} from './types'
|
||||
|
||||
// 重新导出类型供外部使用
|
||||
export type {
|
||||
RoleSelectVo,
|
||||
RoleTransferVo,
|
||||
RoleVo,
|
||||
} from './types'
|
||||
|
||||
// 角色管理相关API
|
||||
|
||||
// 获取所有角色列表
|
||||
export function getRoleList() {
|
||||
return request.Get<Service.ResponseResult<RoleVo[]>>('/coder/sysRole/list')
|
||||
}
|
||||
|
||||
// 获取角色下拉框数据
|
||||
export function getRoleElSelect() {
|
||||
return request.Get<Service.ResponseResult<RoleSelectVo[]>>('/coder/sysRole/listRoleElSelect')
|
||||
}
|
||||
|
||||
// 查询正常角色穿梭框
|
||||
export function getNormalRoleForUser(userId: number) {
|
||||
return request.Get<Service.ResponseResult<RoleTransferVo[]>>(`/coder/sysRole/listNormalRole/${userId}`)
|
||||
}
|
||||
|
||||
// 分配用户角色
|
||||
export function assignUserRole(userId: number, roleIds: string) {
|
||||
return request.Get<Service.ResponseResult<string>>(`/coder/sysRole/assignUserRole/${userId}/${roleIds}`)
|
||||
}
|
||||
|
||||
// 兼容性导出 - 保持原有函数名以确保向后兼容
|
||||
export const fetchRoleList = getRoleList
|
||||
export const fetchRoleElSelect = getRoleElSelect
|
||||
export const fetchNormalRoleForUser = getNormalRoleForUser
|
||||
19
src/service/api/system/role/types.ts
Normal file
19
src/service/api/system/role/types.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// 角色信息类型
|
||||
export interface RoleVo {
|
||||
roleId: number
|
||||
roleName: string
|
||||
roleCode: string
|
||||
}
|
||||
|
||||
// 角色选择器选项类型
|
||||
export interface RoleSelectVo {
|
||||
label: string
|
||||
value: number
|
||||
}
|
||||
|
||||
// 角色穿梭框选项类型
|
||||
export interface RoleTransferVo {
|
||||
label: string
|
||||
value: number
|
||||
parentId: string
|
||||
}
|
||||
121
src/service/api/system/user/index.ts
Normal file
121
src/service/api/system/user/index.ts
Normal file
@ -0,0 +1,121 @@
|
||||
import { request } from '../../../http'
|
||||
import type {
|
||||
PageUserVo,
|
||||
PasswordUpdateBo,
|
||||
PersonalDataVo,
|
||||
UserQueryBo,
|
||||
UserVo,
|
||||
} from './types'
|
||||
|
||||
// 重新导出类型供外部使用
|
||||
export type {
|
||||
PageUserVo,
|
||||
PasswordUpdateBo,
|
||||
PersonalDataVo,
|
||||
UserQueryBo,
|
||||
UserSearchForm,
|
||||
UserVo,
|
||||
} from './types'
|
||||
|
||||
// 用户管理相关API
|
||||
|
||||
// 分页查询用户列表
|
||||
export function getUserList(params: UserQueryBo) {
|
||||
return request.Get<Service.ResponseResult<PageUserVo>>('/coder/sysLoginUser/listPage', { params })
|
||||
}
|
||||
|
||||
// 查询所有用户(不分页)
|
||||
export function getAllUsers(params?: Omit<UserQueryBo, 'pageNo' | 'pageSize'>) {
|
||||
return request.Get<Service.ResponseResult<UserVo[]>>('/coder/sysLoginUser/list', { params })
|
||||
}
|
||||
|
||||
// 根据ID查询用户
|
||||
export function getUserById(id: number) {
|
||||
return request.Get<Service.ResponseResult<UserVo>>(`/coder/sysLoginUser/getById/${id}`)
|
||||
}
|
||||
|
||||
// 新增用户
|
||||
export function addUser(data: UserVo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/add', data)
|
||||
}
|
||||
|
||||
// 修改用户信息
|
||||
export function updateUser(data: UserVo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/update', data)
|
||||
}
|
||||
|
||||
// 删除用户
|
||||
export function deleteUser(id: number) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/deleteById/${id}`)
|
||||
}
|
||||
|
||||
// 批量删除用户
|
||||
export function batchDeleteUsers(ids: number[]) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/batchDelete', ids)
|
||||
}
|
||||
|
||||
// 修改用户状态
|
||||
export function updateUserStatus(userId: number, userStatus: string) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/updateStatus/${userId}/${userStatus}`)
|
||||
}
|
||||
|
||||
// 重置用户密码
|
||||
export function resetUserPassword(id: number, password: string) {
|
||||
return request.Post<Service.ResponseResult<string>>(`/coder/sysLoginUser/resetPwd/${id}/${password}`)
|
||||
}
|
||||
|
||||
// 个人资料相关API
|
||||
|
||||
// 获取个人资料
|
||||
export function getPersonalData() {
|
||||
return request.Get<Service.ResponseResult<PersonalDataVo>>('/coder/sysLoginUser/getPersonalData')
|
||||
}
|
||||
|
||||
// 修改个人资料
|
||||
export function updatePersonalData(data: PersonalDataVo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/updateBasicData', data)
|
||||
}
|
||||
|
||||
// 修改登录密码
|
||||
export function updateUserPassword(data: PasswordUpdateBo) {
|
||||
return request.Post<Service.ResponseResult<string>>('/coder/sysLoginUser/updateUserPwd', data)
|
||||
}
|
||||
|
||||
// 用户数据导入导出相关API
|
||||
|
||||
// 下载用户导入模板
|
||||
export function downloadExcelTemplate() {
|
||||
const method = request.Get<Blob>('/coder/sysLoginUser/downloadExcelTemplate')
|
||||
method.meta = {
|
||||
isBlob: true,
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
// 导出用户数据
|
||||
export function exportExcelData(params?: UserQueryBo) {
|
||||
const method = request.Get<Blob>('/coder/sysLoginUser/exportExcelData', { params })
|
||||
method.meta = {
|
||||
isBlob: true,
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
// 导入用户数据
|
||||
export function importUserData(file: File, updateSupport = false) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('updateSupport', String(updateSupport))
|
||||
|
||||
return request.Post<Service.ResponseResult<{
|
||||
total: number
|
||||
success: number
|
||||
failed: number
|
||||
message: string
|
||||
}>>('/coder/sysLoginUser/importExcelData', formData)
|
||||
}
|
||||
|
||||
// 兼容性导出 - 保持原有函数名以确保向后兼容
|
||||
export const fetchUserPage = getUserList
|
||||
export const fetchAllUsers = getAllUsers
|
||||
export const fetchUserById = getUserById
|
||||
73
src/service/api/system/user/types.ts
Normal file
73
src/service/api/system/user/types.ts
Normal file
@ -0,0 +1,73 @@
|
||||
// 用户查询参数类型
|
||||
export interface UserQueryBo {
|
||||
pageNo?: number
|
||||
pageSize?: number
|
||||
loginName?: string
|
||||
userName?: string
|
||||
userType?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
userStatus?: string
|
||||
beginTime?: string
|
||||
endTime?: string
|
||||
}
|
||||
|
||||
// 用户信息类型 (完整的用户实体)
|
||||
export interface UserVo {
|
||||
userId: number
|
||||
loginName: string
|
||||
userName: string
|
||||
password?: string
|
||||
userType: string
|
||||
email?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
avatar?: string
|
||||
userStatus: string // 0-启用 1-停用
|
||||
loginIp?: string
|
||||
loginTime?: string
|
||||
pwdUpdateTime?: string
|
||||
remark?: string
|
||||
createBy?: string
|
||||
createTime?: string
|
||||
updateBy?: string
|
||||
updateTime?: string
|
||||
roleIds?: number[]
|
||||
}
|
||||
|
||||
// 分页结果类型
|
||||
export interface PageUserVo {
|
||||
records: UserVo[]
|
||||
total: number
|
||||
size: number
|
||||
current: number
|
||||
pages: number
|
||||
}
|
||||
|
||||
// 个人资料类型
|
||||
export interface PersonalDataVo {
|
||||
userName: string
|
||||
email?: string
|
||||
phone?: string
|
||||
sex?: string
|
||||
avatar?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
// 密码修改类型
|
||||
export interface PasswordUpdateBo {
|
||||
oldPassword: string
|
||||
newPassword: string
|
||||
confirmPassword: string
|
||||
}
|
||||
|
||||
// 用户搜索表单类型
|
||||
export interface UserSearchForm {
|
||||
loginName?: string
|
||||
userName?: string
|
||||
phone?: string
|
||||
userStatus?: string
|
||||
beginTime?: string
|
||||
endTime?: string
|
||||
timeRange?: [number, number] | null
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import { fetchUpdateToken } from '@/service'
|
||||
import { fetchUpdateToken } from '@/service/api/auth'
|
||||
import { useAuthStore } from '@/store'
|
||||
import { local } from '@/utils'
|
||||
import { coiMsgError } from '@/utils/coi'
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
export * from './api/login'
|
||||
export * from './api/system'
|
||||
Loading…
Reference in New Issue
Block a user