feat: 添加文档管理功能并优化样式
添加文档管理功能,包括文档展示区域和API接口 新增文档相关CSS样式,优化移动端显示 更新Go模块依赖版本
This commit is contained in:
63
script.js
63
script.js
@@ -1,11 +1,12 @@
|
||||
// 配置
|
||||
const ADMIN_PASSWORD = 'admin123'; // 管理员密码
|
||||
const API_BASE_URL = 'http://47.92.113.131:6903/api'; // 后端API基础URL
|
||||
const API_BASE_URL = 'http://localhost:6903/api'; // 后端API基础URL
|
||||
|
||||
// 初始化
|
||||
function init() {
|
||||
checkLoginStatus();
|
||||
loadAppList();
|
||||
getDoc();
|
||||
}
|
||||
|
||||
// 检查登录状态
|
||||
@@ -126,6 +127,11 @@ async function loadAppList() {
|
||||
downloadBtn.className = 'download-btn';
|
||||
downloadBtn.textContent = '下载';
|
||||
downloadBtn.onclick = () => downloadApp(app.id, app.fileName);
|
||||
|
||||
const deleteBtn = document.createElement('button');
|
||||
deleteBtn.className = 'download-btn';
|
||||
deleteBtn.textContent = '删除';
|
||||
deleteBtn.onclick = () => deleteApp(app.id);
|
||||
|
||||
const copyLinkBtn = document.createElement('button');
|
||||
copyLinkBtn.className = 'download-btn';
|
||||
@@ -140,6 +146,7 @@ async function loadAppList() {
|
||||
buttonsContainer.style.display = 'flex';
|
||||
buttonsContainer.style.gap = '10px';
|
||||
buttonsContainer.appendChild(downloadBtn);
|
||||
buttonsContainer.appendChild(deleteBtn);
|
||||
buttonsContainer.appendChild(copyLinkBtn);
|
||||
|
||||
appItem.appendChild(buttonsContainer);
|
||||
@@ -215,6 +222,13 @@ async function uploadApp() {
|
||||
}
|
||||
}
|
||||
|
||||
// 删除App
|
||||
function deleteApp(appId) {
|
||||
if (!confirm('如果确定删除此APP,请将矩阵 A = [[3,1,0],[1,2,1],[0,1,1]]的特征值、特征向量,并验证A是正定矩阵的解题步骤做出来,然后我也没做')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 下载App
|
||||
function downloadApp(appId, fileName) {
|
||||
try {
|
||||
@@ -266,5 +280,52 @@ function copyDirectLink(appId, fileName) {
|
||||
});
|
||||
}
|
||||
|
||||
async function getDocApi() {
|
||||
try {
|
||||
showLoading();
|
||||
|
||||
const docContent = document.getElementById('docContent');
|
||||
docContent.innerHTML = ``;
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/docs`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
timeout: 10000 // 10秒超时
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP错误!状态:${response.status}`);
|
||||
}
|
||||
|
||||
const docs = await response.json();
|
||||
|
||||
if (docs.length === 0) {
|
||||
docContent.innerHTML = '<p style="text-align: center;">暂无文档</p>';
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
const doc = docs[i];
|
||||
const docItem = document.createElement('div');
|
||||
docItem.className = 'doc-item';
|
||||
docItem.innerHTML = `
|
||||
<p>${doc.docBody}</p>
|
||||
`;
|
||||
docContent.appendChild(docItem);
|
||||
}
|
||||
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取文档失败:', error);
|
||||
docContent.innerHTML = '<p style="text-align: center;">获取文档失败:' + error.message + '</p>';
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 获取文档内容
|
||||
function getDoc() {
|
||||
getDocApi();
|
||||
}
|
||||
|
||||
// 页面加载完成后初始化
|
||||
window.onload = init;
|
||||
Reference in New Issue
Block a user