add python code

This commit is contained in:
2026-06-16 09:35:51 +08:00
parent daecbf4603
commit daf9e50938
17 changed files with 763 additions and 19 deletions
+74 -3
View File
@@ -77,14 +77,28 @@
<div class="drawer-panel">
<div class="drawer-header">
<span class="drawer-title">💻 代码查看</span>
<div class="drawer-lang-tabs">
<button
class="lang-tab"
:class="{ active: language === 'c' }"
@click="switchLanguage('c')"
>C</button>
<button
class="lang-tab"
:class="{ active: language === 'python' }"
@click="switchLanguage('python')"
>Python</button>
</div>
<button class="drawer-close-btn" @click="closeDrawer"></button>
</div>
<div class="drawer-body">
<CodeViewer
:filePath="currentFile.path"
:fileName="currentFile.name"
:key="currentFilePath"
:filePath="currentFilePath"
:fileName="currentFileName"
:fileLabel="currentFile.label"
:description="currentFile.description"
:language="language"
/>
</div>
</div>
@@ -113,6 +127,30 @@ const props = defineProps({
const route = useRoute()
const chapterId = computed(() => props.id || route.params.id)
const currentFile = ref(null)
const language = ref('c')
// 根据语言生成文件路径
const currentFilePath = computed(() => {
if (!currentFile.value) return null
if (language.value === 'python') {
return currentFile.value.pyPath || currentFile.value.path.replace(/^c\//, 'py/').replace(/\.c$/, '.py')
}
return currentFile.value.path
})
const currentFileName = computed(() => {
if (!currentFile.value) return ''
if (language.value === 'python') {
return currentFile.value.pyPath
? currentFile.value.pyPath.split('/').pop()
: currentFile.value.name.replace(/\.c$/, '.py')
}
return currentFile.value.name
})
function switchLanguage(lang) {
language.value = lang
}
const chapter = computed(() => getChapterById(chapterId.value))
@@ -127,6 +165,7 @@ function selectFile(file) {
function closeDrawer() {
currentFile.value = null
language.value = 'c'
}
function getFolderDescription(folderName) {
@@ -383,7 +422,7 @@ function getFolderDescription(folderName) {
.drawer-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
@@ -393,6 +432,38 @@ function getFolderDescription(folderName) {
font-size: 17px;
font-weight: 700;
color: var(--text-primary);
margin-right: auto;
}
.drawer-lang-tabs {
display: flex;
gap: 4px;
background: var(--hover-bg);
padding: 3px;
border-radius: 8px;
}
.lang-tab {
background: none;
border: none;
padding: 6px 16px;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
color: var(--text-secondary);
transition: all 0.15s;
font-family: var(--mono);
}
.lang-tab:hover {
color: var(--text-primary);
}
.lang-tab.active {
background: var(--bg);
color: var(--primary-color);
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.drawer-close-btn {