fix(editor): 语法检查按钮接真——原为原型期假实现(sleep 600ms恒报通过,用户删中括号仍提示成功);后端POST /strategy/file/{name}/check(compile()不落盘,SyntaxError返行号+消息,与保存的py_compile门禁同源);前端调真接口,错误显示「第N行:消息」红tag+toast,编辑即清;3新后端测试(删括号必报错) [vps]
This commit is contained in:
@@ -23,6 +23,7 @@ const dirty = ref(false)
|
||||
const saving = ref(false)
|
||||
const checking = ref(false)
|
||||
const syntaxOk = ref<boolean | null>(null)
|
||||
const syntaxError = ref<string | null>(null)
|
||||
|
||||
const active = computed(() => files.value.find((f) => f.name === activeName.value))
|
||||
|
||||
@@ -60,6 +61,7 @@ async function select(f: StrategyFile): Promise<void> {
|
||||
activeName.value = f.name
|
||||
dirty.value = false
|
||||
syntaxOk.value = null
|
||||
syntaxError.value = null
|
||||
loadingCode.value = true
|
||||
try {
|
||||
const { data } = await apiClient.get<{ code: string }>(`/strategy/file/${f.name}`)
|
||||
@@ -78,14 +80,29 @@ watch(code, () => {
|
||||
if (echoGrace) return
|
||||
dirty.value = true
|
||||
syntaxOk.value = null
|
||||
syntaxError.value = null
|
||||
})
|
||||
|
||||
async function onCheck(): Promise<void> {
|
||||
if (!active.value) return
|
||||
checking.value = true
|
||||
await new Promise((r) => setTimeout(r, 600)) // 模拟 py_compile
|
||||
syntaxOk.value = true
|
||||
checking.value = false
|
||||
ElMessage.success('语法检查通过')
|
||||
syntaxError.value = null
|
||||
try {
|
||||
const { data } = await apiClient.post<{ ok: boolean; error?: string; line?: number | null }>(
|
||||
`/strategy/file/${activeName.value}/check`, { code: code.value })
|
||||
if (data.ok) {
|
||||
syntaxOk.value = true
|
||||
ElMessage.success('语法检查通过')
|
||||
} else {
|
||||
syntaxOk.value = false
|
||||
syntaxError.value = data.line != null ? `第 ${data.line} 行:${data.error ?? '语法错误'}` : (data.error ?? '语法错误')
|
||||
ElMessage.error(syntaxError.value)
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '语法检查请求失败')
|
||||
} finally {
|
||||
checking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onSave(): Promise<void> {
|
||||
@@ -162,6 +179,7 @@ function runBacktest(): void {
|
||||
<span class="path mono">{{ active?.dir }}{{ activeName }}</span>
|
||||
<span v-if="dirty" class="tag tag-dirty">未保存</span>
|
||||
<span v-if="syntaxOk" class="tag tag-ok mono">✓ 语法正确</span>
|
||||
<span v-else-if="syntaxError" class="tag tag-err mono" :title="syntaxError">✗ {{ syntaxError }}</span>
|
||||
</div>
|
||||
<div class="bar-right">
|
||||
<span class="modified mono">{{ active?.modified }}</span>
|
||||
@@ -298,6 +316,7 @@ function runBacktest(): void {
|
||||
font-family: var(--mono);
|
||||
}
|
||||
.tag-dirty { color: var(--lamp-warn); background: var(--amber-soft); border: 1px solid rgba(255, 176, 0, 0.3); }
|
||||
.tag-err { color: var(--lamp-err, #ff5470); background: rgba(255, 84, 112, 0.1); border: 1px solid rgba(255, 84, 112, 0.3); max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tag-ok { color: var(--lamp-ok); background: rgba(46, 230, 138, 0.1); border: 1px solid rgba(46, 230, 138, 0.3); }
|
||||
|
||||
.monaco-wrap {
|
||||
|
||||
Reference in New Issue
Block a user