|
|
@ -1,15 +1,17 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="container"> |
|
|
|
<div class="container"> |
|
|
|
<div class="main"> |
|
|
|
<div class="main"> |
|
|
|
<!-- <pre><code ref="editor" class="edit-text html" contenteditable="true" @input="highlightCode">console.log('Hello, World!');</code></pre> --> |
|
|
|
<div |
|
|
|
<div class="edit-text" contenteditable="true" spellcheck="false"> |
|
|
|
class="edit-text" |
|
|
|
<!-- <highlightjs ref="editor" :language="language" :code="code" v-model="code" contenteditable="true" @input="highlightCode"></highlightjs> --> |
|
|
|
contenteditable="true" |
|
|
|
oisafkahsdkjfhasdf sdfhkjsahfdlkjas \n /n sldhfkajshfd salkdhflkasf asfasdf |
|
|
|
spellcheck="false" |
|
|
|
</div> |
|
|
|
ref="code" |
|
|
|
|
|
|
|
></div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div class="setting"> |
|
|
|
<div class="setting"> |
|
|
|
<el-button @click="saveCode" v-if="isShowStrring">保存</el-button> |
|
|
|
<el-button @click="saveCode" v-if="isShowStrring">保存</el-button> |
|
|
|
<el-button @click="router.back()" v-else>返回</el-button> |
|
|
|
<el-button @click="router.back()" v-else>返回</el-button> |
|
|
|
|
|
|
|
<el-button @click="copyCode" v-if="isShowStrring">复制答案</el-button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
@ -20,18 +22,60 @@ import { setStepEvent } from "@/utils/setStep"; |
|
|
|
import { formatDate } from "@/utils"; |
|
|
|
import { formatDate } from "@/utils"; |
|
|
|
import settingStore from "@/store/modules/setting"; |
|
|
|
import settingStore from "@/store/modules/setting"; |
|
|
|
import { useRouter } from "vue-router"; |
|
|
|
import { useRouter } from "vue-router"; |
|
|
|
const router = useRouter() |
|
|
|
import { ElMessage } from "element-plus"; |
|
|
|
|
|
|
|
const code = ref(); |
|
|
|
|
|
|
|
const router = useRouter(); |
|
|
|
const useSettingStore = settingStore(); |
|
|
|
const useSettingStore = settingStore(); |
|
|
|
const isShowStrring = Boolean(localStorage.getItem('falg')) || false |
|
|
|
const isShowStrring = Boolean(localStorage.getItem("falg")) || false; |
|
|
|
|
|
|
|
|
|
|
|
const saveCode = () => { |
|
|
|
const saveCode = () => { |
|
|
|
useSettingStore.setValue(true, 'isRunCode'); |
|
|
|
if(!validateJavaCode(answer, code.value.innerText)){ |
|
|
|
localStorage.setItem('isRunCode','true') |
|
|
|
ElMessage({ |
|
|
|
setStepEvent(8,formatDate(new Date())) |
|
|
|
message: "代码编写错误", |
|
|
|
useSettingStore.activeStepIndex = 9 |
|
|
|
type: "warning", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
useSettingStore.setValue(true, "isRunCode"); |
|
|
|
|
|
|
|
localStorage.setItem("isRunCode", "true"); |
|
|
|
|
|
|
|
setStepEvent(8, formatDate(new Date())); |
|
|
|
|
|
|
|
useSettingStore.activeStepIndex = 9; |
|
|
|
|
|
|
|
|
|
|
|
router.push('/program') |
|
|
|
router.push("/program"); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
function normalizeCode(code) { |
|
|
|
|
|
|
|
return code.replace(/\s+/g, ""); // 去除所有空白字符(包括换行) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function validateJavaCode(answer, userCode) { |
|
|
|
|
|
|
|
return normalizeCode(answer) === normalizeCode(userCode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 标准答案 |
|
|
|
|
|
|
|
const answer = `@RequestMapping(value = "/convert", produces = "application/json; charset=utf-8") |
|
|
|
|
|
|
|
public String convert() throws IOException { |
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
String tcp = TcpUtils.tcp(); |
|
|
|
|
|
|
|
if (tcp != null) { |
|
|
|
|
|
|
|
System.out.println("获取到的tcp数据:" + tcp); |
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
|
|
|
String temperature = StrUtil.subBetween(tcp, "温度:", "℃"); |
|
|
|
|
|
|
|
String humidity = StrUtil.subBetween(tcp, "湿度:", "%RH"); |
|
|
|
|
|
|
|
String formatTime = DateUtil.formatTime(date); |
|
|
|
|
|
|
|
Decs da = new Decs(); |
|
|
|
|
|
|
|
da.setId(count); |
|
|
|
|
|
|
|
da.setTemperature(temperature); |
|
|
|
|
|
|
|
da.setHumidity(humidity); |
|
|
|
|
|
|
|
da.setTime(formatTime); |
|
|
|
|
|
|
|
dataList.add(da); |
|
|
|
|
|
|
|
count++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
`; |
|
|
|
|
|
|
|
const copyCode = () => { |
|
|
|
|
|
|
|
navigator.clipboard.writeText(answer).then(() => { |
|
|
|
|
|
|
|
ElMessage.success("复制成功"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
<style scoped> |
|
|
@ -69,9 +113,9 @@ const saveCode = () => { |
|
|
|
outline: none; |
|
|
|
outline: none; |
|
|
|
line-height: 30px; |
|
|
|
line-height: 30px; |
|
|
|
} |
|
|
|
} |
|
|
|
.setting{ |
|
|
|
.setting { |
|
|
|
position: absolute; |
|
|
|
position: absolute; |
|
|
|
top: 20px; |
|
|
|
top: 20px; |
|
|
|
right: 100px; |
|
|
|
right: 100px; |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|