init: 初始系统模板

This commit is contained in:
TsMask
2023-09-05 14:38:23 +08:00
parent a5bc16ae4f
commit 1075c8ae4f
130 changed files with 22531 additions and 1 deletions

59
src/api/login.ts Normal file
View File

@@ -0,0 +1,59 @@
import { request } from '@/plugins/http-fetch';
// 登录方法
export function login(data: Record<string, string>) {
return request({
url: '/login',
method: 'post',
data: data,
whithToken: false,
});
}
/**
* 注册方法
* @param data 注册对象
* @returns object
*/
export function register(data: Record<string, any>) {
return request({
url: '/register',
method: 'post',
data: data,
whithToken: false,
});
}
/**
* 获取用户详细信息
* @returns object
*/
export function getInfo() {
return request({
url: '/getInfo',
method: 'get',
});
}
/**
* 退出方法
* @returns object
*/
export function logout() {
return request({
url: '/logout',
method: 'post',
});
}
/**
* 获取验证码
* @returns object
*/
export function getCaptchaImage() {
return request({
url: '/captchaImage',
method: 'get',
whithToken: false,
});
}

86
src/api/monitor/cache.ts Normal file
View File

@@ -0,0 +1,86 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询缓存详细
* @returns object
*/
export function getCache() {
return request({
url: '/monitor/cache',
method: 'get',
});
}
/**
* 查询缓存名称列表
* @returns object
*/
export function listCacheName() {
return request({
url: '/monitor/cache/getNames',
method: 'get',
});
}
/**
* 查询缓存名称下键名列表
* @param cacheName 缓存名称列表中得到的缓存名称
* @returns object
*/
export function listCacheKey(cacheName: string) {
return request({
url: `/monitor/cache/getKeys/${cacheName}`,
method: 'get',
});
}
/**
* 查询缓存内容
* @param cacheName 键名列表中得到的缓存名称
* @param cacheKey 键名列表中得到的缓存键名
* @returns object
*/
export function getCacheValue(cacheName: string, cacheKey: string) {
return request({
url: `/monitor/cache/getValue/${cacheName}/${cacheKey}`,
method: 'get',
});
}
/**
* 删除缓存名称下键名列表
* @param cacheName 缓存名称列表中得到的缓存名称
* @returns object
*/
export function clearCacheName(cacheName: string) {
return request({
url: `/monitor/cache/clearCacheName/${cacheName}`,
method: 'delete',
});
}
/**
* 删除缓存键名
* @param cacheName 键名列表中得到的缓存名称
* @param cacheKey 键名列表中得到的缓存键名
* @returns object
*/
export function clearCacheKey(cacheName: string, cacheKey: string) {
return request({
url: `/monitor/cache/clearCacheKey/${cacheName}/${cacheKey}`,
method: 'delete',
});
}
/**
* 安全清理缓存名称
*
* 指定可清理的缓存key
* @returns object
*/
export function clearCacheSafe() {
return request({
url: '/monitor/cache/clearCacheSafe',
method: 'delete',
});
}

121
src/api/monitor/job.ts Normal file
View File

@@ -0,0 +1,121 @@
import { request } from '@/plugins/http-fetch';
/**
* 定时任务调度列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportJob(query: Record<string, any>) {
return request({
url: '/monitor/job/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询定时任务调度列表
* @param query 查询参数
* @returns object
*/
export function listJob(query: Record<string, any>) {
return request({
url: '/monitor/job/list',
method: 'get',
params: query,
});
}
/**
* 查询定时任务调度详细
* @param jobId 任务ID
* @returns object
*/
export function getJob(jobId: string | number) {
return request({
url: `/monitor/job/${jobId}`,
method: 'get',
});
}
/**
* 新增定时任务调度
* @param data 任务对象
* @returns object
*/
export function addJob(data: Record<string, any>) {
return request({
url: '/monitor/job',
method: 'post',
data: data,
});
}
/**
* 修改定时任务调度
* @param data 任务对象
* @returns object
*/
export function updateJob(data: Record<string, any>) {
return request({
url: '/monitor/job',
method: 'put',
data: data,
});
}
/**
* 删除定时任务调度
* @param jobId 任务ID
* @returns object
*/
export function delJob(jobId: string | number) {
return request({
url: `/monitor/job/${jobId}`,
method: 'delete',
});
}
/**
* 任务状态修改
* @param jobId 任务ID
* @param status 变更状态值
* @returns
*/
export function changeJobStatus(
jobId: string | number,
status: string | number
) {
return request({
url: '/monitor/job/changeStatus',
method: 'put',
data: {
jobId,
status,
},
});
}
/**
* 定时任务立即执行一次
* @param jobId 任务ID
* @returns object
*/
export function runJob(jobId: string) {
return request({
url: `/monitor/job/run/${jobId}`,
method: 'put',
});
}
/**
* 重置刷新队列
* @returns object
*/
export function resetQueueJob() {
return request({
url: '/monitor/job/resetQueueJob',
method: 'put',
});
}

