first commit.

This commit is contained in:
2023-01-04 10:20:18 +08:00
commit 919fcf5ba9
39 changed files with 4196 additions and 0 deletions

129
src/utils/constants.ts Normal file
View File

@@ -0,0 +1,129 @@
export const JUDGE_STATUS = {
"-2": {
name: "Compile Error",
short: "CE",
color: "yellow",
type: "warning",
},
"-1": {
name: "Wrong Answer",
short: "WA",
color: "red",
type: "error",
},
"0": {
name: "Accepted",
short: "AC",
color: "green",
type: "success",
},
"1": {
name: "Time Limit Exceeded",
short: "TLE",
color: "red",
type: "error",
},
"2": {
name: "Time Limit Exceeded",
short: "TLE",
color: "red",
type: "error",
},
"3": {
name: "Memory Limit Exceeded",
short: "MLE",
color: "red",
type: "error",
},
"4": {
name: "Runtime Error",
short: "RE",
color: "red",
type: "error",
},
"5": {
name: "System Error",
short: "SE",
color: "red",
type: "error",
},
"6": {
name: "Pending",
color: "yellow",
type: "warning",
},
"7": {
name: "Judging",
color: "blue",
type: "info",
},
"8": {
name: "Partial Accepted",
short: "PAC",
color: "blue",
type: "info",
},
"9": {
name: "Submitting",
color: "yellow",
type: "warning",
},
};
export const CONTEST_STATUS = {
NOT_START: "1",
UNDERWAY: "0",
ENDED: "-1",
};
export const CONTEST_STATUS_REVERSE = {
"1": {
name: "Not Started",
color: "yellow",
},
"0": {
name: "Underway",
color: "green",
},
"-1": {
name: "Ended",
color: "red",
},
};
export const RULE_TYPE = {
ACM: "ACM",
OI: "OI",
};
export const CONTEST_TYPE = {
PUBLIC: "Public",
PRIVATE: "Password Protected",
};
export const USER_TYPE = {
REGULAR_USER: "Regular User",
ADMIN: "Admin",
SUPER_ADMIN: "Super Admin",
};
export const PROBLEM_PERMISSION = {
NONE: "None",
OWN: "Own",
ALL: "All",
};
export const STORAGE_KEY = {
AUTHED: "authed",
PROBLEM_CODE: "problemCode",
USER: "user",
};
export function buildProblemCodeKey(problemID: number, contestID = null) {
if (contestID) {
return `${STORAGE_KEY.PROBLEM_CODE}_${contestID}_${problemID}`;
}
return `${STORAGE_KEY.PROBLEM_CODE}_NaN_${problemID}`;
}
export const GOOGLE_ANALYTICS_ID = "UA-111499601-1";

14
src/utils/functions.ts Normal file
View File

@@ -0,0 +1,14 @@
export function getACRate(acCount: number, totalCount: number) {
let rate = totalCount === 0 ? 0.0 : ((acCount / totalCount) * 100).toFixed(2);
return `${rate}%`;
}
export function filterEmptyValue(object: any) {
let query: any = {};
Object.keys(object).forEach((key) => {
if (object[key] || object[key] === 0 || object[key] === false) {
query[key] = object[key];
}
});
return query;
}

26
src/utils/http.ts Normal file
View File

@@ -0,0 +1,26 @@
import axios from "axios";
const http = axios.create({
baseURL: "/api",
xsrfHeaderName: "X-CSRFToken",
xsrfCookieName: "csrftoken",
});
// TODO
http.interceptors.response.use(
(res) => {
if (res.data.error) {
// 若后端返回为登录则为session失效应退出当前登录用户
if (res.data.data.startsWith("Please login")) {
}
return Promise.reject(res.data);
} else {
return Promise.resolve(res.data);
}
},
(err) => {
return Promise.reject(err);
}
);
export default http;

21
src/utils/storage.ts Normal file
View File

@@ -0,0 +1,21 @@
const localStorage = window.localStorage;
export default {
set(key: string, value: any) {
localStorage.setItem(key, JSON.stringify(value));
},
get(key: string) {
const content = localStorage.getItem(key);
if (content) {
return JSON.parse(content);
} else {
return null;
}
},
remove(key: string) {
localStorage.removeItem(key);
},
clear() {
localStorage.clear();
},
};