稳定提交

This commit is contained in:
Guwan 2025-03-21 00:07:42 +08:00
parent 91f6c9237f
commit 3d11c02067
7 changed files with 1709 additions and 145 deletions

View File

@ -9,29 +9,39 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.0",
"vue-router": "^4.2.0",
"element-plus": "^2.5.0",
"@codemirror/basic-setup": "^0.20.0",
"@codemirror/commands": "^6.8.0",
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-javascript": "^6.2.3",
"@codemirror/language": "^6.11.0",
"@codemirror/rangeset": "^0.19.9",
"@codemirror/state": "^6.5.2",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.36.4",
"@element-plus/icons-vue": "^2.3.0",
"echarts": "^5.5.0",
"vue-echarts": "^6.6.0",
"three": "^0.160.0",
"file-saver": "^2.0.5",
"xlsx": "^0.18.5",
"@monaco-editor/loader": "^1.5.0",
"animate.css": "^4.1.1",
"axios": "^1.6.0",
"pinia": "^2.1.0",
"dayjs": "^1.11.0",
"echarts": "^5.5.0",
"element-plus": "^2.5.0",
"file-saver": "^2.0.5",
"js-cookie": "^3.0.5",
"monaco-editor": "^0.30.1",
"js-cookie": "^3.0.5"
"pinia": "^2.1.0",
"three": "^0.160.0",
"vue": "^3.4.0",
"vue-codemirror": "^6.1.1",
"vue-echarts": "^6.6.0",
"vue-monaco-editor": "^0.0.19",
"vue-router": "^4.2.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.0",
"vite": "^5.0.0",
"sass": "^1.70.0",
"unplugin-auto-import": "^0.17.0",
"unplugin-vue-components": "^0.26.0"
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.0"
}
}

View File

@ -1,10 +1,10 @@
<template>
<div class="app">
<AppHeader />
<AppHeader v-if="!$route.meta.hideNav"/>
<main class="main-content">
<router-view />
</main>
<AppFooter />
<AppFooter v-if="!$route.meta.hideNav"/>
</div>
</template>
@ -18,11 +18,11 @@ import AppFooter from './components/AppFooter.vue'
min-height: 100vh;
display: flex;
flex-direction: column;
.main-content {
flex: 1;
margin-top: 60px; //
padding: 20px;
}
}
</style>
</style>

View File

