Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
30685bee
authored
Apr 15, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将 highlight 代码高亮的全局引入,改成局部引入
parent
d5b569ee
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
src/main.ts
+0
-11
src/views/infra/codegen/PreviewCode.vue
+30
-2
No files found.
src/main.ts
View file @
30685bee
...
...
@@ -37,9 +37,6 @@ import App from './App.vue'
import
'./permission'
import
hljs
from
'highlight.js'
//导入代码高亮文件
import
'highlight.js/styles/github.css'
//导入代码高亮样式 新版
import
'@/plugins/tongji'
// 百度统计
import
Logger
from
'@/utils/Logger'
...
...
@@ -48,14 +45,6 @@ import Logger from '@/utils/Logger'
const
setupAll
=
async
()
=>
{
const
app
=
createApp
(
App
)
//自定义一个代码高亮指令
app
.
directive
(
'highlight'
,
function
(
el
)
{
const
blocks
=
el
.
querySelectorAll
(
'code'
)
blocks
.
forEach
((
block
:
any
)
=>
{
hljs
.
highlightElement
(
block
)
})
})
await
setupI18n
(
app
)
setupStore
(
app
)
...
...
src/views/infra/codegen/PreviewCode.vue
View file @
30685bee
...
...
@@ -45,8 +45,8 @@
<el-button
class=
"float-right"
text
type=
"primary"
@
click=
"copy(item.code)"
>
{{
t
(
'common.copy'
)
}}
</el-button>
<div
v-highlight
>
<
code>
{{
item
.
code
}}
</cod
e>
<div>
<
pre><code
class=
"hljs"
v-html=
"highlightedCode(item)"
></code></pr
e>
</div>
</el-tab-pane>
</el-tabs>
...
...
@@ -180,6 +180,34 @@ const copy = async (text: string) => {
message
.
success
(
t
(
'common.copySuccess'
))
}
}
/**
* 代码高亮
*/
import
hljs
from
'highlight.js'
// 导入代码高亮文件
import
'highlight.js/styles/github.css'
// 导入代码高亮样式
import
java
from
'highlight.js/lib/languages/java'
import
xml
from
'highlight.js/lib/languages/java'
import
javascript
from
'highlight.js/lib/languages/javascript'
import
sql
from
'highlight.js/lib/languages/sql'
import
typescript
from
'highlight.js/lib/languages/typescript'
const
highlightedCode
=
(
item
)
=>
{
const
language
=
item
.
filePath
.
substring
(
item
.
filePath
.
lastIndexOf
(
'.'
)
+
1
)
const
result
=
hljs
.
highlight
(
language
,
item
.
code
||
''
,
true
)
return
result
.
value
||
' '
}
/** 初始化 **/
onMounted
(
async
()
=>
{
// 注册代码高亮的各种语言
hljs
.
registerLanguage
(
'java'
,
java
)
hljs
.
registerLanguage
(
'xml'
,
xml
)
hljs
.
registerLanguage
(
'html'
,
xml
)
hljs
.
registerLanguage
(
'vue'
,
xml
)
hljs
.
registerLanguage
(
'javascript'
,
javascript
)
hljs
.
registerLanguage
(
'sql'
,
sql
)
hljs
.
registerLanguage
(
'typescript'
,
typescript
)
})
</
script
>
<
style
lang=
"scss"
>
.app-infra-codegen-preview-container
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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