feat: интеграция smeta-railway — агрегатор, генерация, справочники, проверка

Новые страницы:
- /wizard — агрегатор xlsx (7-шаговый мастер)
- /generate — генерация сметы из описания работ (4 шага → Excel)
- /reference — справочники НР/СП/ГЭСН
- /check — проверка YAML-конфига сметы

Используют smeta-railway как библиотеку (wizard_api, generator_api, chat_api, checker).
Кнопки добавлены в header чата.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-31 07:22:13 +10:00
co-authored by Claude Opus 4.6
parent c45bd5b256
commit adeb92f4d0
6 changed files with 866 additions and 1 deletions
+219
View File
@@ -0,0 +1,219 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Генерация сметы</title>
<style>
:root {
--bg: #f5f0eb; --bg-card: #ffffff; --bg-input: #ffffff;
--text: #3a3a3a; --text-muted: #6b6b6b; --text-light: #8b7355;
--border: #d4c5b2; --border-light: #ede5db;
--accent: #c4463a; --accent-hover: #a83830;
--success: #2b8a3e; --warn: #e8590c; --danger: #e03131; --info: #1971c2;
--shadow-sm: 0 1px 3px rgba(0,0,0,.05);
--shadow-md: 0 4px 16px rgba(0,0,0,.07);
--radius: 10px; --radius-lg: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.container { max-width: 860px; margin: 24px auto; padding: 0 16px; }
.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.header h1 { font-size: 1.2rem; font-weight: 700; }
.header a { color: var(--accent); text-decoration: none; font-size: .85rem; font-weight: 500; }
.card { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 24px; margin-bottom: 16px; }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }
label { display: block; font-size: .85rem; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
input[type="text"], textarea, select { width: 100%; padding: .55rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .9rem; background: var(--bg); outline: none; transition: border-color .2s; font-family: inherit; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); background: var(--bg-card); }
textarea { resize: vertical; min-height: 100px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.btn { padding: .55rem 1.2rem; border: none; border-radius: var(--radius); font-size: .85rem; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-success { background: var(--success); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.gen-step { display: none; }
.gen-step.active { display: block; }
.step-badge { display: inline-block; background: var(--accent); color: #fff; padding: 2px 10px; border-radius: 10px; font-size: .78rem; font-weight: 600; }
.item { padding: 10px 14px; border: 1.5px solid var(--border-light); border-radius: var(--radius); margin-bottom: 8px; }
.item.ok { border-left: 4px solid var(--success); }
.item.bad { border-left: 4px solid var(--danger); }
.item-head { display: flex; justify-content: space-between; align-items: center; }
.item-head strong { font-size: .9rem; }
.item-meta { font-size: .82rem; margin-top: 4px; }
.score { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: .72rem; font-weight: 700; }
.score-hi { background: #d3f9d8; color: var(--success); }
.score-md { background: #fff3bf; color: var(--warn); }
.score-lo { background: #ffe3e3; color: var(--danger); }
.alt { font-size: .78rem; color: var(--info); cursor: pointer; margin-right: 8px; }
.yaml-box { font-family: 'SF Mono', Menlo, monospace; font-size: .8rem; white-space: pre-wrap; background: #2c2c2c; color: #f5f0eb; padding: 16px; border-radius: var(--radius); max-height: 400px; overflow-y: auto; line-height: 1.5; }
.error { color: var(--danger); font-size: .85rem; margin-top: 8px; }
.spinner { width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.d-none { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.chk { display: flex; align-items: center; gap: 6px; margin-top: 16px; }
.chk input { width: auto; }
.chk label { margin: 0; font-size: .9rem; color: var(--text); }
.gap-2 { display: flex; gap: 8px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Генерация сметы</h1>
<a href="/">← Назад к чату</a>
</div>
<div class="mb-2">
<span class="step-badge" id="stepBadge">Шаг 1 из 3</span>
<span style="color:var(--text-muted);font-size:.85rem;margin-left:8px" id="stepLabel">Описание работ</span>
</div>
<!-- Step 1 -->
<div class="gen-step active card" id="g1">
<h2>Опишите работы</h2>
<textarea id="desc" placeholder="Замена 500 шпал на перегоне ст. Свиягино — ст. Ружино, очистка щебня 2 км, замена 3 пар рельсовых плетей по 800м..."></textarea>
<div class="row mt-3">
<div><label>Регион</label><input type="text" id="region" value="Приморский край"></div>
<div><label>Поездов/сут</label><input type="text" id="trains" value="91-108"></div>
</div>
<div class="row mt-2">
<div class="chk"><input type="checkbox" id="vl" checked><label for="vl">Зона ВЛ</label></div>
<div class="chk"><input type="checkbox" id="okno" checked><label for="okno">В "окно"</label></div>
</div>
<button class="btn btn-primary mt-3" onclick="parse()" id="parseBtn">
<span id="parseSpin" class="spinner d-none"></span> Разобрать на позиции
</button>
<div id="parseErr" class="error"></div>
</div>
<!-- Step 2 -->
<div class="gen-step card" id="g2">
<h2>Проверьте позиции и расценки</h2>
<div id="items"></div>
<div class="gap-2 mt-3">
<button class="btn btn-outline" onclick="show(1)">Назад</button>
<button class="btn btn-primary" onclick="genYaml()" id="yamlBtn">
<span id="yamlSpin" class="spinner d-none"></span> Сформировать смету
</button>
</div>
</div>
<!-- Step 3 -->
<div class="gen-step card" id="g3">
<h2>Конфигурация сметы</h2>
<div id="yamlOut" class="yaml-box"></div>
<div class="gap-2 mt-3">
<button class="btn btn-outline" onclick="show(2)">Назад</button>
<button class="btn btn-success" onclick="calcExcel()" id="calcBtn">
<span id="calcSpin" class="spinner d-none"></span> Рассчитать и скачать Excel
</button>
<button class="btn btn-outline" onclick="copy()">Скопировать YAML</button>
</div>
<div id="calcResult" class="mt-2"></div>
</div>
<!-- Step 4 -->
<div class="gen-step card" id="g4">
<h2>Смета готова</h2>
<p>Расчёт выполнен. Скачайте файл Excel.</p>
<div id="downloadInfo" class="mt-2"></div>
<div class="gap-2 mt-3">
<button class="btn btn-outline" onclick="show(3)">Назад к YAML</button>
<a id="downloadLink" class="btn btn-success" href="#" style="text-decoration:none">Скачать Excel</a>
</div>
</div>
</div>
<script>
let matched=[], yamlStr='';
function $(id){return document.getElementById(id);}
function esc(s){return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}
function show(n){
for(let i=1;i<=4;i++) $('g'+i).classList.toggle('active',i===n);
$('stepBadge').textContent=`Шаг ${n} из 4`;
const L={1:'Описание работ',2:'Проверка позиций',3:'Конфигурация',4:'Скачать Excel'};
$('stepLabel').textContent=L[n];
}
async function parse(){
const desc=$('desc').value.trim();
if(!desc){$('parseErr').textContent='Введите описание работ';return;}
$('parseSpin').classList.remove('d-none'); $('parseBtn').disabled=true; $('parseErr').textContent='';
try{
const r1=await fetch('/api/gen/parse',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({description:desc})});
const d1=await r1.json();
if(d1.error){$('parseErr').textContent=d1.error;return;}
if(!d1.items.length){$('parseErr').textContent='Не удалось разобрать описание';return;}
const r2=await fetch('/api/gen/match',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({items:d1.items})});
const d2=await r2.json();
if(d2.error){$('parseErr').textContent=d2.error;return;}
matched=d2.matched;
let h='';
for(const m of matched){
const ok=m.score>0.3;
const sc=m.score>0.6?'score-hi':m.score>0.3?'score-md':'score-lo';
h+=`<div class="item ${ok?'ok':'bad'}">
<div class="item-head"><strong>${esc(m.description)}</strong><span>${esc(m.unit||'')} x ${m.qty||'?'}</span></div>
<div class="item-meta"><span class="score ${sc}">${(m.score*100).toFixed(0)}%</span> <strong>${esc(m.gesn_code)}</strong> ${esc(m.gesn_name||'')}</div>`;
if(m.alternatives&&m.alternatives.length){h+='<div class="mt-2">';for(const a of m.alternatives)h+=`<span class="alt">${a.code} (${(a.score*100).toFixed(0)}%)</span>`;h+='</div>';}
if(m.note)h+=`<div style="font-size:.82rem;color:var(--text-muted);margin-top:4px">${esc(m.note)}</div>`;
h+='</div>';
}
$('items').innerHTML=h;
show(2);
}catch(e){$('parseErr').textContent=e.message;}
finally{$('parseSpin').classList.add('d-none');$('parseBtn').disabled=false;}
}
async function genYaml(){
$('yamlSpin').classList.remove('d-none'); $('yamlBtn').disabled=true;
try{
const r=await fetch('/api/gen/yaml',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({matched_items:matched,region:$('region').value,trains_per_day:$('trains').value,vl_zone:$('vl').checked,okno:$('okno').checked})});
const d=await r.json();
if(d.error){alert(d.error);return;}
yamlStr=d.yaml;
$('yamlOut').textContent=yamlStr;
show(3);
}catch(e){alert(e.message);}
finally{$('yamlSpin').classList.add('d-none');$('yamlBtn').disabled=false;}
}
async function calcExcel(){
$('calcSpin').classList.remove('d-none'); $('calcBtn').disabled=true; $('calcResult').innerHTML='';
try{
const r=await fetch('/api/gen/calculate',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({yaml:yamlStr})});
const d=await r.json();
if(d.error){
$('calcResult').innerHTML=`<div style="color:var(--danger);font-size:.85rem">${esc(d.error)}</div>`;
return;
}
$('downloadLink').href=d.download_url;
$('downloadInfo').innerHTML=`<p>Позиций: ${d.positions}</p>`;
show(4);
}catch(e){$('calcResult').innerHTML=`<div style="color:var(--danger)">${e.message}</div>`;}
finally{$('calcSpin').classList.add('d-none');$('calcBtn').disabled=false;}
}
function copy(){
navigator.clipboard.writeText(yamlStr).then(()=>{
const b=event.target; b.textContent='Скопировано!'; setTimeout(()=>b.textContent='Скопировать',2000);
});
}
function dl(){
const b=new Blob([yamlStr],{type:'text/yaml'}), u=URL.createObjectURL(b), a=document.createElement('a');
a.href=u; a.download='estimate.yaml'; a.click(); URL.revokeObjectURL(u);
}
</script>
</body>
</html>