layui.define(function (exports) { let MOD_NAME = 'tool',dropdown=layui.dropdown; let tool = { loading: false, expressClose:function(index){return '
\
\
\ \ \ \ \ \
\
\ \
\
\
' }, side: function (url, width) { let that = this; if (that.loading == true) { return false; } that.loading = true; sideWidth = '80%'; if(window.innerWidth>1366 && window.innerWidth<=1600){ sideWidth = '86%'; } if(window.innerWidth>1000 && window.innerWidth<=1440){ sideWidth = '93%'; } if(window.innerWidth<=1000){ sideWidth = '95%'; } $(parent.$('.express-close')).addClass('parent-colse'); layer.open({ type: 2, title: false, offset: 'r', anim: 'slideLeft', closeBtn: 0, content: url, area: [sideWidth, '100%'], skin:'layui-layer-gougu-admin', end: function(){ $('body').removeClass('right-open'); $(parent.$('.express-close')).removeClass('parent-colse'); if (layui.pageTable && layui.pageTable.resize) { layui.pageTable.resize(); } }, success: function (obj, index) { $('body').addClass('right-open'); obj.append(that.expressClose(index)); that.loading = false; obj.on('click','.express-close', function () { layer.close(index); }) } }) }, box: function (url,title="内容", width=720,height=405) { let that = this; if (that.loading == true) { return false; } that.loading = true; layer.open({ type: 2, title: title, content: url, area: [width+'px', height+'px'], maxmin: true, end: function(){ if (layui.pageTable && layui.pageTable.resize) { layui.pageTable.resize(); } }, success: function (obj, index) { let btn = ''; obj.append(btn); that.loading = false; obj.on('click','.express-close', function () { layer.close(index); }) } }) }, //右侧ajax请求的方式打开页面参考勾股DEV open: function (url, width) { let that = this; if (that.loading == true) { return false; } that.loading = true; let countWidth = window.innerWidth-(window.innerWidth*0.5)+456; if(window.innerWidth<=1000){ countWidth = 750; } if (width && width > 0) { sideWidth = width + 'px'; } else{ sideWidth = countWidth + 'px'; } $.ajax({ url: url, type: "GET", timeout: 10000, success: function (res) { if (res['code'] && res['code'] > 0) { layer.msg(res.msg); return false; } let index = timestamp = new Date().getTime(); let express = '
' + res + '
'+that.expressClose(index)+'
'; $('body').append(express).addClass('right-open'); $('#expressMask').fadeIn(200); $('#expressLayer').animate({ 'right': 0 }, 200, 'linear', function () { if (typeof (openInit) == "function") { openInit(); } }); that.loading = false; //关闭 $('body').on('click','.express-close', function () { $('#expressMask').fadeOut(100); $('body').removeClass('right-open'); let op_width = $('#expressLayer').outerWidth(); $('#expressLayer').animate({ left: '+=' + op_width + 'px' }, 200, 'linear', function () { $('#expressLayer').remove(); $('#expressMask').remove(); if (layui.pageTable) { layui.pageTable.resize(); } }) }) $(window).resize(function () { let resizeWidth = window.innerWidth-(window.innerWidth*0.5)+456; if(window.innerWidth<=1000){ resizeWidth = 750; } $('#expressLayer').width(resizeWidth); }) }, error: function (xhr, textstatus, thrown) { console.log('错误'); }, complete: function () { that.loading = false; } }); }, load: function (url) { let that = this; if (that.loading == true) { return false; } that.loading = true; $.ajax({ url: url, type: "GET", timeout: 10000, success: function (res) { if (res['code'] && res['code'] > 0) { layer.msg(res.msg); return false; } $('#articleLayer').html(res); openInit(); } , error: function (xhr, textstatus, thrown) { console.log('错误'); }, complete: function () { that.loading = false; } }); }, page: function (url) { let that = this; if (that.loading == true) { return false; } that.loading = true; $.ajax({ url: url, type: "GET", timeout: 10000, success: function (res) { if (res['code'] && res['code'] > 0) { layer.msg(res.msg); return false; } $('#pageBox').html(res); pageInit(); }, error: function (xhr, textstatus, thrown) { console.log('错误'); }, complete: function () { that.loading = false; } }); }, reload: function (delay) { //延迟刷新,一般是在编辑完页面数据后需要自动关闭页面用到 if(delay && delay>0){ setTimeout(function () { location.reload(); }, delay); }else{ location.reload(); } }, ask:function(tips,yes,cancel){ layer.confirm(tips, { icon: 3, title: '提示', success:function(){ $(parent.$('.express-close')).addClass('parent-colse'); }, end:function(){ $(parent.$('.express-close')).removeClass('parent-colse'); } }, function (index) { if (yes && typeof yes === 'function') { yes(); } layer.close(index); }, function (index) { if (cancel && typeof cancel === 'function') { cancel(); } layer.close(index); }); }, close: function (delay,table) { //延迟关闭,一般是在编辑完页面数据后需要自动关闭页面用到 if(delay && delay>0){ setTimeout(function () { $('.express-close').last().click(); }, delay); }else{ $('.express-close').last().click(); } if (typeof(table) == "undefined" || table == '') { table = 'pageTable'; } if (layui[table]) { layui[table].reload(); } else{ tool.reload(delay); } }, ajax: function (options, callback) { let format = 'json'; if (options.hasOwnProperty('data')) { format = options.data.hasOwnProperty('format') ? options.data.format : 'json'; } callback = callback || options.success; callback && delete options.success; let optsetting = { timeout: 10000 }; if (format == 'jsonp') { optsetting = { timeout: 10000, dataType: 'jsonp', jsonp: 'callback' } } let opts = $.extend({}, optsetting, { success: function (res) { if (callback && typeof callback === 'function') { callback(res); } } }, options); $.ajax(opts); }, get: function (url, data, callback) { this.ajax({url: url,type: "GET",data: data}, callback); }, post: function (url, data, callback) { this.ajax({url: url,type: "POST",data: data}, callback); }, put: function (url, data, callback) { this.ajax({url: url,type: "PUT",data: data}, callback); }, delete: function (url, data, callback) { this.ajax({url: url,type: "DELETE",data: data}, callback); }, parentAdmin:function () { if(parent.layui.admin){ return parent.layui.admin; } else{ if(parent.parent.layui.admin){ return parent.parent.layui.admin; } else{ if(parent.parent.parent.layui.admin){ return parent.parent.parent.layui.admin; } else{ return false; } } } }, sideClose(delay,table){ if(parent.layui.tool){ parent.layui.tool.close(delay,table); } else{ console.log('父页面没引用tool模块'); } }, tabAdd:function(url,title,id){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.sonAdd(url,title,id); } }, tabClose:function(){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.sonClose(); } }, tabDelete:function(id){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.tabDelete(id); } }, tabChange:function(id){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.tabChange(id); } }, tabRefresh:function(id){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.refresh(id); } }, officeView:function(id,mode){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.officeView(id,mode); } }, pdfView:function(href){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.pdfView(href); } }, photoView:function(href){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.photoView(href); } }, videoView:function(href){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.videoView(href); } }, audioView:function(href){ let parentAdmin = this.parentAdmin(); if(parentAdmin){ parentAdmin.audioView(href); } }, articleView:function(fileid) { tool.side('/disk/index/view_article?id='+fileid); }, articleEdit:function(fileid) { tool.side('/disk/index/add_article?id='+fileid); }, downloadFile:function(url, fileName) { let link = document.createElement("a"); link.href = url; link.download = fileName; link.click(); layer.msg('文件下载中...', {time: 2000}); }, copyCtrl:function(content) { var save = function(e){ e.clipboardData.setData('text/plain', content); e.preventDefault(); } document.addEventListener('copy', save); document.execCommand('copy'); document.removeEventListener('copy',save); if (content != '') { layer.msg('复制成功'); } } }; //时间选择快捷操作 $('body').on('click', '.tool-time', function () { let that = $(this); let type = that.data('type'); let range = that.data('range'); let min = that.data('min'); let max = that.data('max'); let format = that.data('format'); if (typeof(type) == "undefined" || type === '') { type = 'date'; } if (typeof(range) == "undefined" || type === '') { range = false; } if (typeof(min) == "undefined" || min === '') { min = '1900-1-1'; } if (typeof(max) == "undefined" || max === '') { max = '2099-1-1'; } if (typeof(format) == "undefined" || format === '') { layui.laydate.render({ elem: that, show: true, type: type, range: range, min: min, max: max, fullPanel: true }); }else{ layui.laydate.render({ elem: that, show: true, type: type, range: range, min: min, max: max, format:format, fullPanel: true }); } return false; }); //附件操作 const ctrlBtn=function(ctrl){ //操作按钮'0下载','1查看','2编辑','3重命名','4删除','5移动','6分享','7取消分享','8标星','9取消标星','10还原','11清除' let ctrl_types = ['下载','查看','编辑','重命名','删除','移动','分享','取消分享','标星','取消标星','还原','清除']; let ctrls=[]; for(let i=0;i