Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Yuan Zhixiang
c-render-vue
Commits
91422663
Commit
91422663
authored
Apr 30, 2024
by
Yuan Zhixiang
Browse files
修复CodeViewer行号问题
parent
6201cc97
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/App.vue
View file @
91422663
...
...
@@ -71,6 +71,16 @@ function send_request() { // 将输入的代码/测试用例发送给后端
}
}
const
data
=
ref
({})
// 后端返回的数据
const
code_view
=
computed
(()
=>
{
try
{
return
data
.
value
[
'
code
'
]
}
catch
(
e
){}
return
''
})
const
code_view_split
=
computed
(()
=>
{
return
String
(
code_view
.
value
).
split
(
'
\n
'
);
})
function
parse_result
()
{
// 解析后端返回的结果
remove_back_slash_r
()
loading
.
value
=
false
...
...
@@ -238,6 +248,7 @@ provide('app', {
stdin_input
,
send_request
,
data
,
code_view_split
,
success
,
exception_msg
,
get_step
,
...
...
src/components/CodeViewer.vue
View file @
91422663
<
script
setup
>
import
{
computed
,
inject
}
from
'
vue
'
;
import
{
inject
}
from
'
vue
'
;
import
LineUnit
from
'
./LineUnit.vue
'
;
const
{
data
}
=
inject
(
'
app
'
);
const
code
=
computed
(()
=>
{
return
data
.
value
[
'
code
'
];
})
const
code_split
=
computed
(()
=>
{
return
String
(
code
.
value
).
split
(
'
\n
'
);
})
const
{
code_view_split
}
=
inject
(
'
app
'
);
</
script
>
<
template
>
<div
class=
"container"
>
<LineUnit
v-for=
"(item, index) in code_split"
:code=
"item"
:line=
"index + 1"
/>
<LineUnit
v-for=
"(item, index) in code_
view_
split"
:code=
"item"
:line=
"index + 1"
/>
</div>
</
template
>
...
...
src/components/LineUnit.vue
View file @
91422663
...
...
@@ -3,13 +3,13 @@ import { computed, inject, watch, getCurrentInstance } from 'vue';
const
props
=
defineProps
([
'
line
'
,
'
code
'
])
const
{
current_line
,
click_line
,
highlight_lines
,
total_steps
,
prev_line
,
current_step
}
=
inject
(
'
app
'
)
const
{
current_line
,
click_line
,
highlight_lines
,
code_view_split
,
prev_line
,
current_step
}
=
inject
(
'
app
'
)
const
line
=
computed
(()
=>
{
// 行号
return
props
.
line
})
const
line_string
=
computed
(()
=>
{
const
zero_count
=
String
(
total_steps
.
value
).
length
-
String
(
line
.
value
).
length
const
zero_count
=
String
(
code_view_split
.
value
.
length
).
length
-
String
(
line
.
value
).
length
if
(
zero_count
<=
0
){
return
line
.
value
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment