对接口,完整PC页面

This commit is contained in:
MoYi 2023-12-01 21:57:59 +08:00
parent 161d66f3f7
commit 99acbd797b
5 changed files with 111 additions and 4 deletions

View File

@ -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}});
}

View File

@ -1,3 +1,13 @@
/**
*
*/
export enum Auth {
user, admin
/**
*
*/
USER,
/**
*
*/
ADMIN
}

View File

@ -1,10 +1,37 @@
/**
*
*/
export interface File {
/**
*
*/
downloadCount: number;
/**
* hashsha512
*/
hash: string;
/**
* id
*/
id: number;
/**
*
*/
name: string;
/**
*
*/
size: number;
/**
*
*/
type: string;
/**
*
*/
uploadTime: string;
/**
*
*/
uploaderName: string;
}

View File

@ -1,7 +1,19 @@
import {Auth} from "./Auth";
/**
*
*/
export interface User {
/**
* id
*/
id: string
/**
*
*/
name: string;
/**
*
*/
auth: Auth;
}

View File

@ -243,6 +243,7 @@ const parserByteSize = (byte: number): string => {
//
const HandleCurrentChange = (val: number) => {
CurrentPage.value = val;
showAllFiles();
};
// TODO: 访