feat: file viewer
This commit is contained in:
@@ -357,3 +357,65 @@
|
||||
transition: width 0.2s;
|
||||
}
|
||||
.total-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
|
||||
|
||||
/* Preview modal */
|
||||
.preview-modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 10000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.preview-modal[hidden] { display: none; }
|
||||
.preview-backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
backdrop-filter: blur(2px);
|
||||
}
|
||||
.preview-panel {
|
||||
position: relative;
|
||||
width: min(1100px, 92vw);
|
||||
height: min(820px, 88vh);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.preview-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--panel-2);
|
||||
}
|
||||
.preview-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
color: var(--text);
|
||||
font-size: 14px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.preview-actions { display: flex; gap: 6px; flex-shrink: 0; }
|
||||
.preview-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
background: var(--bg);
|
||||
overflow: auto;
|
||||
}
|
||||
.preview-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--text-dim);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ const batchBtn = $('batchBtn');
|
||||
const batchCount = $('batchCount');
|
||||
const batchDeleteBtn = $('batchDeleteBtn');
|
||||
const batchDeleteCount= $('batchDeleteCount');
|
||||
const previewModal = $('previewModal');
|
||||
const previewBackdrop= $('previewBackdrop');
|
||||
const previewTitle = $('previewTitle');
|
||||
const previewBody = $('previewBody');
|
||||
const previewClose = $('previewClose');
|
||||
const previewDownload= $('previewDownload');
|
||||
|
||||
// pending[i] = { id, file, xhr, status: 'pending'|'uploading'|'done'|'error'|'cancelled', progress, error }
|
||||
let pending = [];
|
||||
@@ -377,12 +383,14 @@ function fileRow(f) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="file-actions">
|
||||
<button class="icon-btn" title="预览" data-preview="${escapeHtml(f.filename)}">▷</button>
|
||||
<button class="icon-btn" title="复制链接" data-url="${escapeHtml(f.url)}">⎘</button>
|
||||
<a class="icon-btn" title="下载" href="${escapeHtml(f.url)}" download>↓</a>
|
||||
<button class="icon-btn danger" title="删除" data-delete="${escapeHtml(f.filename)}">✕</button>
|
||||
</div>
|
||||
`;
|
||||
div.querySelector('.file-check').addEventListener('change', e => onCheckChange(f.filename, e.target.checked));
|
||||
div.querySelector('[data-preview]').onclick = () => openPreview(f.filename, f.url);
|
||||
div.querySelector('[data-url]').onclick = () => copyToClipboard(location.origin + f.url);
|
||||
div.querySelector('[data-delete]').onclick = () => deleteFile(f.filename, div);
|
||||
return div;
|
||||
@@ -439,5 +447,58 @@ async function copyToClipboard(text) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Preview modal (依赖 CDN 加载的 FlyfishFileViewerWebFull 全局对象)
|
||||
// ---------------------------------------------------------------------------
|
||||
let previewViewer = null;
|
||||
|
||||
function openPreview(filename, url) {
|
||||
if (!window.FlyfishFileViewerWebFull) {
|
||||
toast('预览组件尚未加载完成, 请稍后再试', 'error');
|
||||
return;
|
||||
}
|
||||
previewTitle.textContent = filename;
|
||||
previewDownload.href = url;
|
||||
previewDownload.download = filename;
|
||||
previewBody.innerHTML = '<div class="preview-loading">加载中...</div>';
|
||||
previewModal.hidden = false;
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
// 卸载上一个实例, 防内存泄漏
|
||||
if (previewViewer && typeof previewViewer.destroy === 'function') {
|
||||
try { previewViewer.destroy(); } catch {}
|
||||
}
|
||||
previewViewer = null;
|
||||
|
||||
// mountViewer 接收 element 或 selector; 用容器 id 保证重入安全
|
||||
try {
|
||||
previewViewer = window.FlyfishFileViewerWebFull.mountViewer(previewBody, {
|
||||
url,
|
||||
options: {
|
||||
theme: 'dark',
|
||||
toolbar: { position: 'bottom-right' },
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
previewBody.innerHTML = `<div class="preview-loading">预览失败: ${escapeHtml(e && e.message || 'unknown')}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function closePreview() {
|
||||
previewModal.hidden = true;
|
||||
document.body.style.overflow = '';
|
||||
if (previewViewer && typeof previewViewer.destroy === 'function') {
|
||||
try { previewViewer.destroy(); } catch {}
|
||||
}
|
||||
previewViewer = null;
|
||||
previewBody.innerHTML = '';
|
||||
}
|
||||
|
||||
previewClose.addEventListener('click', closePreview);
|
||||
previewBackdrop.addEventListener('click', closePreview);
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape' && !previewModal.hidden) closePreview();
|
||||
});
|
||||
|
||||
// formatRemain / isAlmostExpired / iconFor / formatSize / formatTime / escapeHtml
|
||||
// 见 helpers.js; 倒计时 setInterval 也在 helpers.js 中启动
|
||||
|
||||
@@ -62,6 +62,22 @@
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<!-- 文件预览弹窗 (CDN 资源经后端 /file-viewer/*filepath 缓存代理, 避免运行时 unpkg 依赖) -->
|
||||
<div class="preview-modal" id="previewModal" hidden>
|
||||
<div class="preview-backdrop" id="previewBackdrop"></div>
|
||||
<div class="preview-panel">
|
||||
<div class="preview-header">
|
||||
<span class="preview-title" id="previewTitle"></span>
|
||||
<div class="preview-actions">
|
||||
<a class="icon-btn" id="previewDownload" title="下载" download>↓</a>
|
||||
<button class="icon-btn" id="previewClose" title="关闭" aria-label="关闭预览">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="preview-body" id="previewBody"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/file-viewer/dist/flyfish-file-viewer-web-full.iife.js"></script>
|
||||
<script src="/static/app.js"></script>
|
||||
<script src="/static/helpers.js"></script>
|
||||
<script src="/static/batch.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user