兼容原阿里云镜像,新push了一个最新的容器到

registry.cn-hangzhou.aliyuncs.com/jianzhichu/dysync.net:latest
登录页面增加提示更新信息
This commit is contained in:
jianzhichu
2026-01-11 21:33:22 +08:00
parent 00e28fc334
commit f4f87a8634
3 changed files with 596 additions and 263 deletions
+369 -252
View File
@@ -1,48 +1,59 @@
<script lang="ts" setup>
// 步骤2:声明父组件传递的 showSetting 事件(关键!)
const emits = defineEmits(['showSetting']);
import { ref, h, VNode, onMounted } from 'vue';
import { ref, onMounted } from 'vue'; // 移除 h、VNode 导入
import { StepinHeaderAction } from 'stepin';
import DayNightSwitch from '@/components/switch/DayNightSwitch.vue';
import { TagsOutlined, CopyOutlined } from '@ant-design/icons-vue'; // 移除不需要的图标
import { TagsOutlined, CopyOutlined, GithubOutlined } from '@ant-design/icons-vue';
import Fullscreen from '../fullscreen/Fullscreen.vue';
import { useApiStore } from '@/store';
import { notification, message } from 'ant-design-vue';
import { message, Popover } from 'ant-design-vue'; // 移除 notification
// 版本数据和当前版本状态
const dyVersions = ref<string[]>([]);
const copyLoading = ref<Record<string, boolean>>({}); // 复制按钮加载状态
const notificationKey = ref<string>('version-notification');
const copyLoading = ref<Record<string, boolean>>({});
// 版本 popover 显隐控制
const versionPopoverVisible = ref<boolean>(false);
// 复制版本号方法(优化:去除“(当前版本)”标记,只复制纯版本号)
// 复制版本号方法(优化:兼容所有浏览器,修复 navigator.clipboard 不存在的问题)
// 仓库地址常量
const gitRepos = ref([
{
name: 'Gitee',
url: 'https://gitee.com/deathvicky/dysync.net',
color: '#FF6600',
},
{
name: 'GitHub',
url: 'https://github.com/jianzhichu/dysync.net',
color: '#6c35de',
},
]);
const gitCopyLoading = ref<Record<string, boolean>>({});
const popoverVisible = ref<boolean>(false);
// 复制版本号方法(保留原有兼容逻辑,无改动)
const copyVersion = (version: string) => {
const pureVersion = version.replace('(当前版本)', '').replace('(最新版)', '').trim(); // 过滤所有标记
const pureVersion = version.replace('(当前版本)', '').replace('(最新版)', '').trim();
copyLoading.value[version] = true;
// 兼容方案:优先使用现代 API,降级使用传统方法
const doCopy = async () => {
try {
// 方案1:现代浏览器 + HTTPS 环境(优先)
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
await navigator.clipboard.writeText(pureVersion);
message.success(`已复制版本: ${pureVersion}`);
return;
}
// 方案2:降级使用 document.execCommand(兼容 HTTP/旧浏览器)
const textarea = document.createElement('textarea');
// 隐藏文本域(避免影响页面)
textarea.style.position = 'absolute';
textarea.style.top = '-9999px';
textarea.style.left = '-9999px';
textarea.value = pureVersion;
document.body.appendChild(textarea);
// 选中并复制
textarea.select();
const success = document.execCommand('copy');
document.body.removeChild(textarea); // 清理 DOM
document.body.removeChild(textarea);
if (success) {
message.success(`已复制版本: ${pureVersion}`);
@@ -50,7 +61,6 @@ const copyVersion = (version: string) => {
throw new Error('execCommand 复制失败');
}
} catch (error) {
// 方案3:最终降级 - 提示手动复制
message.warning(`复制失败,请手动复制:${pureVersion}`);
console.warn('复制版本号失败:', error);
} finally {
@@ -61,162 +71,54 @@ const copyVersion = (version: string) => {
doCopy();
};
// 定义版本列表组件(移除所有额外当前版本标记)
// 定义版本列表组件(完整版本:保留所有原有逻辑+样式优化+单行显示)
const renderVersionList = (): VNode => {
return h(
'div',
{
class: 'custom-version-list',
style: {
width: '100%',
padding: '10px 0',
boxSizing: 'border-box',
display: 'block',
},
},
[
dyVersions.value.length > 0
? dyVersions.value.map((tag, index) => {
// 判断是否包含当前版本/最新版标记
const isCurrentVersion = tag.includes('(当前版本)');
const isLatestVersion = tag.includes('(最新版)');
return h(
'div',
{
class: [
'custom-version-item',
isCurrentVersion ? 'custom-current-version' : '',
isLatestVersion ? 'custom-latest-version' : '',
],
key: index,
title: isCurrentVersion
? '当前使用版本 - 点击右侧按钮复制版本号'
: isLatestVersion
? '最新版本 - 点击右侧按钮复制版本号'
: '点击右侧按钮复制版本号',
style: {
width: '100%',
padding: '8px 12px',
borderBottom: '1px solid #f0f0f0',
borderRadius: '4px',
transition: 'all 0.2s ease',
boxSizing: 'border-box',
// 核心:Flex布局确保文字+按钮一行显示
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
whiteSpace: 'nowrap', // 禁止整行换行
// 版本标记背景色(区分当前版和最新版)
backgroundColor: isCurrentVersion
? 'rgba(24, 144, 255, 0.05)'
: isLatestVersion
? 'rgba(46, 125, 50, 0.05)'
: 'transparent',
},
},
[
// 文本容器(单行溢出省略+标记颜色区分)
h(
'div',
{
style: {
display: 'flex',
alignItems: 'center',
// 给复制按钮留固定宽度,避免文本挤压
maxWidth: 'calc(100% - 40px)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap', // 文本单行显示
},
},
[
h(
'span',
{
style: {
fontSize: '14px',
color: isCurrentVersion
? '#1890ff' // 当前版本文字色
: isLatestVersion
? '#2e7d32' // 最新版本文字色
: '#1f2937', // 普通版本文字色
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
},
tag // 显示带标记的完整文本(如:v1.0.0(当前版本))
),
]
),
// 复制按钮(固定大小+加载动画+hover效果)
h(
'button',
{
style: {
width: '24px',
height: '24px',
border: 'none',
borderRadius: '4px',
backgroundColor: 'transparent',
color: copyLoading.value[tag]
? '#d1d5db' // 加载中颜色
: isCurrentVersion
? '#1890ff' // 当前版本按钮色
: isLatestVersion
? '#2e7d32' // 最新版本按钮色
: '#9ca3af', // 普通版本按钮色
cursor: copyLoading.value[tag] ? 'not-allowed' : 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '0',
margin: '0',
flexShrink: '0', // 禁止按钮收缩
transition: 'all 0.2s ease',
},
onClick: (e: Event) => {
e.stopPropagation(); // 阻止事件冒泡
copyVersion(tag);
},
disabled: copyLoading.value[tag],
title: copyLoading.value[tag] ? '复制中...' : '复制版本号',
},
[
h(CopyOutlined, {
style: {
fontSize: '14px',
// 加载时旋转动画
animation: copyLoading.value[tag] ? 'custom-spin 1s linear infinite' : 'none',
},
}),
]
),
]
);
})
: h(
'div',
{
style: {
textAlign: 'center',
color: '#999',
padding: '20px 0',
fontSize: '14px',
backgroundColor: '#f9fafb',
borderRadius: '8px',
margin: '0 12px',
},
},
'暂无版本数据'
),
]
);
// 辅助方法:判断是否为当前版本(模板中使用)
const isCurrentVersion = (version: string) => {
return version.includes('(当前版本)');
};
// 获取版本列表并显示Notification(核心修改这里)
// 辅助方法:判断是否为最新版本(模板中使用)
const isLatestVersion = (version: string) => {
return version.includes('(最新版)');
};
// 复制仓库地址方法(保留原有逻辑,无改动)
const copyGitUrl = (repo: { name: string; url: string; color: string }) => {
gitCopyLoading.value[repo.url] = true;
const doCopy = async () => {
try {
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
await navigator.clipboard.writeText(repo.url);
message.success(`已复制 ${repo.name} 地址`);
return;
}
const textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.top = '-9999px';
textarea.style.left = '-9999px';
textarea.value = repo.url;
document.body.appendChild(textarea);
textarea.select();
const success = document.execCommand('copy');
document.body.removeChild(textarea);
if (success) {
message.success(`已复制 ${repo.name} 地址`);
} else {
throw new Error('execCommand 复制失败');
}
} catch (error) {
message.warning(`复制 ${repo.name} 地址失败,请手动复制`);
console.warn(`复制 ${repo.name} 地址失败:`, error);
} finally {
gitCopyLoading.value[repo.url] = false;
}
};
doCopy();
};
// 版本查看方法(获取数据后控制 popover 显隐)
const showVersionNotification = () => {
useApiStore()
.CheckTag()
@@ -226,21 +128,19 @@ const showVersionNotification = () => {
const versionLen = dyVersions.value.length;
if (versionLen > 0) {
const newVersions = [...dyVersions.value]; // 深拷贝避免修改原数据
const newVersions = [...dyVersions.value];
if (versionLen === 1) {
// 只有1个版本:标记为“最新版”
newVersions[0] = `${newVersions[0]}(最新版)`;
} else {
// 大于1个版本:第一个加“当前版本”,最后一个加“最新版”
newVersions[0] = `${newVersions[0]}(当前版本)`;
const lastIndex = versionLen - 1;
newVersions[lastIndex] = `${newVersions[lastIndex]}(最新版)`;
}
dyVersions.value = newVersions;
}
openVersionNotification();
// 打开版本 popover
versionPopoverVisible.value = true;
} else {
message.error(res.message);
}
@@ -251,41 +151,6 @@ const showVersionNotification = () => {
});
};
// 打开版本通知
const openVersionNotification = () => {
notification.open({
key: notificationKey.value,
message: '', // 空消息标题
duration: 5, // 5秒自动关闭(可改为0不自动关闭)
placement: 'topRight',
description: renderVersionList(),
style: {
width: '520px',
minWidth: '520px',
marginTop: '50px',
height: 'auto',
boxShadow: '0 4px 12px rgba(0, 0, 0, 0.08)',
borderRadius: '8px',
boxSizing: 'border-box',
},
});
// 强制覆盖AntD默认换行样式
setTimeout(() => {
const notificationEl = document.querySelector('.custom-version-notification');
if (notificationEl) {
const descriptionEls = notificationEl.querySelectorAll('.ant-notification-notice-description');
descriptionEls.forEach((el) => {
const htmlEl = el as HTMLElement;
htmlEl.style.whiteSpace = 'normal';
htmlEl.style.width = '100%';
htmlEl.style.height = 'auto';
htmlEl.style.overflow = 'visible';
});
}
}, 0);
};
// 全局注入加载动画样式
onMounted(() => {
if (!document.querySelector('#custom-spin-style')) {
@@ -300,19 +165,107 @@ onMounted(() => {
document.head.appendChild(style);
}
});
// Git 弹窗控制方法
const showGit = () => {
popoverVisible.value = !popoverVisible.value;
console.log('打开开源地址弹窗');
};
</script>
<template>
<!-- 步骤1:添加 div 作为单个根元素 -->
<StepinHeaderAction>
<DayNightSwitch />
</StepinHeaderAction>
<!-- 版本按钮 -->
<!-- 版本查看:纯模板实现,移除 renderVersionList -->
<StepinHeaderAction>
<div @click="showVersionNotification" class="action-item">
<TagsOutlined class="action-icon" />
<div class="action-item">
<a-popover v-model:visible="versionPopoverVisible" placement="bottom" trigger="click" overlay-class="version-popover-overlay" @visible-change="(visible) => versionPopoverVisible = visible">
<template #content>
<div class="version-popover-content">
<!-- 版本列表:纯模板 v-for 实现,替代 VNode 渲染 -->
<div class="custom-version-list" v-if="dyVersions.length > 0">
<div class="custom-version-item" :class="{
'custom-current-version': isCurrentVersion(version),
'custom-latest-version': isLatestVersion(version)
}" v-for="(version, index) in dyVersions" :key="index" :title="isCurrentVersion(version)
? '当前使用版本 - 点击右侧按钮复制版本号'
: isLatestVersion(version)
? '最新版本 - 点击右侧按钮复制版本号'
: '点击右侧按钮复制版本号'">
<!-- 版本文本 -->
<div class="version-text">
<span :style="{
color: isCurrentVersion(version) ? '#1890ff' : isLatestVersion(version) ? '#2e7d32' : '#1f2937'
}">
{{ version }}
</span>
</div>
<!-- 复制按钮 -->
<button class="version-copy-btn" :disabled="copyLoading[version]" @click.stop="copyVersion(version)" :title="copyLoading[version] ? '复制中...' : '复制版本号'">
<CopyOutlined :style="{
fontSize: '14px',
color: copyLoading[version]
? '#d1d5db'
: isCurrentVersion(version)
? '#1890ff'
: isLatestVersion(version)
? '#2e7d32'
: '#9ca3af',
animation: copyLoading[version] ? 'custom-spin 1s linear infinite' : 'none'
}" />
</button>
</div>
</div>
</div>
</template>
<a-tooltip placement="bottom">
<template #title>
<span>版本查看</span>
</template>
<TagsOutlined class="action-icon" @click="showVersionNotification" />
</a-tooltip>
</a-popover>
</div>
</StepinHeaderAction>
<!-- Git 开源地址弹窗(保留原有实现) -->
<StepinHeaderAction>
<div class="action-item">
<a-popover v-model:visible="popoverVisible" placement="bottom" trigger="click" overlay-class="git-popover-overlay" @visible-change="(visible) => popoverVisible = visible">
<template #content>
<div class="git-popover-content">
<div class="git-repo-item" v-for="repo in gitRepos" :key="repo.url">
<div class="git-repo-name" :style="{ color: repo.color }">
<span class="git-repo-tag" :style="{ backgroundColor: repo.color }"></span>
{{ repo.name }}
</div>
<div class="git-repo-url-wrapper">
<a :href="repo.url" target="_blank" class="git-repo-url" :style="{ color: repo.color }" title="点击打开仓库地址">
{{ repo.url }}
</a>
<button class="git-copy-btn" :disabled="gitCopyLoading[repo.url]" @click.stop="copyGitUrl(repo)" title="复制仓库地址">
<CopyOutlined :style="{
fontSize: '12px',
color: gitCopyLoading[repo.url] ? '#d1d5db' : repo.color,
animation: gitCopyLoading[repo.url] ? 'custom-spin 1s linear infinite' : 'none'
}" />
</button>
</div>
</div>
</div>
</template>
<a-tooltip placement="bottom">
<template #title>
<span>项目开源地址</span>
</template>
<GithubOutlined class="action-icon" @click="showGit" />
</a-tooltip>
</a-popover>
</div>
</StepinHeaderAction>
<StepinHeaderAction>
<Fullscreen class="-mx-xs -my-sm h-[56px] px-xs py-sm flex items-center" target=".stepin-layout" />
</StepinHeaderAction>
@@ -339,50 +292,214 @@ onMounted(() => {
font-size: 20px;
}
/* 样式兜底:确保每个版本项内部单行,外部纵向排列 */
:deep(.custom-version-notification) {
.ant-notification-notice-description {
white-space: normal !important; /* 允许版本项纵向换行 */
width: 100% !important;
height: auto !important;
overflow: visible !important;
/* 版本 Popover 样式(纯模板适配) */
:deep(.version-popover-overlay) {
.ant-popover-inner {
padding: 16px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
width: 520px;
}
.custom-version-item {
display: flex !important;
align-items: center !important;
justify-content: space-between !important;
white-space: nowrap !important; /* 禁止版本项内部换行 */
padding: 8px 12px !important; /* 重置内边距,去掉左侧竖线空间 */
&:hover {
background-color: #f5fafe !important;
}
&:last-child {
border-bottom: none !important;
}
}
/* 当前版本轻微高亮(可选,可删除) */
.custom-current-version {
background-color: rgba(24, 144, 255, 0.05) !important;
&:hover {
background-color: rgba(24, 144, 255, 0.1) !important;
}
}
/* 按钮hover样式 */
button:hover {
background-color: rgba(24, 144, 255, 0.1) !important;
color: #1890ff !important;
.ant-popover-arrow-content {
background-color: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
}
/* 新增:根容器样式(和原布局保持一致) */
.version-popover-content {
width: 100%;
box-sizing: border-box;
}
/* 版本列表(模板对应样式) */
.custom-version-list {
width: 100%;
padding: 8px 0;
box-sizing: border-box;
}
.custom-version-item {
width: 100%;
padding: 8px 12px;
border-bottom: 1px solid #f0f0f0;
border-radius: 4px;
transition: all 0.2s ease;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
white-space: nowrap;
background-color: transparent;
&:hover {
background-color: #f5fafe;
}
&:last-child {
border-bottom: none;
}
}
/* 当前版本/最新版本高亮 */
.custom-current-version {
background-color: rgba(24, 144, 255, 0.05) !important;
&:hover {
background-color: rgba(24, 144, 255, 0.1) !important;
}
}
.custom-latest-version {
background-color: rgba(46, 125, 50, 0.05) !important;
&:hover {
background-color: rgba(46, 125, 50, 0.1) !important;
}
}
/* 版本文本容器 */
.version-text {
display: flex;
align-items: center;
maxwidth: calc(100% - 40px);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 版本复制按钮 */
.version-copy-btn {
width: 24px;
height: 24px;
border: none;
border-radius: 4px;
background-color: transparent;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
margin: 0;
flex-shrink: 0;
transition: all 0.2s ease;
&:hover {
background-color: rgba(24, 144, 255, 0.1);
color: #1890ff !important;
}
&:disabled {
cursor: not-allowed;
opacity: 0.5;
}
}
/* 暂无版本数据 */
.no-version-data {
text-align: center;
color: #999;
padding: 20px 0;
font-size: 14px;
background-color: #f9fafb;
border-radius: 8px;
margin: 0 12px;
}
/* Git Popover 样式 */
:deep(.git-popover-overlay) {
.ant-popover-inner {
padding: 16px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
width: 360px;
}
.ant-popover-arrow-content {
background-color: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
}
.git-popover-content {
width: 100%;
box-sizing: border-box;
}
.git-repo-item {
margin-bottom: 12px;
&:last-child {
margin-bottom: 0;
}
}
.git-repo-name {
display: flex;
align-items: center;
font-size: 14px;
font-weight: 500;
margin-bottom: 6px;
}
.git-repo-tag {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-right: 6px;
}
.git-repo-url-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background-color: #f9fafb;
border-radius: 4px;
font-size: 13px;
}
.git-repo-url {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-decoration: none;
&:hover {
text-decoration: underline;
opacity: 0.8;
}
}
.git-copy-btn {
width: 24px;
height: 24px;
border: none;
border-radius: 4px;
background-color: transparent;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
margin-left: 8px;
flex-shrink: 0;
&:hover {
background-color: rgba(0, 0, 0, 0.05);
}
&:disabled {
cursor: not-allowed;
opacity: 0.5;
}
}
/* 根容器样式 */
.header-actions-root {
display: flex;
align-items: center;
gap: 8px; // 按钮之间间距,可根据需要调整
gap: 8px;
}
</style>