代码生成支持富文本控件

pull/197/head
RuoYi 2020-08-07 09:27:11 +08:00
parent a4c4f737a8
commit cec1d3adcb
6 changed files with 134 additions and 1 deletions

View File

@ -80,6 +80,9 @@ public class GenConstants
/** 上传控件 */ /** 上传控件 */
public static final String HTML_UPLOAD = "upload"; public static final String HTML_UPLOAD = "upload";
/** 富文本控件 */
public static final String HTML_SUMMERNOTE = "summernote";
/** 字符串类型 */ /** 字符串类型 */
public static final String TYPE_STRING = "String"; public static final String TYPE_STRING = "String";

View File

@ -59,7 +59,7 @@ public class GenTableColumn extends BaseEntity
/** 查询方式EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围 */ /** 查询方式EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围 */
private String queryType; private String queryType;
/** 显示类型input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件 */ /** 显示类型input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、summernote富文本控件 */
private String htmlType; private String htmlType;
/** 字典类型 */ /** 字典类型 */

View File

@ -116,6 +116,11 @@ public class GenUtils
{ {
column.setHtmlType(GenConstants.HTML_UPLOAD); column.setHtmlType(GenConstants.HTML_UPLOAD);
} }
// 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
{
column.setHtmlType(GenConstants.HTML_SUMMERNOTE);
}
} }
/** /**

View File

@ -597,6 +597,7 @@
<option value="select" {{if htmlType==="select"}}selected{{/if}}>下拉框</option> <option value="select" {{if htmlType==="select"}}selected{{/if}}>下拉框</option>
<option value="radio" {{if htmlType==="radio"}}selected{{/if}}>单选框</option> <option value="radio" {{if htmlType==="radio"}}selected{{/if}}>单选框</option>
<option value="checkbox" {{if htmlType==="checkbox"}}selected{{/if}}>复选框</option> <option value="checkbox" {{if htmlType==="checkbox"}}selected{{/if}}>复选框</option>
<option value="summernote" {{if htmlType==="summernote"}}selected{{/if}}>富文本</option>
<option value="datetime" {{if htmlType==="datetime"}}selected{{/if}}>日期控件</option> <option value="datetime" {{if htmlType==="datetime"}}selected{{/if}}>日期控件</option>
<option value="upload" {{if htmlType==="upload"}}selected{{/if}}>上传控件</option> <option value="upload" {{if htmlType==="upload"}}selected{{/if}}>上传控件</option>
</select> </select>

View File

@ -14,6 +14,12 @@
#break #break
#end #end
#end #end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
<th:block th:include="include :: summernote-css" />
#break
#end
#end
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -62,6 +68,14 @@
</div> </div>
</div> </div>
</div> </div>
#elseif($column.htmlType == "summernote")
<div class="form-group">
<label class="col-sm-3 control-label#if($column.required) is-required#end">${comment}</label>
<div class="col-sm-8">
<input type="hidden" class="form-control" name="${field}">
<div class="summernote" id="${field}"></div>
</div>
</div>
#elseif($column.htmlType == "select" && "" != $dictType) #elseif($column.htmlType == "select" && "" != $dictType)
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">${comment}</label> <label class="col-sm-3 control-label">${comment}</label>
@ -168,6 +182,12 @@
<th:block th:include="include :: bootstrap-fileinput-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/>
#break #break
#end #end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
<th:block th:include="include :: summernote-js" />
#break
#end
#end #end
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "${moduleName}/${businessName}" var prefix = ctx + "${moduleName}/${businessName}"
@ -212,6 +232,46 @@
#break #break
#end #end
#end #end
#foreach($column in $columns)
#if($column.edit && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
$(function() {
$('.summernote').summernote({
lang: 'zh-CN',
callbacks: {
onChange: function(contents, $edittable) {
$("input[name='" + this.id + "']").val(contents);
},
onImageUpload: function(files) {
var obj = this;
var data = new FormData();
data.append("file", files[0]);
$.ajax({
type: "post",
url: ctx + "common/upload",
data: data,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
$('#' + obj.id).summernote('insertImage', result.url);
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertWarning("图片上传失败。");
}
});
}
}
});
});
#break
#end
#end
#if($table.tree) #if($table.tree)
/*${functionName}-新增-选择父部门树*/ /*${functionName}-新增-选择父部门树*/

View File

@ -14,6 +14,12 @@
#break #break
#end #end
#end #end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
<th:block th:include="include :: summernote-css" />
#break
#end
#end
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -62,6 +68,14 @@
</div> </div>
</div> </div>
</div> </div>
#elseif($column.htmlType == "summernote")
<div class="form-group">
<label class="col-sm-3 control-label#if($column.required) is-required#end">${comment}</label>
<div class="col-sm-8">
<input type="hidden" class="form-control" th:field="*{${field}}">
<div class="summernote" id="${field}"></div>
</div>
</div>
#elseif($column.htmlType == "select" && "" != $dictType) #elseif($column.htmlType == "select" && "" != $dictType)
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">${comment}</label> <label class="col-sm-3 control-label">${comment}</label>
@ -168,6 +182,12 @@
<th:block th:include="include :: bootstrap-fileinput-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/>
#break #break
#end #end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
<th:block th:include="include :: summernote-js" />
#break
#end
#end #end
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "${moduleName}/${businessName}"; var prefix = ctx + "${moduleName}/${businessName}";
@ -218,6 +238,50 @@
#break #break
#end #end
#end #end
#foreach($column in $columns)
#if($column.edit && !$column.superColumn && !$column.pk && $column.htmlType == "summernote")
$(function() {
$('.summernote').each(function(i) {
$('#' + this.id).summernote({
lang: 'zh-CN',
callbacks: {
onChange: function(contents, $edittable) {
$("input[name='" + this.id + "']").val(contents);
},
onImageUpload: function(files) {
var obj = this;
var data = new FormData();
data.append("file", files[0]);
$.ajax({
type: "post",
url: ctx + "common/upload",
data: data,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
$('#' + obj.id).summernote('insertImage', result.url);
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertWarning("图片上传失败。");
}
});
}
}
});
var content = $("input[name='" + this.id + "']").val();
$('#' + this.id).summernote('code', content);
})
});
#break
#end
#end
#if($table.tree) #if($table.tree)
/*${functionName}-新增-选择父部门树*/ /*${functionName}-新增-选择父部门树*/