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%';
}
layer.open({
type: 2,
title: false,
offset: 'r',
anim: 'slideLeft',
closeBtn: 0,
content: url,
area: [sideWidth, '100%'],
skin:'layui-layer-gougu-admin',
end: function(){
$(parent.$('.express-close')).removeClass('parent-colse');
$('body').removeClass('right-open');
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);
});
setTimeout(function(){
$(parent.$('.express-close')).addClass('parent-colse');
},500)
}
})
},
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,reload) {
//延迟关闭,一般是在编辑完页面数据后需要自动关闭页面用到
if (typeof(delay) === "undefined" || delay === '') {
delay = 0;
}
if (typeof(table) === "undefined" || table === '') {
table = 'pageTable';
}
if (typeof(reload) === "undefined" || reload === '') {
reload = 1;
}
if(delay>0){
setTimeout(function () {
$('.express-close').last().click();
}, delay);
}else{
$('.express-close').last().click();
}
if (layui[table]) {
layui[table].reload();
}
else{
if(reload==1){
tool.reload(delay);
}
}
},
ajax: function (options, callback, clickbtn) {
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);
}
},
beforeSend:function(){
if (clickbtn && typeof clickbtn === 'object') {
clickbtn.attr('disabled',true).html('提交中 ...');
}
},
complete: function () {
if (clickbtn && typeof clickbtn === 'object') {
setTimeout(function(){
clickbtn.removeAttr('disabled').html('立即提交');
},1000);
}
}
}, options);
$.ajax(opts);
},
get: function (url, data, callback) {
this.ajax({url: url,type: "GET",data: data}, callback);
},
post: function (url, data, callback, clickbtn) {
this.ajax({url: url,type: "POST",data: data}, callback, clickbtn);
},
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{
if(parent.parent.parent.parent.layui.admin){
return parent.parent.parent.parent.layui.admin;
}
else{
return false;
}
}
}
}
},
sideClose(delay,table,reload){
if(parent.layui.tool){
parent.layui.tool.close(delay,table,reload);
}
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('复制成功');
}
},
//格式化文件大小
renderSize:function(val){
if(null==val||val==''){
return "0 Bytes";
}
var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB");
var index=0;
var srcsize = parseFloat(val);
index=Math.floor(Math.log(srcsize)/Math.log(1024));
var size =srcsize/Math.pow(1024,index);
size=size.toFixed(2);//保留的小数位数
return size+unitArr[index];
},
//格式化附件展示
fileCard:function(file,view){
if(!file.hasOwnProperty('file_id')){
file['file_id'] = file['id'];
}
let image=['jpg','jpeg','png','gif'];
let office=['doc','docx','xls','xlsx','ppt','pptx'];
let type_icon = 'icon-xiangmuguanli';
let type = 0;//0下载+重命名+删除,1下载+查看+重命名+删除,2下载+查看+编辑+重命名+删除
let ext = 'zip';
let view_btn = '';
if(file['fileext'] == 'pdf'){
type_icon = 'icon-kejian';
ext = 'pdf';
type = 1;
}
if(image.includes(file['fileext'])){
type_icon = 'icon-sucaiguanli';
ext = 'image';
type = 1;
}
if(office.includes(file['fileext'])){
type_icon = 'icon-shenbao';
ext = 'office';
type = 1;
}
if(view == ''){
view_btn = '';
}
else{
view_btn = '';
}
let file_del='';
if(file['delete_time'] > 0){
file_del = 'file-hasdelete';
}
let item = '\
\
\
'+file['name']+'
\
'+this.renderSize(file['filesize'])+','+layui.util.toDateString(file['create_time']*1000, 'yyyy-MM-dd hh:mm:ss')+'
\
\
'+view_btn+'
\
';
return item;
}
};
//时间选择快捷操作
$('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清除'
let ctrl_types = ['下载','查看','编辑','重命名','删除','移动','标星','取消标星','还原','清除'];
let ctrls=[];
for(let i=0;i