2026-02-06 03:34:50 +08:00
|
|
|
|
<template>
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="dep-demo">
|
|
|
|
|
|
<div class="header">
|
|
|
|
|
|
<div class="title">依赖方向:分层架构的核心规则</div>
|
|
|
|
|
|
<div class="subtitle">理解依赖方向,才能真正掌握分层架构</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="content-box">
|
|
|
|
|
|
<div class="layers">
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div class="layer outer">
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="layer-label">外层(UI / 外部系统)</div>
|
|
|
|
|
|
<div class="layer-box">Controller</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="dep-arrow">↓ 依赖</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div class="layer middle">
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="layer-label">中层(应用层)</div>
|
|
|
|
|
|
<div class="layer-box">Service</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="dep-arrow">↓ 依赖</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
<div class="layer inner">
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="layer-label">内层(领域层)</div>
|
|
|
|
|
|
<div class="layer-box">Domain / Repository</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="principle-box">
|
2026-03-01 12:28:47 +08:00
|
|
|
|
<div class="p-title">核心原则:依赖倒置(DIP)</div>
|
|
|
|
|
|
<p>上层模块不应该依赖下层模块的具体实现,而应该依赖于抽象。</p>
|
|
|
|
|
|
<div class="rules">
|
|
|
|
|
|
<div v-for="r in rules" :key="r.title" class="rule">
|
|
|
|
|
|
<strong>{{ r.title }}</strong>
|
|
|
|
|
|
<div class="rule-desc">{{ r.desc }}</div>
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-03-01 12:28:47 +08:00
|
|
|
|
const rules = [
|
|
|
|
|
|
{ title: 'Controller → Service 接口', desc: 'Controller 只依赖 Service 的接口,不依赖实现类' },
|
|
|
|
|
|
{ title: 'Service → Repository 接口', desc: 'Service 只依赖 Repository 接口,不关心数据怎么存' },
|
|
|
|
|
|
{ title: '所有层依赖 Domain', desc: 'Domain 是核心,被所有上层依赖,但 Domain 不依赖任何层' }
|
|
|
|
|
|
]
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.dep-demo { padding: 20px; background: var(--vp-c-bg-soft); border-radius: 12px; }
|
|
|
|
|
|
.header { text-align: center; margin-bottom: 20px; }
|
|
|
|
|
|
.title { font-size: 16px; font-weight: 600; color: var(--vp-c-text-1); }
|
|
|
|
|
|
.subtitle { font-size: 13px; color: var(--vp-c-text-3); margin-top: 4px; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.content-box {
|
|
|
|
|
|
padding: 18px; border-radius: 10px;
|
|
|
|
|
|
background: var(--vp-c-bg); border: 1px solid var(--vp-c-divider);
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.layers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
|
|
|
|
|
|
.layer-label { font-size: 11px; color: var(--vp-c-text-3); margin-bottom: 4px; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
.layer-box {
|
2026-03-01 12:28:47 +08:00
|
|
|
|
padding: 14px; border-radius: 6px; text-align: center;
|
|
|
|
|
|
font-weight: 500; color: var(--vp-c-text-1);
|
|
|
|
|
|
background: var(--vp-c-bg-soft); border-left: 3px solid var(--vp-c-divider);
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.layer.outer .layer-box { border-left-color: #10b981; }
|
|
|
|
|
|
.layer.middle .layer-box { border-left-color: #f59e0b; }
|
|
|
|
|
|
.layer.inner .layer-box { border-left-color: #3b82f6; }
|
|
|
|
|
|
.dep-arrow { text-align: center; color: var(--vp-c-text-3); font-size: 12px; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
|
|
|
|
|
.principle-box {
|
2026-03-01 12:28:47 +08:00
|
|
|
|
padding: 16px; border-radius: 8px;
|
|
|
|
|
|
background: var(--vp-c-brand-soft); border-left: 3px solid var(--vp-c-brand-1);
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.p-title { font-size: 14px; font-weight: 600; color: var(--vp-c-text-1); margin-bottom: 8px; }
|
|
|
|
|
|
.principle-box p { margin: 0 0 12px; font-size: 13px; color: var(--vp-c-text-2); line-height: 1.6; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.rules { display: flex; flex-direction: column; gap: 8px; }
|
|
|
|
|
|
.rule {
|
|
|
|
|
|
padding: 10px; border-radius: 6px;
|
|
|
|
|
|
background: var(--vp-c-bg); font-size: 13px; color: var(--vp-c-text-1);
|
2026-02-06 03:34:50 +08:00
|
|
|
|
}
|
2026-03-01 12:28:47 +08:00
|
|
|
|
.rule-desc { font-size: 12px; color: var(--vp-c-text-3); margin-top: 2px; }
|
2026-02-06 03:34:50 +08:00
|
|
|
|
</style>
|