+
{{ d.file }}({{ d.line }},{{ d.column }}) {{ d.code }}:{{ d.message }}
提示:{{ d.hint }}
@@ -158,24 +204,17 @@ body {
}
.editor {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
padding: 8px;
border-right: 1px solid #e5e7eb;
overflow: hidden;
}
.code {
- width: 100%;
- height: calc(100vh - 120px);
- box-sizing: border-box;
- font-family: "JetBrains Mono", "Cascadia Code", Consolas, "Noto Sans Mono CJK SC", monospace;
- font-size: 13px;
- line-height: 1.5;
- tab-size: 4;
- /* 关闭连字:避免 >= 显示成 ≥,学生照着输入时出错 */
- font-variant-ligatures: none;
- border: 1px solid #e5e7eb;
- padding: 8px;
- resize: none;
+ flex: 1;
+ min-height: 0;
}
.run-area {
@@ -212,6 +251,14 @@ body {
font-size: 12px;
}
+.diag {
+ cursor: pointer;
+}
+
+.diag:hover {
+ text-decoration: underline;
+}
+
.diag.error,
.error {
color: #b91c1c;
diff --git a/web/src/editor/CodeEditor.vue b/web/src/editor/CodeEditor.vue
new file mode 100644
index 0000000..f512350
--- /dev/null
+++ b/web/src/editor/CodeEditor.vue
@@ -0,0 +1,150 @@
+
+
+
+
+
+ 此文件由窗体设计器生成,一般不要手动修改;控件的属性和事件请在设计器里设置。
+
+
+
+
+
+
diff --git a/web/src/editor/drafts.ts b/web/src/editor/drafts.ts
new file mode 100644
index 0000000..fef0a5a
--- /dev/null
+++ b/web/src/editor/drafts.ts
@@ -0,0 +1,31 @@
+// 学生改过的代码保存在浏览器本地(localStorage),刷新页面不丢失。
+// 这只是方便功能:隐私窗口、清除网站数据等情况下可能读写失败,失败时当作没有草稿。
+// 作业的正式保存以后放到服务器上。
+import type { SourceFile } from '@iot/shared'
+
+const PREFIX = 'iot-sim:draft:'
+
+export function loadDraft(sampleId: string): SourceFile[] | null {
+ try {
+ const raw = localStorage.getItem(PREFIX + sampleId)
+ return raw ? (JSON.parse(raw) as SourceFile[]) : null
+ } catch {
+ return null
+ }
+}
+
+export function saveDraft(sampleId: string, files: SourceFile[]) {
+ try {
+ localStorage.setItem(PREFIX + sampleId, JSON.stringify(files))
+ } catch {
+ // 存储不可用或已满:忽略
+ }
+}
+
+export function clearDraft(sampleId: string) {
+ try {
+ localStorage.removeItem(PREFIX + sampleId)
+ } catch {
+ // 忽略
+ }
+}
diff --git a/web/src/editor/monaco.ts b/web/src/editor/monaco.ts
new file mode 100644
index 0000000..f67b236
--- /dev/null
+++ b/web/src/editor/monaco.ts
@@ -0,0 +1,12 @@
+// 按需加载 Monaco(0.57 的模块布局):编辑器 API + 全部编辑功能(查找、折叠、括号匹配等)+ C# 语法高亮,
+// 不加载其他几十种语言和 JS/TS/CSS 语言服务,体积小很多。
+import * as monaco from 'monaco-editor/editor/editor.api'
+import 'monaco-editor/features/register.all'
+import 'monaco-editor/languages/definitions/csharp/register'
+import EditorWorker from 'monaco-editor/editor/editor.worker?worker'
+
+self.MonacoEnvironment = {
+ getWorker: () => new EditorWorker(),
+}
+
+export { monaco }