格式如下:
<div class="form-group">
<label class="col-sm-3 control-label">时段:</label>
<div class="col-sm-6">
<div class="input-group date">
<input name="startTime" th:value="${#dates.format(certificate.startTime,'yyyy-MM-dd HH:mm:ss')}" type="text" class="input-sm form-control" id="startTime" placeholder="开始时间" autocomplete="off"/>
<span class="input-group-addon">至</span>
<input name="endTime" th:value="${#dates.format(certificate.endTime,'yyyy-MM-dd HH:mm:ss')}" type="text" class="input-sm form-control" id="endTime" placeholder="结束时间" autocomplete="off"/>
</div>
</div>
</div>
全页内容如下:
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('测试')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-material-edit" th:object="${certificate}">
<input type="hidden" name="id" th:field="*{id}">
<div class="form-group">
<label class="col-sm-3 control-label">时段:</label>
<div class="col-sm-6">
<div class="input-group date">
<input name="startTime" th:value="${#dates.format(certificate.startTime,'yyyy-MM-dd HH:mm:ss')}" type="text" class="input-sm form-control" id="startTime" placeholder="开始时间" autocomplete="off"/>
<span class="input-group-addon">至</span>
<input name="endTime" th:value="${#dates.format(certificate.endTime,'yyyy-MM-dd HH:mm:ss')}" type="text" class="input-sm form-control" id="endTime" placeholder="结束时间" autocomplete="off"/>
</div>
</div>
</div>
<div class="form-group" style="margin-top:30px;">
<label class="col-sm-3 control-label">名称:</label>
<div class="col-sm-6">
<input name="certificateName" id="materialName1" class="form-control" th:field="*{certificateName}" type="text" required
style="width:calc(100% - 100px);float: left; margin-right: 3px;">
<button id="uploadBtn" type="button" class="btn btn-sm btn-primary"
style="display: inline-block; width: 95px;position: relative;float: left;height: 33px;"><i
class="fa fa-check"></i>上 传
</button>
</div>
</div>
<input type="hidden" name="savePath" th:field="*{savePath}"/>
<div class="form-group">
<label class="col-sm-3 control-label">预览图片:</label>
<div class="col-sm-6">
<a class=""><img class="img img-xs" th:src="*{savePath}"></a>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">获得者:</label>
<div class="col-sm-6">
<div class="input-group">
<input name="userIds" id="userIds" th:field="*{userIds}" type="hidden">
<input class="form-control userIds" th:field="*{userNames}" type="text" disabled="">
<a class="input-group-addon" onclick="selectUsers()"><i class="fa fa-search"></i></a>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">备注:</label>
<div class="col-sm-6">
<textarea name="remark" th:field="*{remark}" class="form-control"></textarea>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<script th:src="@{/ajax/libs/plupload/plupload.full.min.js}"></script>
<script type="text/javascript">
var prefix = ctx + "personal/book";
var uploader = new plupload.Uploader({ //实例化一个plupload上传对象
runtimes: 'html5,silverlight,html4,flash',
browse_button: 'uploadBtn',
url: ctx + "cms/uploadMaterial",
flash_swf_url: "/ajax/libs/plupload/Moxie.swf",
silverlight_xap_url: "/ajax/libs/plupload/Moxie.xap",
filters: {
max_file_size: '200mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb)
mime_types: [{title: "图片文件", extensions: "jpg,jpeg,gif,png,bmp"},
{title: "压缩文件", extensions: "zip,rar,gz"}
]
}//只允许上传图片文件
});
//绑定文件添加进队列事件
uploader.bind('FilesAdded', function (uploader, files) {
uploader.start(); //开始上传
});
uploader.bind('Error', function (up, err) {
alert(err.message);//上传出错的时候触发
});
uploader.bind("FileUploaded", function (up, file, res) {
var json = res.response;
json = JSON.parse(json);
if (json.code != 0 && json.code != '0') {
$.modal.alertError(json.msg);
}
uploadCallback(json.data);
})
window.onload = function () {
layui.use('laydate', function(){
var laydate = layui.laydate;
var startDate = laydate.render({
elem: '#startTime',
type: 'datetime',
/*theme: 'molv',*/
trigger: 'click',
done: function(value, date) {
// 开始时间大于等于今天
if (value !== '') {
if (value > $('#endTime').val()) {
$('#endTime').val("");
}
endDate.config.min.year = date.year;
endDate.config.min.month = date.month - 1;
endDate.config.min.date = date.date;
endDate.config.min.hours = date.hours;
endDate.config.min.minutes = date.minutes;
endDate.config.min.seconds = date.seconds;
} else {
endDate.config.min.year = '';
endDate.config.min.month = '';
endDate.config.min.date = '';
endDate.config.min.hours = '';
endDate.config.min.minutes = '';
endDate.config.min.seconds = '';
}
}
});
var endDate = laydate.render({
elem: '#endTime',
min: $('#startTime').val(),
type: 'datetime',
/*theme: 'molv',*/
trigger: 'click',
});
});
uploader.init(); //初始化
};
function uploadCallback(json) {
$("#materialName1").val(json.name.split('.')[0]);
$("#savePath").val(json.path);
$(".img").attr("src", json.path);
}
function selectUsers() {
$.modal.open("选择证书获得者(可多选)", prefix + "/user/" + ($("#userIds").val() != "" ? $("#userIds").val() + ",": "-1,"));
}
function userResults(re) {
$("#userIds").val(re.ids);
$(".userIds").val(re.names);
}
function submitHandler() {
if (verifyInput()) {
$.operate.save(prefix + '/edit', $('#form-material-edit').serialize());
}
}
function verifyInput() {
var flag = true;
var materialName1 = $("#materialName1").val();
if(!materialName1 || materialName1 === ""){
$.modal.alertError("请选择证书!");
flag = false;
}
var startTime = $("#startTime").val();
if(!startTime || startTime === ""){
$.modal.alertError("请选择开始有效时间!");
flag = false;
}
var endTime = $("#endTime").val();
if(!endTime || endTime === ""){
$.modal.alertError("请选择结束有效时间!");
flag = false;
}
return flag;
}
// 预览图片
$("#form-material-edit").off("click").on("click", '.img', function() {
var html="<div id='outerdiv' style='position: fixed; top: 0px; left: 0px; background: rgba(0, 0, 0, 0.7); z-index: 2; width: 100%; height: 100%; display: none;'>\n" +
" <div id='innerdiv' style='position: absolute; top: 80.8px; left: 446.079px;'>\n" +
" <img id='bigimg' style='border: 5px solid rgb(255, 255, 255); width: 969.842px;' src=''>\n" +
" </div>\n" +
"</div>";
$("body").append(html);
var outerdiv="#outerdiv";
var innerdiv="#innerdiv";
var bigimg="#bigimg";
var url = $(this).attr('src');
$(bigimg).attr("src", url);
$("<img/>").attr("src", url).load(function(){
var windowW = $(window).width();
var windowH = $(window).height();
var realWidth = this.width;
var realHeight = this.height;
var imgWidth, imgHeight;
var scale = 0.8;
if(realHeight>windowH*scale) {
imgHeight = windowH*scale;
imgWidth = imgHeight/realHeight*realWidth;
if(imgWidth>windowW*scale) {
imgWidth = windowW*scale;
}
} else if(realWidth>windowW*scale) {
imgWidth = windowW*scale;
imgHeight = imgWidth/realWidth*realHeight;
} else {
imgWidth = realWidth;
imgHeight = realHeight;
}
$(bigimg).css("width",imgWidth);
var w = (windowW-imgWidth)/2;
var h = (windowH-imgHeight)/2;
$(innerdiv).css({"top":h, "left":w});
$(outerdiv).fadeIn("fast");
});
$(outerdiv).click(function(){
$(this).fadeOut("fast");
});
});
</script>
</body>
</html>