/** * 文档的列表 * @author xurc * @date 2020-10-23 */ layui.define(['layer','element','form','table','upload','dynamicCondition' ],function(exports){ var webUtil = $webUtil; var Class = function(){ this.MODELNAME = "platform/fileManage/VciFileList"; this.moduleKey = "VciFileList"; this.backPath = configData.compatibility?path:configData.fileServicePath; this.url = { // controller:'vciFileDocClassifyController/', controller:'vciFileQueryController/', dataGrid:'gridFiles', upload:'vciFileUploadController/uploadFile',//上传文件 reviseByFileOid:'vciFileUploadController/uploadFile',//修改文件 deleteUrl:'vciFileDownloadController/deleteFile', downloadByFileOid:'vciFileDownloadController/downloadByFileOid',//下载文件 }; this.getContent=function(){ var that = this; var html = ""; html = [ '
', '
', '
', that.getToolbarHtml(), '
', '', '
', '
', '
' ].join(""); return html; }; this.getToolbarHtml =function(){ var that = this; var html = [ '
', '', '', '', '', '', '
' ].join(""); return html; }; this.createSearchHtml = function () { var that = this; webUtil.bindDefultButtonLisenter(that, that.id); webUtil.createSearchHtml({id:"编号",name:"名称"} ,$("[layui-filter='toolbar_" + that.id + "']"), "table_" + that.id); }; this.init = function(){ var that = this; webUtil.copyConfig(that,that.moduleKey); that.initMainTable(); that.createSearchHtml(); }; this.initMainTable = function (parentFieldName) { var that = this; var table = layui.table; that.checkColumns(); var tableWidth = $("#border_" + that.id).width(); var options = { elem: '#table_' + that.id, id: 'table_' + that.id, backPath:that.backPath, url: that.url.controller + that.url.dataGrid, page: { limit: 20, page: 1 }, extraParams: { ownbizOid: 'share', ownbizBtm: 'share' }, width:tableWidth, cols: [that.columns], done:function(res,cur,total){ if(!that.fristMainLoad ){ }else{ if(total>0) { table.selectRecord('table_' + that.id, {index:0}); } } that.fristMainLoad = true; } }; if(parentFieldName){ options.treeConfig = { treepid:parentFieldName, treeid:'id', showField:'name' }; } table.render(options); }; this.checkColumns = function(){ var that = this; var table = layui.table; if(that.columns==null || that.columns.length==0){ that.columns = [table.getIndexColumn(),table.getCheckColumn(), { field:'name', title:'文件名称', width:250 },{ field:'fileSize', title:'大小', width:80, templet:function(d){ if(!d.fileSize || d.fileSize == null || d.fileSize*1 == 0 || isNaN(d.fileSize*1) ){ return "未知大小"; }else{ //原始大小是B var filesize = d.fileSize*1; if(filesize>1024*1024*1024*1024){ return parseInt(filesize/(1024*1024*1024*1024)) + "TB"; }else if(filesize> 1024*1024*1024){ return parseInt(filesize/(1024*1024*1024)) + "GB"; }else if(filesize> 1024*1024){ return parseInt(filesize/(1024*1024)) + "MB"; }else if(filesize> 1024){ return parseInt(filesize/1024) + "KB"; }else { return filesize + "B"; } } } },{ field:'secretGradeText', title:'密级', width:60 },{ field:'fileDocClassifyName', title:'文档类型', width:130 },{ field:'creator', title:'上传人/时间', width:210, templet:function(d){ return d.creator + "(" + $webUtil.formateDateTimeNoSecond(d.createTime) + ")"; } },{ field:'downloadCount', title:'下载数量', width:90 }]; } }; this.getFormItems = function(onlyShow) { var that = this; var table = layui.table; return [ { field:'name', title:'文件名称', required: true, type: 'text', readOnly:onlyShow },{ field: 'secretGrade', title: '密级', required: true, readOnly:onlyShow, type:'combox', data:[{"key":"10","value":"内部"},{"key":"20","value":"一般"},{"key":"30","value":"重要"}] }]; }; this.UPLOAD = function(){ var that = this; that.uploadOrEdit(true); }; this.EDIT = function(){ var that = this; var selectData = layui.table.checkStatus("table_" + that.id).data[0]; if(selectData == undefined) { webUtil.showErrorMsg('请选择一条数据!'); return false; } that.uploadOrEdit(false,selectData.oid); }; this.uploadOrEdit = function(add,fileoid){ var that = this; var form = layui.form; var filter ='upload_form'+that.id; var uploadIndex = layer.open({ type:1, title: add ? '上传文件(最大3G)' : '修改文件(最大3G)', skin:'layui-layer-lan', content:'
', area:['350px','200px'], closeBtn:2, shade:true, shadeClose:true, resize: false, success:function(layero){ form.addItems(filter,[{ field:'ownBtmname', title:'ownBtmname', hidden:true },{ field:'ownbizOid', title:'ownbizOid', hidden:true },{ field:'fileDocClassify', title:'文件类型', hidden:true },{ field:'fileDocClassifyName', title:'文件类型名称', hidden:true }], function(){ form.setValues({ ownBtmname: "share", ownbizOid: "share", fileDocClassify: "ADMIN_SHARE", fileDocClassifyName: "管理员共享文件" },filter); if ($("#button_" + filter)) { $("#button_" + filter).remove(); } if($("#button_"+filter).length <= 0) { $("#form_" + filter).append(''); } var upload = layui.upload; //执行实例 var uploadForm = upload.render({ elem: '#button_' + filter //绑定元素 ,accept:'file' ,auto:true ,url: that.backPath + that.url.upload//上传接口 ,before:function(obj){ if(form.validata(filter)){ var values = form.getValues(filter); if(!add) { values.fileOid = fileoid; values.oid = fileoid; values.updateFileFlag = true; } obj.setData(values); $webUtil.showProgress("文件上传中……"); return true; }else{ $webUtil.showErrorMsg("请先输入内容后再选择文件"); return false; } } ,done: function(result){ if(result.success){ layer.close(uploadIndex); $webUtil.showMsg(add ? "文件上传成功" : "文件修改成功"); that.refresh(); $webUtil.closeProgress(); }else{ $webUtil.showErrorMsg(result.msg); $webUtil.closeProgress(); } } ,error: function(){ //请求异常回调 $webUtil.showErrorMsg("上传文件出现了异常"); } }); } ,{},{ defaultColumnOneRow:1 }); } }); }; this.DEL = function(){ var that = this; var oid = webUtil.getOidFromGrid("table_" +that.id,true,true); if(!oid){ return false; } var ts= webUtil.getOidFromGrid("table_" +that.id,false,false,"ts"); webUtil.showConfirmMsg("是否删除这条数据?如果被引用将不能被删除!",function () { webUtil.deleteRequest(that.url.deleteUrl,{fileOids:oid,ts:ts},function(result){ if(result.success){ webUtil.showMsgFromResult(result,"删除成功"); that.refresh(); }else{ webUtil.showErrorMsg(result.msg); } },function(xhr,err){ webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); },that.backPath); }); }; this.DOWNLOADFILE = function(thisButtonPoint){ //下载按钮 var that = this; var selectData = layui.table.checkStatus("table_" + that.id).data[0]; if(selectData == undefined) { webUtil.showErrorMsg('请选择数据!'); return false; } that.downloadFileByOid(selectData.oid); }; this.downloadFileByOid =function(oid){ var that = this; //下载文件 var iframeId = MD5(oid + $webUtil.getSystemVar($webUtil.systemValueKey.userOid)); $webUtil.fileDownload(that.backPath + that.url.downloadByFileOid + "?fileOid=" + oid +"&downloadUUID=" + iframeId); }; this.refresh = function () { var that = this; var that = this; layui.table.reload("table_" + that.id); }; }; var cs = new Class(); exports(cs.MODELNAME,cs); });