对接口,完整PC页面
This commit is contained in:
parent
161d66f3f7
commit
99acbd797b
@ -5,6 +5,7 @@ import {md5Hex} from "./CryptoUtils";
|
||||
import {User} from "../entities/User";
|
||||
import {Auth} from "../entities/Auth";
|
||||
import {File} from "../entities/File";
|
||||
import {SearchType} from "../entities/SearchType.ts";
|
||||
|
||||
export const baseUrl = 'http://localhost:8081';
|
||||
|
||||
@ -44,12 +45,24 @@ axios.interceptors.response.use(function (response) {
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
/**
|
||||
* 登录接口
|
||||
* @param username 用户名
|
||||
* @param password 密码(未加密的)
|
||||
*/
|
||||
export const login = (username: string, password: string) => {
|
||||
return instance.post<Result<User>>("/api/user/login", {
|
||||
name: username,
|
||||
password: md5Hex(password)
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 注册接口
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param auth 注册的权限(Auth.user或Auth.admin)
|
||||
* @param verifyCode 注册管理员所需的验证码(若注册的权限为Auth.user则无需填写)
|
||||
*/
|
||||
export const register = (username: string, password: string, auth: Auth, verifyCode?: string) => {
|
||||
return instance.post<Result<User>>("/api/user/register", {
|
||||
name: username,
|
||||
@ -58,13 +71,26 @@ export const register = (username: string, password: string, auth: Auth, verifyC
|
||||
verifyCode: verifyCode,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取验证码(只能以管理员用户运行,后端会验签)
|
||||
*/
|
||||
export const generatorVerifyCode = () => {
|
||||
return instance.get<Result<string>>("/api/user/verifyCode")
|
||||
}
|
||||
|
||||
// 获取文件
|
||||
/**
|
||||
* 获取所有文件
|
||||
* @param page 页数
|
||||
* @param num 一页多少文件
|
||||
*/
|
||||
export const getAllFiles = (page: number, num: number) => {
|
||||
return instance.get<PageResult<File>>("/api/file/getAll", {params: {num, page}});
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
/**
|
||||
* 上传文件接口
|
||||
* @param options 上传选项(会在el-upload的http-request方法调用时传入)
|
||||
* @param controller 取消控制器(自己创建后传入)
|
||||
*/
|
||||
export const upload = (options: UploadRequestOptions, controller: AbortController) => {
|
||||
const param = new FormData();
|
||||
param.append("file", options.file);
|
||||
@ -81,4 +107,35 @@ export const upload = (options: UploadRequestOptions, controller: AbortControlle
|
||||
},
|
||||
signal: controller.signal
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取下载链接
|
||||
* @param id 文件id
|
||||
*/
|
||||
export const getLink = (id: number) => {
|
||||
return instance.get<Result<string>>("/api/file/link", {params: {id}});
|
||||
}
|
||||
/**
|
||||
* 删除文件
|
||||
* @param id 文件id
|
||||
*/
|
||||
export const remove = (id: number) => {
|
||||
return instance.post<Result<boolean>>("/api/file/remove", {id});
|
||||
}
|
||||
/**
|
||||
* 搜索
|
||||
* @param page 页数
|
||||
* @param num 一页多少文件
|
||||
* @param searchType 搜索类型
|
||||
* @param data 搜索数据
|
||||
*/
|
||||
export const search = (page: number, num: number, searchType: SearchType, data: string) => {
|
||||
return instance.get<PageResult<File>>("/api/file/search", {params: {page, num, searchType, data}});
|
||||
}
|
||||
/**
|
||||
* 获取访问情况
|
||||
* @param count 获取的天数
|
||||
*/
|
||||
export const getAccessInformation = (count: number) => {
|
||||
return instance.get<File[]>("/api/access/get", {params: {count}});
|
||||
}
|
@ -1,3 +1,13 @@
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
export enum Auth {
|
||||
user, admin
|
||||
/**
|
||||
* 普通用户
|
||||
*/
|
||||
USER,
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN
|
||||
}
|
@ -1,10 +1,37 @@
|
||||
/**
|
||||
* 文件类
|
||||
*/
|
||||
export interface File {
|
||||
/**
|
||||
* 下载数
|
||||
*/
|
||||
downloadCount: number;
|
||||
/**
|
||||
* 文件hash(sha512)
|
||||
*/
|
||||
hash: string;
|
||||
/**
|
||||
* 文件id
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 文件大小(字节为单位)
|
||||
*/
|
||||
size: number;
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* 上传时间
|
||||
*/
|
||||
uploadTime: string;
|
||||
/**
|
||||
* 上传者名称
|
||||
*/
|
||||
uploaderName: string;
|
||||
}
|
@ -1,7 +1,19 @@
|
||||
import {Auth} from "./Auth";
|
||||
|
||||
/**
|
||||
* 用户类
|
||||
*/
|
||||
export interface User {
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
auth: Auth;
|
||||
}
|
@ -243,6 +243,7 @@ const parserByteSize = (byte: number): string => {
|
||||
// 处理当前页变化
|
||||
const HandleCurrentChange = (val: number) => {
|
||||
CurrentPage.value = val;
|
||||
showAllFiles();
|
||||
};
|
||||
|
||||
// TODO: 右侧访问量统计与上传文件
|
||||
|
Loading…
x
Reference in New Issue
Block a user