53
src/api/monitor/jobLog.ts Normal file
View File

@@ -0,0 +1,53 @@
import { request } from '@/plugins/http-fetch';
/**
* 定时任务调度日志列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportJobLog(
query: Record<string, any>
) {
return request({
url: '/monitor/jobLog/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询调度日志列表
* @param query 查询参数
* @returns object
*/
export function listJobLog(query: Record<string, any>) {
return request({
url: '/monitor/jobLog/list',
method: 'get',
params: query,
});
}
/**
* 删除调度日志
* @param jobLogId 任务日志Id
* @returns object
*/
export function delJobLog(jobLogId: string) {
return request({
url: `/monitor/jobLog/${jobLogId}`,
method: 'delete',
});
}
/**
* 清空调度日志
* @returns object
*/
export function cleanJobLog() {
return request({
url: '/monitor/jobLog/clean',
method: 'delete',
});
}

View File

@@ -0,0 +1,67 @@
import { request } from '@/plugins/http-fetch';
/**
* 登录日志列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportLogininfor(
query: Record<string, any>
) {
return request({
url: '/monitor/logininfor/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询登录日志列表
* @param query 查询参数
* @returns object
*/
export function listLogininfor(
query: Record<string, any>
) {
return request({
url: '/monitor/logininfor/list',
method: 'get',
params: query,
});
}
/**
* 删除登录日志
* @param infoId 登录日志Id
* @returns object
*/
export function delLogininfor(infoId: string) {
return request({
url: `/monitor/logininfor/${infoId}`,
method: 'delete',
});
}
/**
* 清空登录日志
* @returns object
*/
export function cleanLogininfor() {
return request({
url: '/monitor/logininfor/clean',
method: 'delete',
});
}
/**
* 解锁用户登录状态
* @param userName 登录账号
* @returns object
*/
export function unlockLogininfor(userName: string) {
return request({
url: `/monitor/logininfor/unlock/${userName}`,
method: 'put',
});
}

26
src/api/monitor/online.ts Normal file
View File

@@ -0,0 +1,26 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询在线用户列表
* @param query 查询参数
* @returns object
*/
export function listOnline(query: Record<string, any>) {
return request({
url: '/monitor/online/list',
method: 'get',
params: query,
});
}
/**
* 强退用户
* @param tokenId 授权标识
* @returns object
*/
export function forceLogout(tokenId: string) {
return request({
url: `/monitor/online/${tokenId}`,
method: 'delete',
});
}

View File

@@ -0,0 +1,55 @@
import { request } from '@/plugins/http-fetch';
/**
* 操作日志列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportOperlog(
query: Record<string, any>
) {
return request({
url: '/monitor/operlog/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询操作日志列表
* @param query 查询参数
* @returns object
*/
export function listOperlog(
query: Record<string, any>
) {
return request({
url: '/monitor/operlog/list',
method: 'get',
params: query,
});
}
/**
* 删除操作日志
* @param operId 操作日志ID
* @returns object
*/
export function delOperlog(operId: string) {
return request({
url: `/monitor/operlog/${operId}`,
method: 'delete',
});
}
/**
* 清空操作日志
* @returns object
*/
export function cleanOperlog() {
return request({
url: '/monitor/operlog/clean',
method: 'delete',
});
}

View File

@@ -0,0 +1,9 @@
import { request } from '@/plugins/http-fetch';
/**获取服务信息 */
export function getServer() {
return request({
url: '/monitor/server',
method: 'get',
});
}

56
src/api/profile.ts Normal file
View File

