add python code
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
class="tool-btn run-btn"
|
||||
@click="runCode"
|
||||
:disabled="running"
|
||||
:title="running ? '正在编译运行...' : '编译并运行 C 代码'"
|
||||
:title="running ? '正在运行...' : `运行${language === 'python' ? ' Python' : ' C'}代码`"
|
||||
>
|
||||
{{ running ? '⏳' : '▶' }} 运行
|
||||
</button>
|
||||
@@ -66,13 +66,14 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { loadCodeFile, highlightC } from '../utils/codeUtils.js'
|
||||
import { loadCodeFile, highlightC, highlightPython } from '../utils/codeUtils.js'
|
||||
|
||||
const props = defineProps({
|
||||
filePath: String,
|
||||
fileName: String,
|
||||
fileLabel: String,
|
||||
description: String
|
||||
description: String,
|
||||
language: { type: String, default: 'c' } // 'c' | 'python'
|
||||
})
|
||||
|
||||
const codeContent = ref('')
|
||||
@@ -90,6 +91,7 @@ const FONT_STEP = 2
|
||||
|
||||
const highlightedCode = computed(() => {
|
||||
if (!codeContent.value) return ''
|
||||
if (props.language === 'python') return highlightPython(codeContent.value)
|
||||
return highlightC(codeContent.value)
|
||||
})
|
||||
|
||||
@@ -166,8 +168,10 @@ async function runCode() {
|
||||
runOutput.value = null
|
||||
outputCollapsed.value = false
|
||||
|
||||
const apiEndpoint = props.language === 'python' ? '/api/run-py' : '/api/run-c'
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/run-c', {
|
||||
const res = await fetch(apiEndpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code: codeContent.value })
|
||||
|
||||
Reference in New Issue
Block a user