@ -0,0 +1,192 @@
<template>
<div class="editor-container">
<div ref="editor" class="code-editor"></div>
</div>
</template>
<script>
import { ref, onMounted, onBeforeUnmount, defineProps, defineEmits } from "vue";
import { EditorView, keymap, gutter, GutterMarker, lineNumbers } from "@codemirror/view";
import { EditorState, StateField, StateEffect } from "@codemirror/state";
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
import { RangeSet } from "@codemirror/rangeset";
import { javascript } from "@codemirror/lang-javascript";
import { oneDark } from "@codemirror/theme-one-dark";
import { indentUnit } from "@codemirror/language";
class BreakpointMarker extends GutterMarker {
toDOM() {
const marker = document.createElement("div");
marker.className = "breakpoint-marker";
marker.textContent = "●";
return marker;
}
}
export default {
name: "CodeEditor",
props: {
modelValue: String, //
language: String, // JS
height: {
type: String,
default: '600px'
}
},
emits: ["update:modelValue"], //
setup(props, { emit }) {
const editor = ref(null);
let editorView = null;
const setBreakpoint = StateEffect.define();
const breakpointsField = StateField.define({
create: () => new Set(),
update(breakpoints, tr) {
const newBreakpoints = new Set(breakpoints);
for (let effect of tr.effects) {
if (effect.is(setBreakpoint)) {
const line = effect.value;
if (newBreakpoints.has(line)) {
newBreakpoints.delete(line);
} else {
newBreakpoints.add(line);
}
}
}
return newBreakpoints;
},
});
const breakpointGutter = gutter({
class: "cm-breakpoint-gutter",
markers: (view) => {
const breakpoints = view.state.field(breakpointsField);
const markers = [];
for (const line of breakpoints) {
try {
const lineInfo = view.state.doc.line(line);
markers.push(new BreakpointMarker().range(lineInfo.from));
} catch (e) {
console.warn("Invalid line number skipped:", line);
}
}
return RangeSet.of(markers, true);
},
domEventHandlers: {
click: (view, block) => {
const lineNumber = view.state.doc.lineAt(block.from).number;
view.dispatch({
effects: [setBreakpoint.of(lineNumber)],
});
return true;
},
},
});
onMounted(() => {
if (!editor.value) return;
editorView = new EditorView({
state: EditorState.create({
doc: props.modelValue || "",
extensions: [
lineNumbers(),
breakpointGutter,
breakpointsField,
javascript(),
oneDark,
indentUnit.of(" "), // 使4
keymap.of([
...defaultKeymap,
indentWithTab
]),
EditorView.updateListener.of((update) => {
if (update.docChanged) {
emit("update:modelValue", update.state.doc.toString());
}
}),
EditorView.theme({
"&": {
fontSize: "14px",
height: "100%"
},
".cm-content": {
fontFamily: "'Fira Code', monospace",
padding: "12px 0",
},
".cm-line": {
padding: "0 12px",
lineHeight: "1.6"
},
".cm-gutters": {
backgroundColor: "#1e1e1e",
color: "#666",
border: "none"
},
".cm-activeLineGutter": {
backgroundColor: "#333"
},
".cm-activeLine": {
backgroundColor: "rgba(255,255,255,0.03)"
}
}),
EditorView.baseTheme({
".cm-breakpoint-gutter": {
width: "30px",
backgroundColor: "#1e1e1e",
borderRight: "1px solid #333"
},
".breakpoint-marker": {
color: "#ff5555",
fontSize: "14px",
cursor: "pointer",
textAlign: "center"
},
}),
],
}),
parent: editor.value,
});
});
onBeforeUnmount(() => {
editorView?.destroy();
});
return { editor };
},
};
</script>
<style>
.editor-container {
width: 100%;
height: 100%;
background: #282c34;
}
.code-editor {
height: 100%;
overflow: auto;
}
/* 自定义滚动条样式 */
.code-editor ::-webkit-scrollbar {
width: 12px;
height: 12px;
}
.code-editor ::-webkit-scrollbar-track {
background: #21252b;
}
.code-editor ::-webkit-scrollbar-thumb {
background: #454c59;
border-radius: 6px;
border: 3px solid #21252b;
}
.code-editor ::-webkit-scrollbar-thumb:hover {
background: #535b6a;
}
</style>

View File

@ -67,7 +67,16 @@ const routes = [
path: '/exam/start/:id',
component: () => import('../views/paper/exam/exam.vue'),
name: 'StartExam',
meta: { title: '开始考试' },
meta: {
title: '开始考试',
isExam: true,
hideNav: true
},
hidden: true
},

View File

