feat: add local build console
This commit is contained in:
1 parent
4ec4372b35
commit
3760650c70
9 files changed
+72
-43
No files matched your search
@@ -0,0 +1,8 @@
|
||||
<!doctype html><meta charset="utf-8"><title>OSM Asset Console</title><style>:root{--ink:#172033;--muted:#718096;--line:#dde3ed;--blue:#3867e8;--bg:#f3f6fb}*{box-sizing:border-box}body{font:15px/1.6 Inter,system-ui;margin:0 auto;max-width:1180px;padding:44px 30px 80px;background:var(--bg);color:var(--ink)}h1{font-size:42px;letter-spacing:-1.8px;margin:0}h1+p{max-width:660px;color:var(--muted);margin-top:6px;font-size:16px}section{background:white;border:1px solid var(--line);border-radius:18px;padding:24px;margin:16px 0;box-shadow:0 12px 28px #13244a0a}h2{font-size:18px;margin:0 0 14px}button,input,select{font:inherit;padding:10px 12px;border:1px solid var(--line);border-radius:9px;background:#fff;margin:3px}button{background:var(--blue);color:#fff;border-color:var(--blue);font-weight:650;cursor:pointer}button:hover{filter:brightness(.92)}#health{display:inline-block;padding:9px 14px;border-radius:999px;color:var(--blue);font-weight:650;background:#edf2ff}#clear{background:#526076;border-color:#526076}#remove{background:#c33b35;border-color:#c33b35}.card{display:grid;grid-template-columns:1fr auto;border-top:1px solid #edf0f5;padding:18px 4px;gap:8px}.card:first-child{border:0}.card a{color:var(--blue);font-weight:650;margin-right:12px}.card button{grid-column:2;grid-row:1/4;align-self:center}pre{margin:0;padding:18px;border-radius:12px;background:#111827;color:#d8e0ec;max-height:340px;overflow:auto}@media(max-width:640px){body{padding:28px 16px}.card{display:block}}</style><h1>OSM Asset Console</h1><p>从道路包到可交付场景的本地工作台。导入输入、构建资产、检查预览,全程保留可复现的项目记录。</p><section id="health">正在检查环境…</section><section><h2>新建区域</h2><input id="key" placeholder="配置名称,例如 lake-v2"><input id="osm" type="file" accept=".osm,.xml"><input id="zip" type="file" accept=".zip"><select id="tree"><option>natural</option><option>procedural</option><option>shapespark</option></select><button id="inspect">检查 ZIP</button><button id="import">导入并保存</button><span id="note"></span></section><section><h2>历史区域</h2><div id="areas"></div><button id="clear">清理选中构建产物</button><button id="remove">移除选中区域</button><p>清理仅影响控制台托管的输入/输出,并移入废纸篓。</p></section><section><h2>构建日志</h2><pre id="log">尚未启动构建</pre></section><script>
|
||||
const $=id=>document.getElementById(id), api=(u,o={})=>fetch(u,{headers:{'content-type':'application/json'},...o}).then(async r=>{let x=await r.json();if(!r.ok)throw Error(x.error);return x}), b64=f=>new Promise((ok,no)=>{let r=new FileReader;r.onload=()=>ok(r.result.split(',')[1]);r.onerror=no;r.readAsDataURL(f)});let selected=[];
|
||||
async function load(){let [h,d]=await Promise.all([api('/api/health'),api('/api/areas')]);$('health').textContent=`Node ${h.node} · Blender ${h.blender?'已就绪':'未找到'} · ${h.areas} 个历史配置`; $('areas').innerHTML=d.areas.map(a=>`<div class=card><label><input type=checkbox value="${a.key}"> <b>${a.key}</b></label> — ${a.id||a.error}<br>树木:${a.treeStyle||'-'}<br>${a.preview?`<a target=_blank href="${a.preview}">打开预览</a> `:''}${a.manifest?`<a target=_blank href="${a.manifest}">package manifest</a> `:''}<button data-build="${a.key}">构建</button></div>`).join('');document.querySelectorAll('[data-build]').forEach(x=>x.onclick=()=>build(x.dataset.build));document.querySelectorAll('#areas input').forEach(x=>x.onchange=()=>selected=[...document.querySelectorAll('#areas input:checked')].map(x=>x.value));}
|
||||
async function build(key){try{let r=await api('/api/build',{method:'POST',body:JSON.stringify({key})});$('note').textContent=`正在构建 ${key}…`;let t=setInterval(async()=>{let j=await api('/api/job');$('log').textContent=j.logs.join('');if(j.done){clearInterval(t);$('note').textContent=j.code===0?'构建完成,可打开预览':'构建失败,请查看日志';load()}},700)}catch(e){$('note').textContent=`无法启动构建:${e.message}`}}
|
||||
$('inspect').onclick=async()=>{try{$('note').textContent='ZIP: '+JSON.stringify(await api('/api/inspect',{method:'POST',body:JSON.stringify({zip:await b64($('zip').files[0])})}))}catch(e){$('note').textContent=e.message}};
|
||||
$('import').onclick=async()=>{try{let r=await api('/api/import',{method:'POST',body:JSON.stringify({key:$('key').value,osm:await b64($('osm').files[0]),zip:await b64($('zip').files[0]),treeStyle:$('tree').value})});$('note').textContent=`已保存 ${r.key}`;load()}catch(e){$('note').textContent=e.message}};
|
||||
for(let [id,mode] of [['clear','outputs'],['remove','remove']])$(id).onclick=async()=>{if(!selected.length){$('note').textContent='请先勾选一个或多个区域';return}if(confirm(`将 ${selected.join(', ')} 移入废纸篓?`)){try{await api('/api/cleanup',{method:'POST',body:JSON.stringify({keys:selected,mode})});selected=[];$('note').textContent='已移入废纸篓';load()}catch(e){$('note').textContent=`清理失败:${e.message}`}}};load();
|
||||
</script>
|
||||
Reference in new issue
Block a user