1
1
<script setup>
2
2
import hljs from ' highlight.js'
3
3
import CopyCode from ' ./CopyCode.vue'
4
- import { computed } from ' vue'
4
+ import { computed , nextTick , ref } from ' vue'
5
5
import TypeShow from ' ./TypeShow.vue'
6
6
const props = defineProps ({
7
7
copy: {
@@ -48,16 +48,20 @@ const props = defineProps({
48
48
codeValue: {
49
49
type: String ,
50
50
requied: true ,
51
- default: ' '
51
+ default: ' ' ,
52
52
},
53
53
fontSize: {
54
54
type: Number ,
55
- default: 18
56
- }
55
+ default: 18 ,
56
+ },
57
+ codeLines: {
58
+ type: Boolean ,
59
+ default: false ,
60
+ },
57
61
})
58
62
const langName = props .langName || props .lang
59
63
const font_size = props .fontSize
60
- const languageClass = ' hljs language-' + props .lang
64
+ const languageClass = ' hljs language-' + props .lang
61
65
// const theme = 'dark'
62
66
const vHighlight = {
63
67
bind (el , binding ) {
@@ -73,15 +77,27 @@ const vHighlight = {
73
77
el .textContent = binding .value
74
78
hljs .highlightElement (el)
75
79
},
76
- updated (el , binding ) {
77
- // console.log(el, binding, '222')
78
- el .textContent = binding .value
79
- hljs .highlightElement (el)
80
- },
80
+ // updated(el, binding) {
81
+ // // console.log(el, binding, '222')
82
+ // el.textContent = binding.value
83
+ // hljs.highlightElement(el)
84
+ // },
81
85
}
82
86
const border_radius = ' 12px'
83
87
const withoutHeader = true
84
88
89
+ let arr = ref ([])
90
+
91
+ const codeArea = ref (null )
92
+ nextTick (() => {
93
+ const preCodeHeightDemo = codeArea .value .offsetHeight
94
+ console .log (preCodeHeightDemo, ' preCodeHeight' )
95
+ const count = Math .floor (preCodeHeightDemo / 24 )
96
+ for (let i = 1 ; i <= count; i++ ) {
97
+ arr .value .push (i)
98
+ }
99
+ // console.log(arr,'arr')
100
+ })
85
101
</script >
86
102
<template >
87
103
<div
@@ -105,8 +121,24 @@ const withoutHeader = true
105
121
<TypeShow v-if =" nameShow" :TL =" langName" ></TypeShow >
106
122
<CopyCode v-if =" copy" :codeValue =" props.codeValue" ></CopyCode >
107
123
</div >
124
+ <!-- <div class="code_area">
125
+ <div>1</div>
126
+ </div> -->
127
+ <div class =" code_area_lines" >
128
+ <div
129
+ :class =" {
130
+ dark: props.theme === 'dark',
131
+ light: props.theme === 'light',
132
+ }"
133
+ v-for =" cur in arr"
134
+ class =" code_area_lines_item"
135
+ >
136
+ {{ cur }}
137
+ </div >
138
+ </div >
108
139
<div
109
140
class =" code_area"
141
+ ref =" codeArea"
110
142
:style =" {
111
143
borderBottomLeftRadius: border_radius,
112
144
borderBottomRightRadius: border_radius,
@@ -115,8 +147,7 @@ const withoutHeader = true
115
147
}"
116
148
:class =" { srollbar_style: props.scrollStyleBool === true }"
117
149
>
118
- <pre
119
- >
150
+ <pre >
120
151
<code
121
152
v-highlight =" props.codeValue"
122
153
:class =" languageClass"
@@ -140,8 +171,11 @@ const withoutHeader = true
140
171
overflow : hidden ;
141
172
padding : 20px ;
142
173
padding-top : 0px ;
174
+ padding-left : 24px ;
143
175
overflow : overlay ;
144
176
border-radius : 5px ;
177
+ display : flex ;
178
+
145
179
& .srollbar_style ::-webkit-scrollbar-track {
146
180
background-color : #eee ;
147
181
// border-radius: 5px;
@@ -168,7 +202,7 @@ const withoutHeader = true
168
202
pre code {
169
203
// padding: 0px 20px 20px 20px;
170
204
font-family : Consolas, Monaco, monospace ;
171
- line-height : 1.5 ;
205
+ line-height : 24 px ;
172
206
font-size : 16px ;
173
207
}
174
208
}
@@ -183,6 +217,35 @@ const withoutHeader = true
183
217
.wrapper-content ::-webkit-scrollbar {
184
218
width : 6px ;
185
219
}
220
+
221
+ .code_area_lines {
222
+ display : flex ;
223
+ flex-direction : column ;
224
+ width : 10px ;
225
+ // justify-content: center;
226
+ padding-top : 40px ;
227
+ align-items : center ;
228
+ position : absolute ;
229
+ transform : translateX (6px );
230
+
231
+ & _item {
232
+ height : 24px ;
233
+ width : 10px ;
234
+ font-size : 12px ;
235
+ color : #adb5bd ;
236
+ text-align : center ;
237
+ display : flex ;
238
+ justify-content : center ;
239
+ align-items : center ;
240
+ opacity : 0.6 ;
241
+ & .dark {
242
+ color : #adb5bd ;
243
+ }
244
+ & .light {
245
+ color : #212529 ;
246
+ }
247
+ }
248
+ }
186
249
</style >
187
250
188
251
<style >
0 commit comments