feat: 首页推荐管理改为下拉选择

- 去掉手填 path/名称输入框, 改为按分类分组的工具下拉框(80+工具)
- 选中自动回填 名称/描述/图标emoji, 描述可微调
- 副标题与底部说明同步(对应精选推荐区块)

验证: 下拉70分类756选项, 选二维码生成器自动填icon/描述, path+name输入框移除

CHANGELOG记录
This commit is contained in:
personal82555 committed 2026-10-13 15:06:14 +08:00
1 parent a2c4ac0ff1
commit 4c3c6a2f28
2 files changed
+70 -14

No files matched your search

+64 -14
View File
@@ -2,6 +2,7 @@
import { computed, ref } from 'vue';
import { useHead } from '@vueuse/head';
import { useUserAuth } from '@/composable/user-auth';
import { useToolStore } from '@/tools/tools.store';
useHead({ title: '管理后台 - IT-TOOLS-PRO' });
@@ -310,6 +311,51 @@ function fmtTime(t: number) {
const reco = ref<any[]>([]);
const recoBusy = ref(false);
// 工具下拉数据:全部工具按分类分组(选择已有功能,无需手填 path/名称)
const toolStore = useToolStore();
const toolGroups = computed(() => {
const byCat = new Map<string, { path: string; name: string; description: string }[]>();
for (const t of toolStore.tools) {
const c = t.category || '其他';
if (!byCat.has(c)) {
byCat.set(c, []);
}
byCat.get(c)!.push({ path: t.path, name: t.name, description: t.description });
}
return [...byCat.entries()]
.map(([cat, list]) => ({ cat, list: [...list].sort((a, b) => a.name.localeCompare(b.name, 'zh')) }))
.sort((a, b) => a.cat.localeCompare(b.cat, 'zh'));
});
const toolMap = computed(() => new Map(toolStore.tools.map(t => [t.path, t])));
// 常见工具 emoji:选中工具时自动填图标
const RECO_EMOJI: Record<string, string> = {
'/ai-chat': '🤖', '/ai-image-lab': '🪄', '/ai-retouch': '🎨', '/copywriting': '✍️',
'/video-tools': '🎥', '/audio-tools': '🎙️', '/seal-maker': '🔴', '/signature-pad': '✍️',
'/zh-convert': '🈶', '/pinyin-converter': '🀄', '/user-center': '👤', '/pricing': '🔑',
'/image-ocr': '🔍', '/pdf-ocr': '📄', '/image-tools': '🖼️', '/pdf-tools': '📑',
'/doc-convert': '🔄', '/text-to-image': '🖼️', '/qrcode-generator': '📱', '/encryption': '🔒',
'/hash-text': '#️⃣', '/jwt-parser': '🎫', '/regex-tester': ' .*', '/json-prettify': '{ }',
'/lorem-ipsum-generator': '📝', '/password-strength-analyser': '🔐', '/color-converter': '🎨',
'/markdown-to-html': 'MD', '/base64-string-converter': '64', '/random-port-generator': '🔌',
'/crontab-generator': '⏰', '/uuid-generator': '🆔', '/token-generator': '🎟️',
'/site-bookmarks': '🔖', '/label-designer': '🏷️', '/emoji-picker': '😀', '/git-memo': '🐙',
'/camera-recorder': '📷', '/chronometer': '⏱️', '/device-information': '💻', '/math-evaluator': '🧮',
};
function emojiFor(path: string) {
return RECO_EMOJI[path] || '🧰';
}
// 选中工具:自动填 名称 / 描述 / 图标(无需手动输入)
function onToolPick(it: any) {
const t = toolMap.value.get(it.path);
if (t) {
it.name = t.name;
it.desc = t.description;
it.icon = emojiFor(t.path);
}
}
async function loadReco() {
const b = await api('/admin/reco');
reco.value = (b.data ?? []).map((x: any) => ({ ...x }));
@@ -327,7 +373,7 @@ async function saveReco() {
}
function recoAdd() {
reco.value.unshift({ path: '/', icon: '📌', name: '', desc: '', enabled: true });
reco.value.unshift({ path: '', icon: '🧰', name: '', desc: '', enabled: true });
}
function recoDel(i: number) {
@@ -529,7 +575,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
<!-- reco -->
<template v-if="tab === 'reco'">
<div class="adm-toolbar">
<h3 class="adm-h3" style="margin:0">🏠 首页推荐管理 <span class="adm-sub">配置首页「近期新功能」展示的工具,按顺序排列,可启停</span></h3>
<h3 class="adm-h3" style="margin:0">🏠 首页推荐管理 <span class="adm-sub">配置首页「⭐ 精选推荐」展示的工具,下拉选择已有功能,按顺序排列,可启停</span></h3>
<button class="adm-btn adm-btn-sm" @click="recoAdd">+ 添加推荐</button>
<button class="adm-btn adm-btn-sm adm-btn-primary" :disabled="recoBusy" @click="saveReco">{{ recoBusy ? '保存中…' : '💾 保存并发布' }}</button>
<span v-if="adminMsg" class="adm-ok">{{ adminMsg }}</span>
@@ -538,10 +584,14 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
<div class="adm-reco-list">
<div v-for="(it, i) in reco" :key="i" class="adm-reco-row">
<span class="adm-reco-ord">{{ i + 1 }}</span>
<input v-model="it.icon" class="adm-reco-icon" maxlength="4" title="图标(emoji)">
<input v-model="it.path" class="adm-reco-path" placeholder="/tool-path">
<input v-model="it.name" class="adm-reco-name" placeholder="名称">
<input v-model="it.desc" class="adm-reco-desc" placeholder="一句话描述">
<input v-model="it.icon" class="adm-reco-icon" maxlength="4" title="图标(emoji),选中工具自动填">
<select v-model="it.path" class="adm-reco-sel" :title="it.path || '选择工具'" @change="onToolPick(it)">
<option value="" disabled>▼ 选择工具</option>
<optgroup v-for="g in toolGroups" :key="g.cat" :label="g.cat">
<option v-for="t in g.list" :key="t.path" :value="t.path">{{ t.name }}</option>
</optgroup>
</select>
<input v-model="it.desc" class="adm-reco-desc" placeholder="描述(选中工具自动填)">
<label class="adm-reco-on"><input v-model="it.enabled" type="checkbox"> 显示</label>
<span class="adm-reco-ops">
<button class="adm-mini" :disabled="i === 0" @click="recoMove(i, -1)" title="上移">↑</button>
@@ -552,7 +602,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
<div v-if="!reco.length" class="adm-empty">暂无推荐项,点右上「添加推荐」新增</div>
</div>
<div class="adm-storage-note" style="margin-top:10px">
💡 点「保存并发布」后首页「近期新功能」立即生效,所有访客可见。<code>path</code> 填工具路由(如 /seal-maker),未启用的项不显示。
💡 点「保存并发布」后首页「⭐ 精选推荐」立即生效,所有访客可见。下拉框直接选择已有工具(自动填名称/描述/图标),未启用的项不显示。
</div>
</template>
@@ -724,7 +774,8 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
flex-shrink: 0;
}
input {
input,
select {
border: 1px solid rgba(128, 128, 128, 0.32);
border-radius: 7px;
padding: 5px 8px;
@@ -740,14 +791,13 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
.adm-reco-icon {
width: 46px;
text-align: center;
flex-shrink: 0;
}
.adm-reco-path {
width: 150px;
}
.adm-reco-name {
width: 120px;
.adm-reco-sel {
width: 190px;
flex-shrink: 0;
cursor: pointer;
}
.adm-reco-desc {