diff --git a/src/api/Requester.ts b/src/api/Requester.ts index 636c403..045ffc9 100644 --- a/src/api/Requester.ts +++ b/src/api/Requester.ts @@ -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>("/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>("/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>("/api/user/verifyCode") +} -// 获取文件 +/** + * 获取所有文件 + * @param page 页数 + * @param num 一页多少文件 + */ export const getAllFiles = (page: number, num: number) => { return instance.get>("/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>("/api/file/link", {params: {id}}); +} +/** + * 删除文件 + * @param id 文件id + */ +export const remove = (id: number) => { + return instance.post>("/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>("/api/file/search", {params: {page, num, searchType, data}}); +} +/** + * 获取访问情况 + * @param count 获取的天数 + */ +export const getAccessInformation = (count: number) => { + return instance.get("/api/access/get", {params: {count}}); } \ No newline at end of file diff --git a/src/entities/Auth.ts b/src/entities/Auth.ts index aead60d..ac1f7d0 100644 --- a/src/entities/Auth.ts +++ b/src/entities/Auth.ts @@ -1,3 +1,13 @@ +/** + * 用户类型 + */ export enum Auth { - user, admin + /** + * 普通用户 + */ + USER, + /** + * 管理员 + */ + ADMIN } \ No newline at end of file diff --git a/src/entities/File.ts b/src/entities/File.ts index 8db8964..2d1d5a1 100644 --- a/src/entities/File.ts +++ b/src/entities/File.ts @@ -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; } \ No newline at end of file diff --git a/src/entities/User.ts b/src/entities/User.ts index 1b2519a..3dec1f4 100644 --- a/src/entities/User.ts +++ b/src/entities/User.ts @@ -1,7 +1,19 @@ import {Auth} from "./Auth"; +/** + * 用户类 + */ export interface User { + /** + * 用户id + */ id: string + /** + * 用户名 + */ name: string; + /** + * 用户类型 + */ auth: Auth; } \ No newline at end of file diff --git a/src/views/AppPC.vue b/src/views/AppPC.vue index e55dc13..44a3a15 100644 --- a/src/views/AppPC.vue +++ b/src/views/AppPC.vue @@ -243,6 +243,7 @@ const parserByteSize = (byte: number): string => { // 处理当前页变化 const HandleCurrentChange = (val: number) => { CurrentPage.value = val; + showAllFiles(); }; // TODO: 右侧访问量统计与上传文件