- 后端: 交易时段(工作日9:15-15:05)/news按需重抓股票列, 60s节流; 其余4列仍每天8点 - 前端: 首页可见时每60s轮询 /relay/news, 隐藏暂停 - 非交易时段/失败不重抓, 不影响接口 测试7项+端到端66s轮询 ✓ CHANGELOG记录
606 lines
17 KiB
Vue
606 lines
17 KiB
Vue
<script setup lang="ts">
|
||
import { IconDragDrop, IconHeart } from '@tabler/icons-vue';
|
||
import { useHead } from '@vueuse/head';
|
||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||
import Draggable from 'vuedraggable';
|
||
import ColoredCard from '../components/ColoredCard.vue';
|
||
import ToolCard from '../components/ToolCard.vue';
|
||
import { useToolStore } from '@/tools/tools.store';
|
||
import { useRecentTools } from '@/composable/recent-tools';
|
||
|
||
// 近期新功能亮点(手动维护,新工具上线时加一条)
|
||
const NEW_FEATURES = [
|
||
{ path: '/seal-maker', icon: '🔴', name: '印章生成器', desc: '圆形公章一键生成,盖章到图片/PDF,支持骑缝章' },
|
||
{ path: '/signature-pad', icon: '✍️', name: '手写签名', desc: '真实笔触模拟,透明 PNG,签合同一步到位' },
|
||
{ path: '/text-to-image', icon: '🖼️', name: '文字生成图片', desc: '多行文字排版出图,字体颜色可调,2x/3x 高清' },
|
||
{ path: '/zh-convert', icon: '🈶', name: '简繁体转换', desc: 'OpenCC 词典,词组级准确互转(台湾/香港标准)' },
|
||
{ path: '/pinyin-converter', icon: '🀄', name: '汉字转拼音', desc: '多音字智能转换,全读音标注,三种声调风格' },
|
||
{ path: '/video-tools', icon: '🎥', name: '视频工具箱', desc: '13 个 ffmpeg 工具:转码/压缩/水印/去水印/GIF' },
|
||
{ path: '/audio-tools', icon: '🎙️', name: '音频工具', desc: '文字转音频、语音识别、声音克隆(部署中)' },
|
||
{ path: '/user-center', icon: '👤', name: '用户中心', desc: '收藏/记录云端同步,换电脑登录即恢复,授权跟随账号' },
|
||
{ path: '/ai-image-lab', icon: '🪄', name: 'AI 图片实验室', desc: '智能抠图去背景、AI 无损放大变清晰、一键证件照' },
|
||
{ path: '/ai-chat', icon: '🤖', name: 'AI 客服', desc: '本站功能问答:工具在哪、怎么用、选哪个,支持多轮对话' },
|
||
{ path: '/copywriting', icon: '✍️', name: '文案工具箱', desc: '一键改写、降 AIGC 率、爆款标题、小红书/朋友圈文案' },
|
||
];
|
||
import { config } from '@/config';
|
||
|
||
const toolStore = useToolStore();
|
||
const { recentTools } = useRecentTools();
|
||
|
||
// 近期新功能:静态清单(新开发功能上线时手动加一条)
|
||
const newFeatures = ref<any[]>(NEW_FEATURES);
|
||
|
||
// 精选推荐:管理后台配置(/relay/reco),独立区块置顶显示;为空则隐藏该区块
|
||
const recoList = ref<any[]>([]);
|
||
onMounted(async () => {
|
||
try {
|
||
const res = await fetch('/relay/reco');
|
||
const j = await res.json();
|
||
if (j.code === 200 && Array.isArray(j.data)) {
|
||
recoList.value = j.data.filter((x: any) => x.path && x.name && x.enabled !== false);
|
||
}
|
||
}
|
||
catch { /* 无推荐则隐藏 */ }
|
||
});
|
||
|
||
// 每日 5 列资讯:GITHUB/国际新闻/AI资讯/IT最新技术/当天最热股票
|
||
// 前 4 列 relay 每天 08:00 抓取;「当天最热股票」交易时段 60s 高频刷新
|
||
const newsCols = ref<any[]>([]);
|
||
const newsDate = ref('');
|
||
async function loadNews() {
|
||
try {
|
||
const res = await fetch('/relay/news');
|
||
const j = await res.json();
|
||
if (j.code === 200 && j.data && Array.isArray(j.data.columns)) {
|
||
newsCols.value = j.data.columns;
|
||
newsDate.value = j.data.date || '';
|
||
}
|
||
}
|
||
catch { /* 无资讯则隐藏 */ }
|
||
}
|
||
let newsTimer: ReturnType<typeof setInterval> | undefined;
|
||
onMounted(() => {
|
||
loadNews();
|
||
// 页面可见时每 60s 拉一次,拿到刷新后的股票列(非交易时段 relay 不重抓,开销可忽略)
|
||
newsTimer = setInterval(() => {
|
||
if (document.visibilityState === 'visible') loadNews();
|
||
}, 60000);
|
||
});
|
||
onUnmounted(() => {
|
||
if (newsTimer) clearInterval(newsTimer);
|
||
});
|
||
|
||
// map recent paths to tool objects (newest first, cap 8)
|
||
const recentToolList = computed(() => {
|
||
const byPath = new Map(toolStore.tools.map(t => [t.path, t]));
|
||
const out: any[] = [];
|
||
for (const r of recentTools.value) {
|
||
const tool = byPath.get(r.path);
|
||
if (tool && !out.includes(tool)) {
|
||
out.push(tool);
|
||
}
|
||
if (out.length >= 8) {
|
||
break;
|
||
}
|
||
}
|
||
return out;
|
||
});
|
||
|
||
useHead({ title: 'IT-TOOLS-PRO - Handy online tools for developers' });
|
||
const { t } = useI18n();
|
||
|
||
const favoriteTools = computed(() => toolStore.favoriteTools);
|
||
|
||
// 全部工具默认折叠,点击标题展开,右侧显示数量
|
||
const showAllTools = ref(false);
|
||
|
||
// Update favorite tools order when drag is finished
|
||
function onUpdateFavoriteTools() {
|
||
toolStore.updateFavoriteTools(favoriteTools.value); // Update the store with the new order
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div class="pt-50px">
|
||
<!-- 每日 5 列资讯 -->
|
||
<div v-if="newsCols.length" class="news-block">
|
||
<div class="nf-head">
|
||
<span class="nf-title">📰 每日资讯</span>
|
||
<span class="nf-sub">每天 08:00 自动更新{{ newsDate ? ' · ' + newsDate : '' }}</span>
|
||
</div>
|
||
<div class="news-grid">
|
||
<div v-for="col in newsCols" :key="col.key" class="news-col">
|
||
<div class="news-col-head">
|
||
<span class="news-col-icon">{{ col.icon }}</span>
|
||
<span class="news-col-title">{{ col.title }}</span>
|
||
</div>
|
||
<div class="news-list">
|
||
<a
|
||
v-for="(it, i) in col.items"
|
||
:key="i"
|
||
class="news-item"
|
||
:href="it.url"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
>
|
||
<span class="news-title">{{ it.title }}</span>
|
||
<span v-if="it.desc" class="news-desc">{{ it.desc }}</span>
|
||
<span class="news-time">{{ it.time }}</span>
|
||
</a>
|
||
<div v-if="!col.items.length" class="news-empty">暂无内容</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 精选推荐(管理后台配置,置顶独立列表) -->
|
||
<div v-if="recoList.length" class="nf-block reco-block">
|
||
<div class="nf-head">
|
||
<span class="nf-title">⭐ 精选推荐 <em class="nf-count">{{ recoList.length }}</em></span>
|
||
<span class="nf-sub">为您精选的实用工具,管理员持续更新</span>
|
||
</div>
|
||
<div class="nf-grid">
|
||
<RouterLink v-for="f in recoList" :key="f.path" :to="f.path" class="nf-card reco-card">
|
||
<span class="nf-icon">{{ f.icon }}</span>
|
||
<span class="nf-body">
|
||
<span class="nf-name">{{ f.name }} <em class="reco-badge">荐</em></span>
|
||
<span class="nf-desc">{{ f.desc }}</span>
|
||
</span>
|
||
</RouterLink>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 近期新功能 -->
|
||
<div class="nf-block">
|
||
<div class="nf-head">
|
||
<span class="nf-title">🆕 近期新功能 <em class="nf-count">{{ newFeatures.length }}</em></span>
|
||
<span class="nf-sub">持续更新中,登录后数据云端同步、授权跟随账号</span>
|
||
</div>
|
||
<div class="nf-grid">
|
||
<RouterLink v-for="f in newFeatures" :key="f.path" :to="f.path" class="nf-card">
|
||
<span class="nf-icon">{{ f.icon }}</span>
|
||
<span class="nf-body">
|
||
<span class="nf-name">{{ f.name }} <em class="nf-badge">新</em></span>
|
||
<span class="nf-desc">{{ f.desc }}</span>
|
||
</span>
|
||
</RouterLink>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="grid-wrapper">
|
||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||
<ColoredCard v-if="config.showBanner" :title="$t('home.follow.title')" :icon="IconHeart">
|
||
{{ $t('home.follow.p1') }}
|
||
<a
|
||
href="https://github.com/CorentinTh/it-tools"
|
||
rel="noopener"
|
||
target="_blank"
|
||
:aria-label="$t('home.follow.githubRepository')"
|
||
>GitHub</a>
|
||
{{ $t('home.follow.p2') }}
|
||
<a
|
||
href="https://x.com/ittoolsdottech"
|
||
rel="noopener"
|
||
target="_blank"
|
||
:aria-label="$t('home.follow.twitterXAccount')"
|
||
>X</a>.
|
||
{{ $t('home.follow.thankYou') }}
|
||
<n-icon :component="IconHeart" />
|
||
</ColoredCard>
|
||
</div>
|
||
|
||
<div v-if="recentToolList.length > 0">
|
||
<h3 class="mb-5px mt-25px text-neutral-400 font-500 grp-h3">
|
||
<span>🕘 {{ $t('home.categories.recentTools') }}</span>
|
||
<span class="grp-count">{{ recentToolList.length }}</span>
|
||
</h3>
|
||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||
<ToolCard v-for="tool in recentToolList" :key="tool.name" :tool="tool" />
|
||
</div>
|
||
</div>
|
||
|
||
<transition name="height">
|
||
<div v-if="toolStore.favoriteTools.length > 0">
|
||
<h3 class="mb-5px mt-25px text-neutral-400 font-500 grp-h3">
|
||
<span>
|
||
{{ $t('home.categories.favoriteTools') }}
|
||
<c-tooltip :tooltip="$t('home.categories.favoritesDndToolTip')">
|
||
<n-icon :component="IconDragDrop" size="18" />
|
||
</c-tooltip>
|
||
</span>
|
||
<span class="grp-count">{{ favoriteTools.length }}</span>
|
||
</h3>
|
||
<Draggable
|
||
:list="favoriteTools"
|
||
class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4"
|
||
ghost-class="ghost-favorites-draggable"
|
||
item-key="name"
|
||
@end="onUpdateFavoriteTools"
|
||
>
|
||
<template #item="{ element: tool }">
|
||
<ToolCard :tool="tool" />
|
||
</template>
|
||
</Draggable>
|
||
</div>
|
||
</transition>
|
||
|
||
<div v-if="toolStore.newTools.length > 0">
|
||
<h3 class="mb-5px mt-25px text-neutral-400 font-500 grp-h3">
|
||
<span>{{ t('home.categories.newestTools') }}</span>
|
||
<span class="grp-count">{{ toolStore.newTools.length }}</span>
|
||
</h3>
|
||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||
<ToolCard v-for="tool in toolStore.newTools" :key="tool.name" :tool="tool" />
|
||
</div>
|
||
</div>
|
||
|
||
<div class="all-tools">
|
||
<div class="all-tools-head" role="button" :aria-expanded="showAllTools" @click="showAllTools = !showAllTools">
|
||
<span class="all-tools-l">
|
||
<span class="all-tools-arrow" :class="{ open: showAllTools }">▶</span>
|
||
{{ $t('home.categories.allTools') }}
|
||
</span>
|
||
<span class="all-tools-count">{{ toolStore.tools.length }}</span>
|
||
</div>
|
||
<transition name="height">
|
||
<div v-if="showAllTools" class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||
<ToolCard v-for="tool in toolStore.tools" :key="tool.name" :tool="tool" />
|
||
</div>
|
||
</transition>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped lang="less">
|
||
// 首页各组数量徽章:紧跟组名显示(统一绿色圆角)
|
||
.nf-count,
|
||
.grp-count {
|
||
display: inline-block;
|
||
min-width: 22px;
|
||
padding: 0 7px;
|
||
border-radius: 999px;
|
||
background: rgba(24, 160, 88, 0.15);
|
||
color: #18a058;
|
||
font-size: 12px;
|
||
font-weight: 700;
|
||
text-align: center;
|
||
flex-shrink: 0;
|
||
line-height: 1.7;
|
||
font-style: normal;
|
||
margin-left: 5px;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
// h3 组标题:标签 + 数量 紧邻
|
||
.grp-h3 {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
|
||
> span:first-child {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
}
|
||
|
||
// 全部工具:默认折叠,标题左侧箭头 + 右侧数量徽章
|
||
.all-tools {
|
||
margin-top: 25px;
|
||
|
||
.all-tools-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
padding: 7px 8px;
|
||
border-radius: 9px;
|
||
margin-bottom: 5px;
|
||
transition: background 0.15s;
|
||
|
||
&:hover {
|
||
background: rgba(128, 128, 128, 0.07);
|
||
}
|
||
|
||
.all-tools-l {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 7px;
|
||
font-size: 15px;
|
||
font-weight: 500;
|
||
color: rgba(0, 0, 0, 0.55);
|
||
}
|
||
|
||
.all-tools-arrow {
|
||
font-size: 11px;
|
||
opacity: 0.6;
|
||
transition: transform 0.18s;
|
||
|
||
&.open {
|
||
transform: rotate(90deg);
|
||
}
|
||
}
|
||
|
||
.all-tools-count {
|
||
min-width: 30px;
|
||
padding: 2px 10px;
|
||
border-radius: 999px;
|
||
background: rgba(24, 160, 88, 0.15);
|
||
color: #18a058;
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
text-align: center;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 精选推荐区块:琥珀色调,与绿色「近期新功能」视觉区分(提高优先级覆盖 .nf-card)
|
||
.nf-block.reco-block {
|
||
.nf-title {
|
||
color: #f0a020;
|
||
}
|
||
|
||
.nf-card.reco-card {
|
||
border-color: rgba(240, 160, 32, 0.4);
|
||
background: linear-gradient(120deg, rgba(240, 160, 32, 0.07), rgba(240, 160, 32, 0.02));
|
||
|
||
&:hover {
|
||
border-color: rgba(240, 160, 32, 0.7);
|
||
}
|
||
}
|
||
}
|
||
|
||
.nf-block {
|
||
margin-bottom: 20px;
|
||
|
||
.nf-head {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 10px;
|
||
margin-bottom: 10px;
|
||
|
||
.nf-title {
|
||
font-size: 17px;
|
||
font-weight: 800;
|
||
}
|
||
|
||
.nf-sub {
|
||
font-size: 12px;
|
||
opacity: 0.5;
|
||
}
|
||
}
|
||
|
||
.nf-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
|
||
gap: 10px;
|
||
}
|
||
|
||
.nf-card {
|
||
display: flex;
|
||
gap: 10px;
|
||
align-items: flex-start;
|
||
border: 1px solid rgba(24, 160, 88, 0.3);
|
||
background: linear-gradient(120deg, rgba(24, 160, 88, 0.05), rgba(24, 160, 88, 0.015));
|
||
border-radius: 10px;
|
||
padding: 10px 12px;
|
||
text-decoration: none;
|
||
color: inherit;
|
||
transition: border-color 0.15s, transform 0.1s;
|
||
|
||
&:hover {
|
||
border-color: #18a058;
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.nf-icon {
|
||
font-size: 20px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.nf-body {
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 2px;
|
||
|
||
.nf-name {
|
||
font-size: 13.5px;
|
||
font-weight: 700;
|
||
|
||
.nf-badge {
|
||
font-style: normal;
|
||
font-size: 10px;
|
||
font-weight: 700;
|
||
color: #fff;
|
||
background: #18a058;
|
||
border-radius: 4px;
|
||
padding: 0 5px;
|
||
margin-left: 4px;
|
||
vertical-align: 1px;
|
||
}
|
||
|
||
.reco-badge {
|
||
font-style: normal;
|
||
font-size: 10px;
|
||
font-weight: 700;
|
||
color: #fff;
|
||
background: #f0a020;
|
||
border-radius: 4px;
|
||
padding: 0 5px;
|
||
margin-left: 4px;
|
||
vertical-align: 1px;
|
||
}
|
||
}
|
||
|
||
.nf-desc {
|
||
font-size: 11.5px;
|
||
opacity: 0.6;
|
||
line-height: 1.55;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 每日 5 列资讯
|
||
.news-block {
|
||
margin-bottom: 20px;
|
||
|
||
.news-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(5, 1fr);
|
||
gap: 10px;
|
||
|
||
@media (max-width: 1280px) {
|
||
grid-template-columns: repeat(3, 1fr);
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
grid-template-columns: repeat(2, 1fr);
|
||
}
|
||
|
||
@media (max-width: 480px) {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
}
|
||
|
||
.news-col {
|
||
border: 1px solid rgba(24, 160, 88, 0.25);
|
||
background: rgba(24, 160, 88, 0.04);
|
||
border-radius: 10px;
|
||
padding: 8px 10px 6px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.news-col-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
padding-bottom: 6px;
|
||
margin-bottom: 4px;
|
||
border-bottom: 1px solid rgba(24, 160, 88, 0.18);
|
||
|
||
.news-col-icon {
|
||
font-size: 15px;
|
||
}
|
||
|
||
.news-col-title {
|
||
font-size: 13px;
|
||
font-weight: 800;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
}
|
||
|
||
.news-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
// 固定显示 5 条的高度(含简介约 66px/条),超出在框内滚动
|
||
height: 330px;
|
||
overflow-y: auto;
|
||
overscroll-behavior: contain;
|
||
scrollbar-width: thin;
|
||
|
||
&::-webkit-scrollbar {
|
||
width: 6px;
|
||
}
|
||
|
||
&::-webkit-scrollbar-thumb {
|
||
background: rgba(24, 160, 88, 0.35);
|
||
border-radius: 3px;
|
||
}
|
||
}
|
||
|
||
.news-item {
|
||
display: block;
|
||
padding: 5px 2px;
|
||
border-radius: 6px;
|
||
text-decoration: none;
|
||
color: inherit;
|
||
transition: background 0.15s;
|
||
|
||
&:hover {
|
||
background: rgba(24, 160, 88, 0.1);
|
||
|
||
.news-title {
|
||
color: #18a058;
|
||
}
|
||
}
|
||
|
||
.news-title {
|
||
display: -webkit-box;
|
||
-webkit-line-clamp: 2;
|
||
-webkit-box-orient: vertical;
|
||
overflow: hidden;
|
||
font-size: 12px;
|
||
line-height: 1.45;
|
||
color: rgba(0, 0, 0, 0.85);
|
||
word-break: break-word;
|
||
}
|
||
|
||
.news-desc {
|
||
display: -webkit-box;
|
||
-webkit-line-clamp: 2;
|
||
-webkit-box-orient: vertical;
|
||
overflow: hidden;
|
||
font-size: 11px;
|
||
line-height: 1.45;
|
||
color: rgba(0, 0, 0, 0.45);
|
||
margin-top: 2px;
|
||
word-break: break-word;
|
||
}
|
||
|
||
.news-time {
|
||
display: block;
|
||
font-size: 10.5px;
|
||
opacity: 0.5;
|
||
margin-top: 2px;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
}
|
||
|
||
.news-empty {
|
||
font-size: 11.5px;
|
||
opacity: 0.45;
|
||
padding: 8px 2px;
|
||
}
|
||
}
|
||
|
||
.height-enter-active,
|
||
.height-leave-active {
|
||
transition: all 0.5s ease-in-out;
|
||
overflow: hidden;
|
||
max-height: 500px;
|
||
}
|
||
|
||
.height-enter-from,
|
||
.height-leave-to {
|
||
max-height: 42px;
|
||
overflow: hidden;
|
||
opacity: 0;
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.ghost-favorites-draggable {
|
||
opacity: 0.4;
|
||
background-color: #ccc;
|
||
border: 2px dashed #666;
|
||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
||
transform: scale(1.1);
|
||
animation: ghost-favorites-draggable-animation 0.2s ease-out;
|
||
}
|
||
|
||
@keyframes ghost-favorites-draggable-animation {
|
||
0% {
|
||
opacity: 0;
|
||
transform: scale(0.9);
|
||
}
|
||
100% {
|
||
opacity: 0.4;
|
||
transform: scale(1.0);
|
||
}
|
||
}
|
||
</style>
|