195 lines
10 KiB
Plaintext
195 lines
10 KiB
Plaintext
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>Комбайн — Yealink</title>
|
||
<style>
|
||
:root{--bg:#0f1720;--card:#18222e;--line:#243244;--txt:#e6edf3;--dim:#8fa3b8;--acc:#3b82f6;--ok:#22c55e;--bad:#ef4444;--warn:#f59e0b}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;font:14px/1.45 -apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--txt)}
|
||
header{padding:14px 20px;border-bottom:1px solid var(--line);display:flex;gap:20px;align-items:center;flex-wrap:wrap}
|
||
h1{font-size:17px;margin:0;font-weight:600}
|
||
.stat{color:var(--dim);font-size:12px}
|
||
.stat b{color:var(--txt)}
|
||
nav{display:flex;gap:4px;padding:10px 20px;border-bottom:1px solid var(--line)}
|
||
nav button{background:transparent;border:1px solid transparent;color:var(--dim);padding:7px 14px;border-radius:7px;cursor:pointer;font-size:13px}
|
||
nav button.on{background:var(--card);border-color:var(--line);color:var(--txt)}
|
||
main{padding:18px 20px;max-width:1500px}
|
||
.grid{display:grid;grid-template-columns:320px 1fr;gap:16px}
|
||
.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px}
|
||
h3{margin:0 0 10px;font-size:13px;color:var(--dim);text-transform:uppercase;letter-spacing:.5px}
|
||
input,select{background:#0d1520;border:1px solid var(--line);color:var(--txt);padding:7px 9px;border-radius:6px;font-size:13px;width:100%}
|
||
label{display:block;font-size:12px;color:var(--dim);margin:8px 0 4px}
|
||
button.primary{background:var(--acc);border:0;color:#fff;padding:9px 16px;border-radius:7px;cursor:pointer;font-size:13px;font-weight:600;width:100%;margin-top:12px}
|
||
table{width:100%;border-collapse:collapse;font-size:13px}
|
||
th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line)}
|
||
th{color:var(--dim);font-weight:500;font-size:12px}
|
||
tr:hover td{background:#1d2836}
|
||
.hostlist{max-height:70vh;overflow:auto}
|
||
.hostlist div{padding:7px 9px;border-radius:6px;cursor:pointer;font-size:13px;display:flex;justify-content:space-between}
|
||
.hostlist div:hover{background:#1d2836}
|
||
.hostlist div.on{background:#1e3a5f}
|
||
.hostlist span{color:var(--dim);font-size:11px}
|
||
.tag{display:inline-block;background:#1e3a5f;color:#93c5fd;padding:2px 7px;border-radius:20px;font-size:11px;margin:2px 3px 2px 0}
|
||
.tag.ok{background:#14532d;color:#86efac}
|
||
.tag.bad{background:#4c1d1d;color:#fca5a5}
|
||
.tag.warn{background:#4a2f0a;color:#fcd34d}
|
||
.pill{font-size:11px;padding:2px 7px;border-radius:20px;background:#1e3a5f;color:#93c5fd}
|
||
.muted{color:var(--dim);font-size:12px}
|
||
.warnbox{border-left:3px solid var(--warn);background:#2a2008;padding:9px 12px;border-radius:6px;margin:10px 0;font-size:13px}
|
||
.okbox{border-left:3px solid var(--ok);background:#0d2417;padding:9px 12px;border-radius:6px;margin:10px 0;font-size:13px}
|
||
svg{width:100%;height:520px;background:#0b1219;border-radius:10px;border:1px solid var(--line)}
|
||
.hidden{display:none}
|
||
.kv{display:grid;grid-template-columns:170px 1fr;gap:2px 12px;font-size:13px}
|
||
.kv div:nth-child(odd){color:var(--dim)}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<header>
|
||
<h1>Комбайн · Yealink</h1>
|
||
<div class="stat">устройств <b id="s-dev">—</b></div>
|
||
<div class="stat">рёбер <b id="s-edge">—</b></div>
|
||
<div class="stat">хостов <b id="s-host">—</b></div>
|
||
<div class="stat">кронштейнов <b id="s-mnt">—</b></div>
|
||
<div class="stat">с атрибутами <b id="s-attr">—</b></div>
|
||
<div class="stat" style="margin-left:auto">режим: сборка, без цен</div>
|
||
</header>
|
||
<nav>
|
||
<button class="on" data-tab="matrix">Матрица</button>
|
||
<button data-tab="pick">Подбор</button>
|
||
<button data-tab="scheme">Схема</button>
|
||
</nav>
|
||
<main>
|
||
<!-- МАТРИЦА -->
|
||
<section id="tab-matrix" class="grid">
|
||
<div class="card">
|
||
<h3>Хосты</h3>
|
||
<input id="q" placeholder="поиск модели…">
|
||
<div class="hostlist" id="hosts"></div>
|
||
</div>
|
||
<div class="card" id="detail"><p class="muted">Выберите хост слева</p></div>
|
||
</section>
|
||
|
||
<!-- ПОДБОР -->
|
||
<section id="tab-pick" class="hidden grid">
|
||
<div class="card">
|
||
<h3>Параметры комнаты</h3>
|
||
<label>Хост</label><select id="p-host"></select>
|
||
<label>Мест</label><input id="p-seats" type="number" value="10" min="1">
|
||
<label>Требуемые функции (через запятую)</label><input id="p-need" placeholder="AEC, Dante, Auto Framing">
|
||
<label>Якорь: уже есть (через запятую)</label><input id="p-add" placeholder="CS10">
|
||
<button class="primary" onclick="runBom()">Собрать BOM</button>
|
||
</div>
|
||
<div class="card" id="bomout"><p class="muted">Заполните параметры и нажмите «Собрать BOM»</p></div>
|
||
</section>
|
||
|
||
<!-- СХЕМА -->
|
||
<section id="tab-scheme" class="hidden">
|
||
<div class="card">
|
||
<h3>Схема соединений</h3>
|
||
<p class="muted" id="scheme-hint">Соберите BOM на вкладке «Подбор» — схема построится здесь.</p>
|
||
<svg id="svg" viewBox="0 0 1000 520"></svg>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
|
||
<script>
|
||
let HOSTS=[], CUR=null;
|
||
const $=s=>document.querySelector(s);
|
||
|
||
async function j(u){const r=await fetch(u);return r.json()}
|
||
|
||
function tab(name){
|
||
document.querySelectorAll('nav button').forEach(b=>b.classList.toggle('on',b.dataset.tab===name));
|
||
['matrix','pick','scheme'].forEach(t=>$('#tab-'+t).classList.toggle('hidden',t!==name));
|
||
}
|
||
document.querySelectorAll('nav button').forEach(b=>b.onclick=()=>tab(b.dataset.tab));
|
||
|
||
async function boot(){
|
||
const s=await j('/api/stats');
|
||
$('#s-dev').textContent=s.devices; $('#s-edge').textContent=s.edges;
|
||
$('#s-host').textContent=s.hosts; $('#s-mnt').textContent=s.mounts;
|
||
$('#s-attr').textContent=s.with_attrs;
|
||
HOSTS=await j('/api/hosts');
|
||
renderHosts(HOSTS);
|
||
$('#p-host').innerHTML=HOSTS.map(h=>`<option value="${h.key}">${h.name}</option>`).join('');
|
||
}
|
||
function renderHosts(list){
|
||
$('#hosts').innerHTML=list.map(h=>
|
||
`<div onclick="pick('${h.key}')"><b>${h.name}</b><span>${h.accessories}</span></div>`).join('');
|
||
}
|
||
$('#q').oninput=e=>{
|
||
const v=e.target.value.toLowerCase();
|
||
renderHosts(HOSTS.filter(h=>h.name.toLowerCase().includes(v)));
|
||
};
|
||
|
||
async function pick(k){
|
||
CUR=k;
|
||
document.querySelectorAll('.hostlist div').forEach(d=>d.classList.remove('on'));
|
||
const d=await j('/api/device?key='+k);
|
||
const attrs=Object.entries(d.attributes||{});
|
||
const accs=(d.accessories||[]).filter(a=>a.supported);
|
||
const noacc=(d.accessories||[]).filter(a=>!a.supported);
|
||
$('#detail').innerHTML=`
|
||
<h2 style="margin:0 0 4px;font-size:19px">${d.name}</h2>
|
||
<div class="muted">роль: ${d.role}</div>
|
||
<h3 style="margin-top:16px">Функции (${d.features.length})</h3>
|
||
<div>${d.features.map(f=>`<span class="tag">${f}</span>`).join('')||'<span class="muted">нет данных</span>'}</div>
|
||
<h3 style="margin-top:16px">Атрибуты (${attrs.length})</h3>
|
||
<div class="kv">${attrs.map(([k,v])=>`<div>${k}</div><div>${v}</div>`).join('')||'<div class="muted">нет</div>'}</div>
|
||
<h3 style="margin-top:16px">Совместимые аксессуары (${accs.length})</h3>
|
||
<table><tr><th>Модель</th><th>Лимит</th><th>Условие</th></tr>
|
||
${accs.map(a=>`<tr><td>${a.model}</td><td>${a.max_qty||'—'}</td><td class="muted">${(a.condition||'').replace(/^[√×\s]+/,'').slice(0,90)}</td></tr>`).join('')}
|
||
</table>
|
||
${noacc.length?`<h3 style="margin-top:16px">Не поддерживается (${noacc.length})</h3><div class="muted">${noacc.map(a=>a.model).join(' · ')}</div>`:''}
|
||
${d.mounts&&d.mounts.length?`<h3 style="margin-top:16px">Кронштейны (${d.mounts.length})</h3><div>${d.mounts.map(m=>`<span class="tag">${m}</span>`).join('')}</div>`:''}
|
||
`;
|
||
}
|
||
|
||
async function runBom(){
|
||
const h=$('#p-host').value, s=$('#p-seats').value,
|
||
n=$('#p-need').value, a=$('#p-add').value;
|
||
const r=await j(`/api/bom?host=${encodeURIComponent(h)}&seats=${s}&need=${encodeURIComponent(n)}&add=${encodeURIComponent(a)}`);
|
||
if(r.error){$('#bomout').innerHTML=`<div class="warnbox">${r.error}</div>`;return}
|
||
$('#bomout').innerHTML=`
|
||
<h2 style="margin:0 0 4px;font-size:18px">${r.host}</h2>
|
||
<div class="muted">${r.seats} мест · требуется захват ${r.need_pickup} м</div>
|
||
<table style="margin-top:12px">
|
||
<tr><th>Роль</th><th>Модель</th><th>Кол</th><th>Обоснование</th></tr>
|
||
${r.bom.map(b=>`<tr><td>${b.role}</td><td><b>${b.model}</b></td><td>${b.qty}</td><td class="muted">${b.why||''}</td></tr>`).join('')}
|
||
</table>
|
||
${r.warnings.length?`<div class="warnbox">⚠ ${r.warnings.join('<br>⚠ ')}</div>`:''}
|
||
${r.cross.length?`<div class="warnbox">Зависимости: ${r.cross.join('; ')}</div>`:''}
|
||
${!r.warnings.length&&!r.cross.length?`<div class="okbox">✓ Конфигурация собрана без замечаний</div>`:''}
|
||
<div class="muted" style="margin-top:8px">Позиций: ${r.bom.length} · единиц: ${r.bom.reduce((a,b)=>a+b.qty,0)}</div>
|
||
`;
|
||
drawScheme(r);
|
||
tab('scheme');
|
||
}
|
||
|
||
function drawScheme(r){
|
||
const svg=$('#svg'); svg.innerHTML='';
|
||
$('#scheme-hint').classList.add('hidden');
|
||
const cx=500, cy=250;
|
||
const nodes=r.bom.filter(b=>b.role!=='Хост');
|
||
const R=190, step=(2*Math.PI)/Math.max(nodes.length,1);
|
||
let out=`<circle cx="${cx}" cy="${cy}" r="78" fill="#1e3a5f" stroke="#3b82f6" stroke-width="2"/>
|
||
<text x="${cx}" y="${cy-4}" text-anchor="middle" fill="#e6edf3" font-size="13" font-weight="600">${esc(r.host)}</text>
|
||
<text x="${cx}" y="${cy+14}" text-anchor="middle" fill="#8fa3b8" font-size="11">хост</text>`;
|
||
nodes.forEach((b,i)=>{
|
||
const a=-Math.PI/2+i*step;
|
||
const x=cx+R*1.6*Math.cos(a), y=cy+R*1.1*Math.sin(a);
|
||
out+=`<line x1="${cx}" y1="${cy}" x2="${x}" y2="${y}" stroke="#243244" stroke-width="2"/>`;
|
||
out+=`<rect x="${x-72}" y="${y-24}" width="144" height="48" rx="9" fill="#18222e" stroke="#2f4a66" stroke-width="1"/>`;
|
||
out+=`<text x="${x}" y="${y-5}" text-anchor="middle" fill="#e6edf3" font-size="12" font-weight="600">${esc(b.model)}</text>`;
|
||
out+=`<text x="${x}" y="${y+12}" text-anchor="middle" fill="#8fa3b8" font-size="10">${esc(b.role)}${b.qty>1?' ×'+b.qty:''}</text>`;
|
||
});
|
||
svg.innerHTML=out;
|
||
}
|
||
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'<','>':'>','&':'&'}[c]))}
|
||
|
||
boot();
|
||
</script>
|
||
</body>
|
||
</html>
|