update
This commit is contained in:
@@ -51,11 +51,16 @@ const isGenerating = ref(false)
|
||||
const hasAnyScript = computed(() => scripts.value.some((s) => s.sql.trim()))
|
||||
const hasBlankScript = computed(() => scripts.value.some((s) => !s.sql.trim()))
|
||||
|
||||
const filledCount = computed(
|
||||
() => scripts.value.filter((s) => s.sql.trim()).length,
|
||||
)
|
||||
|
||||
const canUpload = computed(() => {
|
||||
const filled = scripts.value.filter((s) => s.sql.trim())
|
||||
return (
|
||||
!isPreviewing.value &&
|
||||
filled.length > 0 &&
|
||||
// 至少 2 个数据不同的测试点,防止学生对照题目页的期望结果硬编码
|
||||
filled.length >= 2 &&
|
||||
filled.every((s) => s.display && !s.error && !s.stale)
|
||||
)
|
||||
})
|
||||
@@ -241,7 +246,11 @@ async function upload() {
|
||||
</n-button>
|
||||
</span>
|
||||
</template>
|
||||
所有脚本预览验证通过后才能上传
|
||||
{{
|
||||
filledCount < 2
|
||||
? "SQL 题至少需要 2 个数据不同的测试点,防止硬编码期望结果"
|
||||
: "所有脚本预览验证通过后才能上传"
|
||||
}}
|
||||
</n-tooltip>
|
||||
</n-flex>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
CompletionSource,
|
||||
} from "@codemirror/autocomplete"
|
||||
import type { EditorView } from "@codemirror/view"
|
||||
import { useProblemStore } from "oj/store/problem"
|
||||
import type { LANGUAGE } from "utils/types"
|
||||
import { c } from "./c"
|
||||
import { python } from "./python"
|
||||
@@ -22,6 +23,30 @@ const chineseAnnotations: Record<string, ChineseCompletion[]> = {
|
||||
sql,
|
||||
}
|
||||
|
||||
// SQL 题:当前题目的表名和字段名补全,数据来自 sql_display
|
||||
function sqlSchemaCompletions(): Completion[] {
|
||||
const tables = useProblemStore().problem?.sql_display?.tables ?? []
|
||||
return tables.flatMap((table) => [
|
||||
{
|
||||
label: table.name,
|
||||
detail: "数据表",
|
||||
type: "class",
|
||||
info: `字段:${table.columns
|
||||
.map((col) => (col.type ? `${col.name} ${col.type}` : col.name))
|
||||
.join(", ")}`,
|
||||
boost: 110,
|
||||
},
|
||||
...table.columns.map((col) => ({
|
||||
label: col.name,
|
||||
detail: col.type
|
||||
? `${table.name} 的字段 · ${col.type}`
|
||||
: `${table.name} 的字段`,
|
||||
type: "property",
|
||||
boost: 105,
|
||||
})),
|
||||
])
|
||||
}
|
||||
|
||||
export function enhanceCompletion(language: LANGUAGE): CompletionSource {
|
||||
return async function (
|
||||
context: CompletionContext,
|
||||
@@ -69,6 +94,10 @@ export function enhanceCompletion(language: LANGUAGE): CompletionSource {
|
||||
return completion
|
||||
})
|
||||
|
||||
if (trulyLanguage === "sql") {
|
||||
completions.push(...sqlSchemaCompletions())
|
||||
}
|
||||
|
||||
return {
|
||||
from: word ? word.from : context.pos,
|
||||
options: completions,
|
||||
|
||||
Reference in New Issue
Block a user