add drawer effect
This commit is contained in:
+89
-25
@@ -70,23 +70,27 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 代码查看区域 -->
|
||||
<section v-if="currentFile" class="code-section">
|
||||
<h2 class="section-label code-section-label">💻 代码查看</h2>
|
||||
<!-- 代码查看 Drawer -->
|
||||
<Teleport to="body">
|
||||
<Transition name="drawer">
|
||||
<div v-if="currentFile" class="drawer-overlay" @click.self="closeDrawer">
|
||||
<div class="drawer-panel">
|
||||
<div class="drawer-header">
|
||||
<span class="drawer-title">💻 代码查看</span>
|
||||
<button class="drawer-close-btn" @click="closeDrawer">✕</button>
|
||||
</div>
|
||||
<div class="drawer-body">
|
||||
<CodeViewer
|
||||
:filePath="currentFile.path"
|
||||
:fileName="currentFile.name"
|
||||
:fileLabel="currentFile.label"
|
||||
:description="currentFile.description"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section v-else class="empty-section">
|
||||
<div class="empty-state">
|
||||
<span class="empty-icon">👆</span>
|
||||
<p>请从上方选择一个代码文件查看其源码</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</div>
|
||||
|
||||
<div v-else class="not-found">
|
||||
@@ -121,6 +125,10 @@ function selectFile(file) {
|
||||
currentFile.value = file
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
currentFile.value = null
|
||||
}
|
||||
|
||||
function getFolderDescription(folderName) {
|
||||
const descriptions = {
|
||||
mergesort: '归并排序是分治法的经典应用:将数组一分为二,分别排序后合并。时间复杂度 O(n log n)。',
|
||||
@@ -353,31 +361,87 @@ function getFolderDescription(folderName) {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.code-section {
|
||||
margin: 32px 0;
|
||||
/* ========== Drawer ========== */
|
||||
.drawer-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.code-section-label {
|
||||
margin-bottom: 16px;
|
||||
.drawer-panel {
|
||||
width: min(720px, 90vw);
|
||||
height: 100%;
|
||||
background: var(--bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.empty-section {
|
||||
padding: 60px 0;
|
||||
text-align: center;
|
||||
.drawer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
color: var(--text-tertiary);
|
||||
.drawer-title {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 40px;
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
.drawer-close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
font-size: 15px;
|
||||
.drawer-close-btn:hover {
|
||||
background: var(--hover-bg);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.drawer-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.drawer-body .code-viewer {
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
/* 抽屉过渡动画 */
|
||||
.drawer-enter-active,
|
||||
.drawer-leave-active {
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
.drawer-enter-active .drawer-panel,
|
||||
.drawer-leave-active .drawer-panel {
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.drawer-enter-from,
|
||||
.drawer-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.drawer-enter-from .drawer-panel,
|
||||
.drawer-leave-to .drawer-panel {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
|
||||
.not-found {
|
||||
|
||||
Reference in New Issue
Block a user