diff --git a/client/src/App.vue b/client/src/App.vue index 0fa7082..596e059 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,37 +1,50 @@ \ No newline at end of file + +const route = useRoute() + +// Check if current route is Admin or Login page +const isAdminOrLogin = computed(() => { + const path = route.path + return path.startsWith('/admin') || path === '/login' +}) + diff --git a/client/src/components/admin/AdminLayout.vue b/client/src/components/admin/AdminLayout.vue index d8da94b..9470e13 100644 --- a/client/src/components/admin/AdminLayout.vue +++ b/client/src/components/admin/AdminLayout.vue @@ -1,108 +1,156 @@ \ No newline at end of file +/* Scoped styles replaced by Tailwind classes */ + diff --git a/client/src/pages/Login.vue b/client/src/pages/Login.vue index eeb7462..76b02a3 100644 --- a/client/src/pages/Login.vue +++ b/client/src/pages/Login.vue @@ -1,41 +1,103 @@ @@ -55,42 +117,37 @@ const form = ref({ }) const error = ref('') +const isLoading = ref(false) const handleLogin = async () => { + isLoading.value = true + error.value = '' + try { const response = await login(form.value) // 保存token到本地存储 localStorage.setItem('token', response.token) localStorage.setItem('user', JSON.stringify(response.user)) - toast.showToast('登录成功', 'success') + toast.showToast('欢迎回来,管理员', 'success') // 登录成功后重定向到管理后台 router.push('/admin') } catch (err: any) { error.value = err.response?.data?.error || '登录失败,请检查用户名和密码' toast.showToast('登录失败', 'error') + } finally { + isLoading.value = false } } diff --git a/client/src/pages/admin/PostForm.vue b/client/src/pages/admin/PostForm.vue index 4318ba3..c82b015 100644 --- a/client/src/pages/admin/PostForm.vue +++ b/client/src/pages/admin/PostForm.vue @@ -1,108 +1,132 @@ @@ -188,18 +212,18 @@ const handleSubmit = async () => { if (isEditing.value) { // Update existing post await updatePost(route.params.id as string, form) - toast.success('文章更新成功') + toast.showToast('文章更新成功', 'success') } else { // Create new post await createPost(form) - toast.success('文章创建成功') + toast.showToast('文章创建成功', 'success') } // Redirect to posts list router.push('/admin/posts') } catch (error: any) { console.error('Error submitting form:', error) - toast.error(error.message || (isEditing.value ? '更新文章失败' : '创建文章失败')) + toast.showToast(error.message || (isEditing.value ? '更新文章失败' : '创建文章失败'), 'error') } finally { isSubmitting.value = false } @@ -227,159 +251,24 @@ onMounted(async () => { form.isPublished = post.isPublished === 1 ? 1 : 0 } catch (error: any) { console.error('Failed to fetch post data:', error) - toast.error('加载文章数据失败: ' + (error.message || '未知错误')) + toast.showToast('加载文章数据失败: ' + (error.message || '未知错误'), 'error') } } }) \ No newline at end of file + diff --git a/client/src/pages/admin/Posts.vue b/client/src/pages/admin/Posts.vue index 76f825e..d4b19d2 100644 --- a/client/src/pages/admin/Posts.vue +++ b/client/src/pages/admin/Posts.vue @@ -1,51 +1,60 @@ @@ -65,7 +74,7 @@ const fetchPosts = async () => { posts.value = await getAdminPosts() } catch (error) { console.error('Error fetching posts:', error) - toast.error('获取文章列表失败') + toast.showToast('获取文章列表失败', 'error') } } @@ -73,11 +82,11 @@ const deletePost = async (id: number) => { if (confirm('确定要删除这篇文章吗?')) { try { await deletePostApi(id) - toast.success('文章删除成功') + toast.showToast('文章删除成功', 'success') fetchPosts() } catch (error) { console.error('Error deleting post:', error) - toast.error('删除文章失败') + toast.showToast('删除文章失败', 'error') } } } @@ -88,147 +97,5 @@ onMounted(() => { \ No newline at end of file +/* Scoped styles removed, using Tailwind classes */ + diff --git a/client/src/pages/admin/Settings.vue b/client/src/pages/admin/Settings.vue index 7c1d8e6..ac42182 100644 --- a/client/src/pages/admin/Settings.vue +++ b/client/src/pages/admin/Settings.vue @@ -1,81 +1,101 @@