feat(license): 支持授权文件导入并固定生产公钥指纹校验

This commit is contained in:
lianjianwei2024
2026-10-12 17:23:40 +08:00
parent fb1875e8b2
commit 7fb7969a2f
9 changed files with 498 additions and 12 deletions

View File

@@ -475,7 +475,7 @@ a:hover{text-decoration:underline}
</div>
</div>
<script src="common.js?v=20261011f"></script>
<script src="common.js?v=20261012a"></script>
<script src="period.js"></script>
<script>
const $=id=>document.getElementById(id);

View File

@@ -2001,7 +2001,8 @@ function licDlg() {
'<div id="licSt" class="lic-st">加载中…</div>' +
'<div class="lic-btns">' +
'<button class="btn" id="licRf" onclick="licRefresh()">立即刷新授权(联网续租)</button>' +
'<button class="btn" id="licFb" onclick="licToggleForm()">重新激活 / 更换凭据</button></div>' +
'<button class="btn" id="licFb" onclick="licToggleForm()">重新激活 / 更换凭据</button>' +
'<button class="btn" id="licImpB" onclick="licImpToggle()">导入授权文件(.license.json)</button></div>' +
'<div id="licForm" style="display:none">' +
'<div class="lic-row"><label>实例 ID(instance_id)</label>' +
'<input id="licIid" spellcheck="false" placeholder="形如 11111111-2222-…"></div>' +
@@ -2011,6 +2012,11 @@ function licDlg() {
'<input id="licSec" type="password"></div>' +
'<div class="lic-btns"><button class="btn pri" id="licGo" onclick="licActivate()">激活</button></div>' +
'</div>' +
'<div id="licImp" style="display:none">' +
'<div class="lic-row"><label>选择软件提供方交付的授权文件(≤16KiB,导入后仍需在线激活)</label>' +
'<input type="file" id="licImpFile" accept=".json,application/json" onchange="licImpPick(this)"></div>' +
'<div id="licImpPv" class="lic-st" style="display:none"></div>' +
'</div>' +
'<div class="lic-tip">续费由软件提供方在授权平台操作,在线状态下一分钟内自动生效,无需重装;' +
'「立即刷新授权」可手动联网续租。激活密钥只保存在本机(Windows 加密存储),不会上传到别处。</div>' +
'</div></div>';
@@ -2021,6 +2027,10 @@ function licDlg() {
mask.classList.add('on');
const f = document.getElementById('licForm'); // 重开时表单复位收起(上轮未关的残留)
if (f) f.style.display = 'none';
const im = document.getElementById('licImp'); // 导入区同样复位
if (im) im.style.display = 'none';
const ipv = document.getElementById('licImpPv');
if (ipv) { ipv.style.display = 'none'; ipv.innerHTML = ''; }
licLoad();
clearInterval(_licPoll);
_licPoll = setInterval(licLoad, 15000);
@@ -2074,6 +2084,58 @@ function licToggleForm() {
const f = document.getElementById('licForm');
f.style.display = f.style.display === 'none' ? '' : 'none';
}
function licImpToggle() {
const d = document.getElementById('licImp');
d.style.display = d.style.display === 'none' ? '' : 'none';
}
function licImpErr(m) {
const p = document.getElementById('licImpPv');
p.style.display = '';
p.innerHTML = '<b class="bad">' + esc(m) + '</b>';
}
function licImpPick(inp) {
const file = inp.files && inp.files[0];
if (!file) return;
if (file.size > 16384) { licImpErr('文件超过 16KiB,不是有效授权文件。'); return; }
const r = new FileReader();
r.onload = () => { try { licImpPreview(JSON.parse(r.value)); }
catch (e) { licImpErr('文件不是有效 JSON。'); } };
r.readAsText(file, 'utf-8');
inp.value = '';
}
function licImpPreview(o) {
if (!o || typeof o !== 'object' || Array.isArray(o) ||
o.format !== 'yhy-license-activation' || o.version !== 1 ||
!o.instance_id || !o.license_key || !o.secret || !o.api_base_url) {
licImpErr('格式不符:需要 yhy-license-activation v1 授权文件。'); return;
}
window._licImpFile = o;
fetch('/api/license/status').then(r => r.json()).then(j => {
const d = j.data || {}, p = document.getElementById('licImpPv');
const warn = (d.instance_id && String(d.instance_id).toLowerCase() !== String(o.instance_id).toLowerCase())
? '<b class="bad">⚠ 本机已配置其他实例,导入将更换凭据(历史时间记录保留)。</b><br>' : '';
p.style.display = '';
p.innerHTML = warn + '实例:' + esc(o.instance_id) + '<br>授权中心:' + esc(o.api_base_url) +
'<div class="lic-btns" style="margin-bottom:0"><button class="btn pri" onclick="licImpGo()">确认导入并激活</button></div>';
}).catch(() => licImpErr('无法读取授权状态(本机服务异常?)'));
}
function licImpGo() {
fetch('/api/license/import', { method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file: window._licImpFile, replace_confirmed: true }) })
.then(r => r.json()).then(j => {
const res = ((j.data || {}).result) || {};
if (j.ok) {
const p = document.getElementById('licImpPv');
p.style.display = 'none'; p.innerHTML = '';
document.getElementById('licImp').style.display = 'none';
toast('导入激活成功', '');
} else {
licImpErr(res.message || '导入失败,请核对授权文件。');
}
licLoad();
}).catch(() => licImpErr('网络错误:无法连接本机服务'));
}
function licActivate() {
const b = { instance_id: document.getElementById('licIid').value.trim(),
license_key: document.getElementById('licLk').value.trim(),

View File

@@ -464,7 +464,7 @@ body.grptree-dragging{cursor:col-resize !important;user-select:none}
</div>
</div>
<script src="common.js?v=20261011f"></script>
<script src="common.js?v=20261012a"></script>
<script src="period.js"></script>
<script>
let SID=0, CUR=null, CURTYPE='lme', HROWS=[];
@@ -1424,6 +1424,26 @@ function setStop(){
if(kwActive()) return;
clearTimeout(_stopT); _stopT=setTimeout(search, 250);
}
/* 筛选栏输入框右缘小叉(2026-10-12 主人定):有值才显示,点一下清空并触发该框自己的联动;
视觉复用 comboFree 的 .combo/.combo-x(common.css 统一样式)。仅历史对比筛选栏用。 */
function filterInputX(inp, onClear){
if (inp._fx) return;
const wrap = document.createElement('span');
wrap.className = 'combo'; wrap.dataset.for = inp.id || '';
inp.parentNode.insertBefore(wrap, inp);
wrap.append(inp);
wrap.style.width = getComputedStyle(inp).width; // 包裹层占位原宽(工具条上的固定宽框)
inp.style.width = '100%';
const clr = document.createElement('span');
clr.className = 'combo-x'; clr.textContent = '×'; clr.title = '清空';
clr.style.display = 'none';
wrap.append(clr);
const sync = () => { clr.style.display = inp.value ? 'block' : 'none'; };
inp.addEventListener('input', sync);
clr.onclick = () => { inp.value = ''; sync(); onClear(); inp.focus(); };
inp._fx = true;
sync();
}
/* 分页(2026-10-08 主人定):检索每次 500 条,下一页=再取后 500;上一页/下一页在工具条最右,
仅检索模式显示。HPAGE 跨页保持,重新「查询」/清空关键词/重置都回第 1 页。 */
let HPAGE=1;
@@ -1474,6 +1494,11 @@ comboFree($('funit'), ()=> (curTab()==='p0' ? window.__ORG_OPTS : window.__BU_OP
$('funit').style.padding='3px 22px 3px 8px'; // 工具条控件更矮(盖掉 comboFree 默认内边距)
$('fpmin').addEventListener('input', setPrc); // 价格范围:输入即查(防抖在 setPrc)
$('fpmax').addEventListener('input', setPrc);
// 筛选栏输入框右缘小叉(2026-10-12 主人定):搜索/屏蔽词/价格范围四框;单位框 comboFree 自带
filterInputX($('hkw'), () => setKw($('hkw').value));
filterInputX($('fstop'), () => setStop());
filterInputX($('fpmin'), () => setPrc());
filterInputX($('fpmax'), () => setPrc());
$('hatt').addEventListener('change', setAtt); // 附件 全部/有/无
mkPeriod($('hperBtn'), ()=>{ updPerBtn(); if(!kwActive()) search(); }); // 期次:选完更新按钮文案;无关键字即查
mkPeriod($('oper')); // 打开工程:基准期次(起~止,同月填一样)