@ -6,7 +6,7 @@ import { useUserStore } from '../stores/user'
const service = axios.create({
// baseURL: import.meta.env.VITE_API_BASE_URL || '/api', // 从环境变量获取 API 基础 URL
//baseURL: 'http://localhost:8101', // 从环境变量获取 API 基础 URL
baseURL: 'http://localhost:8084', // 从环境变量获取 API 基础 URL
baseURL: 'http://localhost:8101', // 从环境变量获取 API 基础 URL
timeout: 15000, // 请求超时时间
})
@ -23,7 +23,7 @@ service.interceptors.request.use(
config.headers['token'] = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDE3ODAxNDMsInVzZXJuYW1lIjoiYWRtaW4ifQ._jKmdu1T-zpf_qSWRTBtovJ51v2ONC6CGF-60MLJOOE`
config.headers['token'] = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDI0NzI5MzUsInVzZXJuYW1lIjoiYWRtaW4ifQ.-4e5HlHyM9gYlfkaraNdIcPDAeegiPoe3KPRaID9fRY`
// 根据请求方法和数据类型动态设置 Content-Type

View File

@ -1,16 +1,410 @@
<template>
<div class="mall">
<h1 class="page-title">商城</h1>
<p>商城功能正在开发中敬请期待...</p>
<div class="challenge-container">
<div class="challenge-header">
<div class="title-section">
<h2>{{ challenge.title }}</h2>
<div class="difficulty easy">简单</div>
</div>
<div class="challenge-info">
<span class="info-tag">
<i class="fas fa-memory"></i>
内存限制{{ challenge.memoryLimit }} MB
</span>
<span class="info-tag">
<i class="fas fa-code"></i>
{{ challenge.language }}
</span>
<span class="info-tag">
<i class="fas fa-clock"></i>
时间限制1000ms
</span>
</div>
</div>
<div class="challenge-content">
<div class="test-cases-section">
<div class="section-header">
<h3><i class="fas fa-vial"></i> 测试用例</h3>
<span class="case-count">{{ challenge.testCases.length }} 个用例</span>
</div>
<div class="test-cases">
<div v-for="(test, index) in challenge.testCases"
:key="index"
class="test-case-card">
<div class="test-case-header">
<span class="case-number">#{{ index + 1 }}</span>
<span class="case-status success">
<i class="fas fa-check-circle"></i>
</span>
</div>
<div class="test-case-content">
<div class="test-input">
<div class="label">输入</div>
<code>{{ test.input }}</code>
</div>
<div class="test-output">
<div class="label">期望输出</div>
<code>{{ test.expectedOutput }}</code>
</div>
</div>
</div>
</div>
</div>
<div class="editor-section">
<div class="editor-header">
<div class="editor-tabs">
<div class="tab active">
<i class="fas fa-code"></i>
代码编辑器
</div>
</div>
<div class="editor-actions">
<button class="action-btn">
<i class="fas fa-redo"></i>
重置
</button>
<button class="submit-btn" @click="submitCode">
<i class="fas fa-paper-plane"></i>
提交代码
</button>
</div>
</div>
<CodeEditor
v-model="userCode"
:language="challenge.language"
class="code-editor-wrapper"
/>
</div>
<div v-if="result" class="result-section">
<div class="section-header">
<h3><i class="fas fa-poll"></i> 执行结果</h3>
</div>
<pre class="result-content">{{ result }}</pre>
</div>
</div>
</div>
</template>
<script setup>
<script>
import { ref } from "vue";
import CodeEditor from "@/components/CodeEditor/CodeEditor.vue";
export default {
components: { CodeEditor },
setup() {
const challenge = {
title: "两数之和",
memoryLimit: 256,
language: "javascript",
testCases: [
{ input: "[2,7,11,15], 9", expectedOutput: "[0,1]" },
{ input: "[3,2,4], 6", expectedOutput: "[1,2]" },
{ input: "[3,3], 6", expectedOutput: "[0,1]" },
],
};
const userCode = ref('// 在这里编写你的代码\nfunction twoSum(nums, target) {\n return [];\n}');
const result = ref(null);
const submitCode = () => {
result.value = {
code: userCode.value,
challenge,
};
console.log("提交代码:", result.value);
};
return { challenge, userCode, submitCode, result };
},
};
</script>
<style lang="scss" scoped>
.mall {
<style scoped>
.challenge-container {
max-width: 1200px;
margin: 0 auto;
margin: 20px auto;
padding: 20px;
background: #ffffff;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
</style>
.challenge-header {
margin-bottom: 24px;
padding-bottom: 20px;
border-bottom: 1px solid #eef2f7;
}
.title-section {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
.challenge-header h2 {
margin: 0;
color: #1a202c;
font-size: 26px;
font-weight: 600;
}
.difficulty {
padding: 4px 12px;
border-radius: 20px;
font-size: 13px;
font-weight: 500;
}
.difficulty.easy {
background: #e6f6e6;
color: #2f9e44;
}
.challenge-info {
display: flex;
gap: 12px;
}
.info-tag {
display: inline-flex;
align-items: center;
padding: 8px 16px;
background: #f8fafc;
border-radius: 8px;
font-size: 14px;
color: #64748b;
transition: all 0.2s;
}
.info-tag:hover {
background: #f1f5f9;
transform: translateY(-1px);
}
.info-tag i {
margin-right: 8px;
color: #3b82f6;
}
.challenge-content {
display: grid;
grid-template-columns: 320px 1fr;
gap: 24px;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.section-header h3 {
margin: 0;
font-size: 18px;
color: #1a202c;
display: flex;
align-items: center;
gap: 8px;
}
.section-header h3 i {
color: #3b82f6;
}
.case-count {
font-size: 14px;
color: #64748b;
background: #f1f5f9;
padding: 4px 12px;
border-radius: 16px;
}
.test-cases {
display: flex;
flex-direction: column;
gap: 16px;
}
.test-case-card {
border: 1px solid #e2e8f0;
border-radius: 10px;
overflow: hidden;
transition: all 0.2s;
}
.test-case-card:hover {
border-color: #cbd5e1;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.test-case-header {
padding: 12px 16px;
background: #f8fafc;
display: flex;
justify-content: space-between;
align-items: center;
}
.case-number {
font-weight: 500;
color: #64748b;
}
.case-status {
font-size: 14px;
}
.case-status.success i {
color: #2f9e44;
}
.test-case-content {
padding: 16px;
}
.test-input, .test-output {
margin: 8px 0;
}
.label {
font-weight: 500;
color: #475569;
margin-bottom: 4px;
}
code {
display: block;
background: #f8fafc;
padding: 8px 12px;
border-radius: 6px;
font-family: 'Fira Code', monospace;
font-size: 13px;
color: #334155;
border: 1px solid #e2e8f0;
}
.editor-section {
display: flex;
flex-direction: column;
gap: 16px;
}
.editor-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 0 8px 0;
}
.editor-tabs {
display: flex;
gap: 2px;
}
.tab {
padding: 8px 16px;
font-size: 14px;
color: #64748b;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
}
.tab.active {
background: #f1f5f9;
color: #3b82f6;
font-weight: 500;
}
.editor-actions {
display: flex;
gap: 12px;
}
.action-btn {
padding: 8px 16px;
border: 1px solid #e2e8f0;
background: white;
border-radius: 6px;
color: #64748b;
font-size: 14px;
cursor: pointer;
display: flex;
align-items: center;
gap: 6px;
transition: all 0.2s;
}
.action-btn:hover {
border-color: #cbd5e1;
background: #f8fafc;
}
.submit-btn {
padding: 8px 20px;
background: #3b82f6;
color: white;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s;
}
.submit-btn:hover {
background: #2563eb;
transform: translateY(-1px);
}
.code-editor-wrapper {
border-radius: 10px;
overflow: hidden;
border: 1px solid #e2e8f0;
flex-grow: 1;
height: 600px;
}
.result-section {
grid-column: 1 / -1;
background: #f8fafc;
border-radius: 10px;
padding: 20px;
}
.result-content {
margin: 0;
padding: 16px;
background: white;
border-radius: 8px;
border: 1px solid #e2e8f0;
font-family: 'Fira Code', monospace;
font-size: 13px;
line-height: 1.5;
}
@media (max-width: 1024px) {
.challenge-content {
grid-template-columns: 1fr;
}
.test-cases-section, .editor-section {
grid-column: 1;
}
.info-tag {
padding: 6px 12px;
}
}
</style>

File diff suppressed because it is too large Load Diff