Skip to content

Commit eb289dd

Browse files
committed
Update HelloWorld.vue
优化页面动画效果; 存在左侧工具栏提示信息不见了
1 parent 9426196 commit eb289dd

File tree

1 file changed

+147
-48
lines changed

1 file changed

+147
-48
lines changed

src/components/HelloWorld.vue

Lines changed: 147 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="visionos-container">
33
<!-- 左侧工具栏 -->
44
<div class="sidebar">
5+
<div class="active-bg-indicator" :style="activeIndicatorStyle"></div>
56
<div class="menu-button"
67
v-for="(menu, index) in menus"
78
:key="index"
@@ -10,60 +11,63 @@
1011
<div class="menu-icon">
1112
<i :class="menu.icon"></i>
1213
</div>
13-
<div class="tooltip">{{ menu.label }}</div>
14+
<span class="tooltip">{{ menu.label }}</span>
1415
</div>
1516
</div>
1617

1718
<!-- 主体内容区域 -->
1819
<div class="content">
19-
<!-- 主页内容 -->
20-
<div v-if="activeMenu === 'home'" class="content-wrapper">
21-
<div class="home-page">
22-
<h1>欢迎使用 Coder Tools Platform</h1>
23-
<p class="subtitle">专为开发者打造的高效工具集</p>
24-
25-
<div class="cards-container">
26-
<div class="tool-card" v-for="(menu, index) in menus.filter(m => m.id !== 'home')" :key="index" @click="switchMenu(menu.id)">
27-
<div class="card-icon">
28-
<i :class="menu.icon"></i>
29-
</div>
30-
<div class="card-content">
31-
<h3>{{ menu.label }}</h3>
32-
<p>{{ menu.description }}</p>
20+
<!-- 使用Vue的过渡组件包装内容 -->
21+
<transition name="fade-transform" mode="out-in">
22+
<!-- 主页内容 -->
23+
<div v-if="activeMenu === 'home'" class="content-wrapper" key="home">
24+
<div class="home-page">
25+
<h1>欢迎使用 Coder Tools Platform</h1>
26+
<p class="subtitle">专为开发者打造的高效工具集</p>
27+
28+
<div class="cards-container">
29+
<div class="tool-card" v-for="(menu, index) in menus.filter(m => m.id !== 'home')" :key="index" @click="switchMenu(menu.id)">
30+
<div class="card-icon">
31+
<i :class="menu.icon"></i>
32+
</div>
33+
<div class="card-content">
34+
<h3>{{ menu.label }}</h3>
35+
<p>{{ menu.description }}</p>
36+
</div>
3337
</div>
3438
</div>
3539
</div>
3640
</div>
37-
</div>
38-
39-
<!-- JSON工具内容 -->
40-
<div v-else-if="activeMenu === 'json'" class="content-wrapper">
41-
<div class="feature-page json-feature-page">
42-
<div class="feature-header">
43-
<h2>JSON 工具</h2>
44-
<p>JSON格式化、验证、压缩和转换工具</p>
41+
42+
<!-- JSON工具内容 -->
43+
<div v-else-if="activeMenu === 'json'" class="content-wrapper" key="json">
44+
<div class="feature-page json-feature-page">
45+
<div class="feature-header">
46+
<h2>JSON 工具</h2>
47+
<p>JSON格式化、验证、压缩和转换工具</p>
48+
</div>
49+
<JsonTool />
4550
</div>
46-
<JsonTool />
4751
</div>
48-
</div>
49-
50-
<!-- 时间戳工具内容 -->
51-
<div v-else-if="activeMenu === 'timestamp'" class="content-wrapper">
52-
<div class="feature-page">
53-
<h2>时间戳转换工具</h2>
54-
<p>在不同时间格式之间快速转换</p>
55-
<!-- 时间戳工具具体实现 -->
52+
53+
<!-- 时间戳工具内容 -->
54+
<div v-else-if="activeMenu === 'timestamp'" class="content-wrapper" key="timestamp">
55+
<div class="feature-page">
56+
<h2>时间戳转换工具</h2>
57+
<p>在不同时间格式之间快速转换</p>
58+
<!-- 时间戳工具具体实现 -->
59+
</div>
5660
</div>
57-
</div>
58-
59-
<!-- Java工具内容 -->
60-
<div v-else-if="activeMenu === 'java'" class="content-wrapper">
61-
<div class="feature-page">
62-
<h2>Java 工具</h2>
63-
<p>Java相关的开发辅助工具</p>
64-
<!-- Java工具具体实现 -->
61+
62+
<!-- Java工具内容 -->
63+
<div v-else-if="activeMenu === 'java'" class="content-wrapper" key="java">
64+
<div class="feature-page">
65+
<h2>Java 工具</h2>
66+
<p>Java相关的开发辅助工具</p>
67+
<!-- Java工具具体实现 -->
68+
</div>
6569
</div>
66-
</div>
70+
</transition>
6771
</div>
6872
</div>
6973
</template>
@@ -82,6 +86,7 @@ export default {
8286
data() {
8387
return {
8488
activeMenu: 'home',
89+
hoverMenu: null,
8590
menus: [
8691
{
8792
id: 'home',
@@ -110,9 +115,31 @@ export default {
110115
]
111116
}
112117
},
118+
computed: {
119+
activeIndicatorStyle() {
120+
const menuIndex = this.menus.findIndex(menu => menu.id === this.activeMenu);
121+
if (menuIndex === -1) return {};
122+
123+
// 计算当前选中按钮的位置 (每个按钮高度 + 间距)
124+
const buttonHeight = 45; // 按钮高度
125+
const gap = 15; // 按钮之间的间距
126+
const offsetY = menuIndex * (buttonHeight + gap); // 不再加上顶部padding
127+
128+
return {
129+
transform: `translateY(${offsetY}px) translateX(-50%)`,
130+
opacity: 1
131+
};
132+
}
133+
},
113134
methods: {
114135
switchMenu(menuId) {
115136
this.activeMenu = menuId;
137+
},
138+
handleMouseEnter(menuId) {
139+
this.hoverMenu = menuId;
140+
},
141+
handleMouseLeave() {
142+
this.hoverMenu = null;
116143
}
117144
}
118145
}
@@ -150,6 +177,35 @@ export default {
150177
transition: all 0.3s ease;
151178
z-index: 100;
152179
border: 1px solid rgba(255, 255, 255, 0.7);
180+
/* 确保容器大小完全由内容决定 */
181+
height: auto;
182+
min-height: fit-content;
183+
max-height: 80vh; /* 限制最大高度为视窗高度的80% */
184+
overflow-y: auto; /* 内容过多时显示滚动条 */
185+
/* 隐藏滚动条但保持功能 */
186+
scrollbar-width: none; /* Firefox */
187+
-ms-overflow-style: none; /* IE/Edge */
188+
}
189+
190+
/* 隐藏Webkit浏览器的滚动条 */
191+
.sidebar::-webkit-scrollbar {
192+
display: none;
193+
}
194+
195+
.active-bg-indicator {
196+
position: absolute;
197+
width: 45px;
198+
height: 45px;
199+
border-radius: 18px;
200+
background: linear-gradient(135deg, rgba(255,76,197,0.9) 0%, rgba(151,47,246,0.9) 100%);
201+
transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
202+
opacity: 0;
203+
/* 修改定位方式,确保水平居中 */
204+
left: 50%;
205+
top: 15px; /* 顶部padding */
206+
transform: translateX(-50%);
207+
z-index: -1;
208+
box-shadow: 0 4px 15px rgba(255,76,197,0.3);
153209
}
154210
155211
.menu-button {
@@ -162,6 +218,7 @@ export default {
162218
border-radius: 18px;
163219
cursor: pointer;
164220
transition: all 0.2s ease;
221+
z-index: 2;
165222
}
166223
167224
.menu-button:hover {
@@ -170,9 +227,10 @@ export default {
170227
}
171228
172229
.menu-button.active {
173-
background: linear-gradient(135deg, rgba(255,76,197,0.9) 0%, rgba(151,47,246,0.9) 100%);
174230
color: white;
175-
box-shadow: 0 4px 15px rgba(255,76,197,0.3);
231+
background-color: transparent;
232+
box-shadow: none;
233+
transform: scale(1.08);
176234
}
177235
178236
.menu-icon {
@@ -182,10 +240,11 @@ export default {
182240
justify-content: center;
183241
}
184242
243+
/* 彻底重写工具提示样式 */
185244
.tooltip {
186245
position: absolute;
187246
left: 60px;
188-
background: rgba(255, 255, 255, 0.9);
247+
background: rgba(255, 255, 255, 0.95);
189248
padding: 5px 10px;
190249
border-radius: 10px;
191250
font-size: 12px;
@@ -194,14 +253,24 @@ export default {
194253
opacity: 0;
195254
visibility: hidden;
196255
transform: translateX(-10px);
197-
transition: all 0.2s ease;
256+
transition: all 0.3s ease;
198257
backdrop-filter: blur(10px);
199258
-webkit-backdrop-filter: blur(10px);
200259
border: 1px solid rgba(255, 255, 255, 0.7);
201260
font-weight: 500;
261+
color: #333;
262+
z-index: 1000;
263+
pointer-events: none;
264+
display: block; /* 确保元素显示为块级元素 */
202265
}
203266
204267
.menu-button:hover .tooltip {
268+
opacity: 1;
269+
visibility: visible;
270+
transform: translateX(0);
271+
}
272+
273+
.menu-button.active:hover .tooltip {
205274
opacity: 1;
206275
visibility: visible;
207276
transform: translateX(0);
@@ -215,6 +284,7 @@ export default {
215284
height: 100%;
216285
width: 100%;
217286
box-sizing: border-box;
287+
position: relative;
218288
}
219289
220290
.content-wrapper {
@@ -224,6 +294,11 @@ export default {
224294
box-sizing: border-box;
225295
display: flex;
226296
justify-content: center;
297+
position: absolute;
298+
top: 0;
299+
left: 0;
300+
right: 0;
301+
bottom: 0;
227302
}
228303
229304
/* 主页样式 */
@@ -281,17 +356,25 @@ export default {
281356
background: rgba(255, 255, 255, 0.9);
282357
}
283358
359+
/* 优化卡片图标样式 */
284360
.card-icon {
285361
font-size: 24px;
286-
width: 50px;
287-
height: 50px;
362+
width: 56px;
363+
height: 56px; /* 增加高度,确保为正方形 */
364+
min-width: 56px; /* 确保最小宽度 */
288365
display: flex;
289366
align-items: center;
290367
justify-content: center;
291368
margin-right: 15px;
292-
border-radius: 15px;
369+
border-radius: 18px; /* 增加圆角使其更加柔和 */
293370
background: rgba(0, 122, 255, 0.1);
294371
color: #007AFF;
372+
transition: all 0.3s ease;
373+
}
374+
375+
.tool-card:hover .card-icon {
376+
background: rgba(0, 122, 255, 0.2); /* 悬停时背景色更深 */
377+
transform: scale(1.05); /* 轻微放大效果 */
295378
}
296379
297380
.card-content h3 {
@@ -360,4 +443,20 @@ export default {
360443
flex: 1;
361444
margin-top: 10px;
362445
}
446+
447+
/* 添加页面过渡效果 */
448+
.fade-transform-enter-active,
449+
.fade-transform-leave-active {
450+
transition: all 0.5s;
451+
}
452+
453+
.fade-transform-enter-from {
454+
opacity: 0;
455+
transform: translateY(20px);
456+
}
457+
458+
.fade-transform-leave-to {
459+
opacity: 0;
460+
transform: translateY(-20px);
461+
}
363462
</style>

0 commit comments

Comments
 (0)