@@ -0,0 +1,56 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询用户个人信息
* @returns object
*/
export function getUserProfile() {
return request({
url: '/system/user/profile',
method: 'get',
});
}
/**
* 修改用户个人信息
* @param data 用户对象
* @returns object
*/
export function updateUserProfile(data: Record<string, any>) {
return request({
url: '/system/user/profile',
method: 'put',
data: data,
});
}
/**
* 用户密码重置
* @param userId 用户ID
* @param status 变更状态值
* @returns object
*/
export function updateUserPwd(oldPassword: string, newPassword: string) {
return request({
url: '/system/user/profile/updatePwd',
method: 'put',
data: {
oldPassword,
newPassword,
},
});
}
/**
* 用户头像上传
* @param data 表单数据对象
* @returns object
*/
export function uploadAvatar(data: FormData) {
return request({
url: '/system/user/profile/avatar',
method: 'post',
data,
dataType: 'form-data',
});
}

12
src/api/router.ts Normal file
View File

@@ -0,0 +1,12 @@
import { request } from '@/plugins/http-fetch';
/**
* 获取路由
* @returns object
*/
export const getRouters = () => {
return request({
url: '/getRouters',
method: 'get',
});
};

103
src/api/system/config.ts Normal file
View File

@@ -0,0 +1,103 @@
import { request } from '@/plugins/http-fetch';
/**
* 参数配置列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportConfig(
query: Record<string, any>
) {
return request({
url: '/system/config/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询参数配置列表
* @param query 查询参数
* @returns object
*/
export function listConfig(query: Record<string, any>) {
return request({
url: '/system/config/list',
method: 'get',
params: query,
});
}
/**
* 查询参数详细
* @param configId 参数配置ID
* @returns object
*/
export function getConfig(configId: string | number) {
return request({
url: `/system/config/${configId}`,
method: 'get',
});
}
/**
* 根据参数键名查询参数值
* @param configKey 参数键名
* @returns object
*/
export function getConfigKey(configKey: string) {
return request({
url: `/system/config/configKey/${configKey}`,
method: 'get',
});
}
/**
* 新增参数配置
* @param data 参数配置对象
* @returns object
*/
export function addConfig(data: Record<string, any>) {
return request({
url: '/system/config',
method: 'post',
data: data,
});
}
/**
* 修改参数配置
* @param data 参数配置对象
* @returns object
*/
export function updateConfig(data: Record<string, any>) {
return request({
url: '/system/config',
method: 'put',
data: data,
});
}
/**
* 删除参数配置
* @param configId 参数配置ID
* @returns object
*/
export function delConfig(configId: string | number) {
return request({
url: `/system/config/${configId}`,
method: 'delete',
});
}
/**
* 刷新参数缓存
* @returns object
*/
export function refreshCache() {
return request({
url: '/system/config/refreshCache',
method: 'put',
});
}

99
src/api/system/dept.ts Normal file
View File

@@ -0,0 +1,99 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询部门列表
* @param query 查询参数
* @returns object
*/
export function listDept(query: Record<string, any>) {
return request({
url: '/system/dept/list',
method: 'get',
params: query,
});
}
/**
* 查询部门列表(排除节点)
* @param deptId 部门ID
* @returns object
*/
export function listDeptExcludeChild(deptId: string | number) {
return request({
url: `/system/dept/list/exclude/${deptId}`,
method: 'get',
});
}
/**
* 查询部门详细
* @param deptId 部门ID
* @returns object
*/
export function getDept(deptId: string | number) {
return request({
url: `/system/dept/${deptId}`,
method: 'get',
});
}
/**
* 新增部门
* @param data 部门对象
* @returns object
*/
export function addDept(data: Record<string, any>) {
return request({
url: '/system/dept',
method: 'post',
data: data,
});
}
/**
* 修改部门
* @param data 部门对象
* @returns object
*/
export function updateDept(data: Record<string, any>) {
return request({
url: '/system/dept',
method: 'put',
data: data,
});
}
/**
* 删除部门
* @param deptId 部门ID
* @returns object
*/
export function delDept(deptId: string | number) {
return request({
url: `/system/dept/${deptId}`,
method: 'delete',
});
}
/**
* 查询部门下拉树结构
* @returns object
*/
export function deptTreeSelect() {
return request({
url: '/system/dept/treeSelect',
method: 'get',
});
}
/**
* 部门树结构列表(指定角色)
* @param roleId 角色ID
* @returns object
*/
export function roleDeptTreeSelect(roleId: string | number) {
return request({
url: `/system/dept/roleDeptTreeSelect/${roleId}`,
method: 'get',
});
}

