lingshu-skill 5.8.0 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +39 -3
- package/SKILL.md +2 -2
- package/assets/panel.html +625 -560
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +16 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +8 -8
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +34 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +39 -3
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +2 -2
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +625 -560
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +3 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +4759 -4753
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +28 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +1 -1
- package/scripts/core.py +3 -3
- package/scripts/growth.py +4759 -4753
- package/scripts/panel_server.py +28 -1
- package/scripts/panel_settings.py +1 -1
|
@@ -1229,9 +1229,27 @@ const PANEL_TOKEN = "/*__PANEL_TOKEN__*/";
|
|
|
1229
1229
|
// 服务端超过 panel_idle_minutes(默认 30)没任何请求就优雅退出。
|
|
1230
1230
|
// 页面每 30 秒 ping 一次:**网页开着 = 服务活着;关掉网页 = 到点自退**,
|
|
1231
1231
|
// 于是不会再出现"关了网页后台还在跑、只能去任务管理器杀"。
|
|
1232
|
-
(function
|
|
1232
|
+
(function panelKeepAlive(){
|
|
1233
|
+
// ① 长轮询(主):挂一条"不结束"的请求,服务端按住 25 秒再返回,收到后立刻再发。
|
|
1234
|
+
// 它**不是定时器**,所以不受浏览器对隐藏标签页的节流影响——
|
|
1235
|
+
// 只要标签页还在,服务端就一直看得到这条连接,绝不会因为"默认 1 分钟自退"被误杀。
|
|
1236
|
+
(async function loop(){
|
|
1237
|
+
for (;;) {
|
|
1238
|
+
let ok = false;
|
|
1239
|
+
try {
|
|
1240
|
+
const r = await fetch("/api/alive", {cache: "no-store"});
|
|
1241
|
+
ok = r.ok;
|
|
1242
|
+
} catch (_) {
|
|
1243
|
+
ok = false; // 服务端已经退出/连不上 → 停
|
|
1244
|
+
}
|
|
1245
|
+
if (!ok) break;
|
|
1246
|
+
await new Promise((res) => setTimeout(res, 200));
|
|
1247
|
+
}
|
|
1248
|
+
})();
|
|
1249
|
+
|
|
1250
|
+
// ② 兜底心跳(辅):万一长轮询被中间层掐断,仍有 30 秒一次 ping。
|
|
1251
|
+
// keepalive 让页面正在关闭时也能把最后一次发出去。
|
|
1233
1252
|
const beat = () => {
|
|
1234
|
-
// fetch + keepalive:页面正在关闭时也能把最后一次心跳发出去
|
|
1235
1253
|
try { fetch("/api/ping", {cache: "no-store", keepalive: true}).catch(() => {}); } catch (_) {}
|
|
1236
1254
|
};
|
|
1237
1255
|
beat();
|
|
@@ -1510,6 +1528,25 @@ function fillEmoPick(){
|
|
|
1510
1528
|
}
|
|
1511
1529
|
}
|
|
1512
1530
|
|
|
1531
|
+
// 主动刷新一次 overview 并重绘(页签切换、手动刷新都用它)。
|
|
1532
|
+
// 与 30 秒轮询共用同一段逻辑;editing 时不动,避免把正在输入的表单拽走。
|
|
1533
|
+
async function refreshOverviewOnce(force){
|
|
1534
|
+
if (!S.ov && !force) return;
|
|
1535
|
+
const editing = ["st-mood", "st-note", "st-energy", "st-closeness",
|
|
1536
|
+
"pf-name", "pf-role", "pf-callme", "pf-traits", "pf-likes", "pf-dislikes"]
|
|
1537
|
+
.some(id => document.activeElement === $(id));
|
|
1538
|
+
if (editing && !force) return;
|
|
1539
|
+
try {
|
|
1540
|
+
const seq = ++_ovSeq;
|
|
1541
|
+
S.ov = await api("/api/overview");
|
|
1542
|
+
if (seq !== _ovSeq) return;
|
|
1543
|
+
renderOverview();
|
|
1544
|
+
} catch (e) {
|
|
1545
|
+
// 主动刷新失败不该打断用户:提示一次即可(切页签这种场景不该弹错)
|
|
1546
|
+
console.warn("刷新概览失败:", e);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1513
1550
|
function renderMood(){
|
|
1514
1551
|
const ov = S.ov; if (!ov) return;
|
|
1515
1552
|
fillEmoPick();
|
|
@@ -3153,6 +3190,9 @@ function switchTab(tab){
|
|
|
3153
3190
|
// 数据目录卡靠一段 class 判断写错的 MutationObserver,永远停在「加载中…」)
|
|
3154
3191
|
if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); }
|
|
3155
3192
|
if (tab === "persona") { loadSnapshots(); loadPersonaSuggest(); } // 切到人格页时顺手刷快照列表与画像归纳建议
|
|
3193
|
+
// 概览/心情/梦 三页的数据都在 overview 里(心情与六欲是按时间衰减的活数值)。
|
|
3194
|
+
// 以前只靠 30 秒轮询 + document.hidden 跳过,切过去可能看到最多 30 秒前的旧值。
|
|
3195
|
+
if (["overview", "emotion", "dream"].includes(tab)) refreshOverviewOnce();
|
|
3156
3196
|
if (["knowledge", "notes", "skills", "growth"].includes(tab)) {
|
|
3157
3197
|
if (S.ws) { renderKnowledge(); renderNotes(); renderSkills(); renderDshPlugins(); renderGrowth(); renderOnboarding(); }
|
|
3158
3198
|
else loadWS();
|
|
@@ -5024,394 +5064,408 @@ setTimeout(() => checkUpdate(true), 1200);
|
|
|
5024
5064
|
#pm-close{all:unset;cursor:pointer;padding:10px 18px;font-size:13px;color:var(--muted)}
|
|
5025
5065
|
#pm-close:hover{color:var(--text)}
|
|
5026
5066
|
</style>
|
|
5027
|
-
<script>
|
|
5028
|
-
/* 自定义面板管理 UI:列表面板/启用/删除/打开目录/发布/安装。
|
|
5029
|
-
逻辑独立成块,不动主脚本;复用全局 api()/toast()/esc()/$( alias)。 */
|
|
5030
|
-
(function(){
|
|
5031
|
-
const $id = (i) => document.getElementById(i);
|
|
5032
|
-
|
|
5033
|
-
function overlay(){ return `
|
|
5034
|
-
<div id="pm-overlay" class="hidden">
|
|
5035
|
-
<div id="pm-card">
|
|
5036
|
-
<div id="pm-tabs">
|
|
5037
|
-
<button data-pm-tab="installed" class="on">已安装</button>
|
|
5038
|
-
<button data-pm-tab="market">面板市场</button>
|
|
5039
|
-
<span style="flex:1"></span>
|
|
5040
|
-
<button id="pm-close" title="关闭">✕</button>
|
|
5041
|
-
</div>
|
|
5042
|
-
<div id="pm-body"></div>
|
|
5043
|
-
</div>
|
|
5044
|
-
</div>`;}
|
|
5045
|
-
|
|
5046
|
-
// 打开覆盖层(首次点击时才注入 DOM)
|
|
5047
|
-
function open(){
|
|
5048
|
-
let ov = $id("pm-overlay");
|
|
5049
|
-
if (!ov){ document.body.insertAdjacentHTML("beforeend", overlay()); ov = $id("pm-overlay");
|
|
5050
|
-
ov.addEventListener("click", e => { if (e.target === ov) close(); });
|
|
5051
|
-
$id("pm-close").onclick = close;
|
|
5052
|
-
ov.querySelectorAll("[data-pm-tab]").forEach(b => b.onclick = () => {
|
|
5053
|
-
ov.querySelectorAll("[data-pm-tab]").forEach(x => x.classList.toggle("on", x === b));
|
|
5054
|
-
b.dataset.pmTab === "market" ? renderMarket() : renderInstalled();
|
|
5055
|
-
});
|
|
5056
|
-
}
|
|
5057
|
-
ov.classList.remove("hidden");
|
|
5058
|
-
renderInstalled();
|
|
5059
|
-
}
|
|
5060
|
-
function close(){ const ov = $id("pm-overlay"); if (ov) ov.classList.add("hidden"); }
|
|
5061
|
-
$id("btn-panels").onclick = open;
|
|
5062
|
-
// Esc 关闭:其它浮层(弹窗/命令面板)都认 Esc,这里不认会显得半截
|
|
5063
|
-
document.addEventListener("keydown", e => {
|
|
5064
|
-
if (e.key !== "Escape") return;
|
|
5065
|
-
const ov = $id("pm-overlay");
|
|
5066
|
-
if (ov && !ov.classList.contains("hidden")) close();
|
|
5067
|
-
});
|
|
5068
|
-
|
|
5069
|
-
async function ppost(action, extra){
|
|
5070
|
-
return api("/api/panels", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5071
|
-
body: JSON.stringify(Object.assign({action}, extra || {}))});
|
|
5072
|
-
}
|
|
5073
|
-
|
|
5074
|
-
// ---------------- 已安装标签页 ----------------
|
|
5075
|
-
async function renderInstalled(){
|
|
5076
|
-
const body = $id("pm-body");
|
|
5077
|
-
body.innerHTML = '<div class="empty">加载中…</div>';
|
|
5078
|
-
try{
|
|
5079
|
-
const d = await api("/api/panels");
|
|
5080
|
-
const rows = (d.panels || []).map(p => {
|
|
5081
|
-
const isActive = p.name === d.active || (p.name === "default" && d.active === "default");
|
|
5082
|
-
const act = isActive ? '<span class="pm-tag">当前使用</span>' : "";
|
|
5083
|
-
const src = p.source === "builtin" ? '<span class="pm-tag">内置</span>' : "";
|
|
5084
|
-
const err = p.valid === false ? `<span class="pm-tag err">损坏</span>` : "";
|
|
5085
|
-
let btns = "";
|
|
5086
|
-
if (p.name !== "default" && p.valid !== false && !isActive)
|
|
5087
|
-
btns += `<button class="btn mini" data-pm-act="activate" data-id="${esc(p.name)}">启用</button>`;
|
|
5088
|
-
if (p.name !== "default" && p.valid !== false)
|
|
5089
|
-
btns += `<button class="btn mini" data-pm-act="upload" data-id="${esc(p.name)}">上传到市场</button>`;
|
|
5090
|
-
if (p.name !== "default")
|
|
5091
|
-
btns += `<button class="btn mini" data-pm-act="delete" data-id="${esc(p.name)}"
|
|
5092
|
-
style="background:rgba(201,107,95,.14);color:var(--red-text)">删除</button>`;
|
|
5093
|
-
return `<div class="pm-item">
|
|
5094
|
-
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}</small>
|
|
5095
|
-
${act}${src}${err}</div>
|
|
5096
|
-
<div class="ds">${esc(p.invalid_reason || p.description || "")}</div></div>${btns}</div>`;
|
|
5097
|
-
}).join("");
|
|
5098
|
-
body.innerHTML = `
|
|
5099
|
-
<div class="pm-toolbar">
|
|
5100
|
-
<span class="sub" style="flex:1;word-break:break-all">已安装目录:${esc(d.installed_dir)}</span>
|
|
5101
|
-
<button class="btn mini" data-pm-act="open-folder">打开文件夹</button>
|
|
5102
|
-
<button class="btn mini" data-pm-act="scaffold">新建面板(脚手架)</button>
|
|
5103
|
-
<button class="btn mini" data-pm-act="refresh">刷新</button>
|
|
5104
|
-
</div>
|
|
5105
|
-
${rows || '<div class="empty">还没有已安装的自定义面板</div>'}`;
|
|
5106
|
-
}catch(e){ body.innerHTML = `<div class="empty">加载失败:${esc(e.message)}</div>`; }
|
|
5107
|
-
}
|
|
5108
|
-
|
|
5109
|
-
// ---------------- 面板市场标签页(本机共享库 + 云端市场 Gitee/GitHub) ----------------
|
|
5110
|
-
let cloudCfg = null; // 云端配置状态缓存(status)
|
|
5111
|
-
async function renderMarket(){
|
|
5112
|
-
const body = $id("pm-body");
|
|
5113
|
-
body.innerHTML = '<div class="empty">加载中…</div>';
|
|
5114
|
-
try{
|
|
5115
|
-
const d = await api("/api/panels/market");
|
|
5116
|
-
const inst = await api("/api/panels");
|
|
5117
|
-
const installedNames = new Set((inst.panels || [])
|
|
5118
|
-
.filter(p => p.source === "installed").map(p => p.name));
|
|
5119
|
-
let html = `<div class="pm-toolbar">
|
|
5120
|
-
<span class="sub" style="flex:1;word-break:break-all">本机市场目录:${esc(d.market_dir)}
|
|
5121
|
-
(拷贝目录/zip 即可流通;下方「云端市场」可跨设备分享)</span>
|
|
5122
|
-
<button class="btn mini" data-pm-act="open-folder-market">打开文件夹</button>
|
|
5123
|
-
<button class="btn mini" data-pm-act="refresh-market">刷新</button>
|
|
5124
|
-
</div>`;
|
|
5125
|
-
// 云端市场区:配置 + 在线面板卡片(带截图预览)
|
|
5126
|
-
html += await renderCloudSection(inst);
|
|
5127
|
-
// 本机市场列表
|
|
5128
|
-
const all = [...(d.panels || []), ...(d.zips || [])];
|
|
5129
|
-
if (all.length){
|
|
5130
|
-
html += '<div class="sub" style="margin:14px 0 6px">本机市场中的面板(安装=复制到已安装目录):</div>';
|
|
5131
|
-
html += all.map(p => {
|
|
5132
|
-
const done = installedNames.has(p.name);
|
|
5133
|
-
return `<div class="pm-item">
|
|
5134
|
-
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}
|
|
5135
|
-
${p.zip ? '<span class="pm-tag">zip</span>' : ""}</small></div>
|
|
5136
|
-
<div class="ds">${esc(p.description || "")}</div></div>
|
|
5137
|
-
${done ? '<span class="pm-tag">已安装</span>'
|
|
5138
|
-
: `<button class="btn mini" data-pm-act="install" data-id="${esc(p.name)}">安装</button>`}
|
|
5139
|
-
</div>`;}).join("");
|
|
5140
|
-
} else {
|
|
5141
|
-
html += '<div class="empty">本机市场目录为空——可从下方云端市场一键下载安装。</div>';
|
|
5142
|
-
}
|
|
5143
|
-
body.innerHTML = html;
|
|
5144
|
-
}catch(e){ body.innerHTML = `<div class="empty">加载失败:${esc(e.message)}</div>`; }
|
|
5145
|
-
}
|
|
5146
|
-
|
|
5147
|
-
// 云端市场区块:未配置→引导表单;已配置→在线面板列表(截图卡片)+ 发布入口
|
|
5148
|
-
async function renderCloudSection(inst){
|
|
5149
|
-
let out = '<div class="sub" style="margin:14px 0 6px">☁ 云端市场(Gitee / GitHub 仓库托管)</div>';
|
|
5150
|
-
try{ cloudCfg = await api("/api/panels/cloud"); }catch(e){ cloudCfg = null; }
|
|
5151
|
-
const st = cloudCfg && cloudCfg.status || {};
|
|
5152
|
-
if (!st.gitee_ready){
|
|
5153
|
-
// 首次配置表单:Gitee 必填(浏览可匿名,发布需 token)
|
|
5154
|
-
return out + `<div class="card" style="max-width:640px">
|
|
5155
|
-
<div class="ds" style="margin-bottom:10px">填一个公开 Gitee 仓库(如
|
|
5156
|
-
<code>yourname/lingshu-panels</code>)作为面板云端仓库;要发布还需
|
|
5157
|
-
<a href="https://gitee.com/profile/personal_access_tokens" target="_blank" rel="noopener">私人令牌</a>(勾选 projects 权限)。
|
|
5158
|
-
GitHub 可选,配置后自动镜像同步。</div>
|
|
5159
|
-
<div style="display:grid;gap:8px">
|
|
5160
|
-
<input id="pc-gitee-repo" placeholder="Gitee 仓库 owner/repo(必填)" style="width:100%">
|
|
5161
|
-
<input id="pc-gitee-token" placeholder="Gitee 私人令牌(发布需要)" style="width:100%">
|
|
5162
|
-
<input id="pc-github-repo" placeholder="GitHub 仓库 owner/repo(可选,镜像)" style="width:100%">
|
|
5163
|
-
<input id="pc-github-token" placeholder="GitHub token(配了 GitHub 才需要)" style="width:100%">
|
|
5164
|
-
<div><button class="btn mini" data-pm-act="cloud-save-cfg">保存云端配置</button></div>
|
|
5165
|
-
</div></div>`;
|
|
5166
|
-
}
|
|
5167
|
-
const errs = (cloudCfg && cloudCfg.errors || []).filter(Boolean);
|
|
5168
|
-
if (errs.length)
|
|
5169
|
-
out += `<div class="ds" style="color:var(--red);margin:4px 0">⚠ ${esc(errs.join(";"))}
|
|
5170
|
-
(云端不可达,可先浏览本机市场)</div>`;
|
|
5171
|
-
const panels = (cloudCfg && cloudCfg.panels) || [];
|
|
5172
|
-
out += `<div class="pm-toolbar">
|
|
5173
|
-
<span class="sub" style="flex:1">云端共 ${panels.length} 个面板
|
|
5174
|
-
${cloudCfg && cloudCfg.cached ? "(缓存,60s 自动刷新)" : ""}</span>
|
|
5175
|
-
<button class="btn mini" data-pm-act="cloud-refresh">刷新云端</button>
|
|
5176
|
-
<button class="btn mini" data-pm-act="cloud-cfg">重新配置</button>
|
|
5177
|
-
</div>`;
|
|
5178
|
-
if (panels.length){
|
|
5179
|
-
out += '<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;margin:8px 0">';
|
|
5180
|
-
out += panels.map(p => {
|
|
5181
|
-
const shot = p.screenshot
|
|
5182
|
-
? `<img src="/api/panels/cloud/shot?name=${encodeURIComponent(p.name)}&ext=${encodeURIComponent(p.screenshot)}"
|
|
5183
|
-
style="width:100%;height:130px;object-fit:cover;border-radius:8px;border:1px solid var(--line);cursor:zoom-in"
|
|
5184
|
-
data-pm-act="cloud-view" data-id="${esc(p.name)}" data-ext="${esc(p.screenshot)}" alt="">`
|
|
5185
|
-
: `<div style="width:100%;height:130px;border-radius:8px;border:1px dashed var(--line);
|
|
5186
|
-
display:flex;align-items:center;justify-content:center;color:var(--faint);font-size:12px">暂无截图</div>`;
|
|
5187
|
-
const installed = (inst.panels || []).some(x => x.source === "installed" && x.name === p.name);
|
|
5188
|
-
return `<div class="card" style="padding:10px">
|
|
5189
|
-
${shot}
|
|
5190
|
-
<div class="nm" style="margin:8px 0 2px">${esc(p.title)}
|
|
5191
|
-
<small>v${esc(p.version)} · ${esc(p.name)}</small></div>
|
|
5192
|
-
<div class="ds" style="min-height:34px;max-height:52px;overflow:hidden">${esc(p.description || "")}</div>
|
|
5193
|
-
<div style="display:flex;gap:6px;margin-top:8px;flex-wrap:wrap">
|
|
5194
|
-
${installed ? '<span class="pm-tag">已安装</span>'
|
|
5195
|
-
: `<button class="btn mini" data-pm-act="cloud-download" data-id="${esc(p.name)}">下载安装</button>`}
|
|
5196
|
-
<button class="btn mini" data-pm-act="cloud-view" data-id="${esc(p.name)}" data-ext="${esc(p.screenshot || "")}">详情</button>
|
|
5197
|
-
</div></div>`;
|
|
5198
|
-
}).join("");
|
|
5199
|
-
out += '</div>';
|
|
5200
|
-
} else {
|
|
5201
|
-
out += '<div class="empty">云端仓库还是空的——做完面板点下面的「发布到云端」,或先安装本机已有的。</div>';
|
|
5202
|
-
}
|
|
5203
|
-
// 发布入口:选一个已安装面板 + 可选截图
|
|
5204
|
-
const mine = (inst.panels || []).filter(p => p.source === "installed" && p.valid !== false);
|
|
5205
|
-
out += `<div class="sub" style="margin:12px 0 6px">发布我的面板到云端${st.publish_ready ? "" : "(需先在配置里填 Gitee token)"}:</div>`;
|
|
5206
|
-
out += mine.length ? mine.map(p => `<div class="pm-item">
|
|
5207
|
-
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}</small></div>
|
|
5208
|
-
<div class="ds">${esc(p.description || "")}</div></div>
|
|
5209
|
-
<label class="btn mini" style="cursor:pointer">选截图
|
|
5210
|
-
<input type="file" accept="image/png,image/jpeg,image/webp" style="display:none"
|
|
5211
|
-
data-pm-shot="${esc(p.name)}"></label>
|
|
5212
|
-
<button class="btn mini" data-pm-act="cloud-publish" data-id="${esc(p.name)}">发布</button>
|
|
5213
|
-
</div>`).join("")
|
|
5214
|
-
: '<div class="ds">已安装目录里还没有可发布的面板。</div>';
|
|
5215
|
-
return out;
|
|
5216
|
-
}
|
|
5217
|
-
// 选中截图文件暂存(发布时随面板一起上传)
|
|
5218
|
-
const pendingShots = {};
|
|
5219
|
-
document.addEventListener("change", (e) => {
|
|
5220
|
-
const inp = e.target.closest("[data-pm-shot]");
|
|
5221
|
-
if (!inp || !inp.files || !inp.files[0]) return;
|
|
5222
|
-
const f = inp.files[0];
|
|
5223
|
-
if (f.size > 2 * 1024 * 1024){ toast("截图超过 2MB,请压缩后再选", true); inp.value = ""; return; }
|
|
5224
|
-
const r = new FileReader();
|
|
5225
|
-
r.onload = () => { pendingShots[inp.dataset.pmShot] = r.result;
|
|
5226
|
-
toast("截图已就绪,点「发布」一起上传"); };
|
|
5227
|
-
r.readAsDataURL(f);
|
|
5228
|
-
});
|
|
5229
|
-
|
|
5230
|
-
// 统一按钮动作分发(事件委托,body 重渲染不用重绑)
|
|
5231
|
-
document.addEventListener("click", async (e) => {
|
|
5232
|
-
const btn = e.target.closest("[data-pm-act]");
|
|
5233
|
-
if (!btn) return;
|
|
5234
|
-
const act = btn.dataset.pmAct;
|
|
5235
|
-
if (act === "refresh"){ renderInstalled(); return; }
|
|
5236
|
-
if (act === "refresh-market"){ renderMarket(); return; }
|
|
5237
|
-
if (act === "open-folder"){
|
|
5238
|
-
try{ await ppost("open-folder", {which: "installed"}); }catch(err){ toast(err.message, true); } return;
|
|
5239
|
-
}
|
|
5240
|
-
if (act === "open-folder-market"){
|
|
5241
|
-
try{ await ppost("open-folder", {which: "market"}); }catch(err){ toast(err.message, true); } return;
|
|
5242
|
-
}
|
|
5243
|
-
if (act === "scaffold"){
|
|
5244
|
-
const nm = prompt("面板名(小写字母/数字/-/_,也是目录名):");
|
|
5245
|
-
if (!nm) return;
|
|
5246
|
-
const tt = prompt("展示名(面板标题):", nm) || nm;
|
|
5247
|
-
btn.disabled = true;
|
|
5248
|
-
try{
|
|
5249
|
-
await api("/api/panels/scaffold", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5250
|
-
body: JSON.stringify({name: nm.trim(), title: tt.trim()})});
|
|
5251
|
-
toast("已创建面板骨架,打开文件夹即可编辑;改完点「启用」即刻生效");
|
|
5252
|
-
renderInstalled();
|
|
5253
|
-
}catch(err){ toast(err.message, true); }
|
|
5254
|
-
btn.disabled = false;
|
|
5255
|
-
return;
|
|
5256
|
-
}
|
|
5257
|
-
if (act === "activate"){
|
|
5258
|
-
btn.disabled = true;
|
|
5259
|
-
try{ await ppost("activate", {name: btn.dataset.id});
|
|
5260
|
-
toast("已启用,正在热加载面板…"); location.reload(); }
|
|
5261
|
-
catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5262
|
-
return;
|
|
5263
|
-
}
|
|
5264
|
-
if (act === "delete"){
|
|
5265
|
-
if (!confirm("确定删除该面板目录?此操作不可恢复。")) return;
|
|
5266
|
-
try{ await ppost("delete", {name: btn.dataset.id, source: curTab()}); toast("已删除");
|
|
5267
|
-
curTab() === "market" ? renderMarket() : renderInstalled(); }
|
|
5268
|
-
catch(err){ toast(err.message, true); }
|
|
5269
|
-
return;
|
|
5270
|
-
}
|
|
5271
|
-
if (act === "upload"){
|
|
5272
|
-
btn.disabled = true;
|
|
5273
|
-
try{
|
|
5274
|
-
await ppost("upload", {name: btn.dataset.id});
|
|
5275
|
-
toast("已上传到面板市场(剪切移动)");
|
|
5276
|
-
renderMarket();
|
|
5277
|
-
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5278
|
-
return;
|
|
5279
|
-
}
|
|
5280
|
-
if (act === "install"){
|
|
5281
|
-
btn.disabled = true;
|
|
5282
|
-
try{
|
|
5283
|
-
const r = await ppost("install", {name: btn.dataset.id});
|
|
5284
|
-
toast(`已安装 ${r.title || r.name} v${r.version},可在「已安装」里启用`);
|
|
5285
|
-
renderMarket();
|
|
5286
|
-
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5287
|
-
return;
|
|
5288
|
-
}
|
|
5289
|
-
// ---------------- 云端市场动作 ----------------
|
|
5290
|
-
if (act === "cloud-refresh"){
|
|
5291
|
-
btn.disabled = true;
|
|
5292
|
-
renderMarket(); // renderCloudSection 会带 force=false 重新拉(有 60s 缓存)
|
|
5293
|
-
return;
|
|
5294
|
-
}
|
|
5295
|
-
if (act === "cloud-save-cfg" || act === "cloud-cfg"){
|
|
5296
|
-
if (act === "cloud-cfg"){ // 重新配置:清空云端配置后回到引导表单
|
|
5297
|
-
btn.disabled = true;
|
|
5298
|
-
try{
|
|
5299
|
-
await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5300
|
-
body: JSON.stringify({action:"clear-config"})});
|
|
5301
|
-
toast("云端配置已清除,请重新填写");
|
|
5302
|
-
}catch(err){ toast(err.message, true); }
|
|
5303
|
-
btn.disabled = false;
|
|
5304
|
-
renderMarket();
|
|
5305
|
-
return;
|
|
5306
|
-
}
|
|
5307
|
-
btn.disabled = true;
|
|
5308
|
-
try{
|
|
5309
|
-
await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5310
|
-
body: JSON.stringify({action:"save-config",
|
|
5311
|
-
gitee_repo: ($id("pc-gitee-repo")||{}).value || "",
|
|
5312
|
-
gitee_token: ($id("pc-gitee-token")||{}).value || "",
|
|
5313
|
-
github_repo: ($id("pc-github-repo")||{}).value || "",
|
|
5314
|
-
github_token: ($id("pc-github-token")||{}).value || ""})});
|
|
5315
|
-
toast("云端配置已保存");
|
|
5316
|
-
renderMarket();
|
|
5317
|
-
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5318
|
-
return;
|
|
5319
|
-
}
|
|
5320
|
-
if (act === "cloud-download"){
|
|
5321
|
-
btn.disabled = true;
|
|
5322
|
-
btn.textContent = "下载中…";
|
|
5323
|
-
try{
|
|
5324
|
-
const r = await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5325
|
-
body: JSON.stringify({action:"download", name: btn.dataset.id})});
|
|
5326
|
-
toast(`已下载安装 ${r.title || r.name} v${r.version},可在「已安装」里启用`);
|
|
5327
|
-
renderMarket();
|
|
5328
|
-
}catch(err){ toast(err.message, true); btn.disabled = false; btn.textContent = "下载安装"; }
|
|
5329
|
-
return;
|
|
5330
|
-
}
|
|
5331
|
-
if (act === "cloud-publish"){
|
|
5332
|
-
btn.disabled = true;
|
|
5333
|
-
try{
|
|
5334
|
-
const r = await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5335
|
-
body: JSON.stringify({action:"publish", name: btn.dataset.id,
|
|
5336
|
-
screenshot: pendingShots[btn.dataset.id] || ""})});
|
|
5337
|
-
toast(`已发布到:${(r.pushed || []).join("、")}` + (r.errors && r.errors.length ? `(部分失败:${r.errors.join(";")})` : ""));
|
|
5338
|
-
delete pendingShots[btn.dataset.id];
|
|
5339
|
-
renderMarket();
|
|
5340
|
-
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5341
|
-
return;
|
|
5342
|
-
}
|
|
5343
|
-
if (act === "cloud-view"){
|
|
5344
|
-
// 详情弹窗:截图大图 + 描述 + 版本信息;无截图则只展示文字
|
|
5345
|
-
const nm = btn.dataset.id, ext = btn.dataset.ext || "";
|
|
5346
|
-
let shotHtml = "";
|
|
5347
|
-
if (ext) shotHtml = `<img src="/api/panels/cloud/shot?name=${encodeURIComponent(nm)}&ext=${encodeURIComponent(ext)}"
|
|
5348
|
-
style="width:100%;border-radius:8px;border:1px solid var(--line)" alt="">`;
|
|
5349
|
-
const p = ((cloudCfg || {}).panels || []).find(x => x.name === nm) || {};
|
|
5350
|
-
alert(`【${p.title || nm}】v${p.version || "?"}\n作者:${p.author || "未署名"}\n更新:${p.updated || "?"}\n大小:${p.size ? Math.round(p.size/1024) + " KB" : "?"}\n\n${p.description || "(无描述)"}`);
|
|
5351
|
-
return;
|
|
5352
|
-
}
|
|
5353
|
-
});
|
|
5354
|
-
// 当前在哪个标签页(installed / market):删除按钮的 source 参数要用
|
|
5355
|
-
function curTab(){
|
|
5356
|
-
const on = $id("pm-tabs") && $id("pm-tabs").querySelector(".on");
|
|
5357
|
-
return on ? on.dataset.pmTab : "installed";
|
|
5358
|
-
}
|
|
5359
|
-
|
|
5360
|
-
// 回退提示:服务端注入的激活面板名——若激活了自定义面板,全屏 iframe 热加载它。
|
|
5361
|
-
// 兜底三层:iframe onerror/3s 超时 → 提示并自动切回 default;iframe 内 JS 崩溃
|
|
5362
|
-
// 只崩 iframe 自身,不影响外壳;面板扫描 invalid 根本不会被激活(后端预检)。
|
|
5363
|
-
const ACT = window.__LINGSHU_ACTIVE__ || {panel: "default"};
|
|
5364
|
-
function loadCustom(pname, entry){
|
|
5365
|
-
const fr = document.createElement("iframe");
|
|
5366
|
-
fr.id = "custom-panel-frame";
|
|
5367
|
-
// entry 来自面板 manifest(/api/panels 列表下发),不是写死的 index.html——
|
|
5368
|
-
// manifest 允许作者自定义入口文件名,写死会让这类面板 404 → 被超时兜底误回退
|
|
5369
|
-
fr.src = "/api/panels/file?panel=" + encodeURIComponent(pname) +
|
|
5370
|
-
"&path=" + encodeURIComponent(entry || "index.html") + "&as_page=1";
|
|
5371
|
-
fr.style.cssText = "position:fixed;inset:0;width:100vw;height:100vh;border:none;z-index:800;background:#14181e";
|
|
5372
|
-
fr.onerror = () => fallback(pname, "iframe 加载失败");
|
|
5373
|
-
document.body.appendChild(fr);
|
|
5374
|
-
// 超时兜底:3 秒内 iframe 没触发 load(说明资源坏了/接口 404),自动回退
|
|
5375
|
-
let ok = false;
|
|
5376
|
-
fr.addEventListener("load", () => { ok = true; });
|
|
5377
|
-
setTimeout(() => { if (!ok) fallback(pname, "加载超时"); }, 3000);
|
|
5378
|
-
// 悬浮逃生口:永远能一键回到默认面板
|
|
5379
|
-
const escBtn = document.createElement("button");
|
|
5380
|
-
escBtn.id = "panel-escape";
|
|
5381
|
-
escBtn.textContent = "⇱ 返回默认面板";
|
|
5382
|
-
escBtn.style.cssText = "position:fixed;right:14px;top:14px;z-index:850;cursor:pointer;" +
|
|
5383
|
-
"background:#1b2028;color:#e6e1d5;border:1px solid #2a3140;border-radius:9px;padding:7px 14px;font-size:12px";
|
|
5384
|
-
escBtn.onclick = async () => {
|
|
5385
|
-
try{
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5067
|
+
<script>
|
|
5068
|
+
/* 自定义面板管理 UI:列表面板/启用/删除/打开目录/发布/安装。
|
|
5069
|
+
逻辑独立成块,不动主脚本;复用全局 api()/toast()/esc()/$( alias)。 */
|
|
5070
|
+
(function(){
|
|
5071
|
+
const $id = (i) => document.getElementById(i);
|
|
5072
|
+
|
|
5073
|
+
function overlay(){ return `
|
|
5074
|
+
<div id="pm-overlay" class="hidden">
|
|
5075
|
+
<div id="pm-card">
|
|
5076
|
+
<div id="pm-tabs">
|
|
5077
|
+
<button data-pm-tab="installed" class="on">已安装</button>
|
|
5078
|
+
<button data-pm-tab="market">面板市场</button>
|
|
5079
|
+
<span style="flex:1"></span>
|
|
5080
|
+
<button id="pm-close" title="关闭">✕</button>
|
|
5081
|
+
</div>
|
|
5082
|
+
<div id="pm-body"></div>
|
|
5083
|
+
</div>
|
|
5084
|
+
</div>`;}
|
|
5085
|
+
|
|
5086
|
+
// 打开覆盖层(首次点击时才注入 DOM)
|
|
5087
|
+
function open(){
|
|
5088
|
+
let ov = $id("pm-overlay");
|
|
5089
|
+
if (!ov){ document.body.insertAdjacentHTML("beforeend", overlay()); ov = $id("pm-overlay");
|
|
5090
|
+
ov.addEventListener("click", e => { if (e.target === ov) close(); });
|
|
5091
|
+
$id("pm-close").onclick = close;
|
|
5092
|
+
ov.querySelectorAll("[data-pm-tab]").forEach(b => b.onclick = () => {
|
|
5093
|
+
ov.querySelectorAll("[data-pm-tab]").forEach(x => x.classList.toggle("on", x === b));
|
|
5094
|
+
b.dataset.pmTab === "market" ? renderMarket() : renderInstalled();
|
|
5095
|
+
});
|
|
5096
|
+
}
|
|
5097
|
+
ov.classList.remove("hidden");
|
|
5098
|
+
renderInstalled();
|
|
5099
|
+
}
|
|
5100
|
+
function close(){ const ov = $id("pm-overlay"); if (ov) ov.classList.add("hidden"); }
|
|
5101
|
+
$id("btn-panels").onclick = open;
|
|
5102
|
+
// Esc 关闭:其它浮层(弹窗/命令面板)都认 Esc,这里不认会显得半截
|
|
5103
|
+
document.addEventListener("keydown", e => {
|
|
5104
|
+
if (e.key !== "Escape") return;
|
|
5105
|
+
const ov = $id("pm-overlay");
|
|
5106
|
+
if (ov && !ov.classList.contains("hidden")) close();
|
|
5107
|
+
});
|
|
5108
|
+
|
|
5109
|
+
async function ppost(action, extra){
|
|
5110
|
+
return api("/api/panels", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5111
|
+
body: JSON.stringify(Object.assign({action}, extra || {}))});
|
|
5112
|
+
}
|
|
5113
|
+
|
|
5114
|
+
// ---------------- 已安装标签页 ----------------
|
|
5115
|
+
async function renderInstalled(){
|
|
5116
|
+
const body = $id("pm-body");
|
|
5117
|
+
body.innerHTML = '<div class="empty">加载中…</div>';
|
|
5118
|
+
try{
|
|
5119
|
+
const d = await api("/api/panels");
|
|
5120
|
+
const rows = (d.panels || []).map(p => {
|
|
5121
|
+
const isActive = p.name === d.active || (p.name === "default" && d.active === "default");
|
|
5122
|
+
const act = isActive ? '<span class="pm-tag">当前使用</span>' : "";
|
|
5123
|
+
const src = p.source === "builtin" ? '<span class="pm-tag">内置</span>' : "";
|
|
5124
|
+
const err = p.valid === false ? `<span class="pm-tag err">损坏</span>` : "";
|
|
5125
|
+
let btns = "";
|
|
5126
|
+
if (p.name !== "default" && p.valid !== false && !isActive)
|
|
5127
|
+
btns += `<button class="btn mini" data-pm-act="activate" data-id="${esc(p.name)}">启用</button>`;
|
|
5128
|
+
if (p.name !== "default" && p.valid !== false)
|
|
5129
|
+
btns += `<button class="btn mini" data-pm-act="upload" data-id="${esc(p.name)}">上传到市场</button>`;
|
|
5130
|
+
if (p.name !== "default")
|
|
5131
|
+
btns += `<button class="btn mini" data-pm-act="delete" data-id="${esc(p.name)}"
|
|
5132
|
+
style="background:rgba(201,107,95,.14);color:var(--red-text)">删除</button>`;
|
|
5133
|
+
return `<div class="pm-item">
|
|
5134
|
+
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}</small>
|
|
5135
|
+
${act}${src}${err}</div>
|
|
5136
|
+
<div class="ds">${esc(p.invalid_reason || p.description || "")}</div></div>${btns}</div>`;
|
|
5137
|
+
}).join("");
|
|
5138
|
+
body.innerHTML = `
|
|
5139
|
+
<div class="pm-toolbar">
|
|
5140
|
+
<span class="sub" style="flex:1;word-break:break-all">已安装目录:${esc(d.installed_dir)}</span>
|
|
5141
|
+
<button class="btn mini" data-pm-act="open-folder">打开文件夹</button>
|
|
5142
|
+
<button class="btn mini" data-pm-act="scaffold">新建面板(脚手架)</button>
|
|
5143
|
+
<button class="btn mini" data-pm-act="refresh">刷新</button>
|
|
5144
|
+
</div>
|
|
5145
|
+
${rows || '<div class="empty">还没有已安装的自定义面板</div>'}`;
|
|
5146
|
+
}catch(e){ body.innerHTML = `<div class="empty">加载失败:${esc(e.message)}</div>`; }
|
|
5147
|
+
}
|
|
5148
|
+
|
|
5149
|
+
// ---------------- 面板市场标签页(本机共享库 + 云端市场 Gitee/GitHub) ----------------
|
|
5150
|
+
let cloudCfg = null; // 云端配置状态缓存(status)
|
|
5151
|
+
async function renderMarket(){
|
|
5152
|
+
const body = $id("pm-body");
|
|
5153
|
+
body.innerHTML = '<div class="empty">加载中…</div>';
|
|
5154
|
+
try{
|
|
5155
|
+
const d = await api("/api/panels/market");
|
|
5156
|
+
const inst = await api("/api/panels");
|
|
5157
|
+
const installedNames = new Set((inst.panels || [])
|
|
5158
|
+
.filter(p => p.source === "installed").map(p => p.name));
|
|
5159
|
+
let html = `<div class="pm-toolbar">
|
|
5160
|
+
<span class="sub" style="flex:1;word-break:break-all">本机市场目录:${esc(d.market_dir)}
|
|
5161
|
+
(拷贝目录/zip 即可流通;下方「云端市场」可跨设备分享)</span>
|
|
5162
|
+
<button class="btn mini" data-pm-act="open-folder-market">打开文件夹</button>
|
|
5163
|
+
<button class="btn mini" data-pm-act="refresh-market">刷新</button>
|
|
5164
|
+
</div>`;
|
|
5165
|
+
// 云端市场区:配置 + 在线面板卡片(带截图预览)
|
|
5166
|
+
html += await renderCloudSection(inst);
|
|
5167
|
+
// 本机市场列表
|
|
5168
|
+
const all = [...(d.panels || []), ...(d.zips || [])];
|
|
5169
|
+
if (all.length){
|
|
5170
|
+
html += '<div class="sub" style="margin:14px 0 6px">本机市场中的面板(安装=复制到已安装目录):</div>';
|
|
5171
|
+
html += all.map(p => {
|
|
5172
|
+
const done = installedNames.has(p.name);
|
|
5173
|
+
return `<div class="pm-item">
|
|
5174
|
+
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}
|
|
5175
|
+
${p.zip ? '<span class="pm-tag">zip</span>' : ""}</small></div>
|
|
5176
|
+
<div class="ds">${esc(p.description || "")}</div></div>
|
|
5177
|
+
${done ? '<span class="pm-tag">已安装</span>'
|
|
5178
|
+
: `<button class="btn mini" data-pm-act="install" data-id="${esc(p.name)}">安装</button>`}
|
|
5179
|
+
</div>`;}).join("");
|
|
5180
|
+
} else {
|
|
5181
|
+
html += '<div class="empty">本机市场目录为空——可从下方云端市场一键下载安装。</div>';
|
|
5182
|
+
}
|
|
5183
|
+
body.innerHTML = html;
|
|
5184
|
+
}catch(e){ body.innerHTML = `<div class="empty">加载失败:${esc(e.message)}</div>`; }
|
|
5185
|
+
}
|
|
5186
|
+
|
|
5187
|
+
// 云端市场区块:未配置→引导表单;已配置→在线面板列表(截图卡片)+ 发布入口
|
|
5188
|
+
async function renderCloudSection(inst){
|
|
5189
|
+
let out = '<div class="sub" style="margin:14px 0 6px">☁ 云端市场(Gitee / GitHub 仓库托管)</div>';
|
|
5190
|
+
try{ cloudCfg = await api("/api/panels/cloud"); }catch(e){ cloudCfg = null; }
|
|
5191
|
+
const st = cloudCfg && cloudCfg.status || {};
|
|
5192
|
+
if (!st.gitee_ready){
|
|
5193
|
+
// 首次配置表单:Gitee 必填(浏览可匿名,发布需 token)
|
|
5194
|
+
return out + `<div class="card" style="max-width:640px">
|
|
5195
|
+
<div class="ds" style="margin-bottom:10px">填一个公开 Gitee 仓库(如
|
|
5196
|
+
<code>yourname/lingshu-panels</code>)作为面板云端仓库;要发布还需
|
|
5197
|
+
<a href="https://gitee.com/profile/personal_access_tokens" target="_blank" rel="noopener">私人令牌</a>(勾选 projects 权限)。
|
|
5198
|
+
GitHub 可选,配置后自动镜像同步。</div>
|
|
5199
|
+
<div style="display:grid;gap:8px">
|
|
5200
|
+
<input id="pc-gitee-repo" placeholder="Gitee 仓库 owner/repo(必填)" style="width:100%">
|
|
5201
|
+
<input id="pc-gitee-token" placeholder="Gitee 私人令牌(发布需要)" style="width:100%">
|
|
5202
|
+
<input id="pc-github-repo" placeholder="GitHub 仓库 owner/repo(可选,镜像)" style="width:100%">
|
|
5203
|
+
<input id="pc-github-token" placeholder="GitHub token(配了 GitHub 才需要)" style="width:100%">
|
|
5204
|
+
<div><button class="btn mini" data-pm-act="cloud-save-cfg">保存云端配置</button></div>
|
|
5205
|
+
</div></div>`;
|
|
5206
|
+
}
|
|
5207
|
+
const errs = (cloudCfg && cloudCfg.errors || []).filter(Boolean);
|
|
5208
|
+
if (errs.length)
|
|
5209
|
+
out += `<div class="ds" style="color:var(--red);margin:4px 0">⚠ ${esc(errs.join(";"))}
|
|
5210
|
+
(云端不可达,可先浏览本机市场)</div>`;
|
|
5211
|
+
const panels = (cloudCfg && cloudCfg.panels) || [];
|
|
5212
|
+
out += `<div class="pm-toolbar">
|
|
5213
|
+
<span class="sub" style="flex:1">云端共 ${panels.length} 个面板
|
|
5214
|
+
${cloudCfg && cloudCfg.cached ? "(缓存,60s 自动刷新)" : ""}</span>
|
|
5215
|
+
<button class="btn mini" data-pm-act="cloud-refresh">刷新云端</button>
|
|
5216
|
+
<button class="btn mini" data-pm-act="cloud-cfg">重新配置</button>
|
|
5217
|
+
</div>`;
|
|
5218
|
+
if (panels.length){
|
|
5219
|
+
out += '<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;margin:8px 0">';
|
|
5220
|
+
out += panels.map(p => {
|
|
5221
|
+
const shot = p.screenshot
|
|
5222
|
+
? `<img src="/api/panels/cloud/shot?name=${encodeURIComponent(p.name)}&ext=${encodeURIComponent(p.screenshot)}"
|
|
5223
|
+
style="width:100%;height:130px;object-fit:cover;border-radius:8px;border:1px solid var(--line);cursor:zoom-in"
|
|
5224
|
+
data-pm-act="cloud-view" data-id="${esc(p.name)}" data-ext="${esc(p.screenshot)}" alt="">`
|
|
5225
|
+
: `<div style="width:100%;height:130px;border-radius:8px;border:1px dashed var(--line);
|
|
5226
|
+
display:flex;align-items:center;justify-content:center;color:var(--faint);font-size:12px">暂无截图</div>`;
|
|
5227
|
+
const installed = (inst.panels || []).some(x => x.source === "installed" && x.name === p.name);
|
|
5228
|
+
return `<div class="card" style="padding:10px">
|
|
5229
|
+
${shot}
|
|
5230
|
+
<div class="nm" style="margin:8px 0 2px">${esc(p.title)}
|
|
5231
|
+
<small>v${esc(p.version)} · ${esc(p.name)}</small></div>
|
|
5232
|
+
<div class="ds" style="min-height:34px;max-height:52px;overflow:hidden">${esc(p.description || "")}</div>
|
|
5233
|
+
<div style="display:flex;gap:6px;margin-top:8px;flex-wrap:wrap">
|
|
5234
|
+
${installed ? '<span class="pm-tag">已安装</span>'
|
|
5235
|
+
: `<button class="btn mini" data-pm-act="cloud-download" data-id="${esc(p.name)}">下载安装</button>`}
|
|
5236
|
+
<button class="btn mini" data-pm-act="cloud-view" data-id="${esc(p.name)}" data-ext="${esc(p.screenshot || "")}">详情</button>
|
|
5237
|
+
</div></div>`;
|
|
5238
|
+
}).join("");
|
|
5239
|
+
out += '</div>';
|
|
5240
|
+
} else {
|
|
5241
|
+
out += '<div class="empty">云端仓库还是空的——做完面板点下面的「发布到云端」,或先安装本机已有的。</div>';
|
|
5242
|
+
}
|
|
5243
|
+
// 发布入口:选一个已安装面板 + 可选截图
|
|
5244
|
+
const mine = (inst.panels || []).filter(p => p.source === "installed" && p.valid !== false);
|
|
5245
|
+
out += `<div class="sub" style="margin:12px 0 6px">发布我的面板到云端${st.publish_ready ? "" : "(需先在配置里填 Gitee token)"}:</div>`;
|
|
5246
|
+
out += mine.length ? mine.map(p => `<div class="pm-item">
|
|
5247
|
+
<div class="grow"><div class="nm">${esc(p.title)}<small>v${esc(p.version)} · ${esc(p.name)}</small></div>
|
|
5248
|
+
<div class="ds">${esc(p.description || "")}</div></div>
|
|
5249
|
+
<label class="btn mini" style="cursor:pointer">选截图
|
|
5250
|
+
<input type="file" accept="image/png,image/jpeg,image/webp" style="display:none"
|
|
5251
|
+
data-pm-shot="${esc(p.name)}"></label>
|
|
5252
|
+
<button class="btn mini" data-pm-act="cloud-publish" data-id="${esc(p.name)}">发布</button>
|
|
5253
|
+
</div>`).join("")
|
|
5254
|
+
: '<div class="ds">已安装目录里还没有可发布的面板。</div>';
|
|
5255
|
+
return out;
|
|
5256
|
+
}
|
|
5257
|
+
// 选中截图文件暂存(发布时随面板一起上传)
|
|
5258
|
+
const pendingShots = {};
|
|
5259
|
+
document.addEventListener("change", (e) => {
|
|
5260
|
+
const inp = e.target.closest("[data-pm-shot]");
|
|
5261
|
+
if (!inp || !inp.files || !inp.files[0]) return;
|
|
5262
|
+
const f = inp.files[0];
|
|
5263
|
+
if (f.size > 2 * 1024 * 1024){ toast("截图超过 2MB,请压缩后再选", true); inp.value = ""; return; }
|
|
5264
|
+
const r = new FileReader();
|
|
5265
|
+
r.onload = () => { pendingShots[inp.dataset.pmShot] = r.result;
|
|
5266
|
+
toast("截图已就绪,点「发布」一起上传"); };
|
|
5267
|
+
r.readAsDataURL(f);
|
|
5268
|
+
});
|
|
5269
|
+
|
|
5270
|
+
// 统一按钮动作分发(事件委托,body 重渲染不用重绑)
|
|
5271
|
+
document.addEventListener("click", async (e) => {
|
|
5272
|
+
const btn = e.target.closest("[data-pm-act]");
|
|
5273
|
+
if (!btn) return;
|
|
5274
|
+
const act = btn.dataset.pmAct;
|
|
5275
|
+
if (act === "refresh"){ renderInstalled(); return; }
|
|
5276
|
+
if (act === "refresh-market"){ renderMarket(); return; }
|
|
5277
|
+
if (act === "open-folder"){
|
|
5278
|
+
try{ await ppost("open-folder", {which: "installed"}); }catch(err){ toast(err.message, true); } return;
|
|
5279
|
+
}
|
|
5280
|
+
if (act === "open-folder-market"){
|
|
5281
|
+
try{ await ppost("open-folder", {which: "market"}); }catch(err){ toast(err.message, true); } return;
|
|
5282
|
+
}
|
|
5283
|
+
if (act === "scaffold"){
|
|
5284
|
+
const nm = prompt("面板名(小写字母/数字/-/_,也是目录名):");
|
|
5285
|
+
if (!nm) return;
|
|
5286
|
+
const tt = prompt("展示名(面板标题):", nm) || nm;
|
|
5287
|
+
btn.disabled = true;
|
|
5288
|
+
try{
|
|
5289
|
+
await api("/api/panels/scaffold", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5290
|
+
body: JSON.stringify({name: nm.trim(), title: tt.trim()})});
|
|
5291
|
+
toast("已创建面板骨架,打开文件夹即可编辑;改完点「启用」即刻生效");
|
|
5292
|
+
renderInstalled();
|
|
5293
|
+
}catch(err){ toast(err.message, true); }
|
|
5294
|
+
btn.disabled = false;
|
|
5295
|
+
return;
|
|
5296
|
+
}
|
|
5297
|
+
if (act === "activate"){
|
|
5298
|
+
btn.disabled = true;
|
|
5299
|
+
try{ await ppost("activate", {name: btn.dataset.id});
|
|
5300
|
+
toast("已启用,正在热加载面板…"); location.reload(); }
|
|
5301
|
+
catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5302
|
+
return;
|
|
5303
|
+
}
|
|
5304
|
+
if (act === "delete"){
|
|
5305
|
+
if (!confirm("确定删除该面板目录?此操作不可恢复。")) return;
|
|
5306
|
+
try{ await ppost("delete", {name: btn.dataset.id, source: curTab()}); toast("已删除");
|
|
5307
|
+
curTab() === "market" ? renderMarket() : renderInstalled(); }
|
|
5308
|
+
catch(err){ toast(err.message, true); }
|
|
5309
|
+
return;
|
|
5310
|
+
}
|
|
5311
|
+
if (act === "upload"){
|
|
5312
|
+
btn.disabled = true;
|
|
5313
|
+
try{
|
|
5314
|
+
await ppost("upload", {name: btn.dataset.id});
|
|
5315
|
+
toast("已上传到面板市场(剪切移动)");
|
|
5316
|
+
renderMarket();
|
|
5317
|
+
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5318
|
+
return;
|
|
5319
|
+
}
|
|
5320
|
+
if (act === "install"){
|
|
5321
|
+
btn.disabled = true;
|
|
5322
|
+
try{
|
|
5323
|
+
const r = await ppost("install", {name: btn.dataset.id});
|
|
5324
|
+
toast(`已安装 ${r.title || r.name} v${r.version},可在「已安装」里启用`);
|
|
5325
|
+
renderMarket();
|
|
5326
|
+
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5327
|
+
return;
|
|
5328
|
+
}
|
|
5329
|
+
// ---------------- 云端市场动作 ----------------
|
|
5330
|
+
if (act === "cloud-refresh"){
|
|
5331
|
+
btn.disabled = true;
|
|
5332
|
+
renderMarket(); // renderCloudSection 会带 force=false 重新拉(有 60s 缓存)
|
|
5333
|
+
return;
|
|
5334
|
+
}
|
|
5335
|
+
if (act === "cloud-save-cfg" || act === "cloud-cfg"){
|
|
5336
|
+
if (act === "cloud-cfg"){ // 重新配置:清空云端配置后回到引导表单
|
|
5337
|
+
btn.disabled = true;
|
|
5338
|
+
try{
|
|
5339
|
+
await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5340
|
+
body: JSON.stringify({action:"clear-config"})});
|
|
5341
|
+
toast("云端配置已清除,请重新填写");
|
|
5342
|
+
}catch(err){ toast(err.message, true); }
|
|
5343
|
+
btn.disabled = false;
|
|
5344
|
+
renderMarket();
|
|
5345
|
+
return;
|
|
5346
|
+
}
|
|
5347
|
+
btn.disabled = true;
|
|
5348
|
+
try{
|
|
5349
|
+
await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5350
|
+
body: JSON.stringify({action:"save-config",
|
|
5351
|
+
gitee_repo: ($id("pc-gitee-repo")||{}).value || "",
|
|
5352
|
+
gitee_token: ($id("pc-gitee-token")||{}).value || "",
|
|
5353
|
+
github_repo: ($id("pc-github-repo")||{}).value || "",
|
|
5354
|
+
github_token: ($id("pc-github-token")||{}).value || ""})});
|
|
5355
|
+
toast("云端配置已保存");
|
|
5356
|
+
renderMarket();
|
|
5357
|
+
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5358
|
+
return;
|
|
5359
|
+
}
|
|
5360
|
+
if (act === "cloud-download"){
|
|
5361
|
+
btn.disabled = true;
|
|
5362
|
+
btn.textContent = "下载中…";
|
|
5363
|
+
try{
|
|
5364
|
+
const r = await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5365
|
+
body: JSON.stringify({action:"download", name: btn.dataset.id})});
|
|
5366
|
+
toast(`已下载安装 ${r.title || r.name} v${r.version},可在「已安装」里启用`);
|
|
5367
|
+
renderMarket();
|
|
5368
|
+
}catch(err){ toast(err.message, true); btn.disabled = false; btn.textContent = "下载安装"; }
|
|
5369
|
+
return;
|
|
5370
|
+
}
|
|
5371
|
+
if (act === "cloud-publish"){
|
|
5372
|
+
btn.disabled = true;
|
|
5373
|
+
try{
|
|
5374
|
+
const r = await api("/api/panels/cloud", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5375
|
+
body: JSON.stringify({action:"publish", name: btn.dataset.id,
|
|
5376
|
+
screenshot: pendingShots[btn.dataset.id] || ""})});
|
|
5377
|
+
toast(`已发布到:${(r.pushed || []).join("、")}` + (r.errors && r.errors.length ? `(部分失败:${r.errors.join(";")})` : ""));
|
|
5378
|
+
delete pendingShots[btn.dataset.id];
|
|
5379
|
+
renderMarket();
|
|
5380
|
+
}catch(err){ toast(err.message, true); btn.disabled = false; }
|
|
5381
|
+
return;
|
|
5382
|
+
}
|
|
5383
|
+
if (act === "cloud-view"){
|
|
5384
|
+
// 详情弹窗:截图大图 + 描述 + 版本信息;无截图则只展示文字
|
|
5385
|
+
const nm = btn.dataset.id, ext = btn.dataset.ext || "";
|
|
5386
|
+
let shotHtml = "";
|
|
5387
|
+
if (ext) shotHtml = `<img src="/api/panels/cloud/shot?name=${encodeURIComponent(nm)}&ext=${encodeURIComponent(ext)}"
|
|
5388
|
+
style="width:100%;border-radius:8px;border:1px solid var(--line)" alt="">`;
|
|
5389
|
+
const p = ((cloudCfg || {}).panels || []).find(x => x.name === nm) || {};
|
|
5390
|
+
alert(`【${p.title || nm}】v${p.version || "?"}\n作者:${p.author || "未署名"}\n更新:${p.updated || "?"}\n大小:${p.size ? Math.round(p.size/1024) + " KB" : "?"}\n\n${p.description || "(无描述)"}`);
|
|
5391
|
+
return;
|
|
5392
|
+
}
|
|
5393
|
+
});
|
|
5394
|
+
// 当前在哪个标签页(installed / market):删除按钮的 source 参数要用
|
|
5395
|
+
function curTab(){
|
|
5396
|
+
const on = $id("pm-tabs") && $id("pm-tabs").querySelector(".on");
|
|
5397
|
+
return on ? on.dataset.pmTab : "installed";
|
|
5398
|
+
}
|
|
5399
|
+
|
|
5400
|
+
// 回退提示:服务端注入的激活面板名——若激活了自定义面板,全屏 iframe 热加载它。
|
|
5401
|
+
// 兜底三层:iframe onerror/3s 超时 → 提示并自动切回 default;iframe 内 JS 崩溃
|
|
5402
|
+
// 只崩 iframe 自身,不影响外壳;面板扫描 invalid 根本不会被激活(后端预检)。
|
|
5403
|
+
const ACT = window.__LINGSHU_ACTIVE__ || {panel: "default"};
|
|
5404
|
+
function loadCustom(pname, entry){
|
|
5405
|
+
const fr = document.createElement("iframe");
|
|
5406
|
+
fr.id = "custom-panel-frame";
|
|
5407
|
+
// entry 来自面板 manifest(/api/panels 列表下发),不是写死的 index.html——
|
|
5408
|
+
// manifest 允许作者自定义入口文件名,写死会让这类面板 404 → 被超时兜底误回退
|
|
5409
|
+
fr.src = "/api/panels/file?panel=" + encodeURIComponent(pname) +
|
|
5410
|
+
"&path=" + encodeURIComponent(entry || "index.html") + "&as_page=1";
|
|
5411
|
+
fr.style.cssText = "position:fixed;inset:0;width:100vw;height:100vh;border:none;z-index:800;background:#14181e";
|
|
5412
|
+
fr.onerror = () => fallback(pname, "iframe 加载失败");
|
|
5413
|
+
document.body.appendChild(fr);
|
|
5414
|
+
// 超时兜底:3 秒内 iframe 没触发 load(说明资源坏了/接口 404),自动回退
|
|
5415
|
+
let ok = false;
|
|
5416
|
+
fr.addEventListener("load", () => { ok = true; });
|
|
5417
|
+
setTimeout(() => { if (!ok) fallback(pname, "加载超时"); }, 3000);
|
|
5418
|
+
// 悬浮逃生口:永远能一键回到默认面板
|
|
5419
|
+
const escBtn = document.createElement("button");
|
|
5420
|
+
escBtn.id = "panel-escape";
|
|
5421
|
+
escBtn.textContent = "⇱ 返回默认面板";
|
|
5422
|
+
escBtn.style.cssText = "position:fixed;right:14px;top:14px;z-index:850;cursor:pointer;" +
|
|
5423
|
+
"background:#1b2028;color:#e6e1d5;border:1px solid #2a3140;border-radius:9px;padding:7px 14px;font-size:12px";
|
|
5424
|
+
escBtn.onclick = async () => {
|
|
5425
|
+
try{
|
|
5426
|
+
await api("/api/panels", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5427
|
+
body: JSON.stringify({action:"deactivate"})});
|
|
5428
|
+
}catch(e){
|
|
5429
|
+
// 停用失败还刷新的话,会回到同一个自定义面板——用户会以为按钮没反应。
|
|
5430
|
+
console.warn("停用自定义面板失败:", e);
|
|
5431
|
+
toast("停用失败:" + ((e && e.message) || "接口不可用") + "(未刷新)", true);
|
|
5432
|
+
return;
|
|
5433
|
+
}
|
|
5434
|
+
location.reload();
|
|
5435
|
+
};
|
|
5436
|
+
document.body.appendChild(escBtn);
|
|
5437
|
+
}
|
|
5438
|
+
async function fallback(pname, why){
|
|
5439
|
+
const fr = document.getElementById("custom-panel-frame");
|
|
5440
|
+
if (fr) fr.remove();
|
|
5441
|
+
const escEl = document.getElementById("panel-escape");
|
|
5442
|
+
if (escEl) escEl.remove();
|
|
5443
|
+
try{
|
|
5444
|
+
await api("/api/panels", {method:"POST", headers:{"Content-Type":"application/json"},
|
|
5445
|
+
body: JSON.stringify({action:"deactivate"})});
|
|
5446
|
+
}catch(e){
|
|
5447
|
+
// 回退动作本身失败:说清"回退了但没保存",否则下次打开还是旧面板
|
|
5448
|
+
console.warn("回退时停用自定义面板失败:", e);
|
|
5449
|
+
toast(`自定义面板「${pname}」${why},已临时回退(停用未保存,下次可能仍加载它)`, true);
|
|
5450
|
+
return;
|
|
5451
|
+
}
|
|
5452
|
+
toast(`自定义面板「${pname}」${why},已回退默认面板`, true);
|
|
5453
|
+
}
|
|
5454
|
+
if (ACT.panel && ACT.panel !== "default"){
|
|
5455
|
+
// 激活面板必须是合法已安装面板:列表里 valid=false 或干脆不在 → 直接回退
|
|
5456
|
+
api("/api/panels").then(d => {
|
|
5457
|
+
const hit = (d.panels || []).find(p => p.name === ACT.panel &&
|
|
5458
|
+
p.source === "installed" && p.valid !== false);
|
|
5459
|
+
hit ? loadCustom(ACT.panel, hit.entry)
|
|
5460
|
+
: fallback(ACT.panel, "面板无效或已损坏");
|
|
5461
|
+
}).catch(() => {}); // 列表都拉不到:保持默认面板,别添乱
|
|
5462
|
+
}
|
|
5463
|
+
|
|
5464
|
+
// 回退提示(服务端旧通道,保留兼容)
|
|
5465
|
+
const FB = window.__LINGSHU_FALLBACK__;
|
|
5466
|
+
if (FB && FB.panel) setTimeout(() =>
|
|
5467
|
+
toast(`自定义面板「${FB.panel}」加载失败已回退默认面板:${FB.reason || "未知原因"}`, true), 600);
|
|
5468
|
+
})();
|
|
5415
5469
|
</script>
|
|
5416
5470
|
|
|
5417
5471
|
|
|
@@ -5753,175 +5807,186 @@ setTimeout(() => checkUpdate(true), 1200);
|
|
|
5753
5807
|
window.LSVirtual = { render: render, chunk: CHUNK };
|
|
5754
5808
|
})();
|
|
5755
5809
|
</script>
|
|
5756
|
-
<script>/* 全局搜索 / 命令面板(Ctrl/⌘ + K)。
|
|
5757
|
-
* 命令来源:左侧导航页 + 固定动作;输入 ≥2 字时并查 /api/search(记忆原文)。
|
|
5758
|
-
* 渲染一律 textContent;结果列表是静态骨架 + 文本节点。
|
|
5759
|
-
*/
|
|
5760
|
-
(function () {
|
|
5761
|
-
"use strict";
|
|
5762
|
-
if (window.LSCommand) return;
|
|
5763
|
-
|
|
5764
|
-
var ACTIONS = [
|
|
5765
|
-
{ label: "刷新页面", hint: "reload", run: function () { location.reload(); } },
|
|
5766
|
-
{ label: "打开运行洞察", hint: "insights", run: function () { var d = document.getElementById("ls-dock"); if (d) { d.classList.remove("ls-collapsed"); d.scrollIntoView({ block: "nearest" }); } } },
|
|
5767
|
-
{ label: "切换主题(深/浅/跟随)", hint: "theme", run: function () { var s = document.getElementById("ls-theme"); if (s) { s.value = s.value === "light" ? "dark" : s.value === "dark" ? "auto" : "light"; s.onchange(); } } },
|
|
5768
|
-
{ label: "切换密度(标准/紧凑)", hint: "density", run: function () { var s = document.getElementById("ls-density"); if (s) { s.value = s.value === "compact" ? "cozy" : "compact"; s.onchange(); } } }
|
|
5769
|
-
];
|
|
5770
|
-
|
|
5771
|
-
var overlay = null, input = null, list = null, items = [], active = 0, searchSeq = 0;
|
|
5772
|
-
|
|
5773
|
-
function build() {
|
|
5774
|
-
overlay = document.createElement("div");
|
|
5775
|
-
overlay.id = "ls-cmd";
|
|
5776
|
-
overlay.style.cssText =
|
|
5777
|
-
"position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,.45);display:none;" +
|
|
5778
|
-
"align-items:flex-start;justify-content:center;padding-top:12vh";
|
|
5779
|
-
var box = document.createElement("div");
|
|
5780
|
-
box.style.cssText =
|
|
5781
|
-
"width:min(620px,92vw);background:var(--surface);border:1px solid var(--line);" +
|
|
5782
|
-
"border-radius:14px;box-shadow:0 24px 70px rgba(0,0,0,.5);overflow:hidden";
|
|
5783
|
-
var head = document.createElement("div");
|
|
5784
|
-
head.style.cssText = "padding:10px 12px;border-bottom:1px solid var(--line)";
|
|
5785
|
-
input = document.createElement("input");
|
|
5786
|
-
input.placeholder = "搜索记忆、跳转页面、执行动作…(Esc 关闭)";
|
|
5787
|
-
input.style.cssText = "width:100%;background:transparent;border:0;outline:0;color:var(--text);font-size:15px;padding:4px";
|
|
5788
|
-
head.appendChild(input);
|
|
5789
|
-
list = document.createElement("div");
|
|
5790
|
-
list.style.cssText = "max-height:52vh;overflow:auto;padding:6px";
|
|
5791
|
-
box.appendChild(head);
|
|
5792
|
-
box.appendChild(list);
|
|
5793
|
-
overlay.appendChild(box);
|
|
5794
|
-
overlay.addEventListener("click", function (e) { if (e.target === overlay) close(); });
|
|
5795
|
-
document.body.appendChild(overlay);
|
|
5796
|
-
input.addEventListener("input", function () { query(input.value); });
|
|
5797
|
-
input.addEventListener("keydown", function (e) {
|
|
5798
|
-
if (e.key === "Escape") { close(); return; }
|
|
5799
|
-
if (e.key === "ArrowDown") { e.preventDefault(); move(1); }
|
|
5800
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); move(-1); }
|
|
5801
|
-
else if (e.key === "Enter") { e.preventDefault(); runActive(); }
|
|
5802
|
-
});
|
|
5803
|
-
}
|
|
5804
|
-
|
|
5805
|
-
function row(text, hint, onPick) {
|
|
5806
|
-
var d = document.createElement("div");
|
|
5807
|
-
d.style.cssText = "display:flex;gap:10px;padding:8px 10px;border-radius:8px;cursor:pointer;align-items:baseline";
|
|
5808
|
-
var t = document.createElement("div");
|
|
5809
|
-
t.textContent = text;
|
|
5810
|
-
t.style.cssText = "flex:1;color:var(--text);font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap";
|
|
5811
|
-
d.appendChild(t);
|
|
5812
|
-
if (hint) {
|
|
5813
|
-
var h = document.createElement("div");
|
|
5814
|
-
h.textContent = hint;
|
|
5815
|
-
h.style.cssText = "color:var(--faint);font-size:11px";
|
|
5816
|
-
d.appendChild(h);
|
|
5817
|
-
}
|
|
5818
|
-
d.addEventListener("mouseenter", function () { setActive(items.indexOf(onPick)); });
|
|
5819
|
-
d.addEventListener("click", function () { onPick.run(); });
|
|
5820
|
-
return d;
|
|
5821
|
-
}
|
|
5822
|
-
|
|
5823
|
-
function renderList() {
|
|
5824
|
-
list.innerHTML = "";
|
|
5825
|
-
if (!items.length) {
|
|
5826
|
-
var e = document.createElement("div");
|
|
5827
|
-
e.textContent = "没有匹配项";
|
|
5828
|
-
e.style.cssText = "padding:12px;color:var(--muted);font-size:12px";
|
|
5829
|
-
list.appendChild(e);
|
|
5830
|
-
return;
|
|
5831
|
-
}
|
|
5832
|
-
items.forEach(function (it, i) {
|
|
5833
|
-
var el = row(it.label, it.hint, it);
|
|
5834
|
-
el.dataset.idx = String(i);
|
|
5835
|
-
if (i === active) el.style.background = "var(--surface2)";
|
|
5836
|
-
list.appendChild(el);
|
|
5837
|
-
});
|
|
5838
|
-
}
|
|
5839
|
-
|
|
5840
|
-
function setActive(i) {
|
|
5841
|
-
active = i;
|
|
5842
|
-
Array.prototype.forEach.call(list.children, function (el, k) {
|
|
5843
|
-
el.style.background = k === i ? "var(--surface2)" : "";
|
|
5844
|
-
});
|
|
5845
|
-
}
|
|
5846
|
-
|
|
5847
|
-
function move(d) {
|
|
5848
|
-
if (!items.length) return;
|
|
5849
|
-
active = (active + d + items.length) % items.length;
|
|
5850
|
-
setActive(active);
|
|
5851
|
-
var el = list.children[active];
|
|
5852
|
-
if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
|
|
5853
|
-
}
|
|
5854
|
-
|
|
5855
|
-
function runActive() {
|
|
5856
|
-
var it = items[active];
|
|
5857
|
-
if (it) it.run();
|
|
5858
|
-
}
|
|
5859
|
-
|
|
5860
|
-
function navItems(q) {
|
|
5861
|
-
var out = [];
|
|
5862
|
-
document.querySelectorAll("nav button[data-tab]").forEach(function (b) {
|
|
5863
|
-
var label = (b.textContent || "").replace(/\s+/g, " ").trim();
|
|
5864
|
-
var tab = b.dataset.tab;
|
|
5865
|
-
out.push({
|
|
5866
|
-
label: "跳转:" + label, hint: "页面", text: label + " " + tab,
|
|
5867
|
-
run: function () { close(); if (typeof switchTab === "function") switchTab(tab); }
|
|
5868
|
-
});
|
|
5869
|
-
});
|
|
5870
|
-
ACTIONS.forEach(function (a) { out.push({ label: a.label, hint: a.hint, text: a.label + " " + a.hint, run: function () { close(); a.run(); } }); });
|
|
5871
|
-
return out.filter(function (x) { return !q || x.text.toLowerCase().indexOf(q.toLowerCase()) >= 0; });
|
|
5872
|
-
}
|
|
5873
|
-
|
|
5874
|
-
function query(q) {
|
|
5875
|
-
q = (q || "").trim();
|
|
5876
|
-
active = 0;
|
|
5877
|
-
items = navItems(q);
|
|
5878
|
-
renderList();
|
|
5879
|
-
if (q.length < 2) return;
|
|
5880
|
-
var seq = ++searchSeq;
|
|
5881
|
-
if (typeof api !== "function") return;
|
|
5882
|
-
api("/api/search?q=" + encodeURIComponent(q) + "&k=8").then(function (rows) {
|
|
5883
|
-
if (seq !== searchSeq) return;
|
|
5884
|
-
var extra = (rows || []).map(function (r) {
|
|
5885
|
-
var m = r.memory || r;
|
|
5886
|
-
var txt = String(m.text || "").slice(0, 90);
|
|
5887
|
-
return {
|
|
5888
|
-
label: "记忆:" + txt, hint: "打开并筛选记忆", text: txt,
|
|
5889
|
-
run: function () {
|
|
5890
|
-
close();
|
|
5891
|
-
// 落到记忆页后把搜索框填成这条记忆的原文片段,而不是只停在列表顶部。
|
|
5892
|
-
// 先填再切页:switchTab 自己会拉一次列表,避免重复请求。
|
|
5893
|
-
var box = document.getElementById("search");
|
|
5894
|
-
if (box) box.value = txt.slice(0, 24);
|
|
5895
|
-
if (typeof switchTab === "function") switchTab("memories");
|
|
5896
|
-
}
|
|
5897
|
-
};
|
|
5898
|
-
});
|
|
5899
|
-
items = navItems(q).slice(0, 6).concat(extra);
|
|
5900
|
-
renderList();
|
|
5901
|
-
}).catch(function () {
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5810
|
+
<script>/* 全局搜索 / 命令面板(Ctrl/⌘ + K)。
|
|
5811
|
+
* 命令来源:左侧导航页 + 固定动作;输入 ≥2 字时并查 /api/search(记忆原文)。
|
|
5812
|
+
* 渲染一律 textContent;结果列表是静态骨架 + 文本节点。
|
|
5813
|
+
*/
|
|
5814
|
+
(function () {
|
|
5815
|
+
"use strict";
|
|
5816
|
+
if (window.LSCommand) return;
|
|
5817
|
+
|
|
5818
|
+
var ACTIONS = [
|
|
5819
|
+
{ label: "刷新页面", hint: "reload", run: function () { location.reload(); } },
|
|
5820
|
+
{ label: "打开运行洞察", hint: "insights", run: function () { var d = document.getElementById("ls-dock"); if (d) { d.classList.remove("ls-collapsed"); d.scrollIntoView({ block: "nearest" }); } } },
|
|
5821
|
+
{ label: "切换主题(深/浅/跟随)", hint: "theme", run: function () { var s = document.getElementById("ls-theme"); if (s) { s.value = s.value === "light" ? "dark" : s.value === "dark" ? "auto" : "light"; s.onchange(); } } },
|
|
5822
|
+
{ label: "切换密度(标准/紧凑)", hint: "density", run: function () { var s = document.getElementById("ls-density"); if (s) { s.value = s.value === "compact" ? "cozy" : "compact"; s.onchange(); } } }
|
|
5823
|
+
];
|
|
5824
|
+
|
|
5825
|
+
var overlay = null, input = null, list = null, items = [], active = 0, searchSeq = 0;
|
|
5826
|
+
|
|
5827
|
+
function build() {
|
|
5828
|
+
overlay = document.createElement("div");
|
|
5829
|
+
overlay.id = "ls-cmd";
|
|
5830
|
+
overlay.style.cssText =
|
|
5831
|
+
"position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,.45);display:none;" +
|
|
5832
|
+
"align-items:flex-start;justify-content:center;padding-top:12vh";
|
|
5833
|
+
var box = document.createElement("div");
|
|
5834
|
+
box.style.cssText =
|
|
5835
|
+
"width:min(620px,92vw);background:var(--surface);border:1px solid var(--line);" +
|
|
5836
|
+
"border-radius:14px;box-shadow:0 24px 70px rgba(0,0,0,.5);overflow:hidden";
|
|
5837
|
+
var head = document.createElement("div");
|
|
5838
|
+
head.style.cssText = "padding:10px 12px;border-bottom:1px solid var(--line)";
|
|
5839
|
+
input = document.createElement("input");
|
|
5840
|
+
input.placeholder = "搜索记忆、跳转页面、执行动作…(Esc 关闭)";
|
|
5841
|
+
input.style.cssText = "width:100%;background:transparent;border:0;outline:0;color:var(--text);font-size:15px;padding:4px";
|
|
5842
|
+
head.appendChild(input);
|
|
5843
|
+
list = document.createElement("div");
|
|
5844
|
+
list.style.cssText = "max-height:52vh;overflow:auto;padding:6px";
|
|
5845
|
+
box.appendChild(head);
|
|
5846
|
+
box.appendChild(list);
|
|
5847
|
+
overlay.appendChild(box);
|
|
5848
|
+
overlay.addEventListener("click", function (e) { if (e.target === overlay) close(); });
|
|
5849
|
+
document.body.appendChild(overlay);
|
|
5850
|
+
input.addEventListener("input", function () { query(input.value); });
|
|
5851
|
+
input.addEventListener("keydown", function (e) {
|
|
5852
|
+
if (e.key === "Escape") { close(); return; }
|
|
5853
|
+
if (e.key === "ArrowDown") { e.preventDefault(); move(1); }
|
|
5854
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); move(-1); }
|
|
5855
|
+
else if (e.key === "Enter") { e.preventDefault(); runActive(); }
|
|
5856
|
+
});
|
|
5857
|
+
}
|
|
5858
|
+
|
|
5859
|
+
function row(text, hint, onPick) {
|
|
5860
|
+
var d = document.createElement("div");
|
|
5861
|
+
d.style.cssText = "display:flex;gap:10px;padding:8px 10px;border-radius:8px;cursor:pointer;align-items:baseline";
|
|
5862
|
+
var t = document.createElement("div");
|
|
5863
|
+
t.textContent = text;
|
|
5864
|
+
t.style.cssText = "flex:1;color:var(--text);font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap";
|
|
5865
|
+
d.appendChild(t);
|
|
5866
|
+
if (hint) {
|
|
5867
|
+
var h = document.createElement("div");
|
|
5868
|
+
h.textContent = hint;
|
|
5869
|
+
h.style.cssText = "color:var(--faint);font-size:11px";
|
|
5870
|
+
d.appendChild(h);
|
|
5871
|
+
}
|
|
5872
|
+
d.addEventListener("mouseenter", function () { setActive(items.indexOf(onPick)); });
|
|
5873
|
+
d.addEventListener("click", function () { onPick.run(); });
|
|
5874
|
+
return d;
|
|
5875
|
+
}
|
|
5876
|
+
|
|
5877
|
+
function renderList() {
|
|
5878
|
+
list.innerHTML = "";
|
|
5879
|
+
if (!items.length) {
|
|
5880
|
+
var e = document.createElement("div");
|
|
5881
|
+
e.textContent = "没有匹配项";
|
|
5882
|
+
e.style.cssText = "padding:12px;color:var(--muted);font-size:12px";
|
|
5883
|
+
list.appendChild(e);
|
|
5884
|
+
return;
|
|
5885
|
+
}
|
|
5886
|
+
items.forEach(function (it, i) {
|
|
5887
|
+
var el = row(it.label, it.hint, it);
|
|
5888
|
+
el.dataset.idx = String(i);
|
|
5889
|
+
if (i === active) el.style.background = "var(--surface2)";
|
|
5890
|
+
list.appendChild(el);
|
|
5891
|
+
});
|
|
5892
|
+
}
|
|
5893
|
+
|
|
5894
|
+
function setActive(i) {
|
|
5895
|
+
active = i;
|
|
5896
|
+
Array.prototype.forEach.call(list.children, function (el, k) {
|
|
5897
|
+
el.style.background = k === i ? "var(--surface2)" : "";
|
|
5898
|
+
});
|
|
5899
|
+
}
|
|
5900
|
+
|
|
5901
|
+
function move(d) {
|
|
5902
|
+
if (!items.length) return;
|
|
5903
|
+
active = (active + d + items.length) % items.length;
|
|
5904
|
+
setActive(active);
|
|
5905
|
+
var el = list.children[active];
|
|
5906
|
+
if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
|
|
5907
|
+
}
|
|
5908
|
+
|
|
5909
|
+
function runActive() {
|
|
5910
|
+
var it = items[active];
|
|
5911
|
+
if (it) it.run();
|
|
5912
|
+
}
|
|
5913
|
+
|
|
5914
|
+
function navItems(q) {
|
|
5915
|
+
var out = [];
|
|
5916
|
+
document.querySelectorAll("nav button[data-tab]").forEach(function (b) {
|
|
5917
|
+
var label = (b.textContent || "").replace(/\s+/g, " ").trim();
|
|
5918
|
+
var tab = b.dataset.tab;
|
|
5919
|
+
out.push({
|
|
5920
|
+
label: "跳转:" + label, hint: "页面", text: label + " " + tab,
|
|
5921
|
+
run: function () { close(); if (typeof switchTab === "function") switchTab(tab); }
|
|
5922
|
+
});
|
|
5923
|
+
});
|
|
5924
|
+
ACTIONS.forEach(function (a) { out.push({ label: a.label, hint: a.hint, text: a.label + " " + a.hint, run: function () { close(); a.run(); } }); });
|
|
5925
|
+
return out.filter(function (x) { return !q || x.text.toLowerCase().indexOf(q.toLowerCase()) >= 0; });
|
|
5926
|
+
}
|
|
5927
|
+
|
|
5928
|
+
function query(q) {
|
|
5929
|
+
q = (q || "").trim();
|
|
5930
|
+
active = 0;
|
|
5931
|
+
items = navItems(q);
|
|
5932
|
+
renderList();
|
|
5933
|
+
if (q.length < 2) return;
|
|
5934
|
+
var seq = ++searchSeq;
|
|
5935
|
+
if (typeof api !== "function") return;
|
|
5936
|
+
api("/api/search?q=" + encodeURIComponent(q) + "&k=8").then(function (rows) {
|
|
5937
|
+
if (seq !== searchSeq) return;
|
|
5938
|
+
var extra = (rows || []).map(function (r) {
|
|
5939
|
+
var m = r.memory || r;
|
|
5940
|
+
var txt = String(m.text || "").slice(0, 90);
|
|
5941
|
+
return {
|
|
5942
|
+
label: "记忆:" + txt, hint: "打开并筛选记忆", text: txt,
|
|
5943
|
+
run: function () {
|
|
5944
|
+
close();
|
|
5945
|
+
// 落到记忆页后把搜索框填成这条记忆的原文片段,而不是只停在列表顶部。
|
|
5946
|
+
// 先填再切页:switchTab 自己会拉一次列表,避免重复请求。
|
|
5947
|
+
var box = document.getElementById("search");
|
|
5948
|
+
if (box) box.value = txt.slice(0, 24);
|
|
5949
|
+
if (typeof switchTab === "function") switchTab("memories");
|
|
5950
|
+
}
|
|
5951
|
+
};
|
|
5952
|
+
});
|
|
5953
|
+
items = navItems(q).slice(0, 6).concat(extra);
|
|
5954
|
+
renderList();
|
|
5955
|
+
}).catch(function (err) {
|
|
5956
|
+
// 以前这里是空的 catch:接口一挂,列表只剩导航项,用户以为"搜不到"。
|
|
5957
|
+
// 现在把失败也当成一条结果摆出来,至少让人知道是搜索坏了而不是没内容。
|
|
5958
|
+
console.warn("命令面板搜索失败:", err);
|
|
5959
|
+
var tip = (err && err.message) ? err.message : "接口不可用";
|
|
5960
|
+
items = navItems(q).slice(0, 6).concat([{
|
|
5961
|
+
label: "搜索失败:" + tip, hint: "重试",
|
|
5962
|
+
text: "搜索失败 " + tip,
|
|
5963
|
+
run: function () { query(input.value); }
|
|
5964
|
+
}]);
|
|
5965
|
+
renderList();
|
|
5966
|
+
});
|
|
5967
|
+
}
|
|
5968
|
+
|
|
5969
|
+
function open() {
|
|
5970
|
+
if (!overlay) build();
|
|
5971
|
+
overlay.style.display = "flex";
|
|
5972
|
+
input.value = "";
|
|
5973
|
+
query("");
|
|
5974
|
+
setTimeout(function () { input.focus(); }, 0);
|
|
5975
|
+
}
|
|
5976
|
+
|
|
5977
|
+
function close() {
|
|
5978
|
+
if (overlay) overlay.style.display = "none";
|
|
5979
|
+
searchSeq++;
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
document.addEventListener("keydown", function (e) {
|
|
5983
|
+
if ((e.metaKey || e.ctrlKey) && (e.key === "k" || e.key === "K")) {
|
|
5984
|
+
e.preventDefault();
|
|
5985
|
+
if (overlay && overlay.style.display === "flex") close(); else open();
|
|
5986
|
+
}
|
|
5987
|
+
});
|
|
5988
|
+
|
|
5989
|
+
window.LSCommand = { open: open, close: close };
|
|
5990
|
+
})();
|
|
5926
5991
|
</script>
|
|
5927
5992
|
</body></html>
|