代码生成支持上传控件

This commit is contained in:
RuoYi
2020-07-07 17:08:31 +08:00
parent 23b98a3ef8
commit 44df8c4c8b
7 changed files with 104 additions and 14 deletions

View File

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

View File

@ -111,6 +111,11 @@ public class GenUtils
{
column.setHtmlType(GenConstants.HTML_SELECT);
}
// 文件字段设置上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
{
column.setHtmlType(GenConstants.HTML_UPLOAD);
}
}
/**

View File

@ -520,6 +520,7 @@
<option value="radio" {{if htmlType==="radio"}}selected{{/if}}></option>
<option value="checkbox" {{if htmlType==="checkbox"}}selected{{/if}}></option>
<option value="datetime" {{if htmlType==="datetime"}}selected{{/if}}></option>
<option value="upload" {{if htmlType==="upload"}}selected{{/if}}></option>
</select>
</div>
</script>

View File

@ -8,6 +8,12 @@
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
<th:block th:include="include :: bootstrap-fileinput-css"/>
#break
#end
#end
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -46,6 +52,16 @@
<input name="${field}" class="form-control" type="text"#if($column.required) required#end>
</div>
</div>
#elseif($column.htmlType == "upload")
<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" name="${field}">
<div class="file-loading">
<input class="form-control file-upload" id="${field}" name="file" type="file">
</div>
</div>
</div>
#elseif($column.htmlType == "select" && "" != $dictType)
<div class="form-group">
<label class="col-sm-3 control-label">${comment}</label>
@ -146,6 +162,12 @@
<th:block th:include="include :: datetimepicker-js" />
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
<th:block th:include="include :: bootstrap-fileinput-js"/>
#break
#end
#end
<script th:inline="javascript">
var prefix = ctx + "${moduleName}/${businessName}"
@ -175,6 +197,21 @@
});
#end
#end
#foreach($column in $columns)
#if($column.edit && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
$(".file-upload").fileinput({
uploadUrl: '/common/upload',
maxFileCount: 1,
autoReplace: true
}).on('fileuploaded', function (event, data, previewId, index) {
$("input[name='" + event.currentTarget.id + "']").val(data.response.url)
}).on('fileremoved', function (event, id, index) {
$("input[name='" + event.currentTarget.id + "']").val('')
})
#break
#end
#end
#if($table.tree)
/*${functionName}-新增-选择父部门树*/

View File

@ -8,6 +8,12 @@
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
<th:block th:include="include :: bootstrap-fileinput-css"/>
#break
#end
#end
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
@ -46,6 +52,16 @@
<input name="${field}" th:field="*{${field}}" class="form-control" type="text"#if($column.required) required#end>
</div>
</div>
#elseif($column.htmlType == "upload")
<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" name="${field}" th:field="*{${field}}">
<div class="file-loading">
<input class="form-control file-upload" id="${field}" name="file" type="file">
</div>
</div>
</div>
#elseif($column.htmlType == "select" && "" != $dictType)
<div class="form-group">
<label class="col-sm-3 control-label">${comment}</label>
@ -146,6 +162,12 @@
<th:block th:include="include :: datetimepicker-js" />
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
<th:block th:include="include :: bootstrap-fileinput-js"/>
#break
#end
#end
<script th:inline="javascript">
var prefix = ctx + "${moduleName}/${businessName}";
@ -175,6 +197,27 @@
});
#end
#end
#foreach($column in $columns)
#if($column.edit && !$column.superColumn && !$column.pk && $column.htmlType == "upload")
$(".file-upload").each(function (i) {
var val = $("input[name='" + this.id + "']").val()
$(this).fileinput({
'uploadUrl': '/common/upload',
initialPreviewAsData: true,
initialPreview: [val],
maxFileCount: 1,
autoReplace: true
}).on('fileuploaded', function (event, data, previewId, index) {
$("input[name='" + event.currentTarget.id + "']").val(data.response.url)
}).on('fileremoved', function (event, id, index) {
$("input[name='" + event.currentTarget.id + "']").val('')
})
$(this).fileinput('_initFileActions');
});
#break
#end
#end
#if($table.tree)
/*${functionName}-新增-选择父部门树*/