View File

@@ -0,0 +1,90 @@
import { request } from '@/plugins/http-fetch';
/**
* 字典数据列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportData(query: Record<string, any>) {
return request({
url: '/system/dict/data/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询字典数据列表
* @param query 查询值
* @returns
*/
export function listData(query: Record<string, any>) {
return request({
url: '/system/dict/data/list',
method: 'get',
params: query,
});
}
/**
* 查询字典数据详细
* @param dictCode 字典代码值
* @returns object
*/
export function getData(dictCode: string | number) {
return request({
url: `/system/dict/data/${dictCode}`,
method: 'get',
});
}
/**
* 新增字典数据
* @param data 字典数据对象
* @returns object
*/
export function addData(data: Record<string, any>) {
return request({
url: '/system/dict/data',
method: 'post',
data: data,
});
}
/**
* 修改字典数据
* @param data 字典数据对象
* @returns object
*/
export function updateData(data: Record<string, any>) {
return request({
url: '/system/dict/data',
method: 'put',
data: data,
});
}
/**
* 删除字典数据
* @param dictCode 字典代码值
* @returns object
*/
export function delData(dictCode: string | number) {
return request({
url: `/system/dict/data/${dictCode}`,
method: 'delete',
});
}
/**
* 字典数据列表(指定字典类型)
* @param dictType 字典类型
* @returns object
*/
export function getDictDataType(dictType: string) {
return request({
url: `/system/dict/data/type/${dictType}`,
method: 'get',
});
}

102
src/api/system/dict/type.ts Normal file
View File

@@ -0,0 +1,102 @@
import { request } from '@/plugins/http-fetch';
/**
* 字典类型列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportType(query: Record<string, any>) {
return request({
url: '/system/dict/type/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询字典类型列表
* @param query 查询值
* @returns
*/
export function listType(query: Record<string, any>) {
return request({
url: '/system/dict/type/list',
method: 'get',
params: query,
});
}
/**
* 查询字典类型详细
* @param dictId 字典编号
* @returns object
*/
export function getType(dictId: string | number) {
return request({
url: `/system/dict/type/${dictId}`,
method: 'get',
});
}
/**
* 新增字典类型
* @param data 字典数据对象
* @returns object
*/
export function addType(data: Record<string, any>) {
return request({
url: '/system/dict/type',
method: 'post',
data: data,
});
}
/**
* 修改字典类型
* @param data 字典数据对象
* @returns object
*/
export function updateType(data: Record<string, any>) {
return request({
url: '/system/dict/type',
method: 'put',
data: data,
});
}
/**
* 删除字典类型
* @param dictCode 字典代码值
* @returns object
*/
export function delType(dictId: string | number) {
return request({
url: `/system/dict/type/${dictId}`,
method: 'delete',
});
}
/**
* 刷新字典缓存
* @param data 字典数据对象
* @returns object
*/
export function refreshCache() {
return request({
url: '/system/dict/type/refreshCache',
method: 'put',
});
}
/**
* 获取字典选择框列表
* @param data 字典数据对象
* @returns object
*/
export function getDictOptionselect() {
return request({
url: '/system/dict/type/getDictOptionselect',
method: 'get',
});
}

87
src/api/system/menu.ts Normal file
View File

