获取上传文件路径等信息
/*js 获取表单信息*/ result.data.diseaseControlReportFile.xxxx
//控制器
@RequestMapping("/detail")
@ResponseBody
public ResponseData detail(NewDiseaseControlParam newDiseaseControlParam) {
NewDiseaseControl detail = this.newDiseaseControlService.getById(newDiseaseControlParam.getId());
if (ToolUtil.isNotEmpty(detail.getDiseaseControlReportFileId()))//获取文件id
{
FileInfo diseaseControlReportFile = fileInfoService.getOne(new QueryWrapper<FileInfo>().eq("file_id", detail.getDiseaseControlReportFileId()));//mybaitspuls
newDiseaseControlParam.setDiseaseControlReportFile(diseaseControlReportFile);
}
BeanUtil.copyProperties(detail, newDiseaseControlParam);
return ResponseData.success(newDiseaseControlParam);
}
//model类param NewDiseaseControlParam
private FileInfo diseaseControlReportFile;
上传下载文件
js:
upload.render({
elem: '#upload'
,url: Feng.ctxPath + '/system/upload'
,accept: 'file'
,number: 1
,choose: function(obj){
obj.preview(function(index, file, result){
NewDiseaseControlInfoDlg.data.fileName = file.name;
})
}
,done: function(res, index, upload){ //成功的回调
Feng.success("上传文件成功")
$("#upload").css("display","none")
NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = res.data.fileId
$("#diseaseControlReportFileId").append('<div class="setFile" id="'+NewDiseaseControlInfoDlg.data.diseaseControlReportFileId+'">'+NewDiseaseControlInfoDlg.data.fileName +
'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" type="button" style="margin: 7px;">删除</button></div>')
//删除
$('.demo-delete').click(function (){
$(this).parent("div").remove();
$("#upload").css("display","block")
NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = "";
// NewDiseaseControlInfoDlg.data.approveStatisticalReportFileIds.splice($(this).parent("div").attr("id"),1);
Feng.success("文件删除成功");
})
}
,error: function(index, upload){ //错误回调
Feng.error("上传文件失败!");
}
});
//获取详情信息,填充表单
var ajax = new $ax(Feng.ctxPath + "/newDiseaseControl/detail?id=" + Feng.getUrlParam("id"));
var result = ajax.start();
if(result.data.diseaseControlReportFileId !=null && result.data.diseaseControlReportFileId !=undefined && result.data.diseaseControlReportFileId !=""){
$("#diseaseControlReportFileId").append('<div><a class="setdiseaseControlReportFileId" itemAttr='+result.data.diseaseControlReportFile.filePath+'>'+result.data.diseaseControlReportFile.fileName+'</a>' +
'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete1" type="button" style="margin: 7px;">删除</button></div>')
}else {
$("#diseaseControlReportFileId").append('<div class="setdiseaseControlReportFileId">'+'无附件'+
'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete1" type="button" style="margin: 7px;">删除</button></div>')
};
$('.demo-delete1').click(function (){
$(this).parent("div").remove();
$("#upload").css("display","block");
NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = "";
Feng.success("文件删除成功");
})
form.val('newDiseaseControlForm', result.data);
//表单提交事件
form.on('submit(btnSubmit)', function (data) {
data.field.diseaseControlReportFileId = NewDiseaseControlInfoDlg.data.diseaseControlReportFileId;
//网页
<button type="button" class="layui-btn layui-btn-normal" id="upload">点击上传</button>
<div class="file" id="diseaseControlReportFileId" name="diseaseControlReportFileId">
</div>
多文件上传根据html,div判断是否上传,先转jQuery
data.field.approveStatisticalReportFileIds=","
var fileDivs = $(".setword-show")
$.each(fileDivs, function (index,item) {
data.field.approveStatisticalReportFileIds += ($(item).attr(("data-file-id")))+","
})
console.log(data.field.approveStatisticalReportFileIds);
layui 字典,下拉选择
NewTageSchoolInfoDlg.initDict = function (dictTypeCode, selectName) {
return new Promise(function (door, err) {
$.post(Feng.ctxPath + "/dict/listDictsByCode", {"dictTypeCode": dictTypeCode}, function (response) {
console.log(response);
$.each(response.data, function (index, item) {
$("[name=" + selectName + "]").append("<option value='" + item.name + "'>" + item.name + "</option>")
})
form.render("select");
door(true);
})
})
}
Promise.all([
NewTageSchoolInfoDlg.initDict("SCHOOL_TYPE","schoolType"),
]).then(res => {
form.val('newTageSchoolForm', result.data);
form.render("select");
})
日期范围限定layui
var startTime = laydate.render({ elem: '#startMonth' ,type:'month' , done: function (value,date) { console.log(value,date) endTime.config.min = { year: date.year, month: date.month - 1,//关键 date: date.date, hours: date.hours, minutes: date.minutes, seconds: date.seconds }; } }); var endTime = laydate.render({ elem:'#endMonth' ,type:'month' , done: function (value,date) { startTime.config.max = { year: date.year, month: date.month - 1,//关键 date: date.date, hours: date.hours, minutes: date.minutes, seconds: date.seconds }; } })
不同人不同权限shiro.hasPermission
创建新菜单然后配置权限
@if(shiro.hasPermission("/newAirPollution/edit")){ <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</ a> @}
通过流下载文件
@ResponseBody @RequestMapping("/download") public HttpServletResponse download(String fileid,HttpServletResponse response) throws Exception{ //通过文件id获取文件相关内容 FileInfo File = fileInfoService.getById(fileid); String path = File.getFilePath(); File file = new File(path); String filename = File.getFileName(); String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase(); // 以流的形式下载文件。 InputStream fis = new BufferedInputStream(new FileInputStream(path)); byte[] buffer =new byte[fis.available()]; fis.read(buffer); fis.close(); // 设置response的Header response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes())); response.addHeader("Content-Length", "" + file.length()); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream;charset=UTF-8"); toClient.write(buffer); toClient.flush(); toClient.close(); return response; }
var fileid = result.data.reportContentFile.fileId; $(".download1").click(function (){ window.open(Feng.ctxPath + "/newSociologySecurity/download?fileid="+fileid); })
传递url:
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z