feat:右上角接入授权中心——常驻版本徽章+公告铃铛+新版本横幅;server 加 /api/hub/*(安装统计/心跳/公告/更新检查,机器码存 hub.json);KEY 经 restart.sh 动态注入;/api/web-site 名称同步米图设计
NodeJS with Webpack / build (push) Canceled after 0s
NodeJS with Webpack / build (push) Canceled after 0s
This commit is contained in:
1 parent
759f8a6232
commit
fdd7c2f639
6 files changed
+385
-3
No files matched your search
@@ -0,0 +1,227 @@
|
||||
<template>
|
||||
<span class="hub-info">
|
||||
<!-- 新版本横幅(知道了后按版本号记忆隐藏) -->
|
||||
<div v-if="hasNew" class="hub-banner">
|
||||
<span>
|
||||
发现新版本 v{{ upd.latest_version }}
|
||||
<template v-if="upd.changelog">:{{ upd.changelog }}</template>
|
||||
</span>
|
||||
<a v-if="upd.download_url" :href="upd.download_url" target="_blank">去更新</a>
|
||||
<a class="know" @click="dismissBanner">知道了</a>
|
||||
</div>
|
||||
|
||||
<!-- 右上角常驻版本徽章 -->
|
||||
<Tooltip
|
||||
:content="hasNew ? `有新版本 v${upd.latest_version}` : `当前版本 v${version}`"
|
||||
placement="bottom"
|
||||
>
|
||||
<Tag :color="hasNew ? 'orange' : 'default'" class="ver-chip" @click="load(true)">
|
||||
v{{ version }}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
|
||||
<!-- 公告铃铛(有未读亮红点) -->
|
||||
<Badge :dot="unread" :offset="[8, 3]">
|
||||
<Icon
|
||||
custom="ivu-icon-ios-notifications-outline"
|
||||
size="20"
|
||||
style="cursor: pointer"
|
||||
@click="openPanel"
|
||||
/>
|
||||
</Badge>
|
||||
|
||||
<!-- 公告面板 -->
|
||||
<div v-if="annVisible" class="ann-pop">
|
||||
<div class="ann-hd">
|
||||
<span>📢 公告</span>
|
||||
<Icon type="md-close" style="cursor: pointer" @click="annVisible = false" />
|
||||
</div>
|
||||
<div v-if="!anns.length" class="ann-empty">暂无公告</div>
|
||||
<div v-for="a in anns" :key="a.id" class="ann-item">
|
||||
<div class="t">{{ a.title }}</div>
|
||||
<div class="c">{{ a.content }}</div>
|
||||
<div class="d">{{ String(a.created_at || '').slice(0, 10) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 弹窗公告(每条只弹一次,按 id 记忆) -->
|
||||
<Modal v-model="popupShow" :title="popupAnn ? popupAnn.title : ''" footer-hide>
|
||||
<div class="popup-c">{{ popupAnn ? popupAnn.content : '' }}</div>
|
||||
</Modal>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script name="HubInfo" setup lang="ts">
|
||||
const version = ref('1.0.0');
|
||||
const upd = ref<{
|
||||
update_available: boolean;
|
||||
latest_version: string;
|
||||
changelog: string;
|
||||
download_url: string;
|
||||
}>({
|
||||
update_available: false,
|
||||
latest_version: '',
|
||||
changelog: '',
|
||||
download_url: '',
|
||||
});
|
||||
const anns = ref<{ id: number; title: string; content: string; created_at: string }[]>([]);
|
||||
const popupList = ref<typeof anns.value>([]);
|
||||
const annVisible = ref(false);
|
||||
const popupShow = ref(false);
|
||||
const popupAnn = ref<(typeof anns.value)[number] | null>(null);
|
||||
|
||||
const readIds = ref(new Set<number>(JSON.parse(localStorage.getItem('mtai.annRead') || '[]')));
|
||||
const seenPop = ref(new Set<number>(JSON.parse(localStorage.getItem('mtai.annSeen') || '[]')));
|
||||
|
||||
const hasNew = computed(
|
||||
() =>
|
||||
upd.value.update_available &&
|
||||
!!upd.value.latest_version &&
|
||||
upd.value.latest_version !== version.value &&
|
||||
localStorage.getItem('mtai.updHide') !== upd.value.latest_version
|
||||
);
|
||||
const unread = computed(() => anns.value.some((a) => !readIds.value.has(a.id)));
|
||||
|
||||
function dismissBanner() {
|
||||
localStorage.setItem('mtai.updHide', upd.value.latest_version);
|
||||
}
|
||||
function openPanel() {
|
||||
annVisible.value = !annVisible.value;
|
||||
if (annVisible.value && anns.value.length) {
|
||||
anns.value.forEach((a) => readIds.value.add(a.id));
|
||||
localStorage.setItem('mtai.annRead', JSON.stringify([...readIds.value]));
|
||||
}
|
||||
}
|
||||
|
||||
async function load(_force?: boolean) {
|
||||
try {
|
||||
const d = await (await fetch('/api/hub/status')).json();
|
||||
if (d.version) version.value = d.version;
|
||||
if (d.update) upd.value = d.update;
|
||||
if (Array.isArray(d.announcements)) anns.value = d.announcements;
|
||||
if (Array.isArray(d.popup)) popupList.value = d.popup;
|
||||
// 弹窗公告:有没见过的就弹第一条
|
||||
const fresh = popupList.value.find((a) => !seenPop.value.has(a.id));
|
||||
if (fresh) {
|
||||
popupAnn.value = fresh;
|
||||
popupShow.value = true;
|
||||
seenPop.value.add(fresh.id);
|
||||
localStorage.setItem('mtai.annSeen', JSON.stringify([...seenPop.value]));
|
||||
}
|
||||
} catch {
|
||||
/* 授权中心不可用时静默:版本徽章照常显示本地版本 */
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load();
|
||||
// 心跳(服务端已节流 30min,这里只是触发)
|
||||
fetch('/api/hub/heartbeat', { method: 'POST' }).catch(() => {});
|
||||
// 页面重新可见时补一次(服务端节流兜底)
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') load();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.hub-info {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
position: relative;
|
||||
|
||||
.ver-chip {
|
||||
cursor: pointer;
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
}
|
||||
|
||||
.hub-banner {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 300;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
padding: 7px 12px;
|
||||
background: #fff7e0;
|
||||
border-bottom: 1px solid #ffd591;
|
||||
color: #874d00;
|
||||
font-size: 13px;
|
||||
|
||||
a {
|
||||
color: #d46b08;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.know {
|
||||
color: #8c8c8c;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ann-pop {
|
||||
position: absolute;
|
||||
top: 34px;
|
||||
right: 0;
|
||||
z-index: 400;
|
||||
width: 280px;
|
||||
max-height: 360px;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e5e7eb;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
|
||||
|
||||
.ann-hd {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ann-empty {
|
||||
padding: 22px 12px;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.ann-item {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
|
||||
.t {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.c {
|
||||
margin-top: 4px;
|
||||
color: #4b5563;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.d {
|
||||
margin-top: 4px;
|
||||
color: #9ca3af;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.popup-c {
|
||||
color: #374151;
|
||||
line-height: 1.8;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -22,6 +22,8 @@
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<hubInfo></hubInfo>
|
||||
<Divider type="vertical" />
|
||||
<a href="https://pro.kuaitu.cc/" target="_blank" alt="商业版">
|
||||
<img width="15" :src="proIcon" alt="vue-fbric-editor" />
|
||||
</a>
|
||||
@@ -53,6 +55,7 @@ import waterMark from '@/components/waterMark.vue';
|
||||
import login from '@/components/login';
|
||||
import admin from '@/components/admin';
|
||||
import history from '@/components/history.vue';
|
||||
import hubInfo from '@/components/hubInfo.vue';
|
||||
|
||||
const props = defineProps(['ruler']);
|
||||
const emit = defineEmits(['update:ruler']);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<hubInfo></hubInfo>
|
||||
<Divider type="vertical" />
|
||||
<Button type="primary" to="/" size="smail" target="_blank">新建设计</Button>
|
||||
<Divider type="vertical" />
|
||||
<a href="https://pro.kuaitu.cc/" target="_blank">
|
||||
@@ -100,6 +102,7 @@ import banner from './components/banner.vue';
|
||||
// 顶部组件
|
||||
import logo from '@/components/logo.vue';
|
||||
import lang from '@/components/lang.vue';
|
||||
import hubInfo from '@/components/hubInfo.vue';
|
||||
import login from '@/components/login';
|
||||
|
||||
import { getMaterialPreviewUrl } from '@/hooks/usePageList';
|
||||
|
||||
Reference in new issue
Block a user