/* v31a: ①功能胶囊移到输入框上方贴底横滑 ②底部"视频管理"=与市场同源三分类 */ (function () { 'use strict'; if (window.__mobV31A) return; window.__mobV31A = true; var API = 'https://api-gateway.duoweiying.cn'; function $(id) { return document.getElementById(id); } function uidV() { var u = null; try { u = JSON.parse(localStorage.getItem('user_info') || '{}'); } catch (e) {} return (u && (u.id || u.username)) || localStorage.getItem('user_id') || 'anonymous'; } function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); } function tip(t) { try { var o = $('v31tip'); if (o) o.remove(); var d = document.createElement('div'); d.id = 'v31tip'; d.style.cssText = 'position:fixed;left:50%;bottom:120px;transform:translateX(-50%);z-index:49000;background:#0f172a;color:#fff;font-size:13px;padding:9px 16px;border-radius:18px;max-width:84%;text-align:center;'; d.textContent = t; document.body.appendChild(d); setTimeout(function () { d.remove(); }, 2400); } catch (e) {} } /* ① 胶囊行移动到输入框上方(贴底,横向滑动;不再占对话顶部) */ function moveChips() { try { var nav = $('function-nav'); var area = document.querySelector('.input-area'); if (!nav || !area) return; if (nav._m31m) return; nav._m31m = true; area.parentNode.insertBefore(nav, area); nav.style.cssText = 'flex:none;display:flex!important;flex-wrap:nowrap!important;gap:8px;padding:6px 12px;overflow-x:auto!important;white-space:nowrap!important;background:#f8fafc;scrollbar-width:none;-webkit-overflow-scrolling:touch;'; var ch = nav.querySelectorAll('button'); for (var i = 0; i < ch.length; i++) { ch[i].style.flex = '0 0 auto'; ch[i].style.flexShrink = '0'; ch[i].style.whiteSpace = 'nowrap'; } } catch (e) {} } /* ===== WR-562k11 (2026-10-16): 直链归一 + 成片操作(播放/下载/分享/删除) ===== 背景: 成片直链字段是 video_url; 旧代码只读 url/file_path -> 播放器永不出现(“不能预览播放”); /static/ 在 console 域 403, 相对路径会被当作页面相对路径 404 = “假链接打不开”。 与后端 file_management._fm_public_url 同口径。 */ var OBS_PUB_V = 'https://categorized-assets-smart-center.obs.cn-east-3.myhuaweicloud.com'; function absV(u) { u = String(u || ''); if (!u) return ''; if (/^(https?:)?\/\//i.test(u) || /^data:/i.test(u) || /^blob:/i.test(u)) return u; if (u.charAt(0) === '/') { if (u.indexOf('/static/') === 0) return 'https://ai.duoweiying.cn' + u; return OBS_PUB_V + u; } return OBS_PUB_V + '/' + u.replace(/^\.?\//, ''); } function isVidV(u) { return /\.(mp4|webm|mov|m4v|avi|mkv)(\?|$)/i.test(String(u || '')); } function entV() { var u = uidV(); if (!u || u === 'anonymous') return Promise.resolve(false); if (u === 'admin-001' || u === 'admin') return Promise.resolve(true); return fetch(API + '/api/user-settings/status?user_id=' + encodeURIComponent(u)) .then(function (r) { return r.json(); }).then(function (d) { var st = (d && (d.data || d.status)) || {}; var sub = st.subscription || st.subscriptions || []; var active = false; try { active = Array.isArray(sub) ? sub.some(function (x) { return x && (x.status === 'active' || (x.end && new Date(x.end) > new Date())); }) : (sub && sub.status === 'active'); } catch (e) {} return active || (Number(st.balance_yuan || st.balance || 0) > 0); }).catch(function () { return false; }); } window.v31Play = function (u) { try { var ov = document.getElementById('v31PlayOv'); if (!ov) { ov = document.createElement('div'); ov.id = 'v31PlayOv'; ov.style.cssText = 'position:fixed;inset:0;background:rgba(2,6,23,.86);z-index:52000;display:flex;align-items:center;justify-content:center;'; ov.onclick = function (e) { if (e.target === ov) ov.remove(); }; document.body.appendChild(ov); } ov.innerHTML = '
' + '
'; } catch (e) { try { window.open(absV(u), '_blank'); } catch (e2) {} } }; window.v31Save = function (u, n) { var url = absV(u); entV().then(function (ok) { if (!ok) { tip('下载需先订阅/充值后使用(我的 → 充值/订阅)'); return; } var fn = String(n || 'video').replace(/[\\/:*?"<>|]/g, '_'); if (!/\.(mp4|mov|webm|png|jpe?g|gif|webp|mp3|wav)$/i.test(fn)) fn += (isVidV(url) ? '.mp4' : '.mp4'); fetch(url).then(function (r) { return r.blob(); }).then(function (b) { var a = document.createElement('a'); a.href = URL.createObjectURL(b); a.download = fn; document.body.appendChild(a); a.click(); a.remove(); setTimeout(function () { try { URL.revokeObjectURL(a.href); } catch (e) {} }, 4000); tip('💾 已开始下载'); }).catch(function () { tip('下载失败,请稍后重试'); }); }); }; window.v31Share = function (u, n) { var url = absV(u); try { if (navigator.share) { navigator.share({ title: n || '多维鹰成片', text: n || '', url: url }); return; } } catch (e) {} try { navigator.clipboard.writeText(url); tip('链接已复制,可粘贴到社群/朋友圈分享'); } catch (e) { try { window.prompt('复制链接分享:', url); } catch (e2) {} } }; window.v31Del = function (id) { if (!id) { tip('该条目不支持删除'); return; } if (window.wrConfirm) { window.wrConfirm('确定删除该成片?删除后不可恢复。', { title: '删除成片', okText: '删除', okBg: '#e11d48' }).then(function (ok) { if (ok && window.wr562DelByUrl) window.wr562DelByUrl(u); }); return; } if (!confirm('确定删除该成片?删除后不可恢复。')) return; fetch(API + '/ai-army/materials/' + encodeURIComponent(id) + '?user_id=' + encodeURIComponent(uidV()), { method: 'DELETE' }) .then(function (r) { return r.json().catch(function () { return {}; }); }) .then(function (d) { tip(d && d.success ? '🗑 已删除' : ('删除失败:' + ((d && (d.detail || d.message)) || '未知'))); if (d && d.success) { try { window.loadVideoList(); } catch (e) {} } }) .catch(function () { tip('删除网络错误'); }); }; function opsV(it, K2, u) { var n = it.title || it.task_name || it.name || it.filename || '成片'; var bs = 'border:none;border-radius:8px;padding:6px 12px;font-size:12px;color:#fff;cursor:pointer;'; var h = '
'; if (u) { h += ''; h += ''; h += ''; } var id = K2 === 2 ? (it.id || '') : (it.id || it.task_id || ''); if (id) h += ''; h += '
'; return h; } /* ② 底部视频管理 = 三分类(待发布/已发布含回传数据/素材)——与市场「视频管理」同源 */ window.loadVideoList = function () { var box = $('video-container'); if (!box) return; box.style.display = 'block'; box.innerHTML = '
' + [['v31V0', '⏰ 待发布'], ['v31V1', '✅ 已发布'], ['v31V2', '🎬 素材']].map(function (x) { return ''; }).join('') + '
加载中…
'; var K = 0; function load() { var b = $('v31Vb'); if (!b) return; b.innerHTML = '加载中…'; var url = K === 0 ? '/ai-army/tasks/scheduled-list?user_id=' : K === 1 ? '/ai-army/tasks/completed-list?user_id=' : '/ai-army/materials?user_id='; var ext = K === 2 ? '&material_type=video' : ''; fetch(API + url + encodeURIComponent(uidV()) + ext + '&_t=' + Date.now()).then(function (r) { return r.json().catch(function () { return {}; }); }) .then(function (d) { var rows = K === 2 ? (d.data || d.materials || []) : (d.data || d.tasks || []); if (!rows.length) { b.innerHTML = '
' + (K === 0 ? '暂无待发布任务' : K === 1 ? '暂无已发布视频' : '暂无视频素材') + '
'; return; } b.innerHTML = rows.map(function (it) { var t = it.title || it.task_name || it.name || it.filename || '未命名'; var meta = []; if (it.scheduled_time) meta.push('⏰ ' + it.scheduled_time); if (it.views != null) meta.push('播放 ' + it.views); if (it.likes != null) meta.push('赞 ' + it.likes); if (it.status) meta.push(it.status); var u = absV(it.video_url || it.url || it.file_path || it.material_url || it.file_url || ''); var pbtn = K === 0 && (it.task_id || it.id) ? '' : ''; return '
' + esc(t) + '
' + (meta.length ? '
' + meta.join(' · ') + '
' : '') + (u && isVidV(u) ? '' : '') + (u ? opsV(it, K, u) : '') + pbtn + '
'; }).join(''); }).catch(function () { b.innerHTML = '加载失败'; }); } window.v31Pub = function (id) { if (!id) { tip('无任务 ID'); return; } fetch(API + '/ai-army/tasks/' + encodeURIComponent(id) + '/publish', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: uidV() }) }) .then(function (r) { return r.json().catch(function () { return {}; }); }) .then(function (d) { tip((d && d.success) ? '✅ 发布成功' : '发布失败'); load(); }); }; $('v31V0').onclick = function () { K = 0; load(); }; $('v31V1').onclick = function () { K = 1; load(); }; $('v31V2').onclick = function () { K = 2; load(); }; load(); }; /* ③ 定时任务页:新建定时发布入口(对话设置时间) */ var _os = window.loadScheduledTasks; window.loadScheduledTasks = function () { if (typeof _os === 'function') { try { _os(); } catch (e) {} } var box = $('tasks-container'); if (!box) return; setTimeout(function () { if (!box || box.querySelector('[data-v31new]')) return; var b = document.createElement('button'); b.setAttribute('data-v31new', '1'); b.textContent = '+ 新建定时发布(对话设置时间)'; b.style.cssText = 'display:block;width:calc(100% - 20px);margin:10px;padding:12px;border:none;border-radius:12px;background:#334155;color:#fff;font-size:14px;cursor:pointer;'; b.onclick = function () { try { if (typeof window.switchTab === 'function') window.switchTab('home'); } catch (e) {} var inp = $('chat-input'); if (inp) inp.value = '我要定时发布视频:请先让我选择要发布的视频/内容,并设定发布时间(告诉我日期与时间),安排进定时任务队列。'; tip('在对话页告诉我:发布哪个视频 + 什么时间'); }; box.appendChild(b); }, 400); }; function boot() { try { moveChips(); } catch (e) {} } setTimeout(boot, 600); setTimeout(boot, 1800); console.log('[MobV31a] 胶囊贴底/视频三分类/定时入口 就绪'); })();