Files
2026-11-05 15:07:45 +08:00

511 lines
27 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>综资退网评估模板生成工具</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect width='24' height='24' rx='6' fill='%232563eb'/%3E%3Cpath d='M6 9l6-3 6 3v6l-6 3-6-3z' fill='none' stroke='%23fff' stroke-width='1.6'/%3E%3C/svg%3E">
<style>
:root{
--bg:#eef2f9; --card:#fff; --line:#e2e8f2; --line2:#eef2f8;
--txt:#1a2334; --txt2:#55627a; --txt3:#93a0b5;
--pri:#2563eb; --pri-d:#1d4ed8; --pri-l:#e8f0ff;
--cyan:#0891b2; --cyan-l:#e0f7fb;
--green:#059669; --green-l:#e3f8f0;
--amber:#d97706; --amber-l:#fff5e3;
--red:#e11d48; --red-l:#ffe9ee;
}
*{box-sizing:border-box}
body{
margin:0;font-family:"Microsoft YaHei","PingFang SC","Segoe UI",system-ui,sans-serif;
color:var(--txt);font-size:14px;line-height:1.6;min-height:100vh;
background:
radial-gradient(1100px 420px at 12% -8%, #dbe8ff 0%, rgba(219,232,255,0) 62%),
radial-gradient(900px 380px at 92% -4%, #cfeaf7 0%, rgba(207,234,247,0) 60%),
var(--bg);
background-attachment:fixed;
}
.wrap{width:min(1280px,92vw);margin:0 auto;padding:28px 0 60px}
header{display:flex;align-items:center;gap:16px;margin-bottom:20px}
.logo{width:52px;height:52px;border-radius:14px;flex:0 0 auto;
background:linear-gradient(140deg,#3b82f6,#2563eb 55%,#0891b2);
display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px -4px rgba(29,78,216,.35)}
.logo svg{width:28px;height:28px;stroke:#fff;fill:none;stroke-width:1.9}
.eyebrow{display:inline-block;font-size:12px;color:var(--pri);background:var(--pri-l);
border:1px solid #d5e3fb;border-radius:20px;padding:2px 12px;letter-spacing:.6px}
h1{margin:6px 0 0;font-size:24px;font-weight:800;letter-spacing:.5px}
h1 em{font-style:normal;background:linear-gradient(96deg,#2563eb,#3b82f6 45%,#0891b2);
-webkit-background-clip:text;background-clip:text;color:transparent}
.ver{margin-left:auto;font-size:12.5px;color:var(--txt3);text-align:right}
.grid{display:grid;grid-template-columns:1.15fr .85fr;gap:18px;align-items:start}
@media(max-width:960px){.grid{grid-template-columns:1fr}}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:20px 22px;
margin-bottom:18px;box-shadow:0 6px 20px -16px rgba(26,35,52,.35)}
.card h2{display:flex;align-items:center;gap:9px;margin:0 0 14px;font-size:15.5px;font-weight:700}
.ico{width:28px;height:28px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto}
.ico svg{width:16px;height:16px;fill:none;stroke-width:2}
.ico.b{background:var(--pri-l)} .ico.b svg{stroke:var(--pri)}
.ico.c{background:var(--cyan-l)} .ico.c svg{stroke:var(--cyan)}
.ico.g{background:var(--green-l)} .ico.g svg{stroke:var(--green)}
.tabs{display:flex;gap:6px;background:#f4f7fc;border:1px solid var(--line);border-radius:10px;padding:4px;margin-bottom:14px}
.tab{flex:1;text-align:center;padding:7px 10px;border-radius:7px;cursor:pointer;font-size:13px;color:var(--txt2)}
.tab.on{background:#fff;color:var(--pri);font-weight:700;box-shadow:0 1px 3px rgba(26,35,52,.1)}
label.f{display:block;font-size:12.5px;color:var(--txt2);margin:10px 0 4px}
input[type=text],input[type=number]{width:100%;padding:9px 11px;border:1px solid var(--line);border-radius:9px;
font-size:13px;color:var(--txt);background:#fbfcfe;font-family:inherit}
input:focus{outline:none;border-color:var(--pri);background:#fff}
.row{display:flex;gap:12px}.row>*{flex:1}
.btn{padding:9px 18px;border-radius:9px;font-size:13.5px;font-weight:600;cursor:pointer;border:1px solid var(--line);
background:#fff;color:var(--txt2);display:inline-flex;align-items:center;gap:7px;transition:.15s}
.btn svg{width:15px;height:15px;fill:none;stroke-width:2}
.btn.pri{border:0;color:#fff;background:linear-gradient(180deg,#3b82f6,#2563eb)}
.btn.pri:hover:not(:disabled){background:linear-gradient(180deg,#2563eb,#1d4ed8)}
.btn:not(.pri):hover:not(:disabled){background:#f3f5f9}
.btn:disabled{background:#e9ecf2;color:#a8b0be;border:0;cursor:not-allowed}
.acts{display:flex;gap:10px;margin-top:16px;flex-wrap:wrap}
.pick{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:2px}
.pick .fname{font-size:13px;color:var(--txt);font-weight:700;word-break:break-all}
.drop{border:2px dashed #c6d8f2;border-radius:12px;padding:22px;text-align:center;cursor:pointer;
background:linear-gradient(180deg,#fbfdff,#f4f8ff)}
.drop:hover{border-color:var(--pri)}
.drop b{color:var(--pri)}
.drop .sub{font-size:12.5px;color:var(--txt3);margin-top:4px}
.kpis{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
.igrid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:14px}
.ibox{border:1px solid var(--line);border-radius:12px;padding:14px;background:#fbfcfe}
.ibox .t{font-size:13.5px;font-weight:700;color:var(--txt)}
.ibox .s{font-size:11.5px;color:var(--txt3);margin-top:3px;line-height:1.55;min-height:36px}
.ibox .n{font-size:19px;font-weight:800;letter-spacing:.3px;margin:6px 0 10px}
.ibox .n small{font-size:11.5px;font-weight:600;color:var(--txt3);margin-left:3px}
.ibox .btn{width:100%;justify-content:center}
.danger{margin-top:14px;padding-top:13px;border-top:1px dashed var(--line);display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.btn.dg{border-color:#f3c9c9;color:var(--red);background:#fff}
.btn.dg:hover:not(:disabled){background:var(--red-l)}
.kpi{border:1px solid var(--line);border-radius:11px;padding:12px 14px;background:#fbfcfe}
.kpi .k{font-size:12px;color:var(--txt3)}
.kpi .v{font-size:20px;font-weight:800;letter-spacing:.3px;color:var(--txt)}
.kpi .v small{font-size:12px;font-weight:600;color:var(--txt3);margin-left:4px}
.bar{height:6px;border-radius:6px;background:#eef2f8;overflow:hidden;margin-top:10px}
.bar i{display:block;height:100%;background:linear-gradient(90deg,#3b82f6,#0891b2);transition:width .3s}
.st{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;padding:3px 10px;border-radius:20px;
background:#eef1f6;color:var(--txt2)}
.st.ok{background:var(--green-l);color:var(--green)}
.st.run{background:var(--pri-l);color:var(--pri)}
.st.err{background:var(--red-l);color:var(--red)}
.note{font-size:12.5px;color:var(--txt2);background:var(--amber-l);border:1px dashed #f7dcb0;
border-radius:9px;padding:9px 12px;margin-top:12px;white-space:pre-wrap}
#log{height:230px;overflow:auto;background:#fbfcfe;border:1px solid var(--line2);border-radius:10px;
padding:9px 12px;font-family:Consolas,monospace;font-size:12.5px;line-height:1.8}
#log div{white-space:pre-wrap;word-break:break-all;color:var(--txt2)}
#log .t{color:var(--txt3);margin-right:6px}
#log .ok{color:var(--green);font-weight:700} #log .err{color:var(--red);font-weight:700}
#log .warn{color:var(--amber)}
table{width:100%;border-collapse:collapse;font-size:12.5px;table-layout:fixed}
th,td{text-align:left;padding:6px 6px;border-bottom:1px solid var(--line2);vertical-align:middle;overflow:hidden}
th{color:var(--txt3);font-weight:600;white-space:nowrap}
td.c1{width:44px;white-space:nowrap}
td.c2{width:118px;font-family:Consolas,monospace;font-size:11px;color:var(--txt3);white-space:nowrap}
td.c3{width:74px;white-space:nowrap}
td.c4{text-overflow:ellipsis;white-space:nowrap;color:var(--txt3)}
.muted{color:var(--txt3)}
a.dl{color:var(--pri);font-weight:700;text-decoration:none}
</style>
</head>
<body>
<div class="wrap" id="app">
<header>
<div class="logo"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 7l9-4 9 4v10l-9 4-9-4z"/><path d="M3 7l9 4 9-4"/><path d="M12 11v10"/></svg></div>
<div>
<span class="eyebrow">综资退网工具</span>
<h1>退网评估模板<em>生成</em>工具</h1>
</div>
<div class="ver">v1.0 · DuckDB<br><span class="muted">{{ meta.database || '-' }}</span></div>
</header>
<div class="grid">
<div>
<!-- 数据源 -->
<section class="card">
<h2><span class="ico b"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 16V4M7 9l5-5 5 5"/><path d="M4 16v3a1 1 0 001 1h14a1 1 0 001-1v-3"/></svg></span>数据入库</h2>
<div class="tabs">
<div class="tab" :class="{on: tab==='dir'}" @click="tab='dir'">目录扫描(批量报表)</div>
<div class="tab" :class="{on: tab==='upload'}" @click="tab='upload'">网页上传</div>
</div>
<template v-if="tab==='dir'">
<label class="f">数据目录</label>
<input type="text" v-model="dir" placeholder="D:/…/数据">
<div class="drop" style="margin-top:10px" @click="hintDir">
<div><b>子文件夹</b> = 网管批量报表(后续改为 FTP 拉取)</div>
<div class="sub">顶层 xlsx = 网页导入(工参 / 需求清单)</div>
</div>
</template>
<template v-else>
<div class="drop" @click="$refs.file.click()">
<div>点击选择或拖入 <b>Excel</b> 文件</div>
<div class="sub">可多选;上传后按下面的「工参 / 流量」分别入库</div>
</div>
<input ref="file" type="file" accept=".xlsx,.xlsm" multiple hidden @change="onFiles">
<div v-if="batch" class="note" style="background:var(--pri-l);border-color:#cfe0fb;color:var(--pri-d)">
已上传批次:{{ batch }}({{ uploaded.length }} 个文件)
</div>
</template>
<div class="igrid">
<div class="ibox">
<div class="t">工参</div>
<div class="s">4G/5G 小区工参 + 需求清单。同一 CGI 以版本较新的一条为准,旧版本只补缺。</div>
<div class="n">{{ fmt(stats.gongcan) }}<small>个小区</small></div>
<button class="btn pri" :disabled="busyImport" @click="startImport(['gongcan','demand'])">
<svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l14 8-14 8z"/></svg>
{{ busyImport && importKind==='gongcan' ? '入库中…' : '导入工参' }}
</button>
</div>
<div class="ibox">
<div class="t">流量数据</div>
<div class="s">6 类流量/质量报表。按「时间 × CGI」互补追加,可分多次导入。</div>
<div class="n">{{ fmt(stats.flow) }}<small>行</small></div>
<button class="btn pri" :disabled="busyImport" @click="startImport(['flow'])">
<svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l14 8-14 8z"/></svg>
{{ busyImport && importKind==='flow' ? '入库中…' : '导入流量' }}
</button>
</div>
</div>
<div class="acts">
<button class="btn" @click="refreshAll">刷新状态</button>
</div>
<div v-if="importJob" style="margin-top:14px">
<span class="st" :class="stCls(importJob.status)">{{ statusText(importJob.status) }}</span>
<span class="muted" style="margin-left:8px;font-size:12.5px">{{ importJob.message }}</span>
<div class="bar"><i :style="{width: importPct + '%'}"></i></div>
</div>
<div class="danger">
<button class="btn dg" :disabled="busyImport" @click="clearData('flow')">清空流量</button>
<button class="btn dg" :disabled="busyImport" @click="clearData('gongcan')">清空工参</button>
<button class="btn dg" :disabled="busyImport" @click="clearData('all')">清空数据库</button>
<span class="muted" style="font-size:11.5px">清空后需重新导入;操作不可撤销</span>
</div>
</section>
<!-- 生成 -->
<section class="card">
<h2><span class="ico g"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 4h16v16H4z"/><path d="M8 9h8M8 13h8M8 17h5"/></svg></span>生成评估模板</h2>
<label class="f">需求清单(可选:不选就用数据库里的清单)</label>
<div class="pick">
<button class="btn" type="button" :disabled="demandBusy" @click="$refs.demandInput.click()">
<svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 7h6l2 2h8v10H4z"/></svg>
{{ demandBusy ? '读取中…' : '选择清单文件' }}
</button>
<template v-if="demandFile">
<span class="fname">{{ demandFile.name }}</span>
<span class="muted">
识别 {{ fmt(demandFile.rows) }} 行<template v-if="(demandFile.order_types||[]).length">
· {{ demandFile.order_types.join(' / ') }}</template>
</span>
<button class="btn" type="button" @click="clearDemandFile">改用数据库清单</button>
</template>
<span v-else class="muted">当前使用数据库清单({{ fmt(stats.demand) }} 行)</span>
</div>
<input ref="demandInput" type="file" accept=".xlsx,.xlsm" hidden @change="onDemandFile">
<div v-if="demandError" class="note" style="background:var(--red-l);border-color:#f3c9c9;color:var(--red)">
清单文件不可用:{{ demandError }}
</div>
<div v-else-if="demandFile" class="note" style="background:var(--pri-l);border-color:#cfe0fb;color:var(--pri-d)">
本次生成只读这份清单文件,不写入数据库(文件落在 data/uploads/_demand)。
</div>
<div class="row">
<div><label class="f">模板文件</label><input type="text" v-model="template"></div>
</div>
<div class="row">
<div><label class="f">输出目录</label><input type="text" v-model="outDir"></div>
<div style="max-width:130px"><label class="f">周边站点数</label>
<input type="number" min="1" max="10" v-model.number="neighbors"></div>
</div>
<div class="acts">
<button class="btn pri" :disabled="busyExport || demandBusy" @click="startExport">
<svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 4v12M7 11l5 5 5-5"/><path d="M4 20h16"/></svg>
{{ busyExport ? '生成中…' : '生成模板' }}
</button>
<a v-if="exportJob && exportJob.status==='succeeded'" class="btn" :href="'/api/v1/exports/'+exportJob.id+'/file'">
下载 {{ exportJob.output_name }}
</a>
</div>
<div v-if="exportJob" style="margin-top:14px">
<span class="st" :class="stCls(exportJob.status)">{{ statusText(exportJob.status) }}</span>
<span class="muted" style="margin-left:8px;font-size:12.5px">{{ exportJob.message }}</span>
<div class="bar"><i :style="{width: exportPct + '%'}"></i></div>
<div v-if="exportJob.warnings" class="note">{{ exportJob.warnings }}</div>
</div>
</section>
</div>
<div>
<!-- 概览 -->
<section class="card">
<h2><span class="ico c"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 20V10M10 20V4M16 20v-7M22 20H2"/></svg></span>数据概览</h2>
<div class="kpis">
<div class="kpi"><div class="k">4G 工参小区</div><div class="v">{{ fmt(stats.gongcan_4g) }}<small>个</small></div></div>
<div class="kpi"><div class="k">5G 工参小区</div><div class="v">{{ fmt(stats.gongcan_5g) }}<small>个</small></div></div>
<div class="kpi"><div class="k">流量指标行</div><div class="v">{{ fmt(stats.flow) }}<small>行</small></div></div>
<div class="kpi"><div class="k">时间点数</div><div class="v">{{ fmt(stats.flow_points) }}<small>个</small></div></div>
<div class="kpi"><div class="k">需求清单</div><div class="v">{{ fmt(stats.demand) }}<small>行</small></div></div>
<div class="kpi"><div class="k">工参版本</div><div class="v" style="font-size:14px;padding-top:5px">{{ (stats.gongcan_versions||[]).join(' / ') || '—' }}</div></div>
<div class="kpi"><div class="k">退网工单类型</div><div class="v" style="font-size:14px;padding-top:5px">{{ meta.order_type_prefix || '全部' }}</div></div>
</div>
</section>
<!-- 任务 -->
<section class="card">
<h2><span class="ico b"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg></span>最近任务</h2>
<table>
<thead><tr><th>类型</th><th>时间</th><th>状态</th><th>结果</th></tr></thead>
<tbody>
<tr v-for="j in recent" :key="j.id">
<td class="c1">{{ j.kind }}</td>
<td class="c2">{{ j.created_at }}</td>
<td class="c3"><span class="st" :class="stCls(j.status)">{{ statusText(j.status) }}</span></td>
<td class="c4" :title="j.message">{{ j.message }}</td>
</tr>
<tr v-if="!recent.length"><td colspan="4" class="muted">暂无任务</td></tr>
</tbody>
</table>
</section>
</div>
</div>
<section class="card">
<h2><span class="ico c"><svg viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 5h16v14H4z"/><path d="M8 9l3 3-3 3M13 15h4"/></svg></span>运行日志</h2>
<div id="log" ref="logEl">
<div v-for="(l,i) in logs" :key="i" :class="l.level"><span class="t">{{ l.t }}</span>{{ l.msg }}</div>
</div>
</section>
</div>
<script src="/ui/vue.global.prod.js"></script>
<script>
const { createApp, ref, reactive, computed, onMounted, nextTick } = Vue;
createApp({
setup() {
const meta = reactive({ database: '', order_type_prefix: '', data_dir: '', output_dir: '', template: '' });
const stats = reactive({ gongcan_4g: 0, gongcan_5g: 0, flow: 0, flow_points: 0, demand: 0 });
const tab = ref('dir');
const dir = ref('');
const template = ref('');
const outDir = ref('');
const neighbors = ref(3);
const batch = ref('');
const batchPath = ref('');
const uploaded = ref([]);
const importJob = ref(null);
const exportJob = ref(null);
const importPct = ref(0);
const exportPct = ref(0);
const imports = ref([]);
const exports = ref([]);
const logs = ref([]);
const logEl = ref(null);
const demandFile = ref(null); // 生成模板用的清单文件(不入库):{name, path, rows, order_types}
const demandBusy = ref(false);
const demandError = ref('');
const busyImport = computed(() => !!(importJob.value && ['pending','running'].includes(importJob.value.status)));
const importKind = ref('');
const busyExport = computed(() => exportJob.value && ['pending','running'].includes(exportJob.value.status));
const recent = computed(() => {
const a = imports.value.map(j => ({...j, kind:'入库'}));
const b = exports.value.map(j => ({...j, kind:'导出'}));
return [...a, ...b].sort((x,y) => (y.created_at||'').localeCompare(x.created_at||'')).slice(0,8);
});
function now(){ const d=new Date(); return d.toTimeString().slice(0,8); }
function log(msg, level=''){ logs.value.push({t:now(), msg, level}); nextTick(()=>{ if(logEl.value) logEl.value.scrollTop = logEl.value.scrollHeight; }); }
function fmt(n){ return (n===null||n===undefined)?'-':Number(n).toLocaleString('zh-CN'); }
function statusText(s){ return {pending:'排队中', running:'执行中', succeeded:'已完成', failed:'失败'}[s] || s || '-'; }
function stCls(s){ return s==='succeeded'?'ok':(s==='failed'?'err':(s==='running'?'run':'')); }
function hintDir(){ log('子文件夹中的报表将由后端按"网管批量报表"解析;顶层文件按"网页导入"解析。'); }
async function api(path, opts={}) {
const res = await fetch(path, opts);
const text = await res.text();
let data = null;
try { data = text ? JSON.parse(text) : null; } catch(e) { data = { raw: text }; }
if (!res.ok) {
const msg = (data && data.error && data.error.message) || res.statusText;
throw new Error(msg);
}
return data;
}
async function loadMeta(){
try{
const m = await api('/api/v1/meta');
Object.assign(meta, m);
dir.value = m.data_dir; template.value = m.template || (m.data_dir + '/频段清退评估模板.xlsx');
outDir.value = m.output_dir; neighbors.value = m.neighbor_sites || 3;
}catch(e){ log('读取服务信息失败:'+e.message, 'err'); }
}
async function loadStats(){
try{ Object.assign(stats, await api('/api/v1/stats')); }catch(e){ log('读取统计失败:'+e.message,'err'); }
}
async function loadJobs(){
try{
imports.value = (await api('/api/v1/imports')).items || [];
exports.value = (await api('/api/v1/exports')).items || [];
}catch(e){ /* ignore */ }
}
function refreshAll(){ loadStats(); loadJobs(); }
function pollImport(id){
const timer = setInterval(async () => {
try{
const j = await api('/api/v1/imports/'+id);
importJob.value = j;
importPct.value = j.status==='succeeded'?100:(j.status==='running'?65:(j.status==='failed'?100:8));
if (j.status==='succeeded' || j.status==='failed'){
clearInterval(timer);
importKind.value = '';
log(j.status==='succeeded' ? ('入库完成:'+j.message) : ('入库失败:'+j.message), j.status==='succeeded'?'ok':'err');
(j.skipped||[]).forEach(s => log('跳过:'+s, 'warn'));
loadStats(); loadJobs();
}
}catch(e){ clearInterval(timer); log('查询入库任务失败:'+e.message,'err'); }
}, 1500);
}
async function startImport(kinds){
if (busyImport.value) return;
let payload;
if (tab.value === 'upload'){
if (!batch.value) { log('请先选择文件上传', 'warn'); return; }
payload = { source:'upload', path: batchPath.value || batch.value };
} else {
payload = { source:'directory', path: dir.value };
}
payload.kinds = kinds;
const label = (kinds||[]).includes('flow') ? '流量' : '工参';
importKind.value = label === '流量' ? 'flow' : 'gongcan';
log('开始入库'+label+':'+payload.source+' → '+(payload.path||''));
try{
const j = await api('/api/v1/imports', {
method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(payload)
});
importJob.value = j; importPct.value = 5; log('已创建入库任务 '+j.id);
pollImport(j.id);
}catch(e){ importKind.value = ''; log('创建入库任务失败:'+e.message, 'err'); }
}
async function clearData(target){
const names = { all:'全部数据(工参 + 流量 + 清单)', gongcan:'工参', flow:'流量数据' };
if (!confirm('确认清空'+names[target]+'?此操作不可撤销。')) return;
try{
const r = await api('/api/v1/data/'+target, { method:'DELETE' });
log('已清空:'+r.message, 'ok');
refreshAll();
}catch(e){ log('清空失败:'+e.message, 'err'); }
}
async function onFiles(ev){
const files = [...(ev.target.files||[])];
if (!files.length) return;
const fd = new FormData();
files.forEach(f => fd.append('file', f));
log('上传 '+files.length+' 个文件…');
try{
const r = await api('/api/v1/files', { method:'POST', body: fd });
batch.value = r.batch; batchPath.value = r.path; uploaded.value = r.files;
log('上传完成:批次 '+r.batch+'('+r.files.length+' 个文件)','ok');
tab.value = 'upload';
}catch(e){ log('上传失败:'+e.message,'err'); }
ev.target.value = '';
}
function pollExport(id){
const timer = setInterval(async () => {
try{
const j = await api('/api/v1/exports/'+id);
exportJob.value = j;
exportPct.value = j.status==='succeeded'?100:(j.status==='running'?70:(j.status==='failed'?100:8));
if (j.status==='succeeded' || j.status==='failed'){
clearInterval(timer);
log(j.status==='succeeded' ? ('生成完成:'+j.output_name) : ('生成失败:'+j.message), j.status==='succeeded'?'ok':'err');
loadJobs();
}
}catch(e){ clearInterval(timer); log('查询导出任务失败:'+e.message,'err'); }
}, 1500);
}
async function startExport(){
if (busyExport.value || demandBusy.value) return;
if (demandFile.value) log('开始生成模板(清单:'+demandFile.value.name+')…');
else log('开始生成模板(使用数据库中的清单)…');
try{
const payload = { template_path: template.value, output_dir: outDir.value, neighbor_k: neighbors.value };
if (demandFile.value && demandFile.value.path) payload.demand_path = demandFile.value.path;
const j = await api('/api/v1/exports', {
method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(payload)
});
exportJob.value = j; exportPct.value = 5; log('已创建导出任务 '+j.id);
pollExport(j.id);
}catch(e){ log('创建导出任务失败:'+e.message,'err'); }
}
// ---- 生成模板:选择本机清单文件(只上传、不入库)
async function onDemandFile(ev){
const f = (ev.target.files || [])[0];
ev.target.value = '';
if (!f || demandBusy.value) return;
demandError.value = '';
if (!/\.(xlsx|xlsm)$/i.test(f.name)) { demandError.value = '只支持 .xlsx / .xlsm'; log(demandError.value, 'warn'); return; }
demandBusy.value = true;
log('上传清单文件:'+f.name+'('+Math.max(1, Math.round(f.size/1024))+' KB)…');
const fd = new FormData();
fd.append('file', f);
try{
const r = await api('/api/v1/demands/file', { method:'POST', body: fd });
demandFile.value = r;
log(r.message || ('清单已就绪:'+r.name), 'ok');
if ((r.order_types||[]).length) log('清单包含退网工单类型:'+r.order_types.join(' / '));
}catch(e){ demandError.value = e.message; log('清单文件不可用:'+e.message, 'err'); }
demandBusy.value = false;
}
function clearDemandFile(){
demandFile.value = null;
demandError.value = '';
log('已改为使用数据库中的清单');
}
onMounted(async () => {
log('界面就绪,正在读取服务信息…');
await loadMeta(); await loadStats(); await loadJobs();
log('数据目录:'+meta.data_dir, 'ok');
});
return { meta, stats, tab, dir, template, outDir, neighbors, batch, uploaded,
importJob, exportJob, importPct, exportPct, busyImport, importKind, busyExport, recent, logs, logEl,
demandFile, demandBusy, demandError, onDemandFile, clearDemandFile,
fmt, statusText, stCls, hintDir, startImport, startExport, onFiles, refreshAll };
}
}).mount('#app');
</script>
</body>
</html>