diff --git a/README.md b/README.md index 36e6a04..8364bf1 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ - **管理后台**:`/admin` 切到「留言反馈」标签(`X-Admin-Token` 鉴权,令牌存本地 `it-tools-admin-token`),列出时间/类型/内容/联系方式/真实 IP,支持状态流转(未处理→已处理→已回复)与删除,导航标签带未处理数角标;窄屏下表格容器内横向滚动不撑破页面 - **链路**:公开页 → relay `POST /feedback`(验证码校验 + IP 限频)落盘 `data/feedback.json`;管理接口经 nginx `location /admin/` 反代到 `it-tools-relay:8091`。公网入口 https://it.88531.cn/ +### 在线统计与公告推送(2026.11 新增) + +- **右上角常驻**:🔔 公告铃铛(未读红点)+ `v2026.11.12` 版本徽标(源码常量 `SITE_VERSION`,与 Gitea Release tag 同步,发版时更新) +- **公告推送**:铃铛下拉面板列出授权系统公告(标题/时间/正文,未读带红条,点击已读、支持全部已读);`is_popup` 类型公告进站即弹一次(每条只弹一次,已读记录存 localStorage `it-tools-ann-read`) +- **在线统计**:打开页面即经 relay `POST /relay/hub/report` 向授权系统(auth.88531.cn 项目 6)登记安装并上报版本号(机器码复用 license 的 `getMachineId()`),每 30 分钟心跳一次;公告每 15 分钟拉取一次(`GET /relay/hub/announcements`),授权系统后台据此展示安装数/在线数/趋势 +- **失败开放**:授权系统不可达时静默降级,不影响站点任何功能 +- **实现注意**:公告面板与推送弹窗均 ``——实测 top-nav 内 v-if 子树挂载会触发 Vue `insertBefore null` 崩溃;CardAuth 的 heartbeat 会清空 `client_version/device_info`,relay 侧先心跳后 check-update 保证版本号落库 + ## 优势 - **一次激活,全站通用**:输入一次卡密,全部授权功能解锁,无需逐个购买 diff --git a/src/layouts/base.layout.vue b/src/layouts/base.layout.vue index 37b33a1..04135a3 100644 --- a/src/layouts/base.layout.vue +++ b/src/layouts/base.layout.vue @@ -17,6 +17,7 @@ import { useTracker } from '@/modules/tracker/tracker.services'; import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue'; import UserMenu from '@/components/UserMenu.vue'; import FeedbackModal from '@/components/FeedbackModal.vue'; +import { getMachineId } from '@/tools/license/license'; const themeVars = useThemeVars(); const styleStore = useStyleStore(); @@ -35,6 +36,108 @@ const commitSha = config.app.lastCommitSha.slice(0, 7); // ---- 站内留言反馈(右上角入口,弹窗提交,与授权系统无关) ---- const showFeedback = ref(false); +// ---- 授权系统接入(auth.88531.cn 项目 6):在线统计上报 + 公告推送 + 右上角铃铛/版本号 ---- +const SITE_VERSION = '2026.11.12'; // 当前版本号,与 Gitea Release tag 同步(发版时更新) +const annOpen = ref(false); +const announcements = ref[]>([]); +const popupAnn = ref | null>(null); +const annSeenVersion = ref(0); +let annSeen: string[] = []; +try { + annSeen = JSON.parse(localStorage.getItem('it-tools-ann-read') || '[]'); + if (!Array.isArray(annSeen)) annSeen = []; +} +catch { + annSeen = []; +} +const annUnread = computed(() => { + annSeenVersion.value; // 依赖已读版本号,标记已读后重算 + return announcements.value.filter(a => !annSeen.includes(String(a.id))).length; +}); +function annIsUnread(a: Record) { + annSeenVersion.value; + return !annSeen.includes(String(a.id)); +} +function annSaveSeen() { + try { + localStorage.setItem('it-tools-ann-read', JSON.stringify(annSeen)); + } + catch { /* localStorage 不可用时忽略 */ } + annSeenVersion.value++; +} +function annMarkRead(a: Record) { + const id = String(a?.id ?? ''); + if (id && !annSeen.includes(id)) { + annSeen.push(id); + annSaveSeen(); + } +} +function annMarkAll() { + const ids = announcements.value.map(a => String(a?.id ?? '')).filter(Boolean); + annSeen = [...new Set([...annSeen, ...ids])]; + annSaveSeen(); +} +function annTime(t?: string) { + return t ? String(t).slice(0, 16) : ''; +} +function toggleAnn() { + annOpen.value = !annOpen.value; + if (annOpen.value) fetchAnnouncements(); +} +async function fetchAnnouncements() { + try { + const res = await fetch('/relay/hub/announcements?limit=20'); + if (!res.ok) return; + const body = await res.json(); + if (body?.code !== 200) return; + announcements.value = Array.isArray(body.data?.list) ? body.data.list : []; + // 公告推送:popup 列表里没看过的条目每次只弹第一条(其余在铃铛面板可读) + const pops = (Array.isArray(body.data?.popup) ? body.data.popup : []) + .filter((p: any) => p && !annSeen.includes(String(p.id))); + if (pops.length && !popupAnn.value) + popupAnn.value = pops[0]; + } + catch { + // 授权系统不可达时静默降级,不影响站点使用 + } +} +function closePopup() { + if (popupAnn.value) + annMarkRead(popupAnn.value); + popupAnn.value = null; +} +// 在线统计:打开页面即登记安装 + 每 30 分钟心跳,授权系统后台据此统计安装/在线 +async function reportOnline() { + try { + await fetch('/relay/hub/report', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + machine_id: getMachineId(), + client_version: SITE_VERSION, + device_info: `web ${location.host}`, + }), + }); + } + catch { + // 静默降级 + } +} +function onAnnDocClick(e: MouseEvent) { + const el = e.target as Element | null; + // 面板已 Teleport 到 body,不再位于 .ann-wrap 内,需一并放行 + if (annOpen.value && !el?.closest?.('.ann-wrap, .ann-panel')) + annOpen.value = false; +} +onMounted(() => { + reportOnline(); + fetchAnnouncements(); + setInterval(reportOnline, 30 * 60 * 1000); + setInterval(fetchAnnouncements, 15 * 60 * 1000); + document.addEventListener('click', onAnnDocClick); +}); +onUnmounted(() => document.removeEventListener('click', onAnnDocClick)); + // ---- 页脚售后微信:点击复制 ---- const WECHAT_ID = 'q3970260761'; const wechatCopied = ref(false); @@ -272,6 +375,53 @@ onBeforeUnmount(() => { + + +
+ + + 🔔 + + + + + +
+
+ 📢 系统公告 + +
+
+
暂无公告
+
+
+ {{ a.title }} + {{ annTime(a.created_at) }} +
+
{{ a.content }}
+
+
+
+
+
+ + + v{{ SITE_VERSION }} @@ -306,6 +456,19 @@ onBeforeUnmount(() => { + + +
+ +
+
+ @@ -443,6 +606,176 @@ onBeforeUnmount(() => { flex-shrink: 0; } +// 右上角:授权系统公告(铃铛 + 未读红点 + 下拉面板) +.ann-wrap { + position: relative; + flex-shrink: 0; +} +.ann-btn { + position: relative; + font-size: 13px; + padding-left: 8px; + padding-right: 12px; +} +.ann-dot { + position: absolute; + top: 5px; + right: 6px; + width: 8px; + height: 8px; + border-radius: 50%; + background: #ff4d4f; + box-shadow: 0 0 0 2px v-bind('themeVars.bodyColor'); +} +.ann-panel { + position: fixed; + top: 60px; + right: 26px; + z-index: 3000; + width: 320px; + max-width: 84vw; + background: v-bind('themeVars.bodyColor'); + border: 1px solid v-bind('themeVars.textColor3'); + border-radius: 10px; + box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22); + overflow: hidden; + text-align: left; +} +.ann-panel-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 10px 12px; + font-size: 13px; + font-weight: 600; + border-bottom: 1px solid v-bind('themeVars.textColor3'); +} +.ann-readall { + border: none; + background: none; + padding: 0; + font-size: 12px; + color: v-bind('themeVars.primaryColor'); + cursor: pointer; +} +.ann-panel-body { + max-height: 300px; + overflow-y: auto; + padding: 6px 0; +} +.ann-empty { + padding: 18px 12px; + text-align: center; + font-size: 13px; + opacity: 0.6; +} +.ann-item { + padding: 8px 12px; + cursor: pointer; + border-left: 3px solid transparent; + + &:hover { + background: rgba(128, 128, 128, 0.12); + } + &.is-unread { + border-left-color: #ff4d4f; + } +} +.ann-item-head { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: 8px; + font-size: 13px; + + b { + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } +} +.ann-time { + flex-shrink: 0; + font-size: 11px; + opacity: 0.55; +} +.ann-content { + margin-top: 2px; + font-size: 12px; + line-height: 1.5; + opacity: 0.85; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; + word-break: break-word; +} + +// 右上角:当前版本号徽标 +.ver-badge { + flex-shrink: 0; + align-self: center; + padding: 4px 9px; + border-radius: 999px; + font-size: 11px; + line-height: 1; + white-space: nowrap; + cursor: default; + background: rgba(128, 128, 128, 0.16); + border: 1px solid v-bind('themeVars.textColor3'); + color: v-bind('themeVars.textColor2'); +} + +// 授权系统公告推送弹窗(每条只弹一次) +.ann-popup-mask { + position: fixed; + inset: 0; + z-index: 6000; + display: flex; + align-items: center; + justify-content: center; + padding: 20px; + background: rgba(0, 0, 0, 0.45); +} +.ann-popup { + width: 380px; + max-width: 92vw; + padding: 18px 20px 16px; + border-radius: 12px; + background: v-bind('themeVars.bodyColor'); + box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3); + text-align: left; +} +.ann-popup-head { + margin-bottom: 8px; + font-size: 14px; + font-weight: 700; +} +.ann-popup-title { + margin-bottom: 6px; + font-size: 14px; + font-weight: 600; +} +.ann-popup-content { + font-size: 13px; + line-height: 1.7; + opacity: 0.9; + white-space: pre-wrap; + word-break: break-word; +} +.ann-popup-time { + margin-top: 8px; + font-size: 11px; + opacity: 0.5; +} +.ann-popup-ok { + width: 100%; + margin-top: 14px; +} + @media (max-width: 900px) { // 窄屏顶栏放不下完整文字时收缩为纯图标,并收紧间距,避免溢出右边缘 .top-nav {