更新完善功能

This commit is contained in:
MasonLiu committed 2026-09-06 19:20:38 +08:00
1 parent 4e6d6e5307
commit e08a87a4c2
8 files changed
+330 -95

No files matched your search

+63 -63
View File
@@ -372,69 +372,6 @@ admin_topbar('content');
</form>
</div>
<!-- 四大板块:名称 / 说明 / 顺序 -->
<div class="fieldset-card">
<div class="fs-title">四大板块(名称 / 悬停说明文案 / 顺序)</div>
<form method="post">
<?= csrf_field() ?><input type="hidden" name="act" value="boards">
<?php foreach ($cats as $c): $id = (int)$c['id']; ?>
<div class="m-block" style="margin-bottom:10px">
<div class="m-block-head">
<strong><?= he((string)$c['key']) ?></strong>
<span class="ops"><input type="number" name="b_sort[<?= $id ?>]" value="<?= (int)$c['sort'] ?>" min="1" max="99" style="width:70px" title="顺序数值,越小越靠前"></span>
</div>
<div class="m-items">
<div class="icon-ctl" style="margin-top:8px">
<span class="icon-preview"></span>
<input type="text" class="icon-input" name="b_icon[<?= $id ?>]" value="<?= he((string)($c['icon'] ?? '')) ?>" placeholder="字符 / emoji,或粘贴/上传图片">
<button type="button" class="btn btn-sm icon-upload" title="上传图片(≤200KB)">上传</button>
<input type="file" class="icon-file" accept="image/*" hidden>
</div>
<input type="text" name="b_name[<?= $id ?>]" value="<?= he((string)$c['name']) ?>" placeholder="板块名称" style="margin-top:8px">
<textarea name="b_desc[<?= $id ?>]" rows="2" placeholder="悬停说明文案"><?= he(trim((string)$c['description']) !== '' ? (string)$c['description'] : ($boardDefaults[(string)$c['key']] ?? '')) ?></textarea>
</div>
</div>
<?php endforeach; ?>
<button type="submit" class="btn btn-primary">保存板块设置</button>
</form>
</div>
<!-- 首页快捷站点(本域名其它网站) -->
<div class="fieldset-card">
<div class="fs-title">首页快捷站点(四大板块上方的胶囊按钮,新标签页打开)</div>
<form method="post" id="qlForm">
<?= csrf_field() ?><input type="hidden" name="act" value="quicklinks">
<textarea name="data" id="qlData" hidden></textarea>
<p class="tip">用于放置本域名下的其它网站入口;点击后新开标签页。地址需为完整 http(s) 链接。列表顺序即展示顺序。</p>
<div id="qlRows">
<?php $quickLinks = $pdo->query('SELECT * FROM quick_links ORDER BY sort ASC, id ASC')->fetchAll(); ?>
<?php foreach ($quickLinks as $ql): ?>
<div class="l-row" data-id="<?= (int)$ql['id'] ?>">
<span class="icon-ctl">
<span class="icon-preview"></span>
<input type="text" class="icon-input l-icon" value="<?= he((string)$ql['icon']) ?>" placeholder="图标">
<button type="button" class="btn btn-sm icon-upload" title="上传图片(≤200KB)">上传</button>
<input type="file" class="icon-file" accept="image/*" hidden>
</span>
<input type="text" class="l-name" value="<?= he((string)$ql['name']) ?>" placeholder="站点名称(必填)">
<input type="text" class="l-url" value="<?= he((string)$ql['url']) ?>" placeholder="完整网址,如 https://子站.域名.com">
<input type="text" class="l-note" value="<?= he((string)($ql['note'] ?? '')) ?>" placeholder="备注 / 网站介绍(悬停首页按钮显示)">
<label class="t-on"><input type="checkbox" class="l-enabled"<?= (int)$ql['enabled'] === 1 ? ' checked' : '' ?>> 启用</label>
<span class="ops">
<button type="button" class="btn btn-sm l-up" title="上移">↑</button>
<button type="button" class="btn btn-sm l-down" title="下移">↓</button>
<button type="button" class="btn btn-sm btn-danger l-del" title="删除">✕</button>
</span>
</div>
<?php endforeach; ?>
</div>
<div class="field-row" style="margin:12px 0">
<button type="button" class="btn btn-sm" id="qlAdd">+ 添加快捷站点</button>
<button type="submit" class="btn btn-primary">保存快捷站点</button>
</div>
</form>
</div>
<!-- 底部信息 -->
<div class="fieldset-card">
<div class="fs-title">底部信息</div>
@@ -519,6 +456,69 @@ admin_topbar('content');
<div style="margin-top:12px"><button type="submit" class="btn btn-primary">修改密码</button></div>
</form>
</div>
<!-- 四大板块:名称 / 说明 / 顺序 -->
<div class="fieldset-card col-span-2">
<div class="fs-title">四大板块(名称 / 悬停说明文案 / 顺序)</div>
<form method="post">
<?= csrf_field() ?><input type="hidden" name="act" value="boards">
<?php foreach ($cats as $c): $id = (int)$c['id']; ?>
<div class="m-block" style="margin-bottom:10px">
<div class="m-block-head">
<strong><?= he((string)$c['key']) ?></strong>
<span class="ops"><input type="number" name="b_sort[<?= $id ?>]" value="<?= (int)$c['sort'] ?>" min="1" max="99" style="width:70px" title="顺序数值,越小越靠前"></span>
</div>
<div class="m-items">
<div class="icon-ctl" style="margin-top:8px">
<span class="icon-preview"></span>
<input type="text" class="icon-input" name="b_icon[<?= $id ?>]" value="<?= he((string)($c['icon'] ?? '')) ?>" placeholder="字符 / emoji,或粘贴/上传图片">
<button type="button" class="btn btn-sm icon-upload" title="上传图片(≤200KB)">上传</button>
<input type="file" class="icon-file" accept="image/*" hidden>
</div>
<input type="text" name="b_name[<?= $id ?>]" value="<?= he((string)$c['name']) ?>" placeholder="板块名称" style="margin-top:8px">
<textarea name="b_desc[<?= $id ?>]" rows="2" placeholder="悬停说明文案"><?= he(trim((string)$c['description']) !== '' ? (string)$c['description'] : ($boardDefaults[(string)$c['key']] ?? '')) ?></textarea>
</div>
</div>
<?php endforeach; ?>
<button type="submit" class="btn btn-primary">保存板块设置</button>
</form>
</div>
<!-- 首页快捷站点(本域名其它网站) -->
<div class="fieldset-card col-span-2">
<div class="fs-title">首页快捷站点(四大板块上方的胶囊按钮,新标签页打开)</div>
<form method="post" id="qlForm">
<?= csrf_field() ?><input type="hidden" name="act" value="quicklinks">
<textarea name="data" id="qlData" hidden></textarea>
<p class="tip">用于放置本域名下的其它网站入口;点击后新开标签页。地址需为完整 http(s) 链接。列表顺序即展示顺序。</p>
<div id="qlRows">
<?php $quickLinks = $pdo->query('SELECT * FROM quick_links ORDER BY sort ASC, id ASC')->fetchAll(); ?>
<?php foreach ($quickLinks as $ql): ?>
<div class="l-row" data-id="<?= (int)$ql['id'] ?>">
<span class="icon-ctl">
<span class="icon-preview"></span>
<input type="text" class="icon-input l-icon" value="<?= he((string)$ql['icon']) ?>" placeholder="图标">
<button type="button" class="btn btn-sm icon-upload" title="上传图片(≤200KB)">上传</button>
<input type="file" class="icon-file" accept="image/*" hidden>
</span>
<input type="text" class="l-name" value="<?= he((string)$ql['name']) ?>" placeholder="站点名称(必填)">
<input type="text" class="l-url" value="<?= he((string)$ql['url']) ?>" placeholder="完整网址,如 https://子站.域名.com">
<input type="text" class="l-note" value="<?= he((string)($ql['note'] ?? '')) ?>" placeholder="备注 / 网站介绍(悬停首页按钮显示)">
<label class="t-on"><input type="checkbox" class="l-enabled"<?= (int)$ql['enabled'] === 1 ? ' checked' : '' ?>> 启用</label>
<span class="ops">
<button type="button" class="btn btn-sm l-up" title="上移">↑</button>
<button type="button" class="btn btn-sm l-down" title="下移">↓</button>
<button type="button" class="btn btn-sm btn-danger l-del" title="删除">✕</button>
</span>
</div>
<?php endforeach; ?>
</div>
<div class="field-row" style="margin:12px 0">
<button type="button" class="btn btn-sm" id="qlAdd">+ 添加快捷站点</button>
<button type="submit" class="btn btn-primary">保存快捷站点</button>
</div>
</form>
</div>
</div>
</div>
</main>
+145
View File
@@ -168,6 +168,27 @@ admin_topbar('nav');
<div class="err-msg"><?= he($errorMsg) ?></div>
<?php endif; ?>
<div class="fieldset-card" style="margin-bottom:16px">
<div class="fs-title">⚡ 批量导入导航链接(<?= he($catNames[$cat]) ?>)</div>
<p class="tip">在下面一次粘贴多行内容,点击「解析导入」后会按格式自动生成导航块,并<b>追加到下方编辑器末尾</b>,可再编辑确认后统一点「保存全部修改」。<br>
每行一条,支持几种写法:
<code>名称 | 网址 [ | 备注]</code>(也兼容 <code>网址 | 名称</code>)或 <code>[名称](网址)</code> 或 <code>名称 https://网址</code>;以 <code>## 块名</code> 开头的行开启一个新导航块;未写块名则归入“批量导入”。
单个块最多 15 个链接,超出会自动拆分为 <code>块名 2</code>、<code>块名 3</code> …</p>
<textarea id="importText" rows="7" spellcheck="false" placeholder="例如:
## 安全研究
看雪 | https://www.kanxue.com | 逆向/安全社区
先知社区 https://xz.aliyun.com
[FreeBuf](https://www.freebuf.com)
## 资讯
https://www.ithome.com | IT之家"></textarea>
<div class="field-row" style="margin-top:8px">
<button type="button" class="btn btn-primary" id="btnParseImport">解析并导入</button>
<button type="button" class="btn" id="btnClearImport">清空输入框</button>
<span class="tip" style="align-self:center">导入仅是“填入编辑区”,不会立即生效,请务必点击下方的「保存全部修改」。</span>
</div>
<div id="importMsg"></div>
</div>
<form method="post" id="navForm" autocomplete="off">
<?= csrf_field() ?>
<input type="hidden" name="action" value="save">
@@ -280,6 +301,130 @@ admin_topbar('nav');
wrap.insertAdjacentHTML('beforeend', blockHTML(0, '', []));
});
/* ---------- 批量导入解析 ---------- */
var MAX_ITEMS = 15;
var importTextEl = document.getElementById('importText');
var importMsg = document.getElementById('importMsg');
// 单行 -> item;无法识别返回 null
function parseImportLine(raw) {
var s = String(raw).trim();
if (s === '') return null;
// 1) | 分隔:名称 | 网址 [ | 备注](也兼容 网址 | 名称)
if (s.indexOf('|') !== -1) {
var p = s.split('|').map(function (x) { return x.trim(); });
var isUrl = function (x) { return /^https?:\/\//i.test(x); };
var label1 = p[0], url1 = p[1], note1 = p[2] || '';
if (isUrl(p[0]) && p[1] !== '' && !isUrl(p[1])) {
// 网址在前、名称在后
label1 = p[1]; url1 = p[0]; note1 = p[2] || '';
}
if (url1 !== '') return { label: label1, url: url1, note: note1 };
}
// 2) Markdown:[名称](网址 ["备注"])
var m = s.match(/^\[([^\]]*)\]\(\s*([^)\s]+)(?:\s+["“]([^"”]*)["”])?\s*\)$/);
if (m) return { label: m[1].trim(), url: m[2].trim(), note: (m[3] || '').trim() };
// 3) 名称 https://… 或 名称 https://… 备注
var m2 = s.match(/^(.*?)(https?:\/\/\S+)(?:\s+(.*))?$/i);
if (m2 && m2[2]) {
return { label: (m2[1] || '').trim(), url: m2[2].replace(/[),,。]+$/, ''), note: (m2[3] || '').trim() };
}
return null;
}
// host 作为缺省名称
function hostOf(url) {
try {
var u = new URL(url);
return u.hostname.replace(/^www\./, '');
} catch (e) {
return url;
}
}
// 全文 -> [{title, items}]
function importTextToBlocks(text) {
var lines = String(text).split(/\r?\n/);
var blocks = [];
var cur = null; // 当前块
var used = {}; // 已使用的标题(同名自动加序号)
var parsed = 0, skipped = 0;
function makeTitle(base) {
var t = base;
var n = 1;
while (used[t]) {
n++;
t = base + ' ' + n;
}
used[t] = true;
return t;
}
function ensureBlock() {
if (cur && cur.items.length < MAX_ITEMS) return;
var title = makeTitle(cur ? cur.title : '批量导入');
cur = { title: title, items: [] };
blocks.push(cur);
}
lines.forEach(function (ln) {
var s = String(ln).trim();
if (s === '') return;
// 块标题行
var hm = s.match(/^#{1,6}\s+(.+)$/);
if (hm) {
var t = hm[1].trim();
if (t !== '') {
var t2 = makeTitle(t);
cur = { title: t2, items: [] };
blocks.push(cur);
}
return;
}
var it = parseImportLine(s);
if (!it) { skipped++; return; }
if (it.url === '') { skipped++; return; }
if (it.label === '') it.label = hostOf(it.url);
ensureBlock();
cur.items.push(it);
parsed++;
});
return { blocks: blocks, parsed: parsed, skipped: skipped };
}
function bindImport() {
var btn = document.getElementById('btnParseImport');
var clearBtn = document.getElementById('btnClearImport');
if (!btn || !importTextEl || !importMsg) return;
btn.addEventListener('click', function () {
var r = importTextToBlocks(importTextEl.value);
if (!r.parsed) {
importMsg.innerHTML = '<div class="err-msg">未解析到任何链接。请检查格式,每行至少包含“名称 网址”或“名称 | 网址”。</div>';
return;
}
var frag = document.createDocumentFragment();
r.blocks.forEach(function (b) {
var div = createElFromHTML(blockHTML(0, b.title, b.items));
frag.appendChild(div);
});
wrap.appendChild(frag);
var parts = [];
parts.push('<div class="ok-msg">已解析 ' + r.parsed + ' 条链接,生成 ' + r.blocks.length + ' 个导航块并追加到下方。</div>');
if (r.skipped) parts.push('<p class="tip" style="margin-top:6px">另有 ' + r.skipped + ' 行未能识别,已跳过。</p>');
parts.push('<p class="tip">请在下方向下核对;如需调整可修改标题/链接后,统一点击「保存全部修改」生效。</p>');
importMsg.innerHTML = parts.join('');
importTextEl.value = '';
wrap.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
clearBtn.addEventListener('click', function () {
importTextEl.value = '';
importMsg.innerHTML = '';
importTextEl.focus();
});
}
bindImport();
function createElFromHTML(html) {
var t = document.createElement('template');
t.innerHTML = html.trim();