feat: enhance demo components with consistent styling and info boxes

- Add standardized header and info box components to all demo files
- Improve visual consistency with theme colors and spacing
- Add max-height and overflow-y for better content containment
- Update package.json build script with --force flag
- Add .gitignore entries for REFACTORING files
- Fix table formatting in audio-intro.md
This commit is contained in:
sanbuphy
2026-02-14 12:14:07 +08:00
parent cd2ce9e661
commit ebe2bf6109
70 changed files with 12307 additions and 10445 deletions
@@ -1,141 +1,140 @@
<!--
SliceRequestDemo.vue - 搬家快递大作战
"搬家打包"的比喻来解释 HTTP 请求优化切图 vs 雪碧图
SliceRequestDemo.vue - HTTP请求优化对比
"搬家"的比喻来解释雪碧图 vs 切片请求
-->
<template>
<div class="moving-game">
<!-- 故事引入 -->
<div class="story-box">
<div class="story-emoji">📦🚚🏠</div>
<h4 class="story-title">小明搬家记</h4>
<p class="story-text">
小明要搬 6 箱书到新房子有两种搬家方式<br>
<strong>A 方案一箱一箱搬</strong>切图模式 vs <strong>B 方案一次性打包运走</strong>雪碧图模式<br>
看看哪种更省时间
</p>
<div class="slice-request-demo">
<!-- 标题区 -->
<div class="demo-header">
<span class="icon">📦</span>
<span class="title">HTTP请求优化</span>
<span class="subtitle">雪碧图 vs 独立请求</span>
</div>
<!-- 模式选择 -->
<div class="mode-selector">
<div
class="mode-card"
:class="{ active: mode === 'separate' }"
@click="mode = 'separate'"
>
<div class="mode-icon">🛵</div>
<div class="mode-name">A 方案一箱一趟</div>
<div class="mode-desc">小面包车一次拉一箱</div>
<div class="mode-detail">需要 6 趟运输</div>
<!-- 主内容区 -->
<div class="demo-content">
<!-- 故事引入 -->
<div class="story-box">
<p class="story-text">
<strong>通俗说法</strong>就像搬家<br>
<strong>切图模式</strong>一箱一箱搬需要6趟6次HTTP请求<br>
<strong>雪碧图模式</strong>打包一次性运走只需1趟1次HTTP请求
</p>
</div>
<div class="vs-divider">VS</div>
<div
class="mode-card"
:class="{ active: mode === 'packed' }"
@click="mode = 'packed'"
>
<div class="mode-icon">🚚</div>
<div class="mode-name">B 方案打包一车拉</div>
<div class="mode-desc">大卡车6箱一次运走</div>
<div class="mode-detail">只需 1 趟运输</div>
</div>
</div>
<!-- 动画演示区 -->
<div class="animation-area">
<!-- 起点 -->
<div class="location start">
<div class="location-icon">🏠</div>
<div class="location-label">旧家</div>
<div class="boxes-remaining">
剩余箱子: <span class="count">{{ remainingBoxes }}</span>
</div>
</div>
<!-- 道路 -->
<div class="road">
<div class="road-line"></div>
<!-- 运输车辆 -->
<!-- 模式选择 -->
<div class="mode-selector">
<div
v-for="vehicle in vehicles"
:key="vehicle.id"
class="vehicle"
:class="{ 'moving': vehicle.isMoving }"
:style="{ left: vehicle.position + '%' }"
class="mode-card"
:class="{ active: mode === 'separate' }"
@click="mode = 'separate'"
>
<div class="vehicle-body">
{{ mode === 'separate' ? '🛵' : '🚚' }}
<div class="mode-icon">🛵</div>
<div class="mode-name">切图模式</div>
<div class="mode-desc">通俗说法: 一箱一趟</div>
<div class="mode-detail">需要 6 趟运输</div>
</div>
<div class="vs-divider">VS</div>
<div
class="mode-card"
:class="{ active: mode === 'packed' }"
@click="mode = 'packed'"
>
<div class="mode-icon">🚚</div>
<div class="mode-name">雪碧图模式</div>
<div class="mode-desc">通俗说法: 打包一车拉</div>
<div class="mode-detail">只需 1 趟运输</div>
</div>
</div>
<!-- 动画演示区 -->
<div class="animation-area">
<!-- 起点 -->
<div class="location start">
<div class="location-icon">🏠</div>
<div class="location-label">旧家</div>
<div class="boxes-remaining">
剩余箱子: <span class="count">{{ remainingBoxes }}</span>
</div>
<div class="vehicle-cargo" v-if="vehicle.cargo > 0">
{{ mode === 'separate' ? '📦' : '📦×' + vehicle.cargo }}
</div>
<!-- 道路 -->
<div class="road">
<div class="road-line"></div>
<!-- 运输车辆 -->
<div
v-for="vehicle in vehicles"
:key="vehicle.id"
class="vehicle"
:class="{ 'moving': vehicle.isMoving }"
:style="{ left: vehicle.position + '%' }"
>
<div class="vehicle-body">
{{ mode === 'separate' ? '🛵' : '🚚' }}
</div>
<div class="vehicle-cargo" v-if="vehicle.cargo > 0">
{{ mode === 'separate' ? '📦' : '📦×' + vehicle.cargo }}
</div>
</div>
</div>
<!-- 终点 -->
<div class="location end">
<div class="location-icon">🏡</div>
<div class="location-label">新家</div>
<div class="boxes-delivered">
已送达: <span class="count">{{ deliveredBoxes }}</span>/6
</div>
</div>
</div>
<!-- 终点 -->
<div class="location end">
<div class="location-icon">🏡</div>
<div class="location-label">新家</div>
<div class="boxes-delivered">
已送达: <span class="count">{{ deliveredBoxes }}</span>/6
<!-- 统计面板 -->
<div class="stats-panel">
<div class="stat-item">
<div class="stat-label">运输趟数</div>
<div class="stat-value" :class="{ 'good': trips <= 2, 'bad': trips > 2 }">
{{ trips }}
</div>
</div>
<div class="stat-item">
<div class="stat-label">总耗时</div>
<div class="stat-value">{{ totalTime.toFixed(1) }} </div>
</div>
<div class="stat-item">
<div class="stat-label">效率评分</div>
<div class="stat-value" :class="efficiencyClass">
{{ efficiency }}
</div>
</div>
</div>
<!-- 控制按钮 -->
<div class="controls">
<button
class="btn btn-primary"
@click="startSimulation"
:disabled="isRunning"
>
{{ isRunning ? '运输中...' : '开始搬家' }}
</button>
<button
class="btn btn-secondary"
@click="resetSimulation"
>
重置
</button>
</div>
</div>
<!-- 统计面板 -->
<div class="stats-panel">
<div class="stat-item">
<div class="stat-label">运输趟数</div>
<div class="stat-value" :class="{ 'good': trips <= 2, 'bad': trips > 2 }">
{{ trips }}
</div>
</div>
<div class="stat-item">
<div class="stat-label">总耗时</div>
<div class="stat-value">{{ totalTime.toFixed(1) }} </div>
</div>
<div class="stat-item">
<div class="stat-label">效率评分</div>
<div class="stat-value" :class="efficiencyClass">
{{ efficiency }}
</div>
</div>
</div>
<!-- 控制按钮 -->
<div class="controls">
<button
class="btn btn-primary"
@click="startSimulation"
:disabled="isRunning"
>
{{ isRunning ? '运输中...' : '开始搬家' }}
</button>
<button
class="btn btn-secondary"
@click="resetSimulation"
>
重置
</button>
</div>
<!-- 知识点总结 -->
<div class="knowledge-box">
<div class="knowledge-title">💡 核心原理</div>
<div class="knowledge-content">
<p v-if="mode === 'separate'">
<strong>切图模式分开请求</strong>就像一箱一箱搬每次只拉一件货
浏览器要发起 6 HTTP 请求每次都要建立连接传输数据
<span class="highlight-bad">效率低耗时长</span>
</p>
<p v-else>
<strong>雪碧图模式合并请求</strong>就像用大卡车一次性拉走所有箱子
浏览器只需 1 HTTP 请求就能获取所有图片
<span class="highlight-good">大幅减少连接开销速度更快</span>
</p>
</div>
<!-- 信息框 -->
<div class="info-box">
<span class="icon">💡</span>
<strong>核心思想:</strong>
<span v-if="mode === 'separate'">切图模式每次只拉一件货,需要6次HTTP请求,效率低</span>
<span v-else>雪碧图模式打包一次性运走,只需1次HTTP请求,大幅减少连接开销</span>
</div>
</div>
</template>
@@ -254,40 +253,56 @@ const resetStats = () => {
</script>
<style scoped>
.moving-game {
border: 2px solid #e8e8e8;
border-radius: 16px;
background: linear-gradient(135deg, #fafbfc 0%, #f0f4f8 100%);
padding: 24px;
margin: 20px 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
.slice-request-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
background: var(--vp-c-bg-soft);
padding: 1rem;
margin: 1rem 0;
max-height: 600px;
overflow-y: auto;
}
/* 标题区 */
.demo-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.demo-header .icon {
font-size: 1.25rem;
}
.demo-header .title {
font-weight: bold;
font-size: 1rem;
}
.demo-header .subtitle {
color: var(--vp-c-text-2);
font-size: 0.85rem;
margin-left: 0.5rem;
}
/* 主内容区 */
.demo-content {
margin-bottom: 0.75rem;
}
/* 故事框 */
.story-box {
text-align: center;
margin-bottom: 24px;
padding: 20px;
background: linear-gradient(135deg, #fff8e1, #ffecb3);
border-radius: 16px;
border: 2px dashed #ffc107;
}
.story-emoji {
font-size: 48px;
margin-bottom: 8px;
}
.story-title {
font-size: 20px;
font-weight: bold;
color: #8b4513;
margin: 0 0 8px 0;
margin-bottom: 1rem;
padding: 0.75rem;
background: var(--vp-c-bg-alt);
border-radius: 6px;
}
.story-text {
font-size: 14px;
color: #666;
font-size: 0.85rem;
color: var(--vp-c-text-2);
margin: 0;
line-height: 1.6;
}
@@ -297,67 +312,67 @@ const resetStats = () => {
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
margin-bottom: 24px;
gap: 0.75rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.mode-card {
background: white;
border: 3px solid #e0e0e0;
border-radius: 16px;
padding: 20px;
background: var(--vp-c-bg);
border: 2px solid var(--vp-c-divider);
border-radius: 8px;
padding: 1rem;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
min-width: 200px;
transition: all 0.2s;
min-width: 160px;
flex: 1;
max-width: 280px;
max-width: 220px;
}
.mode-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.mode-card.active {
border-color: #4caf50;
background: #e8f5e9;
border-color: var(--vp-c-brand);
background: var(--vp-c-brand-soft);
}
.mode-icon {
font-size: 48px;
margin-bottom: 12px;
font-size: 2rem;
margin-bottom: 0.5rem;
}
.mode-name {
font-size: 16px;
font-size: 0.9rem;
font-weight: bold;
color: #333;
margin-bottom: 8px;
color: var(--vp-c-text-1);
margin-bottom: 0.5rem;
}
.mode-desc {
font-size: 13px;
color: #666;
margin-bottom: 8px;
font-size: 0.75rem;
color: var(--vp-c-text-2);
margin-bottom: 0.5rem;
}
.mode-detail {
font-size: 14px;
font-size: 0.85rem;
font-weight: bold;
color: #e65100;
padding: 4px 12px;
background: #fff3e0;
color: var(--vp-c-brand);
padding: 0.25rem 0.75rem;
background: var(--vp-c-bg-alt);
border-radius: 12px;
display: inline-block;
}
.vs-divider {
font-size: 24px;
font-size: 1.25rem;
font-weight: bold;
color: #999;
padding: 0 8px;
color: var(--vp-c-text-3);
padding: 0 0.5rem;
}
/* 动画演示区 */
@@ -365,52 +380,52 @@ const resetStats = () => {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 20px;
padding: 20px;
background: white;
border-radius: 16px;
border: 2px solid #e0e0e0;
gap: 1rem;
margin-bottom: 1rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 8px;
border: 2px solid var(--vp-c-divider);
}
.location {
text-align: center;
min-width: 100px;
min-width: 80px;
}
.location-icon {
font-size: 40px;
margin-bottom: 8px;
font-size: 2rem;
margin-bottom: 0.5rem;
}
.location-label {
font-size: 14px;
font-size: 0.85rem;
font-weight: bold;
color: #333;
margin-bottom: 8px;
color: var(--vp-c-text-1);
margin-bottom: 0.5rem;
}
.boxes-remaining,
.boxes-delivered {
font-size: 12px;
color: #666;
padding: 4px 8px;
background: #f5f5f5;
border-radius: 8px;
font-size: 0.75rem;
color: var(--vp-c-text-2);
padding: 0.25rem 0.5rem;
background: var(--vp-c-bg-alt);
border-radius: 6px;
}
.count {
font-weight: bold;
color: #e65100;
font-size: 16px;
color: var(--vp-c-brand);
font-size: 0.9rem;
}
.road {
flex: 1;
position: relative;
height: 80px;
background: linear-gradient(to bottom, #e8eaf6 0%, #c5cae9 100%);
border-radius: 8px;
height: 60px;
background: var(--vp-c-bg-alt);
border-radius: 6px;
overflow: hidden;
}
@@ -422,8 +437,8 @@ const resetStats = () => {
height: 4px;
background: repeating-linear-gradient(
90deg,
#7986cb 0px,
#7986cb 20px,
var(--vp-c-brand) 0px,
var(--vp-c-brand) 20px,
transparent 20px,
transparent 40px
);
@@ -441,89 +456,86 @@ const resetStats = () => {
}
.vehicle-body {
font-size: 32px;
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
font-size: 1.5rem;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
.vehicle-cargo {
font-size: 12px;
background: white;
padding: 2px 6px;
border-radius: 8px;
margin-top: 2px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
font-size: 0.75rem;
background: var(--vp-c-bg);
padding: 0.125rem 0.375rem;
border-radius: 6px;
margin-top: 0.125rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
font-weight: bold;
color: #e65100;
color: var(--vp-c-brand);
}
/* 统计面板 */
.stats-panel {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
margin-bottom: 20px;
gap: 1rem;
margin-bottom: 1rem;
}
.stat-item {
background: white;
border-radius: 12px;
padding: 16px;
background: var(--vp-c-bg);
border-radius: 8px;
padding: 1rem;
text-align: center;
border: 2px solid #e0e0e0;
border: 2px solid var(--vp-c-divider);
}
.stat-label {
font-size: 13px;
color: #666;
margin-bottom: 8px;
font-size: 0.75rem;
color: var(--vp-c-text-2);
margin-bottom: 0.5rem;
}
.stat-value {
font-size: 24px;
font-size: 1.25rem;
font-weight: bold;
color: var(--vp-c-text-1);
}
.stat-value.good {
color: #4caf50;
color: var(--vp-c-success);
}
.stat-value.bad {
color: #f44336;
color: var(--vp-c-danger);
}
.stat-value.excellent {
color: #2196f3;
}
.stat-value.good {
color: #4caf50;
color: var(--vp-c-brand);
}
.stat-value.poor {
color: #ff9800;
color: var(--vp-c-warning);
}
/* 控制按钮 */
.controls {
display: flex;
justify-content: center;
gap: 12px;
margin-bottom: 20px;
gap: 0.75rem;
margin-bottom: 1rem;
}
.btn {
padding: 12px 24px;
padding: 0.5rem 1rem;
border: none;
border-radius: 8px;
font-size: 16px;
border-radius: 6px;
font-size: 0.9rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
transition: all 0.2s;
}
.btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.btn:disabled {
@@ -532,48 +544,32 @@ const resetStats = () => {
}
.btn-primary {
background: linear-gradient(135deg, #667eea, #764ba2);
background: var(--vp-c-brand);
color: white;
}
.btn-secondary {
background: #f5f5f5;
color: #666;
background: var(--vp-c-bg-alt);
color: var(--vp-c-text-1);
}
/* 知识点总结 */
.knowledge-box {
background: linear-gradient(135deg, #e3f2fd, #f3e5f5);
border-radius: 12px;
padding: 20px;
border-left: 4px solid #2196f3;
/* 信息框 */
.info-box {
background: var(--vp-c-bg-alt);
padding: 0.75rem;
border-radius: 6px;
font-size: 0.85rem;
color: var(--vp-c-text-2);
display: flex;
gap: 0.25rem;
}
.knowledge-title {
font-size: 16px;
font-weight: bold;
color: #1565c0;
margin-bottom: 12px;
.info-box .icon {
flex-shrink: 0;
}
.knowledge-content {
font-size: 14px;
line-height: 1.6;
color: #333;
}
.knowledge-content p {
margin: 0;
}
.highlight-good {
color: #4caf50;
font-weight: bold;
}
.highlight-bad {
color: #f44336;
font-weight: bold;
.info-box strong {
color: var(--vp-c-text-1);
}
/* 响应式 */
@@ -588,7 +584,7 @@ const resetStats = () => {
.animation-area {
flex-direction: column;
gap: 12px;
gap: 0.75rem;
}
.road {