feat: 管理后台补齐完整功能
- 页面切换卡片:数据大屏/数字孪生/AI 助手/媒体轮播 → MQTT navigate 控制所有大屏 - 立即播放:新增 POST /api/playlist/play(加入播放列表 + MQTT play_target), MediaScreen 监听 play_target 跳转并播放指定媒体 - 远程 URL 支持两种操作:添加到媒体库 / 加入播放列表 - 本地媒体卡片显示 FastAPI 输出 URL(/file/...)+ 一键复制 - 预览弹窗增加「立即播放」;新增 page-switch/media-url/copy-btn 样式
This commit is contained in:
+49
-4
@@ -55,6 +55,16 @@
|
||||
};
|
||||
} catch (err) { /* ignore */ }
|
||||
|
||||
/* ---------- 页面切换(MQTT 控制大屏) ---------- */
|
||||
document.querySelectorAll('[data-nav]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var page = btn.getAttribute('data-nav');
|
||||
post('/api/display/command', { action: 'navigate', params: { page: page } }, function () {
|
||||
toast('已切换大屏至「' + btn.textContent.trim() + '」');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/* ---------- 播放控制 ---------- */
|
||||
document.querySelectorAll('[data-control]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
@@ -150,23 +160,54 @@
|
||||
|
||||
/* ---------- 远程 URL ---------- */
|
||||
var btnAddUrl = document.getElementById('btnAddUrl');
|
||||
if (btnAddUrl) btnAddUrl.addEventListener('click', function () {
|
||||
var btnAddUrlPlay = document.getElementById('btnAddUrlPlay');
|
||||
function addUrlThen(play) {
|
||||
var inp = document.getElementById('urlInput');
|
||||
var url = (inp.value || '').trim();
|
||||
if (!url) { toast('请输入 URL', 'error'); return; }
|
||||
post('/api/media/add-url', { url: url }, function (d) {
|
||||
reload(d && d.duplicate ? 'URL 已存在于媒体库' : '已添加到媒体库');
|
||||
if (play) {
|
||||
post('/api/playlist/play', { path: url }, function () { reload('已加入并开始播放'); });
|
||||
} else {
|
||||
reload(d && d.duplicate ? 'URL 已存在于媒体库' : '已添加到媒体库');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (btnAddUrl) btnAddUrl.addEventListener('click', function () { addUrlThen(false); });
|
||||
if (btnAddUrlPlay) btnAddUrlPlay.addEventListener('click', function () { addUrlThen(true); });
|
||||
|
||||
/* ---------- 复制资源 URL(FastAPI 输出) ---------- */
|
||||
document.querySelectorAll('.copy-btn').forEach(function (btn) {
|
||||
btn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var url = btn.closest('.media-url').getAttribute('data-url') || '';
|
||||
var full = /^https?:\/\//.test(url) ? url : window.location.origin + url;
|
||||
var done = function () { toast('链接已复制'); };
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(full).then(done).catch(function () { fallbackCopy(full); done(); });
|
||||
} else {
|
||||
fallbackCopy(full); done();
|
||||
}
|
||||
});
|
||||
});
|
||||
function fallbackCopy(text) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = text; ta.style.position = 'fixed'; ta.style.opacity = '0';
|
||||
document.body.appendChild(ta); ta.select();
|
||||
try { document.execCommand('copy'); } catch (err) { /* ignore */ }
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
|
||||
/* ---------- 媒体操作(加入播放 / 移出 / 删除) ---------- */
|
||||
/* ---------- 媒体操作(立即播放 / 加入播放 / 移出 / 删除) ---------- */
|
||||
document.querySelectorAll('[data-action]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var card = btn.closest('.media-card');
|
||||
var path = card.getAttribute('data-path');
|
||||
var action = btn.getAttribute('data-action');
|
||||
if (action === 'add-playlist') {
|
||||
if (action === 'play-now') {
|
||||
post('/api/playlist/play', { path: path }, function () { toast('正在播放'); });
|
||||
} else if (action === 'add-playlist') {
|
||||
post('/api/playlist/add', { path: path }, function () { reload('已加入播放列表'); });
|
||||
} else if (action === 'remove-playlist') {
|
||||
post('/api/playlist/remove', { path: path }, function () { reload('已移出播放列表'); });
|
||||
@@ -217,6 +258,10 @@
|
||||
if (!current) return;
|
||||
post('/api/playlist/add', { path: current.path }, function () { closePreview(); reload('已加入播放列表'); });
|
||||
});
|
||||
document.getElementById('previewPlay').addEventListener('click', function () {
|
||||
if (!current) return;
|
||||
post('/api/playlist/play', { path: current.path }, function () { closePreview(); toast('正在播放'); });
|
||||
});
|
||||
document.getElementById('previewDelete').addEventListener('click', function () {
|
||||
if (!current) return;
|
||||
if (!window.confirm('确定删除该文件?')) return;
|
||||
|
||||
Reference in New Issue
Block a user