feat: optional preview image upload in publish modal
This commit is contained in:
@@ -222,15 +222,27 @@ const PageMarket = {
|
||||
_upload() {
|
||||
if (!this._marketToken) { Toast.show('请先登录', 'error'); return; }
|
||||
const overlay = document.createElement('div'); overlay.className = 'modal-overlay';
|
||||
overlay.innerHTML = '<div class="modal" style="min-width:480px;max-width:520px;padding:24px"><h3 style="font-size:18px;font-weight:600;margin-bottom:4px">发布作品</h3><p style="font-size:12px;color:var(--text-secondary);margin-bottom:18px">选择要发布的仪表盘或场景</p><button id="pub-file-btn" class="btn btn-primary btn-sm" style="width:100%;margin-bottom:10px">📁 选择文件 (.tsd / .tss)</button><div style="font-size:13px;color:var(--text-tertiary);margin:10px 0;text-align:center">— 或从本地选择 —</div><div id="pub-local-list" style="max-height:300px;overflow-y:auto">加载中...</div></div>';
|
||||
overlay.innerHTML = '<div class="modal" style="min-width:480px;max-width:520px;padding:24px"><h3 style="font-size:18px;font-weight:600;margin-bottom:4px">发布作品</h3><p style="font-size:12px;color:var(--text-secondary);margin-bottom:18px">选择要发布的仪表盘或场景</p><div style="margin-bottom:12px"><label class="switch-label" style="font-size:13px"><input type="checkbox" id="pub-preview-toggle"><span class="switch-track"></span> 上传预览图</label><span id="pub-preview-file" style="display:none;margin-left:8px;font-size:12px;color:var(--text-tertiary)"></span></div><button id="pub-file-btn" class="btn btn-primary btn-sm" style="width:100%;margin-bottom:10px">📁 选择文件 (.tsd / .tss)</button><div style="font-size:13px;color:var(--text-tertiary);margin:10px 0;text-align:center">— 或从本地选择 —</div><div id="pub-local-list" style="max-height:300px;overflow-y:auto">加载中...</div></div>';
|
||||
document.body.appendChild(overlay);
|
||||
overlay.addEventListener('click', (e) => { if (e.target === overlay) overlay.remove(); });
|
||||
|
||||
let previewFile = null;
|
||||
overlay.querySelector('#pub-preview-toggle').addEventListener('change', function() {
|
||||
if (this.checked) {
|
||||
const inp = document.createElement('input'); inp.type = 'file'; inp.accept = 'image/*';
|
||||
inp.style.display = 'none'; inp.id = 'pub-preview-input';
|
||||
inp.onchange = function() { previewFile = this.files[0]; const el = document.getElementById('pub-preview-file'); if(el){el.textContent=previewFile?previewFile.name:'';el.style.display=previewFile?'':'none'} };
|
||||
document.body.appendChild(inp); inp.click();
|
||||
} else { previewFile=null; const o=document.getElementById('pub-preview-input');if(o)o.remove(); const el=document.getElementById('pub-preview-file');if(el)el.style.display='none' }
|
||||
});
|
||||
|
||||
overlay.querySelector('#pub-file-btn').addEventListener('click', () => {
|
||||
const input = document.createElement('input'); input.type = 'file'; input.accept = '.tsd,.tss';
|
||||
input.onchange = async (e) => {
|
||||
const file = e.target.files[0]; if (!file) return;
|
||||
const isTss = file.name.endsWith('.tss');
|
||||
const fd = new FormData(); fd.append('file', file); fd.append('token', this._marketToken);
|
||||
if (previewFile) fd.append('preview', previewFile);
|
||||
const res = await fetch(isTss ? '/api/market/scenes/upload' : '/api/market/upload', { method: 'POST', body: fd });
|
||||
const data = await res.json();
|
||||
Toast.show(data.error ? '失败: '+data.error : '发布成功', data.error ? 'error' : 'success');
|
||||
|
||||
Reference in New Issue
Block a user