Skip to content

Commit 8818c25

Browse files
committed
feature: 自动化代码预览部分支持黑夜模式
1 parent 75500cf commit 8818c25

File tree

4 files changed

+47
-87
lines changed

4 files changed

+47
-87
lines changed

server/service/system/auto_code_template.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ func (s *autoCodeTemplate) Preview(ctx context.Context, info request.AutoCode) (
200200
if len(key) > len(global.GVA_CONFIG.AutoCode.Root) {
201201
key, _ = filepath.Rel(global.GVA_CONFIG.AutoCode.Root, key)
202202
}
203+
// 获取key的后缀 取消.
204+
suffix := filepath.Ext(key)[1:]
203205
var builder strings.Builder
204-
builder.WriteString("```\n\n")
206+
builder.WriteString("```" + suffix + "\n\n")
205207
builder.WriteString(writer.String())
206208
builder.WriteString("\n\n```")
207209
preview[key] = builder.String()

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"highlight.js": "^11.10.0",
2626
"js-cookie": "^3.0.5",
2727
"marked": "14.1.1",
28+
"marked-highlight": "^2.1.4",
2829
"mitt": "^3.0.1",
2930
"nprogress": "^0.2.0",
3031
"path": "^0.12.7",

web/src/core/config.js

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* 网站配置文件
33
*/
4-
import chalk from "chalk";
4+
const greenText = (text) => `\x1b[32m${text}\x1b[0m`;
55

66
const config = {
77
appName: 'Gin-Vue-Admin',
@@ -12,72 +12,19 @@ const config = {
1212

1313
export const viteLogo = (env) => {
1414
if (config.showViteLogo) {
15-
const chalk = require('chalk')
16-
console.log(
17-
chalk.green(
18-
`> 欢迎使用Gin-Vue-Admin,开源地址:https://github.com/flipped-aurora/gin-vue-admin`
19-
)
20-
)
21-
console.log(
22-
chalk.green(
23-
`> 当前版本:v2.7.3`
24-
)
25-
)
26-
console.log(
27-
chalk.green(
28-
`> 加群方式:微信:shouzi_1994 QQ群:470239250`
29-
)
30-
)
31-
console.log(
32-
chalk.green(
33-
`> 项目地址:https://github.com/flipped-aurora/gin-vue-admin`
34-
)
35-
)
36-
console.log(
37-
chalk.green(
38-
`> 插件市场:https://plugin.gin-vue-admin.com`
39-
)
40-
)
41-
console.log(
42-
chalk.green(
43-
`> GVA讨论社区:https://support.qq.com/products/371961`
44-
)
45-
)
46-
console.log(
47-
chalk.green(
48-
`> 默认自动化文档地址:http://127.0.0.1:${env.VITE_SERVER_PORT}/swagger/index.html`
49-
)
50-
)
51-
console.log(
52-
chalk.green(
53-
`> 默认前端文件运行地址:http://127.0.0.1:${env.VITE_CLI_PORT}`
54-
)
55-
)
56-
57-
console.log(
58-
chalk.green(
59-
`--------------------------------------版权声明--------------------------------------`
60-
)
61-
)
62-
63-
console.log(
64-
chalk.green(
65-
`** 版权所有方:flipped-aurora开源团队 **`
66-
)
67-
)
68-
69-
console.log(
70-
chalk.green(
71-
`** 版权持有公司:北京翻转极光科技有限责任公司 **`
72-
)
73-
)
74-
75-
console.log(
76-
chalk.green(
77-
`** 剔除授权标识需购买商用授权:https://gin-vue-admin.com/empower/index.html **`
78-
)
79-
)
80-
console.log('\n')
15+
console.log(greenText(`> 欢迎使用Gin-Vue-Admin,开源地址:https://github.com/flipped-aurora/gin-vue-admin`));
16+
console.log(greenText(`> 当前版本:v2.7.3`));
17+
console.log(greenText(`> 加群方式:微信:shouzi_1994 QQ群:470239250`));
18+
console.log(greenText(`> 项目地址:https://github.com/flipped-aurora/gin-vue-admin`));
19+
console.log(greenText(`> 插件市场:https://plugin.gin-vue-admin.com`));
20+
console.log(greenText(`> GVA讨论社区:https://support.qq.com/products/371961`));
21+
console.log(greenText(`> 默认自动化文档地址:http://127.0.0.1:${env.VITE_SERVER_PORT}/swagger/index.html`));
22+
console.log(greenText(`> 默认前端文件运行地址:http://127.0.0.1:${env.VITE_CLI_PORT}`));
23+
console.log(greenText(`--------------------------------------版权声明--------------------------------------`));
24+
console.log(greenText(`** 版权所有方:flipped-aurora开源团队 **`));
25+
console.log(greenText(`** 版权持有公司:北京翻转极光科技有限责任公司 **`));
26+
console.log(greenText(`** 剔除授权标识需购买商用授权:https://gin-vue-admin.com/empower/index.html **`));
27+
console.log('\n');
8128
}
8229
}
8330

web/src/view/systemTools/autoCode/component/previewCodeDialg.vue

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@
88
>
99
<div
1010
:id="key"
11-
class="h-[calc(100vh-110px)] bg-white px-5 overflow-y-scroll"
11+
class="h-[calc(100vh-110px)] px-5 overflow-y-scroll"
1212
/>
1313
</el-tab-pane>
1414
</el-tabs>
1515
</template>
1616

1717
<script setup>
18-
import { marked } from 'marked'
18+
import { Marked } from "marked";
19+
import { markedHighlight } from "marked-highlight";
1920
import hljs from 'highlight.js'
20-
import 'highlight.js/styles/atom-one-dark.css'
2121
import { ElMessage } from 'element-plus'
2222
import { onMounted, ref } from 'vue'
23+
import {useAppStore} from "@/pinia";
24+
25+
const appStore = useAppStore()
26+
27+
onMounted(() => {
28+
const isDarkMode = appStore.config.darkMode === 'dark';
29+
if (isDarkMode) {
30+
import('highlight.js/styles/atom-one-dark.css');
31+
} else {
32+
import('highlight.js/styles/atom-one-light.css');
33+
}
34+
});
2335
2436
const props = defineProps({
2537
previewCode: {
@@ -32,26 +44,24 @@ const props = defineProps({
3244
3345
const activeName = ref('')
3446
onMounted(() => {
35-
marked.setOptions({
36-
renderer: new marked.Renderer(),
37-
highlight: function(code) {
38-
return hljs.highlightAuto(code).value
39-
},
40-
pedantic: false,
41-
gfm: true,
42-
tables: true,
43-
breaks: false,
44-
sanitize: false,
45-
smartLists: true,
46-
smartypants: false,
47-
xhtml: false,
48-
langPrefix: 'hljs language-'
49-
})
47+
const marked = new Marked(
48+
markedHighlight({
49+
langPrefix: 'hljs language-',
50+
highlight(code, lang, info) {
51+
console.log(code,lang,info)
52+
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
53+
if (lang === 'vue') {
54+
return hljs.highlight(code, { language: 'html' }).value;
55+
}
56+
return hljs.highlight(code, { language }).value;
57+
}
58+
})
59+
);
5060
for (const key in props.previewCode) {
5161
if (activeName.value === '') {
5262
activeName.value = key
5363
}
54-
document.getElementById(key).innerHTML = marked(props.previewCode[key])
64+
document.getElementById(key).innerHTML = marked.parse(props.previewCode[key])
5565
}
5666
})
5767

0 commit comments

Comments
 (0)