diff --git a/package-lock.json b/package-lock.json index f3ec5dd..e7502c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "date-fns": "^2.29.3", "highlight.js": "^11.7.0", "naive-ui": "^2.34.3", + "normalize.css": "^8.0.1", "party-js": "^2.2.0", "pinia": "^2.0.33", "vue": "^3.2.47", @@ -2966,6 +2967,11 @@ "node": ">=0.10.0" } }, + "node_modules/normalize.css": { + "version": "8.0.1", + "resolved": "https://registry.npmmirror.com/normalize.css/-/normalize.css-8.0.1.tgz", + "integrity": "sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==" + }, "node_modules/npm-run-path": { "version": "4.0.1", "resolved": "https://registry.npmmirror.com/npm-run-path/-/npm-run-path-4.0.1.tgz", diff --git a/package.json b/package.json index fc59ec8..3a5489b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "date-fns": "^2.29.3", "highlight.js": "^11.7.0", "naive-ui": "^2.34.3", + "normalize.css": "^8.0.1", "party-js": "^2.2.0", "pinia": "^2.0.33", "vue": "^3.2.47", diff --git a/src/App.vue b/src/App.vue index 3b0aa83..18d08e8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,4 +1,5 @@ + + + + diff --git a/src/admin/contest/list.vue b/src/admin/contest/list.vue index e69de29..f592bf1 100644 --- a/src/admin/contest/list.vue +++ b/src/admin/contest/list.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/contest/problems.vue b/src/admin/contest/problems.vue index e69de29..b2d548a 100644 --- a/src/admin/contest/problems.vue +++ b/src/admin/contest/problems.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/problem/detail.vue b/src/admin/problem/detail.vue index e69de29..29fecb8 100644 --- a/src/admin/problem/detail.vue +++ b/src/admin/problem/detail.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/problem/list.vue b/src/admin/problem/list.vue index e69de29..49051ee 100644 --- a/src/admin/problem/list.vue +++ b/src/admin/problem/list.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/setting/announcement.vue b/src/admin/setting/announcement.vue new file mode 100644 index 0000000..7224603 --- /dev/null +++ b/src/admin/setting/announcement.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/setting/conf.vue b/src/admin/setting/conf.vue deleted file mode 100644 index e69de29..0000000 diff --git a/src/admin/setting/config.vue b/src/admin/setting/config.vue new file mode 100644 index 0000000..e68ae0d --- /dev/null +++ b/src/admin/setting/config.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/setting/user.vue b/src/admin/setting/user.vue deleted file mode 100644 index e69de29..0000000 diff --git a/src/admin/user/import.vue b/src/admin/user/import.vue new file mode 100644 index 0000000..0b9f1d9 --- /dev/null +++ b/src/admin/user/import.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/admin/user/list.vue b/src/admin/user/list.vue new file mode 100644 index 0000000..deb04e8 --- /dev/null +++ b/src/admin/user/list.vue @@ -0,0 +1,7 @@ + + + + + diff --git a/src/main.ts b/src/main.ts index 634709a..d7d2d96 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ router.beforeEach((to, from, next) => { if (to.matched.some((record) => record.meta.requiresAuth)) { if (!storage.get(STORAGE_KEY.AUTHED)) { toggleLogin(true) + next("/") } else { next() } diff --git a/src/routes.ts b/src/routes.ts index 58a120c..b25ba02 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,5 +1,7 @@ import { RouteRecordRaw } from "vue-router" +import { getProfile } from "./shared/api" import { loadChart } from "./shared/composables/chart" +import { USER_TYPE } from "./utils/constants" export const routes: RouteRecordRaw[] = [ { @@ -95,42 +97,80 @@ export const routes: RouteRecordRaw[] = [ { path: "/admin", component: () => import("~/shared/layout/admin.vue"), + meta: { requiresAuth: true }, + beforeEnter: async () => { + const res = await getProfile() + if (res.data.user.admin_type === USER_TYPE.REGULAR_USER) return "/" + }, children: [ - { path: "", component: () => import("admin/index.vue") }, - { path: "user", component: () => import("admin/setting/user.vue") }, - { path: "conf", component: () => import("admin/setting/conf.vue") }, - { path: "problems", component: () => import("admin/problem/list.vue") }, + { path: "", name: "home", component: () => import("admin/index.vue") }, + { + path: "config", + name: "config", + component: () => import("admin/setting/config.vue"), + }, + { + path: "announcement", + name: "announcement", + component: () => import("admin/setting/announcement.vue"), + }, + { + path: "user/list", + name: "user list", + component: () => import("admin/user/list.vue"), + }, + { + path: "user/import", + name: "user importing", + component: () => import("admin/user/import.vue"), + }, + { + path: "problem/list", + name: "problem list", + component: () => import("admin/problem/list.vue"), + }, { path: "problem/create", + name: "problem create", component: () => import("admin/problem/detail.vue"), }, { path: "problem/:problemID/edit", + name: "problem edit", component: () => import("admin/problem/detail.vue"), props: true, }, - { path: "contests", component: () => import("admin/contest/list.vue") }, + { + path: "contest/list", + name: "contest list", + component: () => import("admin/contest/list.vue"), + }, { path: "contest/create", + name: "contest create", component: () => import("admin/contest/detail.vue"), }, { path: "contest/:contestID/edit", + name: "contest edit", component: () => import("admin/contest/detail.vue"), props: true, }, { path: "contest/:contestID/problems", + name: "contest problems", component: () => import("admin/contest/detail.vue"), props: true, }, { path: "contest/:contestID/problem/create", + name: "contest problem create", component: () => import("admin/problem/detail.vue"), props: true, }, { path: "contest/:contestID/problem/:problemID/edit", + name: "contest problem edit", component: () => import("admin/problem/detail.vue"), props: true, }, diff --git a/src/shared/api.ts b/src/shared/api.ts index 348ebf3..9c76b0b 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -1,4 +1,5 @@ import http from "utils/http" +import { Profile } from "~/utils/types" export function login(data: { username: string; password: string }) { return http.post("login", data) @@ -9,5 +10,5 @@ export function logout() { } export function getProfile(username: string = "") { - return http.get("profile", { params: { username } }) + return http.get("profile", { params: { username } }) } diff --git a/src/shared/layout/admin.vue b/src/shared/layout/admin.vue index 5a3ff6c..b9620dc 100644 --- a/src/shared/layout/admin.vue +++ b/src/shared/layout/admin.vue @@ -1,34 +1,100 @@