Commit 38a72588 authored by Yuan Zhixiang's avatar Yuan Zhixiang
Browse files

App.vue 添加注释

parent 8c49687d
...@@ -9,8 +9,8 @@ import CodeViewer from './components/CodeViewer.vue'; ...@@ -9,8 +9,8 @@ import CodeViewer from './components/CodeViewer.vue';
import InfoView from './components/InfoView.vue'; import InfoView from './components/InfoView.vue';
import StackView from './components/StackView.vue'; import StackView from './components/StackView.vue';
const code_input = ref('') // 输入的代码 const code_input = ref('') // 用户输入的代码
const stdin_input = ref('') // 测试用例 const stdin_input = ref('') // 用户输入的测试用例
function send_request() { // 将输入的代码/测试用例发送给后端 function send_request() { // 将输入的代码/测试用例发送给后端
data.value = {} data.value = {}
if (stdin_input.value.length == 0) { if (stdin_input.value.length == 0) {
...@@ -70,7 +70,7 @@ function remove_back_slash_r() { // 去除后端返回的code中的\r ...@@ -70,7 +70,7 @@ function remove_back_slash_r() { // 去除后端返回的code中的\r
data.value['code'] = code data.value['code'] = code
} }
} }
const success = computed(() => { const success = computed(() => { // 获取后端返回的运行结果
try { try {
if (data.value['trace'][0]['event'] == 'step_line') { if (data.value['trace'][0]['event'] == 'step_line') {
return true return true
...@@ -78,7 +78,7 @@ const success = computed(() => { ...@@ -78,7 +78,7 @@ const success = computed(() => {
} catch (e) { } } catch (e) { }
return false return false
}) })
const exception_msg = computed(() => { const exception_msg = computed(() => { // 获取后端返回的异常信息
try { try {
if (data.value['trace'][0]['event'] == 'uncaught_exception') { if (data.value['trace'][0]['event'] == 'uncaught_exception') {
return data.value['trace'][0]['exception_msg'].replace(/`/g, "'").replace(/‘/g, "'").replace(/’/g, "'") return data.value['trace'][0]['exception_msg'].replace(/`/g, "'").replace(/‘/g, "'").replace(/’/g, "'")
...@@ -86,7 +86,7 @@ const exception_msg = computed(() => { ...@@ -86,7 +86,7 @@ const exception_msg = computed(() => {
} catch (e) { } } catch (e) { }
return '' return ''
}) })
function get_step(_step) { function get_step(_step) { // 获取某一步的运行结果(1~n)
if (_step < 1) { if (_step < 1) {
_step = 1 _step = 1
} }
...@@ -97,27 +97,27 @@ function get_step(_step) { ...@@ -97,27 +97,27 @@ function get_step(_step) {
return data.value['trace'][_step - 1] return data.value['trace'][_step - 1]
} catch (e) { } } catch (e) { }
} }
const current_line = computed(() => { const current_line = computed(() => { // 播放的当前代码对应的行数
try { try {
return get_step(current_step.value)['line'] return get_step(current_step.value)['line']
} catch (e) { } } catch (e) { }
}) })
const next_line = computed(() => { const next_line = computed(() => { // 播放的下一步代码对应的行数
try { try {
return get_step(current_step.value + 1)['line'] return get_step(current_step.value + 1)['line']
} catch (e) { } } catch (e) { }
}) })
const try_failed = ref(false) const try_failed = ref(false) // 尝试运行代码失败
provide('data', { data, success, exception_msg, get_step, current_line, next_line, try_failed }) provide('data', { data, success, exception_msg, get_step, current_line, next_line, try_failed })
const total_steps = ref(1) // 总步骤数 const total_steps = ref(1) // 总步骤数
const current_step = ref(1) // 当前步骤 const current_step = ref(1) // 当前步骤
const highlight_steps = ref([]) // 高亮的步骤 const highlight_steps = ref([]) // 高亮的步骤
function click_step(clicked) { function click_step(clicked) { // 跳转到某一步骤
current_step.value = clicked current_step.value = clicked
} }
const highlight_lines = ref([]) // 高亮的代码行 const highlight_lines = ref([]) // 高亮的代码行
function enable_line(clicked) { function enable_line(clicked) { // 高亮某一行
let actived = 0; let actived = 0;
for (let i = 1; i <= total_steps.value + 1; i++) { for (let i = 1; i <= total_steps.value + 1; i++) {
if (get_step(i)['line'] == clicked) { if (get_step(i)['line'] == clicked) {
...@@ -129,7 +129,7 @@ function enable_line(clicked) { ...@@ -129,7 +129,7 @@ function enable_line(clicked) {
highlight_lines.value.push(clicked) highlight_lines.value.push(clicked)
} }
} }
function disable_line(clicked) { function disable_line(clicked) { // 取消高亮某一行
for (let i = 1; i <= total_steps.value + 1; i++) { for (let i = 1; i <= total_steps.value + 1; i++) {
if (get_step(i)['line'] == clicked) { if (get_step(i)['line'] == clicked) {
highlight_steps.value = highlight_steps.value.filter(item => item != i) highlight_steps.value = highlight_steps.value.filter(item => item != i)
...@@ -137,7 +137,7 @@ function disable_line(clicked) { ...@@ -137,7 +137,7 @@ function disable_line(clicked) {
} }
highlight_lines.value = highlight_lines.value.filter(item => item != clicked) highlight_lines.value = highlight_lines.value.filter(item => item != clicked)
} }
function click_line(clicked) { function click_line(clicked) { // 点击某一行
if (Object.values(highlight_lines.value).includes(clicked)) { if (Object.values(highlight_lines.value).includes(clicked)) {
disable_line(clicked) disable_line(clicked)
} else { } else {
...@@ -146,10 +146,10 @@ function click_line(clicked) { ...@@ -146,10 +146,10 @@ function click_line(clicked) {
} }
provide('step', { total_steps, current_step, highlight_steps, click_step, highlight_lines, click_line }) provide('step', { total_steps, current_step, highlight_steps, click_step, highlight_lines, click_line })
const edit_mode = ref(true) // 编辑模式,成功运行时为false const edit_mode = ref(true) // 编辑模式,对应的是播放模式
provide('edit_mode', edit_mode) provide('edit_mode', edit_mode)
const loading = ref(false) const loading = ref(false) // 发送请求等待后端返回的状态
provide('loading', loading) provide('loading', loading)
</script> </script>
...@@ -249,8 +249,6 @@ provide('loading', loading) ...@@ -249,8 +249,6 @@ provide('loading', loading)
src: url("./assets/MapleMono-SC-Lite.woff2")format('woff2'); src: url("./assets/MapleMono-SC-Lite.woff2")format('woff2');
} }
#app { #app {
height: 100vh; height: 100vh;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment