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
@@ -4,9 +4,10 @@
-->
<template>
<div class="coupling-demo">
<div class="header">
<div class="title">系统解耦从紧耦合到松耦合</div>
<div class="subtitle">观察同步调用与异步消息的区别</div>
<div class="demo-header">
<span class="icon">🔗</span>
<span class="title">系统解耦</span>
<span class="subtitle">从紧耦合到松耦合</span>
</div>
<div class="mode-switch">
@@ -26,7 +27,7 @@
</button>
</div>
<div class="demo-container">
<div class="demo-content">
<!-- 紧耦合模式 -->
<div v-if="!useAsync" class="synchronous-mode">
<div class="scenario">
@@ -65,7 +66,7 @@
<div class="problem-list">
<div class="problem-item">
<span class="icon"></span>
<span><strong>依赖性强</strong>通知服务宕机订单创建失败</span>
<span><strong>依赖性强</strong>通知服务宕机,订单创建失败</span>
</div>
<div class="problem-item">
<span class="icon"></span>
@@ -111,7 +112,7 @@
<div class="consumer-box" :class="{ failed: consumerFailed }">
<div class="consumer-name">短信服务</div>
<div class="consumer-status">
{{ consumerFailed ? '离线不影响订单' : '运行中' }}
{{ consumerFailed ? '离线(不影响订单)' : '运行中' }}
</div>
</div>
<div class="consumer-box">
@@ -122,10 +123,6 @@
<div class="consumer-name">积分服务</div>
<div class="consumer-status">运行中</div>
</div>
<div class="consumer-box new">
<div class="consumer-name">数据分析</div>
<div class="consumer-status">新增 </div>
</div>
</div>
</div>
@@ -137,7 +134,7 @@
<div class="benefit-item">
<span class="icon"></span>
<span
><strong>响应快</strong>订单服务只耗时 50ms发送消息</span
><strong>响应快</strong>订单服务只耗时 50ms(发送消息)</span
>
</div>
<div class="benefit-item">
@@ -153,41 +150,9 @@
</div>
</div>
<div class="comparison-summary">
<div class="summary-title">📊 对比总结</div>
<div class="summary-table">
<table>
<thead>
<tr>
<th>维度</th>
<th>紧耦合 (同步)</th>
<th>松耦合 (异步)</th>
</tr>
</thead>
<tbody>
<tr>
<td>服务依赖</td>
<td class="bad">强依赖一个挂全挂</td>
<td class="good">弱依赖独立运行</td>
</tr>
<tr>
<td>响应时间</td>
<td class="bad">1200ms串行执行</td>
<td class="good">50ms只发消息</td>
</tr>
<tr>
<td>扩展性</td>
<td class="bad">修改订单服务代码</td>
<td class="good">增加新消费者即可</td>
</tr>
<tr>
<td>可用性</td>
<td class="bad">90%任一服务故障</td>
<td class="good">99.9%独立故障域</td>
</tr>
</tbody>
</table>
</div>
<div class="info-box">
<span class="icon">💡</span>
<strong>核心思想:</strong>同步调用强依赖响应慢;异步消息解耦响应快易扩展
</div>
</div>
</template>
@@ -203,7 +168,7 @@ const messageInQueue = ref(false)
const syncCalls = ref([
{ id: 1, service: '调用库存服务', active: false, status: '处理中...' },
{ id: 2, service: '调用积分服务', active: false, status: '处理中...' },
{ id: 3, service: '调用通知服务', active: false, status: '失败订单回滚' }
{ id: 3, service: '调用通知服务', active: false, status: '失败!订单回滚' }
])
const testSyncCall = () => {
@@ -232,42 +197,52 @@ const testAsyncCall = () => {
<style scoped>
.coupling-demo {
border: 1px solid var(--vp-c-divider);
border-radius: 8px;
background: var(--vp-c-bg-soft);
border-radius: 12px;
padding: 1.5rem;
margin: 1.5rem 0;
font-family: var(--vp-font-family-base);
padding: 1rem;
margin: 1rem 0;
max-height: 600px;
overflow-y: auto;
}
.header {
margin-bottom: 1rem;
.demo-header {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.title {
font-weight: 700;
font-size: 1.05rem;
.demo-header .icon {
font-size: 1.25rem;
}
.subtitle {
.demo-header .title {
font-weight: bold;
font-size: 1rem;
color: var(--vp-c-text-1);
}
.demo-header .subtitle {
color: var(--vp-c-text-2);
font-size: 0.9rem;
margin-top: 0.25rem;
font-size: 0.85rem;
margin-left: 0.5rem;
}
.mode-switch {
display: flex;
gap: 1rem;
margin-bottom: 1.5rem;
margin-bottom: 1rem;
}
.mode-btn {
flex: 1;
padding: 0.75rem 1rem;
padding: 0.5rem 0.75rem;
border: 2px solid var(--vp-c-divider);
background: var(--vp-c-bg);
border-radius: 8px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
font-size: 0.85rem;
transition: all 0.2s;
}
@@ -277,18 +252,18 @@ const testAsyncCall = () => {
.mode-btn.active {
background: var(--vp-c-brand);
color: #fff;
color: white;
border-color: var(--vp-c-brand);
}
.demo-container {
margin-bottom: 1.5rem;
.demo-content {
margin-bottom: 0.75rem;
}
.scenario-title {
font-weight: 600;
font-size: 1rem;
margin-bottom: 1rem;
font-size: 0.9rem;
margin-bottom: 0.75rem;
text-align: center;
}
@@ -296,55 +271,55 @@ const testAsyncCall = () => {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
padding: 1.5rem;
gap: 0.75rem;
padding: 1rem;
background: var(--vp-c-bg);
border-radius: 10px;
margin-bottom: 1rem;
border-radius: 8px;
margin-bottom: 0.75rem;
}
.service-box {
background: var(--vp-c-bg-soft);
border: 2px solid var(--vp-c-brand);
border-radius: 10px;
padding: 1rem;
border-radius: 8px;
padding: 0.75rem;
text-align: center;
min-width: 180px;
min-width: 140px;
transition: all 0.3s;
}
.service-box.failed {
border-color: #ef4444;
background: rgba(239, 68, 68, 0.1);
border-color: var(--vp-c-danger);
background: var(--vp-c-danger-soft);
}
.service-name {
font-weight: 600;
font-size: 0.95rem;
font-size: 0.85rem;
margin-bottom: 0.25rem;
}
.service-desc {
font-size: 0.8rem;
font-size: 0.75rem;
color: var(--vp-c-text-2);
}
.error-msg {
margin-top: 0.5rem;
padding: 0.35rem 0.5rem;
background: #ef4444;
background: var(--vp-c-danger);
color: white;
border-radius: 4px;
font-size: 0.8rem;
font-size: 0.75rem;
font-weight: 600;
}
.arrows {
display: flex;
flex-direction: column;
gap: 0.75rem;
gap: 0.5rem;
width: 100%;
max-width: 300px;
max-width: 250px;
}
.sync-call {
@@ -357,7 +332,7 @@ const testAsyncCall = () => {
}
.sync-call.active {
background: rgba(239, 68, 68, 0.1);
background: var(--vp-c-danger-soft);
}
.call-line {
@@ -367,96 +342,91 @@ const testAsyncCall = () => {
}
.sync-call.active .call-line {
background: #ef4444;
background: var(--vp-c-danger);
}
.call-label {
font-size: 0.8rem;
font-size: 0.75rem;
color: var(--vp-c-text-2);
flex: 1;
}
.call-status {
font-size: 0.75rem;
color: #ef4444;
font-size: 0.7rem;
color: var(--vp-c-danger);
font-weight: 600;
}
.mq-bridge {
display: flex;
align-items: center;
gap: 1rem;
gap: 0.75rem;
}
.mq-box {
background: rgba(59, 130, 246, 0.1);
background: var(--vp-c-brand-soft);
border: 2px solid var(--vp-c-brand);
border-radius: 10px;
padding: 1rem;
border-radius: 8px;
padding: 0.75rem;
text-align: center;
min-width: 140px;
min-width: 120px;
}
.mq-icon {
font-size: 2rem;
font-size: 1.5rem;
margin-bottom: 0.5rem;
}
.mq-label {
font-weight: 600;
font-size: 0.9rem;
font-size: 0.85rem;
}
.msg-indicator {
margin-top: 0.5rem;
padding: 0.35rem 0.5rem;
background: #dcfce7;
color: #166534;
background: var(--vp-c-success);
color: white;
border-radius: 4px;
font-size: 0.75rem;
font-size: 0.7rem;
font-weight: 600;
}
.flow-arrow {
font-size: 1.5rem;
font-size: 1.25rem;
color: var(--vp-c-brand);
}
.consumers-group {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
gap: 0.75rem;
grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
gap: 0.5rem;
width: 100%;
max-width: 500px;
max-width: 400px;
}
.consumer-box {
background: var(--vp-c-bg-soft);
border: 2px solid var(--vp-c-brand);
border-radius: 8px;
padding: 0.75rem;
border-radius: 6px;
padding: 0.5rem;
text-align: center;
transition: all 0.3s;
}
.consumer-box.failed {
border-color: #f59e0b;
background: rgba(245, 158, 11, 0.1);
}
.consumer-box.new {
border-color: #22c55e;
background: rgba(34, 197, 94, 0.1);
border-color: var(--vp-c-warning);
background: var(--vp-c-warning-soft);
}
.consumer-name {
font-size: 0.8rem;
font-size: 0.75rem;
font-weight: 600;
margin-bottom: 0.25rem;
}
.consumer-status {
font-size: 0.7rem;
font-size: 0.65rem;
color: var(--vp-c-text-2);
}
@@ -464,8 +434,8 @@ const testAsyncCall = () => {
.benefit-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-bottom: 1rem;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.problem-item,
@@ -473,92 +443,66 @@ const testAsyncCall = () => {
display: flex;
align-items: flex-start;
gap: 0.5rem;
padding: 0.75rem;
border-radius: 8px;
font-size: 0.9rem;
line-height: 1.5;
padding: 0.5rem;
border-radius: 6px;
font-size: 0.8rem;
line-height: 1.4;
}
.problem-item {
background: rgba(239, 68, 68, 0.1);
background: var(--vp-c-danger-soft);
}
.benefit-item {
background: rgba(34, 197, 94, 0.1);
background: var(--vp-c-success-soft);
}
.icon {
font-size: 1.2rem;
font-size: 1rem;
flex-shrink: 0;
}
.test-btn {
width: 100%;
padding: 0.75rem;
padding: 0.5rem;
border: none;
border-radius: 8px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
font-size: 0.85rem;
transition: all 0.2s;
}
.test-btn.fail {
background: #ef4444;
background: var(--vp-c-danger);
color: white;
}
.test-btn.fail:hover {
background: #dc2626;
opacity: 0.9;
}
.test-btn.success {
background: #22c55e;
background: var(--vp-c-success);
color: white;
}
.test-btn.success:hover {
background: #16a34a;
opacity: 0.9;
}
.comparison-summary {
background: var(--vp-c-bg);
border-radius: 10px;
padding: 1rem;
border: 1px solid var(--vp-c-divider);
}
.summary-title {
font-weight: 600;
margin-bottom: 0.75rem;
}
.summary-table {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
th,
td {
.info-box {
background: var(--vp-c-bg-alt);
padding: 0.75rem;
text-align: left;
border-bottom: 1px solid var(--vp-c-divider);
border-radius: 6px;
font-size: 0.85rem;
color: var(--vp-c-text-2);
margin-top: 0.75rem;
display: flex;
gap: 0.25rem;
}
th {
background: var(--vp-c-bg-soft);
font-weight: 600;
}
.bad {
color: #ef4444;
}
.good {
color: #16a34a;
.info-box .icon {
flex-shrink: 0;
}
</style>