diff --git a/src/components/AdminPage.vue b/src/components/AdminPage.vue index 9226ef5..97d9476 100644 --- a/src/components/AdminPage.vue +++ b/src/components/AdminPage.vue @@ -1,4 +1,175 @@ -Admin placeholder + + + + + ← 返回 + 用户管理 + 退出登录 + + + + 新建用户 + + + + + 普通用户 + 管理员 + + 创建 + + {{ error }} + + + + 所有用户 + + + + 用户名 + 角色 + 创建时间 + + + + + + {{ u.username }} + {{ u.role === 'admin' ? '管理员' : '普通用户' }} + {{ new Date(u.createdAt).toLocaleDateString('zh-CN') }} + + 删除 + + + + + + + + + diff --git a/src/components/BookListPage.test.ts b/src/components/BookListPage.test.ts index 898e987..45fe3a0 100644 --- a/src/components/BookListPage.test.ts +++ b/src/components/BookListPage.test.ts @@ -5,6 +5,10 @@ import * as booksApi from '../services/booksApi' import BookListPage from './BookListPage.vue' vi.mock('../services/booksApi') +vi.mock('../composables/useAuth', () => ({ + useAuth: () => ({ user: { value: null }, logout: vi.fn() }), + authedFetch: vi.fn(), +})) describe('BookListPage', () => { beforeEach(() => { diff --git a/src/components/BookListPage.vue b/src/components/BookListPage.vue index 38d39c9..a4b3e49 100644 --- a/src/components/BookListPage.vue +++ b/src/components/BookListPage.vue @@ -2,10 +2,12 @@ import { onMounted, ref } from 'vue' import * as booksApi from '../services/booksApi' import type { BookSummary } from '../services/booksApi' +import { useAuth } from '../composables/useAuth' type LoadStatus = 'loading' | 'loaded' | 'error' -const emit = defineEmits<{ open: [id: string] }>() +const emit = defineEmits<{ open: [id: string]; admin: [] }>() +const { user, logout } = useAuth() const books = ref([]) const loadStatus = ref('loading') @@ -102,7 +104,13 @@ async function removeBook(book: BookSummary): Promise { - 教学设计 + + 教学设计 + + 用户管理 + 退出登录 + + @@ -143,3 +151,21 @@ async function removeBook(book: BookSummary): Promise { + +
{{ error }}