Skip to content

Commit 207de0b

Browse files
committed
添加支持主题切换的图片显示功能并优化相关样式
1 parent 790b39b commit 207de0b

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed

src/components/show/ShowCards.vue

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,29 @@ const componentCards = computed<ShowCard[]>(() => {
133133

134134
<n-image-group show-toolbar-tooltip show-toolbar>
135135
<n-space size="small" align="center">
136-
<n-image lazy :preview-src="resolveImage(img)" width="200" v-for="img in componentCard.images"
137-
:src="resolveImage(img)"/>
136+
<div v-for="img in componentCard.images" class="theme-image-container" :key="typeof img === 'string' ? img : img.light">
137+
<!-- 如果是字符串图片(无主题变化),直接显示 -->
138+
<n-image v-if="typeof img === 'string'" lazy :preview-src="img" width="200" :src="img"/>
139+
<!-- 如果是主题图片对象,显示带过渡效果的双图片 -->
140+
<div v-else class="theme-image-wrapper">
141+
<n-image
142+
lazy
143+
:preview-src="img.light"
144+
width="200"
145+
:src="img.light"
146+
class="theme-image light-image"
147+
:class="{ 'active': !themeActive }"
148+
/>
149+
<n-image
150+
lazy
151+
:preview-src="img.dark"
152+
width="200"
153+
:src="img.dark"
154+
class="theme-image dark-image"
155+
:class="{ 'active': themeActive }"
156+
/>
157+
</div>
158+
</div>
138159
</n-space>
139160
</n-image-group>
140161

@@ -346,7 +367,7 @@ const componentCards = computed<ShowCard[]>(() => {
346367
347368
:deep(.n-image img) {
348369
border-radius: var(--border-radius-lg);
349-
transition: transform var(--transition-normal);
370+
transition: transform var(--transition-normal), opacity var(--transition-normal);
350371
}
351372
352373
/* ==================== 按钮样式 ==================== */
@@ -594,4 +615,55 @@ const componentCards = computed<ShowCard[]>(() => {
594615
background-position: 200% 0;
595616
}
596617
}
618+
619+
/* ==================== 主题图片过渡效果 ==================== */
620+
621+
/**
622+
* 主题图片容器样式
623+
* 支持主题切换的图片容器
624+
*/
625+
.theme-image-container {
626+
display: inline-block;
627+
position: relative;
628+
}
629+
630+
/**
631+
* 主题图片包装器样式
632+
* 用于叠加显示明暗主题图片
633+
*/
634+
.theme-image-wrapper {
635+
position: relative;
636+
display: inline-block;
637+
width: 200px;
638+
height: auto;
639+
}
640+
641+
/**
642+
* 主题图片样式
643+
* 明暗主题图片的基础样式和过渡效果
644+
*/
645+
:deep(.theme-image) {
646+
position: absolute;
647+
top: 0;
648+
left: 0;
649+
opacity: 0;
650+
transition: opacity 0.6s ease-in-out;
651+
width: 100%;
652+
height: 100%;
653+
}
654+
655+
/**
656+
* 第一个主题图片(用于确定容器尺寸)
657+
*/
658+
:deep(.theme-image:first-child) {
659+
position: relative;
660+
}
661+
662+
/**
663+
* 激活状态的主题图片
664+
* 显示当前主题对应的图片
665+
*/
666+
:deep(.theme-image.active) {
667+
opacity: 1;
668+
}
597669
</style>

src/data/show-cards.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@
9292
],
9393
"description": "<p>法欧莉,占领QQ频道!</p><p>快使用QQ扫描下面的图片把法欧莉添加到你的频道中吧~</p>",
9494
"images": [
95-
{
96-
"light": "img/qq-guild-forliy-qrcode.jpg",
97-
"dark": "img/qq-guild-forliy-qrcode.jpg"
98-
}
95+
"img/qq-guild-forliy-qrcode.jpg"
9996
],
10097
"links": [
10198
[

0 commit comments

Comments
 (0)