新增辅助维权工具

This commit is contained in:
MasonLiu committed 2026-09-06 21:27:10 +08:00
1 parent 9e3b62a1ce
commit 4480a437b0
8 files changed
+531 -12

No files matched your search

+68 -11
View File
@@ -61,7 +61,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$sort = max(0, (int)($_POST['sort'] ?? 0));
$pinned = (isset($_POST['pinned']) && $_POST['pinned'] === '1') ? 1 : 0;
$enabled = (isset($_POST['enabled']) && $_POST['enabled'] === '1') ? 1 : 0;
if ($part === '') {
if ($part === '' || $part === '__new__') {
$part = '未分类';
}
if ($title === '') {
@@ -202,14 +202,16 @@ admin_topbar('articles');
'summary' => (string)$row['summary'], 'md' => (string)$row['markdown'],
'sort' => (int)$row['sort'], 'pinned' => (int)$row['pinned'], 'enabled' => (int)$row['enabled'],
] : ['id' => 0, 'part' => '未分类', 'title' => '', 'summary' => '', 'md' => '', 'sort' => 0, 'pinned' => 0, 'enabled' => 1];
// 分区下拉建议(仅列已有分区)
$partSuggest = [];
// 分区下拉选项:未分类 + 全部已有分区;编辑中的自定义分区自动补充,保证能回显选中
$curPart = trim((string)$cur['part']);
if ($curPart === '') { $curPart = '未分类'; }
$partOptions = ['未分类'];
foreach ($list as $a2) {
$p2 = trim((string)$a2['part']);
if ($p2 !== '' && !in_array($p2, $partSuggest, true)) {
$partSuggest[] = $p2;
}
if ($p2 === '' || $p2 === '未分类') continue;
if (!in_array($p2, $partOptions, true)) { $partOptions[] = $p2; }
}
if (!in_array($curPart, $partOptions, true)) { array_unshift($partOptions, $curPart); }
?>
<div class="fieldset-card">
<div class="fs-title"><?= $cur['id'] ? '编辑文章 #' . $cur['id'] : '新增文章' ?></div>
@@ -220,12 +222,14 @@ admin_topbar('articles');
<div class="field-row" style="flex-wrap:wrap">
<div style="flex:1 1 200px;min-width:160px">
<label class="fl">分区 / 栏目</label>
<input type="text" name="part" value="<?= he($cur['part']) ?>" placeholder="如:安全研究 / 随笔" list="artPartList">
<datalist id="artPartList">
<?php foreach ($partSuggest as $ps): ?>
<option value="<?= he($ps) ?>">
<select name="part" id="artPartSel">
<?php foreach ($partOptions as $po): ?>
<option value="<?= he($po) ?>"<?= $curPart === $po ? ' selected' : '' ?>><?= he($po) ?></option>
<?php endforeach; ?>
</datalist>
<option value="__new__">+ 新建分区…</option>
</select>
<input type="text" id="artPartNew" placeholder="输入新分区名称,回车确认" style="display:none">
<span class="tip" style="display:block;margin-top:4px">可直接下拉选择已有分区;需要新栏目时选「+ 新建分区…」并输入名称后回车。</span>
</div>
<div style="flex:2 1 260px;min-width:200px">
<label class="fl">文章标题</label>
@@ -365,6 +369,59 @@ admin_topbar('articles');
xhr.send(fd);
});
})();
(function () {
'use strict';
// 分区下拉:选择「+ 新建分区…」时切换为新分区名输入框,回车/失焦确认后回落
var sel = document.getElementById('artPartSel');
var inp = document.getElementById('artPartNew');
var form = (sel && inp) ? sel.closest('form') : null;
if (!sel || !inp || !form) return;
function showSel() {
sel.style.display = '';
inp.style.display = 'none';
}
function acceptNew() {
var v = inp.value.replace(/^\s+|\s+$/g, '');
if (v === '') return false;
var i, found = false;
for (i = 0; i < sel.options.length; i++) {
if (sel.options[i].value === v) { sel.selectedIndex = i; found = true; break; }
}
if (!found) {
var opt = document.createElement('option');
opt.value = v;
opt.text = v;
sel.appendChild(opt);
sel.value = v;
}
inp.value = '';
showSel();
return true;
}
sel.addEventListener('change', function () {
if (sel.value === '__new__') {
sel.style.display = 'none';
inp.style.display = '';
inp.focus();
}
});
inp.addEventListener('keydown', function (ev) {
if (ev.key === 'Enter') {
ev.preventDefault();
if (!acceptNew()) showSel();
}
});
inp.addEventListener('blur', function () {
if (!acceptNew()) showSel();
});
form.addEventListener('submit', function (ev) {
if (sel.value === '__new__' && !acceptNew()) {
ev.preventDefault();
showSel();
sel.focus();
}
});
})();
</script>
</body>
</html>