Browse Source

代码生成预览支持高亮显示

pull/226/head
RuoYi 4 years ago
parent
commit
4b265bb193
  1. 79
      ruoyi-admin/src/main/resources/static/ajax/libs/highlight/default.min.css
  2. 1102
      ruoyi-admin/src/main/resources/static/ajax/libs/highlight/highlight.min.js
  3. 19
      ruoyi-admin/src/main/resources/static/ruoyi/js/common.js
  4. 13
      ruoyi-generator/src/main/resources/templates/tool/gen/gen.html

79
ruoyi-admin/src/main/resources/static/ajax/libs/highlight/default.min.css vendored

@ -0,0 +1,79 @@
/**
* GitHub Gist Theme
* Author : Anthony Attard - https://github.com/AnthonyAttard
* Author : Louis Barranqueiro - https://github.com/LouisBarranqueiro
*/
.hljs {
display: block;
background: white;
padding: 0.5em;
color: #333333;
overflow-x: auto;
}
.hljs-comment,
.hljs-meta {
color: #969896;
}
.hljs-variable,
.hljs-template-variable,
.hljs-strong,
.hljs-emphasis,
.hljs-quote {
color: #df5000;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-type {
color: #d73a49;
}
.hljs-literal,
.hljs-symbol,
.hljs-bullet,
.hljs-attribute {
color: #0086b3;
}
.hljs-section,
.hljs-name {
color: #63a35c;
}
.hljs-tag {
color: #333333;
}
.hljs-title,
.hljs-attr,
.hljs-selector-id,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo {
color: #6f42c1;
}
.hljs-addition {
color: #55a532;
background-color: #eaffea;
}
.hljs-deletion {
color: #bd2c00;
background-color: #ffecec;
}
.hljs-link {
text-decoration: underline;
}
.hljs-number {
color: #005cc5;
}
.hljs-string {
color: #032f62;
}

1102
ruoyi-admin/src/main/resources/static/ajax/libs/highlight/highlight.min.js vendored

File diff suppressed because one or more lines are too long

19
ruoyi-admin/src/main/resources/static/ruoyi/js/common.js

@ -441,6 +441,25 @@ var sub = {
}
};
// 动态加载css文件
function loadCss(file, headElem) {
var link = document.createElement('link');
link.href = file;
link.rel = 'stylesheet';
link.type = 'text/css';
if (headElem) headElem.appendChild(link);
else document.getElementsByTagName('head')[0].appendChild(link);
}
// 动态加载js文件
function loadJs(file, headElem) {
var script = document.createElement('script');
script.src = file;
script.type = 'text/javascript';
if (headElem) headElem.appendChild(script);
else document.getElementsByTagName('head')[0].appendChild(script);
}
/** 设置全局ajax处理 */
$.ajaxSetup({
complete: function(XMLHttpRequest, textStatus) {

13
ruoyi-generator/src/main/resources/templates/tool/gen/gen.html

@ -53,6 +53,7 @@
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-export-js" />
<script th:src="@{/ajax/libs/highlight/highlight.min.js}"></script>
<script th:inline="javascript">
var prefix = ctx + "tool/gen";
var editFlag = [[${@permission.hasPermi('tool:gen:edit')}]];
@ -142,19 +143,23 @@
if (result.code == web_status.SUCCESS) {
var items = [];
$.each(result.data, function(index, value) {
var highCode = hljs.highlightAuto(value).value;
value = value.replace(/</g, "&lt;");
value = value.replace(/>/g, "&gt;");
var templateName = index.substring(index.lastIndexOf("/") + 1, index.length).replace(/\.vm/g, "");
if(!$.common.equals("sql", templateName) && !$.common.equals("tree.html", templateName) && !$.common.equals("sub-domain.java", templateName)){
items.push({
title: templateName , content: "<pre class=\"layui-code\">" + value + "</pre>"
title: templateName , content: "<pre class=\"layui-code\"><code>" + highCode + "</code></pre>"
})
}
});
top.layer.tab({
area: ['90%', '90%'],
shadeClose: true,
tab: items
area: ['90%', '90%'],
shadeClose: true,
success: function(layero, index){
parent.loadCss(ctx + "ajax/libs/highlight/default.min.css");
},
tab: items
});
} else {
$.modal.alertError(result.msg);

Loading…
Cancel
Save