feat: 更新蓝牙体重秤小程序原型页面及后台管理页面

This commit is contained in:
liuyunqin
2026-07-17 17:28:24 +08:00
parent 6c6e92219a
commit 8a96ead2c8
7 changed files with 674 additions and 235 deletions
+21 -7
View File
@@ -122,11 +122,25 @@ if (title) {
if (filePath) {
document.getElementById('doc-path').textContent = filePath;
/* 用绝对路径(/ 开头),避免 <base href="../"> 在不同浏览器中解析不一致 */
fetch('/' + filePath)
.then(res => {
if (!res.ok) throw new Error('文件未找到 (' + res.status + ')');
var fetchUrl = '/' + filePath;
function tryFetch(url, fallbackUrl) {
return fetch(url).then(function(res) {
if (!res.ok) throw new Error('HTTP ' + res.status);
return res.text();
})
}).catch(function(err) {
/* 主路径失败 → 尝试去掉开头的 / 重新请求 */
if (fallbackUrl && url !== fallbackUrl) {
return fetch(fallbackUrl).then(function(res) {
if (!res.ok) throw new Error('HTTP ' + res.status + ' (fallback)');
return res.text();
});
}
throw err;
});
}
tryFetch(fetchUrl, filePath)
.then(md => {
/* 检测是否为自带 HTML 结构的文件(如共性需求说明.md) */
const isRawHtml = /^\s*<(?:style|div|!doctype|html)/i.test(md);
@@ -227,9 +241,9 @@ if (filePath) {
}
}
})
.catch(err => {
document.getElementById('content').innerHTML = '<div class="loading error">加载失败:' + err.message + '<br><small style="color:var(--text-placeholder);margin-top:8px;display:block">请确认文件路径:' + filePath + '</small></div>';
});
.catch(err => {
document.getElementById('content').innerHTML = '<div class="loading error">加载失败:' + err.message + '<br><small style="color:var(--text-placeholder);margin-top:8px;display:block">📁 文件路径:' + filePath + '<br>🔗 请求地址:' + fetchUrl + '<br>💡 请确认服务器已启动(双击 启动服务器.bat),且文件路径正确</small></div>';
});
} else {
document.getElementById('content').innerHTML = '<div class="loading">未指定文件路径</div>';
}