@@ -0,0 +1,87 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询菜单列表
* @param query 查询参数
* @returns object
*/
export function listMenu(query?: Record<string, any>) {
return request({
url: '/system/menu/list',
method: 'get',
params: query,
});
}
/**
* 查询菜单详细
* @param menuId 菜单ID
* @returns object
*/
export function getMenu(menuId: string | number) {
return request({
url: `/system/menu/${menuId}`,
method: 'get',
});
}
/**
* 查询菜单下拉树结构
* @returns object
*/
export function menuTreeSelect() {
return request({
url: '/system/menu/treeSelect',
method: 'get',
});
}
/**
* 根据角色ID查询菜单下拉树结构
* @param roleId 角色ID
* @returns object
*/
export function roleMenuTreeSelect(roleId: string | number) {
return request({
url: `/system/menu/roleMenuTreeSelect/${roleId}`,
method: 'get',
});
}
/**
* 新增菜单
* @param data 菜单对象
* @returns object
*/
export function addMenu(data: Record<string, any>) {
return request({
url: '/system/menu',
method: 'post',
data: data,
});
}
/**
* 修改菜单
* @param data 菜单对象
* @returns object
*/
export function updateMenu(data: Record<string, any>) {
return request({
url: '/system/menu',
method: 'put',
data: data,
});
}
/**
* 删除菜单
* @param menuId 菜单ID
* @returns object
*/
export function delMenu(menuId: string | number) {
return request({
url: `/system/menu/${menuId}`,
method: 'delete',
});
}

64
src/api/system/notice.ts Normal file
View File

@@ -0,0 +1,64 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询公告列表
* @param query 查询参数
* @returns object
*/
export function listNotice(query: Record<string, any>) {
return request({
url: '/system/notice/list',
method: 'get',
params: query,
});
}
/**
* 查询公告详细
* @param menuId 公告ID
* @returns object
*/
export function getNotice(noticeId: string | number) {
return request({
url: `/system/notice/${noticeId}`,
method: 'get',
});
}
/**
* 新增公告
* @param data 公告对象
* @returns object
*/
export function addNotice(data: Record<string, any>) {
return request({
url: '/system/notice',
method: 'post',
data: data,
});
}
/**
* 修改公告
* @param data 公告对象
* @returns object
*/
export function updateNotice(data: Record<string, any>) {
return request({
url: '/system/notice',
method: 'put',
data: data,
});
}
/**
* 删除公告
* @param noticeId 公告ID
* @returns object
*/
export function delNotice(noticeId: string | number) {
return request({
url: `/system/notice/${noticeId}`,
method: 'delete',
});
}

78
src/api/system/post.ts Normal file
View File

@@ -0,0 +1,78 @@
import { request } from '@/plugins/http-fetch';
/**
* 岗位列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportPost(query: Record<string, any>) {
return request({
url: '/system/post/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询岗位列表
* @param query 查询参数
* @returns object
*/
export function listPost(query: Record<string, any>) {
return request({
url: '/system/post/list',
method: 'get',
params: query,
});
}
/**
* 查询岗位详细
* @param postId 岗位ID
* @returns object
*/
export function getPost(postId: string | number) {
return request({
url: `/system/post/${postId}`,
method: 'get',
});
}
/**
* 新增岗位
* @param data 岗位对象
* @returns object
*/
export function addPost(data: Record<string, any>) {
return request({
url: '/system/post',
method: 'post',
data: data,
});
}
/**
* 修改岗位
* @param data 岗位对象
* @returns object
*/
export function updatePost(data: Record<string, any>) {
return request({
url: '/system/post',
method: 'put',
data: data,
});
}
/**
* 删除岗位
* @param postId 岗位ID
* @returns object
*/
export function delPost(postId: string | number) {
return request({
url: `/system/post/${postId}`,
method: 'delete',
});
}

134
src/api/system/role.ts Normal file
View File

@@ -0,0 +1,134 @@
import { request } from '@/plugins/http-fetch';
/**
* 角色列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportRole(query: Record<string, any>) {
return request({
url: '/system/role/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询角色列表
* @param query 查询参数
* @returns object
*/
export function listRole(query: Record<string, any>) {
return request({
url: '/system/role/list',
method: 'get',
params: query,
});
}
/**
* 查询角色详细
* @param roleId 角色ID
* @returns object
*/
export function getRole(roleId: string | number) {
return request({
url: `/system/role/${roleId}`,
method: 'get',
});
}
/**
* 新增角色
* @param data 角色对象
* @returns object
*/
export function addRole(data: Record<string, any>) {
return request({
url: '/system/role',
method: 'post',
data: data,
});
}
/**
* 修改角色
* @param data 角色对象
* @returns object
*/
export function updateRole(data: Record<string, any>) {
return request({
url: '/system/role',
method: 'put',
data: data,
});
}
/**
* 删除角色
* @param roleId 角色ID
* @returns object
*/
export function delRole(roleId: string | number) {
return request({
url: `/system/role/${roleId}`,
method: 'delete',
});
}
/**
* 角色状态修改
* @param roleId 角色ID
* @param status 角色状态
* @returns object
*/
export function changeRoleStatus(roleId: string, status: string | number) {
return request({
url: '/system/role/changeStatus',
method: 'put',
data: {
roleId,
status,
},
});
}
/**
* 修改角色数据权限
* @param data 角色对象
* @returns object
*/
export function dataScope(data: Record<string, any>) {
return request({
url: '/system/role/dataScope',
method: 'put',
data: data,
});
}
/**
* 角色分配用户列表
* @param query 查询参数
* @returns object
*/
export function authUserAllocatedList(query: Record<string, any>) {
return request({
url: '/system/role/authUser/allocatedList',
method: 'get',
params: query,
});
}
/**
* 角色分配选择授权
* @param data 角色对象
* @returns object
*/
export function authUserChecked(data: Record<string, any>) {
return request({
url: '/system/role/authUser/checked',
method: 'put',
data: data,
});
}

