diff --git a/admin/index.html b/admin/index.html
new file mode 100644
index 0000000..c5ddaca
--- /dev/null
+++ b/admin/index.html
@@ -0,0 +1,309 @@
+
+
+
+ ').html(poem.poem_information).text();
+ // 截取内容预览
+ const contentPreview = content.length > 50 ? content.substring(0, 50) + '...' : content;
+
+ $('#poemsList').append(`
+
+ ${poem.poem_id} |
+ ${poem.poem_name} |
+ ${poem.author_name || '未知'} |
+ ${poem.givelike || 0} |
+ ${poem.collection || 0} |
+
+
+
+
+ |
+
+ `);
+ });
+ },
+ error: handleAjaxError
+ });
+}
+
+// 查看诗词详情
+function viewPoem(poemId) {
+ $.ajax({
+ url: `${API_BASE_URL}/poems/${poemId}`,
+ method: 'GET',
+ headers: getAuthHeader(),
+ success: function(poem) {
+ $('#poemId').val(poem.poem_id);
+ $('#title').val(poem.poem_name);
+ $('#author').val(poem.author_name);
+ $('#content').val(poem.poem_information.replace(/<[^>]+>/g, ''));
+ $('#explain').val(poem.explain);
+
+ // 设置表单为只读
+ $('#poemForm input, #poemForm textarea').prop('readonly', true);
+ $('#savePoem').hide();
+
+ $('#poemModal').modal('show');
+ },
+ error: handleAjaxError
+ });
+}
+
+// 编辑诗词
+function editPoem(poemId) {
+ $.ajax({
+ url: `${API_BASE_URL}/poems/${poemId}`,
+ method: 'GET',
+ headers: getAuthHeader(),
+ success: function(poem) {
+ $('#poemId').val(poem.poem_id);
+ $('#title').val(poem.poem_name);
+ $('#author').val(poem.author_name);
+ $('#content').val(poem.poem_information.replace(/<[^>]+>/g, ''));
+ $('#explain').val(poem.explain);
+
+ // 设置表单可编辑
+ $('#poemForm input, #poemForm textarea').prop('readonly', false);
+ $('#savePoem').show();
+
+ $('#poemModal').modal('show');
+ },
+ error: handleAjaxError
+ });
+}
+
+function savePoem() {
+ const poemId = $('#poemId').val();
+ const poemData = {
+ title: $('#title').val(),
+ author: $('#author').val(),
+ content: $('#content').val()
+ };
+
+ const url = poemId ?
+ `${API_BASE_URL}/poems/${poemId}` :
+ `${API_BASE_URL}/poems`;
+ const method = poemId ? 'PUT' : 'POST';
+
+ $.ajax({
+ url: url,
+ method: method,
+ headers: {
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
+ },
+ data: poemData,
+ success: function() {
+ $('#poemModal').modal('hide');
+ loadPoems();
+ }
+ });
+}
+
+function editPoem(poemId) {
+ $.ajax({
+ url: `${API_BASE_URL}/poems/${poemId}`,
+ method: 'GET',
+ headers: {
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
+ },
+ success: function(poem) {
+ $('#poemId').val(poem.id);
+ $('#title').val(poem.title);
+ $('#author').val(poem.author);
+ $('#content').val(poem.content);
+ $('#poemModal').modal('show');
+ }
+ });
+}
+
+function deletePoem(poemId) {
+ if (confirm('确定要删除该诗词吗?')) {
+ $.ajax({
+ url: `${API_BASE_URL}/poems/${poemId}`,
+ method: 'DELETE',
+ headers: {
+ 'Authorization': `Bearer ${localStorage.getItem('token')}`
+ },
+ success: function() {
+ loadPoems();
+ }
+ });
+ }
+}
+
+function clearPoemForm() {
+ $('#poemId').val('');
+ $('#poemForm')[0].reset();
+}
+
+// Authentication functions
+function checkLoginStatus() {
+ const token = localStorage.getItem('adminToken');
+ if (!token) {
+ window.location.href = 'login.html';
+ return;
+ }
+
+ $.ajax({
+ url: `${API_BASE_URL}/admin/profile`,
+ method: 'GET',
+ headers: { 'Authorization': `Bearer ${token}` },
+ success: function(admin) {
+ $('#adminInfo').text(`欢迎,管理员`);
+ },
+ error: function() {
+ localStorage.removeItem('adminToken');
+ window.location.href = 'login.html';
+ }
+ });
+}
+
+function logout() {
+ localStorage.removeItem('adminToken');
+ window.location.href = 'login.html';
+}
+
+// Helper functions
+function getAuthHeader() {
+ return {
+ 'Authorization': `Bearer ${localStorage.getItem('adminToken')}`
+ };
+}
+
+function handleAjaxError(xhr) {
+ let message = '操作失败';
+ if (xhr.responseJSON && xhr.responseJSON.message) {
+ message += ':' + xhr.responseJSON.message;
+ }
+ alert(message);
+
+ if (xhr.status === 401) {
+ localStorage.removeItem('adminToken');
+ window.location.href = 'login.html';
+ }
+}
\ No newline at end of file
diff --git a/admin/js/login.js b/admin/js/login.js
new file mode 100644
index 0000000..926ac3c
--- /dev/null
+++ b/admin/js/login.js
@@ -0,0 +1,70 @@
+$(document).ready(function() {
+ const API_BASE_URL = 'http://localhost:3000/api';
+
+ // 检查是否已登录
+ const token = localStorage.getItem('adminToken');
+ if (token) {
+ $.ajax({
+ url: `${API_BASE_URL}/admin/profile`,
+ method: 'GET',
+ headers: {
+ 'Authorization': `Bearer ${token}`
+ },
+ success: function() {
+ window.location.href = 'index.html';
+ },
+ error: function() {
+ localStorage.removeItem('adminToken');
+ }
+ });
+ }
+
+ // 处理登录表单提交
+ $('#loginForm').submit(function(e) {
+ e.preventDefault();
+
+ const loginData = {
+ username: $('#username').val().trim(),
+ password: $('#password').val().trim()
+ };
+
+ if (!loginData.username || !loginData.password) {
+ $('#errorAlert').text('请填写用户名和密码').show();
+ return;
+ }
+
+ // 显示加载状态
+ $('#loginBtn').prop('disabled', true);
+ $('#loginBtn .spinner-border').removeClass('d-none');
+ $('#errorAlert').hide();
+
+ // 发送登录请求
+ $.ajax({
+ url: `${API_BASE_URL}/admin/login`,
+ method: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify({
+ admin_name: loginData.username || null,
+ admin_password: loginData.password || null,
+ role: 'admin' // 添加角色标识
+ }),
+ success: function(response) {
+ console.log('Login response:', response); // 添加响应日志
+ if (response && response.token) {
+ localStorage.setItem('adminToken', response.token);
+ window.location.href = 'index.html';
+ } else {
+ $('#errorAlert').text('登录失败:未获取到token').show();
+ }
+ },
+ error: function(xhr) {
+ let errorMessage = '登录失败';
+ if (xhr.responseJSON) {
+ console.error('Server error:', xhr.responseJSON);
+ errorMessage += ':' + (xhr.responseJSON.message || xhr.responseJSON.error || '未知错误');
+ }
+ $('#errorAlert').text(errorMessage).show();
+ }
+ });
+ });
+});
\ No newline at end of file
diff --git a/admin/login.html b/admin/login.html
new file mode 100644
index 0000000..0b70f7e
--- /dev/null
+++ b/admin/login.html
@@ -0,0 +1,48 @@
+
+
+
+
+
+
管理员登录 - 诗词管理系统
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file