@@ -103,60 +103,6 @@ interface CodeOutputEvent
103103 language: string
104104}
105105
106- // 代码模板
107- const codeTemplates: Record <string , string > = {
108- python: ` # Welcome to CodeForge!
109- # Write your Python code here and click Run to execute
110-
111- print("Hello, CodeForge!")
112-
113- # Example: Simple calculation
114- x = 10
115- y = 20
116- result = x + y
117- print(f"The result of {x} + {y} = {result}")
118-
119- # Example: List operations
120- numbers = [1, 2, 3, 4, 5]
121- squared = [n**2 for n in numbers]
122- print(f"Original: {numbers}")
123- print(f"Squared: {squared}") ` ,
124-
125- python2: ` # Welcome to CodeForge - Python 2!
126- # Write your Python 2 code here and click Run to execute
127-
128- print "Hello, CodeForge from Python 2!"
129-
130- # Example: Simple calculation
131- x = 10
132- y = 20
133- result = x + y
134- print "The result of %d + %d = %d" % (x, y, result)
135-
136- # Example: List operations
137- numbers = [1, 2, 3, 4, 5]
138- squared = [n**2 for n in numbers]
139- print "Original:", numbers
140- print "Squared:", squared ` ,
141-
142- python3: ` # Welcome to CodeForge - Python 3!
143- # Write your Python 3 code here and click Run to execute
144-
145- print("Hello, CodeForge from Python 3!")
146-
147- # Example: Simple calculation
148- x = 10
149- y = 20
150- result = x + y
151- print(f"The result of {x} + {y} = {result}")
152-
153- # Example: List operations
154- numbers = [1, 2, 3, 4, 5]
155- squared = [n**2 for n in numbers]
156- print(f"Original: {numbers}")
157- print(f"Squared: {squared}") `
158- }
159-
160106const toast = useToast ()
161107const code = ref (' ' )
162108const currentLanguage = ref (' python2' )
@@ -168,6 +114,7 @@ const activeTab = ref('output')
168114const supportedLanguages = ref <Language []>([])
169115const showAbout = ref (false )
170116const showSettings = ref (false )
117+ const globalConfig = ref (null as any )
171118
172119// 实时输出相关
173120const realTimeOutput = ref (' ' )
@@ -250,8 +197,7 @@ const handleLanguageChange = async (newLanguage: string) => {
250197 currentLanguage .value = newLanguage
251198
252199 // 更新代码模板
253- code .value = codeTemplates [newLanguage ] || ` # ${ getLanguageDisplayName (newLanguage ) } Code
254- # Write your code here... `
200+ code .value = filterPluginTemplate (newLanguage )
255201
256202 // 清空输出
257203 clearOutput ()
@@ -413,20 +359,41 @@ const handleExecutionError = (event: any) => {
413359 }
414360}
415361
362+ const getConfigure = async () => {
363+ try {
364+ globalConfig .value = await invoke <any >(' get_app_config' )
365+ }
366+ catch (error ) {
367+ toast .error (' 获取配置失败 - 错误信息: ' + error )
368+ }
369+ }
370+
371+ const filterPluginTemplate = (plugin : any ) => {
372+ if (globalConfig .value && globalConfig .value .plugins ) {
373+ return globalConfig .value .plugins .find ((p : any ) => p .language === plugin ).template
374+ }
375+
376+ return null
377+ }
378+
416379// 禁用右键菜单
417380window .addEventListener (' contextmenu' , (e ) => e .preventDefault (), false )
418381
419382onMounted (async () => {
420383 await getSupportedLanguages ()
421384 await refreshEnvInfo ()
385+ await getConfigure ()
422386
423387 // 设置初始代码模板
424388 if (supportedLanguages .value .length > 0 ) {
425389 currentLanguage .value = supportedLanguages .value [0 ].value
426- code .value = codeTemplates [currentLanguage .value ] || codeTemplates .python
390+ console .log (' 当前语言:' , currentLanguage .value )
391+ const template = filterPluginTemplate (currentLanguage .value )
392+ console .log (' 使用的模板:' , template )
393+ code .value = template
427394 }
428395 else {
429- code .value = codeTemplates . python
396+ code .value = ' No supported languages found '
430397 }
431398
432399 // 监听来自 Rust 的各种事件
0 commit comments