add python

This commit is contained in:
2026-06-16 13:18:49 +08:00
parent ea1ba5c933
commit 4a37c27938
2 changed files with 54 additions and 5 deletions
+25 -4
View File
@@ -85,7 +85,12 @@
>C</button>
<button
class="lang-tab"
:class="{ active: language === 'python' }"
:class="{
active: language === 'python',
disabled: !hasPythonVersion
}"
:disabled="!hasPythonVersion"
:title="hasPythonVersion ? '切换到 Python 版本' : '该文件暂无 Python 版本'"
@click="switchLanguage('python')"
>Python</button>
</div>
@@ -129,11 +134,16 @@ const chapterId = computed(() => props.id || route.params.id)
const currentFile = ref(null)
const language = ref('c')
// 判断当前文件是否有 Python 版本
const hasPythonVersion = computed(() => {
return currentFile.value && !!currentFile.value.pyPath
})
// 根据语言生成文件路径
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.pyPath
}
return currentFile.value.path
})
@@ -143,11 +153,17 @@ const currentFileName = computed(() => {
if (language.value === 'python') {
return currentFile.value.pyPath
? currentFile.value.pyPath.split('/').pop()
: currentFile.value.name.replace(/\.c$/, '.py')
: currentFile.value.name
}
return currentFile.value.name
})
// 切换语言时,如果目标语言没有对应文件则保持当前语言
function switchLanguage(lang) {
if (lang === 'python' && !hasPythonVersion.value) return
language.value = lang
}
function switchLanguage(lang) {
language.value = lang
}
@@ -458,7 +474,7 @@ function getFolderDescription(folderName) {
font-family: var(--mono);
}
.lang-tab:hover {
.lang-tab:hover:not(:disabled) {
color: var(--text-primary);
}
@@ -468,6 +484,11 @@ function getFolderDescription(folderName) {
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.lang-tab.disabled {
opacity: 0.4;
cursor: not-allowed;
}
.drawer-close-btn {
background: none;
border: none;