141
src/api/system/user.ts Normal file
View File

@@ -0,0 +1,141 @@
import { request } from '@/plugins/http-fetch';
/**
* 导入用户模板数据
* @param data 表单数据对象
* @returns object
*/
export function importData(data: FormData) {
return request({
url: '/system/user/importData',
method: 'post',
data,
dataType: 'form-data',
});
}
/**
* 导入用户模板下载
* @returns bolb
*/
export function importTemplate() {
return request({
url: '/system/user/importTemplate',
method: 'get',
responseType: 'blob',
});
}
/**
* 用户列表导出
* @param query 查询参数
* @returns bolb
*/
export function exportUser(query: Record<string, any>) {
return request({
url: '/system/user/export',
method: 'post',
data: query,
responseType: 'blob',
});
}
/**
* 查询用户列表
* @param query 查询参数
* @returns object
*/
export function listUser(query: Record<string, any>) {
return request({
url: '/system/user/list',
method: 'get',
params: query,
});
}
/**
* 查询用户详细
* @param userId 用户ID新增0
* @returns object
*/
export function getUser(userId: string | number = '0') {
return request({
url: `/system/user/${userId}`,
method: 'get',
});
}
/**
* 新增用户
* @param data 用户对象
* @returns object
*/
export function addUser(data: Record<string, any>) {
return request({
url: '/system/user',
method: 'post',
data: data,
});
}
/**
* 修改用户
* @param data 用户对象
* @returns object
*/
export function updateUser(data: Record<string, any>) {
return request({
url: '/system/user',
method: 'put',
data: data,
});
}
/**
* 删除用户
* @param userId 用户ID
* @returns object
*/
export function delUser(userId: string | number) {
return request({
url: `/system/user/${userId}`,
method: 'delete',
});
}
/**
* 用户密码重置
* @param userId 用户ID
* @param password 密码
* @returns object
*/
export function resetUserPwd(userId: string | number, password: string) {
return request({
url: '/system/user/resetPwd',
method: 'put',
data: {
userId,
password,
},
});
}
/**
* 用户状态修改
* @param userId 用户ID
* @param status 变更状态值
* @returns object
*/
export function changeUserStatus(
userId: string | number,
status: string | number
) {
return request({
url: '/system/user/changeStatus',
method: 'put',
data: {
userId,
status,
},
});
}

195
src/api/tool/file.ts Normal file
View File

