update
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { router } from "./router"
|
import { router } from "./router"
|
||||||
import type { TutorialIn } from "./utils/type"
|
import type { TutorialIn } from "./utils/type"
|
||||||
import { STORAGE_KEY } from "./utils/const"
|
import { BASE_URL, STORAGE_KEY } from "./utils/const"
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
baseURL:
|
baseURL: BASE_URL,
|
||||||
import.meta.env.MODE === "development"
|
|
||||||
? "http://localhost:8000/api"
|
|
||||||
: "https://web.xuyue.cc/api",
|
|
||||||
xsrfCookieName: "xsrfCookieName",
|
xsrfCookieName: "xsrfCookieName",
|
||||||
xsrfHeaderName: "X-CSRFTOKEN",
|
xsrfHeaderName: "X-CSRFTOKEN",
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
|
|||||||
@@ -20,11 +20,12 @@
|
|||||||
import { computed, h } from "vue"
|
import { computed, h } from "vue"
|
||||||
import { useMessage } from "naive-ui"
|
import { useMessage } from "naive-ui"
|
||||||
import { Icon } from "@iconify/vue"
|
import { Icon } from "@iconify/vue"
|
||||||
import { user, authed, roleNormal } from "../store/user"
|
import { user, authed, roleNormal, roleSuper } from "../store/user"
|
||||||
import { loginModal } from "../store/modal"
|
import { loginModal } from "../store/modal"
|
||||||
import { Account } from "../api"
|
import { Account } from "../api"
|
||||||
import { Role } from "../utils/type"
|
import { Role } from "../utils/type"
|
||||||
import { router } from "../router"
|
import { router } from "../router"
|
||||||
|
import { ADMIN_URL } from "../utils/const"
|
||||||
|
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
|
|
||||||
@@ -38,6 +39,15 @@ const menu = computed(() => [
|
|||||||
icon: "streamline-emojis:robot-face-1",
|
icon: "streamline-emojis:robot-face-1",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "管理",
|
||||||
|
key: "admin",
|
||||||
|
show: roleSuper.value,
|
||||||
|
icon: () =>
|
||||||
|
h(Icon, {
|
||||||
|
icon: "skill-icons:django",
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "退出",
|
label: "退出",
|
||||||
key: "logout",
|
key: "logout",
|
||||||
@@ -53,6 +63,9 @@ function clickMenu(name: string) {
|
|||||||
case "dashboard":
|
case "dashboard":
|
||||||
router.push({ name: "tutorial" })
|
router.push({ name: "tutorial" })
|
||||||
break
|
break
|
||||||
|
case "admin":
|
||||||
|
window.open(ADMIN_URL)
|
||||||
|
break
|
||||||
case "logout":
|
case "logout":
|
||||||
handleLogout()
|
handleLogout()
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<n-input v-model:value="query.username" clearable />
|
<n-input v-model:value="query.username" clearable />
|
||||||
</div>
|
</div>
|
||||||
<n-button @click="init">搜索</n-button>
|
<n-button @click="init">搜索</n-button>
|
||||||
<n-button>新建一个</n-button>
|
<n-button @click="goDjangoUserAdd">新建一个</n-button>
|
||||||
<n-button>批量新建</n-button>
|
<n-button>批量新建</n-button>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
<n-flex>
|
<n-flex>
|
||||||
@@ -18,7 +18,8 @@ import { onMounted, reactive, ref } from "vue"
|
|||||||
import { Account } from "../api"
|
import { Account } from "../api"
|
||||||
import { parseTime } from "../utils/helper"
|
import { parseTime } from "../utils/helper"
|
||||||
import type { DataTableColumn } from "naive-ui"
|
import type { DataTableColumn } from "naive-ui"
|
||||||
import type { User } from "../utils/type"
|
import { getRole, type User } from "../utils/type"
|
||||||
|
import { ADMIN_URL } from "../utils/const"
|
||||||
|
|
||||||
const data = ref([])
|
const data = ref([])
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
@@ -43,11 +44,14 @@ const columns: DataTableColumn<User>[] = [
|
|||||||
title: "上次登录",
|
title: "上次登录",
|
||||||
key: "last_login",
|
key: "last_login",
|
||||||
render: (row) =>
|
render: (row) =>
|
||||||
row.last_login ? parseTime(row.last_login, "YYYY-MM-DD HH:mm:ss") : "从未登录",
|
row.last_login
|
||||||
|
? parseTime(row.last_login, "YYYY-MM-DD HH:mm:ss")
|
||||||
|
: "从未登录",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "权限",
|
title: "权限",
|
||||||
key: "role",
|
key: "role",
|
||||||
|
render: (row) => getRole(row.role),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "选项",
|
title: "选项",
|
||||||
@@ -55,6 +59,10 @@ const columns: DataTableColumn<User>[] = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
function goDjangoUserAdd() {
|
||||||
|
window.open(`${ADMIN_URL}/account/user/add/`)
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
data.value = await Account.list(query)
|
data.value = await Account.list(query)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ export const user = reactive({
|
|||||||
export const authed = computed(() => !!user.username)
|
export const authed = computed(() => !!user.username)
|
||||||
export const roleNormal = computed(() => user.role === Role.Normal)
|
export const roleNormal = computed(() => user.role === Role.Normal)
|
||||||
export const roleAdmin = computed(() => user.role === Role.Admin)
|
export const roleAdmin = computed(() => user.role === Role.Admin)
|
||||||
export const roleSuper = computed(() => user.role !== Role.Super)
|
export const roleSuper = computed(() => user.role === Role.Super)
|
||||||
|
|||||||
@@ -36,3 +36,13 @@ export const STORAGE_KEY = {
|
|||||||
TAB: "web-tab",
|
TAB: "web-tab",
|
||||||
FONTSIZE: "web-fontsize",
|
FONTSIZE: "web-fontsize",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ADMIN_URL =
|
||||||
|
import.meta.env.MODE === "development"
|
||||||
|
? "http://localhost:8000/admin"
|
||||||
|
: "https://web.xuyue.cc/admin"
|
||||||
|
|
||||||
|
export const BASE_URL =
|
||||||
|
import.meta.env.MODE === "development"
|
||||||
|
? "http://localhost:8000/api"
|
||||||
|
: "https://web.xuyue.cc/api"
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ export enum Role {
|
|||||||
Normal = "normal",
|
Normal = "normal",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRole(role: Role) {
|
||||||
|
return {
|
||||||
|
[Role.Super]: "超级管理员",
|
||||||
|
[Role.Admin]: "管理员",
|
||||||
|
[Role.Normal]: "普通用户",
|
||||||
|
}[role]
|
||||||
|
}
|
||||||
|
|
||||||
export interface TutorialSlim {
|
export interface TutorialSlim {
|
||||||
display: number
|
display: number
|
||||||
title: string
|
title: string
|
||||||
|
|||||||
Reference in New Issue
Block a user