@@ -0,0 +1,195 @@
import { request } from '@/plugins/http-fetch';
import { encode } from 'js-base64';
/**
* 下载文件
* @param filePath 文件路径带/,如:/upload/default/2023/06/xx.png
* @param range 断点续传标识,填入字符串 `bytes=${startByte}-${endByte}`
* @returns object
*/
export async function downloadFile(filePath: string, range?: string) {
return request({
url: `/file/download/${encode(filePath)}`,
method: 'get',
headers: range ? { range } : {},
responseType: 'blob',
});
}
/**
* 下载文件切片
* @param filePath 文件路径带/,如:/upload/default/2023/06/xx.png
* @param chunkSize 数据块大小MB默认1MB
* @returns bolb
*/
export async function downloadFileChunk(
filePath: string,
chunkSize: number = 1
): Promise<Blob> {
chunkSize = chunkSize * 1024 * 1024;
let start = 0; // 文件块的起始字节
let end = chunkSize - 1; // 文件块的结束字节
let totalSize = 0; // 文件总大小
let downloadedSize = 0; // 已下载的文件大小
let filePart: Blob[] = []; // 文件数据块内容
// 发送带有 Range 请求头的 HTTP 请求
async function sendRequest() {
const range = `bytes=${start}-${end}`;
const res = await downloadFile(filePath, range);
if (res.code === 200 && res.status === 206) {
// 总大小
const contentRange = res.headers.get('content-range') || '0/0';
totalSize = parseInt(contentRange.split('/')[1]);
// 已下载大小
const contentLength = res.headers.get('content-length') || '0';
const chunkSize = parseInt(contentLength);
// 下一段数据块区间
start += chunkSize;
end = Math.min(start + chunkSize - 1, totalSize - 1);
// 记录下载结果
filePart.push(res.data);
downloadedSize += chunkSize;
// 小于总大小继续下载后续数据
if (downloadedSize < totalSize) {
await sendRequest();
}
} else {
return res;
}
}
await sendRequest();
return new Blob(filePart, { type: 'application/octet-stream' });
}
/**
* 上传文件
* @param data 表单数据对象
* @returns object
*/
export function uploadFile(data: FormData) {
return request({
url: '/file/upload',
method: 'post',
data,
dataType: 'form-data',
});
}
/**
* 上传切片文件
* @param file 文件对象
* @param chunkSize 数据块大小MB默认1MB
* @param subPath 归属子路径, 默认default
* @returns
*/
export async function uploadFileChunk(
fileData: File,
chunkSize: number = 1,
subPath: string = 'default'
) {
const { name, size } = fileData;
const chunkSizeInBytes = chunkSize * 1024 * 1024;
// 文件标识使用唯一编码 MD5(文件名+文件大小)
const fileIdentifier = `${name}-${size}`;
// 文件切分为多少份进行上传
const chunksCount = Math.ceil(size / chunkSizeInBytes);
// 切块的数据数据用于上传
const fileChunks: { index: number; chunk: Blob }[] = [];
for (let i = 0; i < chunksCount; i++) {
const start = i * chunkSizeInBytes;
const end = Math.min(start + chunkSizeInBytes, size);
fileChunks.push({
index: i,
chunk: fileData.slice(start, end),
});
}
// 检查是否已上传部分数据块
const resCheck = await chunkCheck(fileIdentifier, name);
if (resCheck.code !== 200) {
return resCheck;
}
let uploadedSize = 0;
let uploadProgress = 0;
for (const { index, chunk } of fileChunks) {
const chunksIndex = `${index}`;
// 跳过已上传块
if (resCheck.data.includes(chunksIndex)) {
continue;
}
// 上传数据块
const formData = new FormData();
formData.append('file', chunk, name);
formData.append('index', chunksIndex);
formData.append('identifier', fileIdentifier);
const resUpload = await chunkUpload(formData);
if (resUpload.code === 200) {
uploadedSize += chunk.size;
uploadProgress = (uploadedSize / size) * 100;
console.log(`上传进度:${uploadProgress}%`);
} else {
// 上传失败处理
break;
}
}
// 上传数据完整后合并数据块
if (uploadedSize === size) {
return await chunkMerge(fileIdentifier, name, subPath);
}
return { code: 500, msg: '上传出错,请重试' };
}
/**
* 切片文件检查
* @param identifier 文件标识
* @param fileName 原文件名称
* @returns object
*/
export function chunkCheck(identifier: string, fileName: string) {
return request({
url: '/file/chunkCheck',
method: 'post',
data: { identifier, fileName },
});
}
/**
* 切片文件合并
* @param identifier 文件标识
* @param fileName 原文件名称
* @param subPath 文件归属
* @returns object
*/
export function chunkMerge(
identifier: string,
fileName: string,
subPath: string = 'default'
) {
return request({
url: '/file/chunkMerge',
method: 'post',
data: { identifier, fileName, subPath },
});
}
/**
* 切片文件上传
* @param data 表单数据对象
* @returns object
*/
export function chunkUpload(data: FormData) {
return request({
url: '/file/chunkUpload',
method: 'post',
data,
dataType: 'form-data',
});
}