/** * Created by Gt680 on 17/7/17. * 后台 Js */ //> 加载完成后执行 $(function () { // 添加后台 LogOut 退出弹框提示 var logOut = function (event) { layer.open({ id: 'oneLogOut', title: false, content: '确认安全退出?', icon: 3, btn: ['退出', '取消'], btn1: function (index, layero) { //> 安全退出 关闭层 event.preventDefault(); document.getElementById('logout-form').submit(); layer.close(index); }, btn2: function (index, layero) { //> 阻止退出 layer.close(index); return false; }, cancel: function (index, layero) { //> 阻止退出 layer.close(index); return false; } }) }; // 延迟绑定 登出onclick事件 $(document).on('click',".logOut",function (event) { logOut(event); }); // 后台 锁屏 var lock = function(){ layer.open({ btn:['取消'], title:false, icon:4, content: '锁屏', scrollbar: false, anim:3, success:function(layero,index){ var nowTime = (new Date()).toLocaleTimeString(); $(layero).find('div b').text('锁屏:'+nowTime)} }); }; // 延迟绑定 锁屏onclick事件 $("#lock").on('click',function(){ lock(); }); // 缩略图 thumbHover class 属性 var thumbHoverLayer; $(document).on('mouseover', '.thumbHover', function() { thumbHoverLayer = layer.tips('', this, { tips:1, time : 0, area: ['300px', 'auto'] }); }); $(document).on('mouseout', '.thumbHover', function() { layer.close(thumbHoverLayer); }); var t_thumbHoverLayer; $(document).on('click', '.t_thumbHover', function() { // t_thumbHoverLayer = layer.tips('', this, { // tips:1, // time : 0, // area: ['380px', 'auto'] // }); var img_url=$(this).data('img'); img_url=img_url.split(';'); var img_data=[]; for (var img_key in img_url) { img_data[img_key]={ "alt": "img"+img_key, "pid": 666+img_key, //图片id "src": img_url[img_key], //原图地址 "thumb": img_url[img_key] //缩略图地址 } } t_thumbHoverLayer = layer.photos({ photos: { "title": "", //相册标题 "id": 123, //相册id "start": 0, //初始显示的图片序号,默认0 "data":img_data // "data": [ //相册包含的图片,数组格式 // { // "alt": "图片名", // "pid": 666, //图片id // "src": $(this).data('img'), //原图地址 // "thumb": $(this).data('img') //缩略图地址 // }, // // ] } ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数) }); // t_thumbHoverLayer = layer.open({ // type: 2, // content:'', // area: ['300px', '195px'], // maxmin: true // }); }); $(document).on('click', '.del_img', function() { layer.close(t_thumbHoverLayer); }); //> 层管理 存储当前层级关系 window.tips_layer = []; // 新增弹出 $(document).on('click','.createForm',function (event) { var evt = event || window.event; var th = null; if( $(evt.target).is('a') ){ th = $(evt.target); }else{ th = $($(evt.target).closest('a')); } var title = null; var title_name=$(this).data('name'); if( th.data('title') == 'create' ){ //> 新增 title = ''+title_name?title_name:新增+''; var area_width=th.data('area-width')?th.data('area-width'):'60%'; }else if( th.data('title') == 'group' ){ title = ''+(title_name?title_name:列表)+''; var area_width='100%'; }else{ //> 编辑 title = ''+(title_name?title_name:编辑)+''; var _check = $($(evt.target).closest('tr')).find('input[name="btSelectItem"]'); _check.prop('checked',true); var area_width=th.data('area-width')?th.data('area-width'):'60%'; } var zIndex=th.attr('target')*1; console.log(area_width+'---------------------------------------------'+zIndex); if(isNaN(zIndex))zIndex=99; console.log(area_width+'---------------------------------------------'+zIndex); window.createUrl = th.data('url'); var area_height=th.data('area-height')?th.data('area-height'):'60%'; if( th.data('area-width') && th.data('area-height') ){ window.tips_layer.push(layer.open({ type: 1, title: title, closeBtn: 1, time: 0, id: 'createLay'+zIndex, // move: false, maxmin:true, area: [area_width, area_height], scrollbar: false, shadeClose: false, skin: '', zIndex: zIndex, //> 当前设置层级 content: '
', full: function (ele) { // $($(ele).find("#createForm")).css({width:'100%'}); }, cancel: function () { if( window.tipsC ){ for( closeT in window.tipsC){ layer.close(window.tipsC[closeT]); } } if( _check ){ _check.prop('checked',false); } tips_layer.pop(); }, moveEnd: function () { } })); }else if (th.data('max-height') && th.data('max-width')){ window.tips_layer.push(layer.open({ type: 1, title: title, closeBtn: 1, time: 0, id: 'createLay', // move: false, maxmin:true, maxWidth: th.data('max-width'), maxHeight: th.data('max-height'), scrollbar: false, shadeClose: false, skin: '', zIndex: 90, //> 当前设置层级 content: '
', full: function (ele) { // $($(ele).find("#createForm")).css({width:'100%'}); }, cancel: function () { if( window.tipsC ){ for( closeT in window.tipsC){ layer.close(window.tipsC[closeT]); } } if( _check ){ _check.prop('checked',false); } tips_layer.pop(); }, moveEnd: function () { } })); }else { window.tips_layer.push(layer.open({ type: 1, title: title, closeBtn: 1, time: 0, id: 'createLay', // move: false, maxmin:true, maxWidth: 700, maxHeight: 400, scrollbar: false, shadeClose: false, skin: '', zIndex: 90, //> 当前设置层级 content: '
', full: function (ele) { // $($(ele).find("#createForm")).css({width:'100%'}); }, cancel: function () { if( window.tipsC ){ for( closeT in window.tipsC){ layer.close(window.tipsC[closeT]); } } if( _check ){ _check.prop('checked',false); } tips_layer.pop(); }, moveEnd: function () { } })); } }); // bind 全屏弹出 $(document).on('click','.maxOpen',function (event) { var evt = event || window.event; var th = null; if( $(evt.target).is('a') ){ th = $(evt.target); }else{ th = $($(evt.target).closest('a')); } var _check = $($(evt.target).closest('tr')).find('input[name="btSelectItem"]'); _check.prop('checked',true); var indexOpen = layer.open({ type: 2, title: '消息列表', closeBtn: 1, time: 0, id: 'maxOpen', content: th.data('url'), area: ['100%', '100%'], maxmin: true, scrollbar: false, shadeClose: false, fixed: false, resize: false, move: false, zIndex: 91, //> 当前设置层级 full: function (ele) { // $($(ele).find("#createForm")).css({width:'100%'}); }, cancel: function () { _check.prop('checked',false); layer.close(indexOpen); tips_layer = []; //> 全部出栈 }, moveEnd: function () { } }); tips_layer.push(indexOpen); }); // 确认按钮 $(document).on('click', '.layer-button', function (event) { var evt = event || window.event; var th = null; if( $(evt.target).is('a') ){ th = $(evt.target); }else{ th = $($(evt.target).closest('a')); } var _check = $($(evt.target).closest('tr')).find('input[name="btSelectItem"]'); _check.prop('checked',true); var _index_index1 = layer.open({ title: false, content: "确认执行 "+th.html()+" ?", btn: ['执行', '取消'], yes: function () { layer.close(_index_index1); $.ajax({ type: "post", url: th.data('url'), data: {}, dataType: 'json', success: function (data1) { layer.msg(data1.message); refresh(); } }); _check.prop('checked',false); }, btn2: function(){ layer.close(_index_index1); _check.prop('checked',false); return false; }, cancel: function () { layer.close(_index_index1); _check.prop('checked',false); return false; } }); }); // 确认按钮 $(document).on('click', '.layer-button-ask', function (event) { var evt = event || window.event; var th = null; if( $(evt.target).is('a') ){ th = $(evt.target); }else{ th = $($(evt.target).closest('a')); } layer.prompt({ title: "失败原因", formType: 0, maxlength: 250, area: ['600px', '180px'] }, function (value, index, elem){ layer.close(index); $.ajax({ type: "post", url: th.data('url'), data: { mark: value }, dataType: 'json', success: function (data1) { layer.msg(data1.message); refresh(); } }); }); }); }); //> 手动触发一次刷新事件 function refresh() { $("button[name='refresh']").trigger('click'); } // - - - - - - - - - - - - - - - - - - - - bootstrap-table - - - - - - - - - - - - - - - - - //> ajax 请求参数 $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, type: 'post', dataType: 'json' }); //> 字段定义 使用 formatter:yesOrNo // bool_data:{ // 'class' : 'cursor', //> 当前控制样式 // 'url' : 'javascript:;', //> 当前链接Url地址;不写默认值 post 形式 // 'table' : 'table', //> 修改当前表名称 table ; 修改字段来自当前的field字段值 // 'pk' : 'id' //> 主键名称不写默认id主键名称 // } function yesOrNo(value,row,index) { bool_datum = this.bool_data; //> value 当前字段值 //> row 当前tr行元素对象 //> index 当前行索引 0,1,2~... if( value > 0 ){ return ''; }else{ return ''; } } function yesOrNoTwo(value,row,index) { bool_datum = this.bool_data; //> value 当前字段值 //> row 当前tr行元素对象 //> index 当前行索引 0,1,2~... if( value > 0 ){ return ''; }else{ return ''; } } //> 使用规则 // input_data: { // 'class' : 'cursor', //> 当前样式 // 'url' : 'javascript', //> url存在 及请求指定地址修改数据 // 'table' : 'table', //> url为空时采用, // 'pk' : 'id' //> 默认修改主键名称 不写 默认id为主键 // } //> sort 排序字段更改 function inputData(value,row,index) { input_datum = this.input_data; //> 获取上面input_data数据 var html = ''; html = ''; return html; } //> bind 点击事件 $(document).on('click','.input-data',function (event) { var evt = event || window.event; var th = $(evt.target); th.removeClass('classJ'); th.prop('type','number'); }); //> 失去焦点 $(document).on('blur','.input-data',function (event) { var evt = event || window.event; var th = $(evt.target); th.addClass('classJ'); th.prop('type','text'); var value = th.val(); //> 新修改的值 var old = th.data('old'); //> 旧值 var table = th.data('table'); //> table 表名称 var num = new Number(value); var value_t = num.toLocaleString(); var value_tt = parseInt(value_t.replace( /\,/g ,'' )); if( value_tt > 100 || value_tt <= 0){ th.val(old); return false; }else{ if( value == old ){ return false; }else{ var url = ''; //> 判断是否请求 if( th.url == undefined ){ url = window.Domain + '/admin/update_sort'; }else{ url = th.url; } $.ajax({ url: url, type: 'post', dataType: 'json', data: { value: value, id: th.data('id'), field: th.data('field'), table: table }, success: function (data) { if( data.status == 0 ){ //> 请求成功 th.attr('data-old',data.value); th.val(data.value); }else if( data.status == 1 ){ th.val(old); layer.msg('保存失败!!!',{icon:2,time:2000}); }else{ th.val(old); layer.msg('非法修改数据!!!',{icon:4,time:2000}); } }, error: function () { th.val(old); layer.msg('请求失败,网络问题!!!',{icon:4,time:2000}); } }); } } }); //> 字段使用 formatter:thumbFormatter function thumbFormatter(value, row, index) { var html = ''; if (value) { html = ''; } return html; } function cthumbFormatter(value, row, index) { var html = ''; if (value) { html = ''; // for (var img_key in value){ // html += ' '; // } } return html; } function thumbFormatterNum(value, row, index) { var html = ''; console.log(value); if (value) { for (var img_key in value){ html += ' '; } } return html; } function operateFormatterSH(value, row, index) { if( row.status == 1 ){ if (this.btn_group) { var html = '
'; var btns; if (typeof this.btn_group == 'function') { btns = this.btn_group(row, index); } else { btns = this.btn_group; } var item; var pkId = this.pkId?this.pkId:'id'; for(var i in btns) { item = btns[i]; url = item.url?item.url:''; url = url.replace('-val-', row[pkId]); confirm_url = item.confirm_url?item.confirm_url:''; confirm_url = confirm_url.replace('-val-', row[pkId]); title = item.title?item.title:'edit'; name = item.name?item.name:''; console.log(name); html += ''+item.name+''; } html += '
'; } return html; } else{ return "-"; } } //构造操作的按钮 formatter:operateFormatter 预留字段skip表示跳过 // btn_group:[ // { // 'name' : '编辑', // 'url' : '{{ route('cars.edit', ['id'=>'-val-'])}}' // }, // { // 'name' : '删除', // 'class' : 'deleteBtn', //> class标签 // 'target': '_self', //> 标签跳转方式 // 'url' : '{{ route('cars.delete', ['id'=>'-val-'])}}', // 'confirm_url': '{{ route('cars.delete', ['id'=>'-val-'])}}' //> 确认按钮 // } // ] function operateFormatter(value, row, index) { if (this.btn_group) { var html = '
'; var btns; if (typeof this.btn_group == 'function') { btns = this.btn_group(row, index); } else { btns = this.btn_group; } var item; var pkId = this.pkId?this.pkId:'id'; for(var i in btns) { item = btns[i]; if( row.skip && item.skip ){ continue; } if( row.skip_one && item.skip_one ){ continue; } if( row.skip_tow && item.skip_tow ){ continue; } url = item.url?item.url:''; url = url.replace('-val-', row[pkId]); confirm_url = item.confirm_url?item.confirm_url:''; confirm_url = confirm_url.replace('-val-', row[pkId]); title = item.title?item.title:'edit'; name = item.name?item.name:''; zIndex = item.zIndex?item.zIndex:''; html += ''+item.name+''; } if( html == '
' ){ html += '--
'; }else{ html += '
'; } } return html; } //> a标签 function aHttp(value, row, index) { var a = ''; if( value ){ a = ''+value+''; } return a; } function aHttpAddress(value, row, index) { var a = ''; if( value ){ str = value.substring(0,9) + '...'; a = ''+str+''; } return a; } function aHttpHash(value, row, index) { var a = ''; if( value ){ str = value.substring(0,9) + '...'; a = ''+str+''; } return a; } //> 字段剪切 function qString(value, row, index) { var str = ''; if( value && value.length > 9 ){ str = value.substring(0,9) + '...'; return ''+str+''; } return ''+value+''; } function qStringOrTrim(value, row, index) { var str = ''; if( value && value.length > 9 ){ str = value.substring(0,9) + '...'; return ''+str+''; }else if( value === null ){ return '-'; } return ''+value+''; } // 发货字段 function quantityOne(value, row, index){ return ''+(value - 4)+''; } //> bind显示事件 移入事件 $(document).on('mouseover','.moveR',function (event) { var evt = event || window.event; var th = $(evt.target); window.moveR = layer.tips(th.data('stringr'),th,{tips:[3,'#20A0FF'],time:0,maxWidth:400}); }); //> bind 移出事件 $(document).on('mouseout','.moveR',function (event) { layer.close(window.moveR); }); //> bootstrap-table 请求对象 var BootStrapInit = { //> 替换参数设置 init: function(models,mainId,init){ var that = this; that.tableSession.init(models); that.bootstrapTable(mainId,init,that); that.buttonFormSearch(init,that); //> 搜索按钮绑定 }, //> bootstrap-table 插件调用 bootstrapTable: function (mainId,init,that) { var tableSession = that.tableSession; var options = { searchForm: 'searchForm', //> 表单搜索id 自定义属性 【*】 url: "", //> 请求url method: "post", //请求类型 POST 、GET contentType: 'application/json', //发送到服务器数据类型(请求头 application/json形式) dataType: 'json', //请求返回数据类型 json toolbar: '#toolbar', //工具按钮用哪个容器 search: false, //显示搜索框(根据客户端搜索意义不大;未请求后台获取数据) showRefresh: true, //是否显示刷新按钮 (根据url地址请求数据) showColumns: true, //是否显示所有的列 minimumCountColumns: 2, //最少允许的列数, striped: true, //隔行变色 pagination: true, //是否显示分页(*) sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*) pageNumber: tableSession.getPage(), //初始化加载第一页,默认第一页 pageSize: tableSession.getPageSize(),//每页的记录行数(*) pageList: [10, 15, 25, 50, 100], //可供选择的每页的行数(*) paginationHAlign: 'right', //指定分页条在水平方向上位置 left / right onlyInfoPagination: false, //true只显示总数 不显示 分页条 cache: false, //是否使用缓存 false:禁用AJAX缓存 sortName: tableSession.getSortedBy(),//默认排序字段 sortable: true, //是否启用排序 sortOrder: tableSession.getOrderBy(),//排序方式 queryParams: that.queryParamsData, //传递参数(*)重写方法 clickToSelect: false, //是否启用点击选中行(对checkbox或rediobox属性有用) idField: 'id', //指定主键列 uniqueId: "id", //每一行的唯一标识,一般为主键列(在tr添加属性data-uniqueid='id'值) showToggle:false, //是否显示详细视图和列表视图的切换按钮 cardView: false, //是否显示详细视图 detailView: false, //是否显示父子表 showPaginationSwitch: true, //隐藏/显示分页条 默认显示 columns: [], onPageChange:function(number, size){//当前页码改变 tableSession.setPage(number); tableSession.setPageSize(size); tableSession.save(); }, onSort: function (name,order) { tableSession.setOrderBy(name); tableSession.setSortedBy(order); tableSession.save(); }, onRefresh: function () { tableSession.setPage(1); tableSession.save(); } }; //> 合并配置 $.extend(options,init); //> 调用Bootstrap-table插件 $('#'+mainId).bootstrapTable(options); }, //> 请求代参方法 queryParamsData: function (params) { var sort = null; var order = null; if( params.sort === 'asc' || params.sort === 'desc' ){ sort = params.sort; order = params.order; }else{ sort = params.order; order = params.sort; } //> params 对象包含指定参数 limit、offset、order、search、sort var formData = { limit: params.limit, //页面大小 offset: params.offset, //页码 orderBy: order, //> order 排序字段 sortedBy: sort, //> asc | desc search: params.search, //> 搜索字段以及搜索规则 pageSize: params.limit, //> 当前页数据 后台分页函数接收该参数paginate($this->request->pageSize) page: params.offset/params.limit + 1, //> 当前页码 searchJoin: 'and' }; //> 自定义参数数据 var temp = {}; //> 获取指定搜索数据 this.searchForm === undefined? formId = this.searchForm: formId = 'searchForm'; var th = $(document).find('#'+formId); var searchDatum = []; //> 处理 input 输入框数据 $(th).find('input').each(function(index,element){ var name = $.trim($(element).prop('name')); var value = $.trim($(element).val()); if( value !== '' ){ searchDatum.push(name+':'+value); } }); //> 处理 select 下拉框、输入数据 $(th).find('select').each(function (index,element) { var name = $.trim($(element).prop('name')); var value = $.trim($(element).val()); if( value !== '' ){ searchDatum.push(name+':'+value); } }); if( searchDatum.length !== 0 ){ //> 合并需要字符串 temp.search = searchDatum.join(';'); } console.log('-------------------------------'); return $.extend(formData,temp); }, tableSession: { //> H5对象存储 data:{}, //> 需要存储的数据 index: null, init: function (index) { this.index = index; this.data = sessionStorage.getItem(this.index); if ( this.data == null ){ this.data = {pageSize:15,page:1,orderBy:null,sortedBy:null}; } else { this.data = JSON.parse(this.data); } }, getData: function(){ return this.data; }, getPage: function () { return this.data.page; }, setPage: function (page) { this.data.page = page; }, getPageSize: function () { return this.data.pageSize; }, setPageSize: function (pageSize) { this.data.pageSize = pageSize; }, getOrderBy: function () { return this.data.orderBy; }, setOrderBy: function (order) { this.data.orderBy = order; }, getSortedBy: function () { return this.data.sortedBy; }, setSortedBy: function(sortedBy){ this.data.sortedBy = sortedBy; }, save: function () { sessionStorage.setItem(this.index,JSON.stringify(this.data)); } }, buttonFormSearch: function (config,that) { //> 搜索按钮绑定 config.searchForm === undefined? formId = config.searchForm: formId = 'searchForm'; if( $(document).find('form').is('#'+formId) ){ //> bind搜索按钮 $(document).find('#'+formId).on('click',' button[type="button"]',function(event){ if( $(document).find('div.bootstrap-table ul.pagination li').length > 3 && !$(document).find('div.bootstrap-table ul.pagination li').eq(1).is('.active') ){ $(document).find('div.bootstrap-table ul.pagination li').eq(1).find('a').trigger('click'); }else{ refresh(); //> 刷新页面 } }); } } }; //> 加载自定义皮肤 样式 layer.config({ extend: 'my-skin/skin.css' }); //> 绑定删除按钮 $(document).on('click','.deleteBtn',function (event) { var evt = event || window.event; var _check = $($(evt.target).closest('tr')).find('input[name="btSelectItem"]'); _check.prop('checked',true); var index = layer.open({ type: 0, content: '确认是否删除操作?', icon: 3, title: false, btn: ['删除','取消'], skin: 'demo-class-one', closeBtn: 1, anim:4, scrollbar:false, yes: function(){ layer.close(index); url = $(evt.target).data('url'); tr = $(evt.target).closest('tr'); deleteAjax(tr,url); return false; }, btn2: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); _check.prop('checked',false); return false; }, cancel: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); _check.prop('checked',false); return false; } }); //> 阻止a标签默认事件 return false; }); // 恢复 $(document).on('click','.restoreBtn',function (event) { var evt = event || window.event; var _check = $($(evt.target).closest('tr')).find('input[name="btSelectItem"]'); _check.prop('checked',true); var index = layer.open({ type: 0, content: '确认是否执行恢复操作?', icon: 3, title: false, btn: ['恢复','取消'], skin: 'demo-class-one', closeBtn: 1, anim:4, scrollbar:false, yes: function(){ layer.close(index); url = $(evt.target).data('url'); tr = $(evt.target).closest('tr'); deleteAjax(tr,url); return false; }, btn2: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); _check.prop('checked',false); return false; }, cancel: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); _check.prop('checked',false); return false; } }); //> 阻止a标签默认事件 return false; }); //> 删除调用ajax function deleteAjax(tr,url) { $.ajax({ url: url, type: 'post', data: {}, dataType: 'json', success: function ( returnDatum ) { if( returnDatum.status === 0 ){ //> 删除成功 $(tr).remove(); //> 删除指定行 //> 提示删除信息 layer.msg('操作成功',{ icon: 1, time: 1500 }); }else if( returnDatum.status === 1 ){ //> 提示删除信息 layer.msg(returnDatum.message,{ icon: 2, time: 2000 }); }else{ layer.msg(returnDatum.message,{ icon: 4, time: 2000 }); } }, error: function () { layer.msg('服务器繁忙,请稍后再试!!!',{ icon:3, time:2000 }); } }); } //> 绑定点击按钮 formatter:yesOrNo 函数调用ajax $(document).on('click',".checkJ",function(event){ var evt = event || window.event; var th = $(evt.target); var id = th.data('id'); var table = th.data('table'); var field = th.data('field'); var url = th.data('url')?th.data('url'):''; var pk = th.data('pk')?th.data('pk'):'id'; if( !url ){url = window.Domain + '/admin/switch';} $.ajax({ url: url, type: "POST", data: {'id' : id,'field' : field,'table' : table,'pk' : pk}, success: function (msg) { if( msg.status == 0 ){ if( msg.value ){ //> true th.removeClass('fa-times-circle'); th.removeAttr('style'); th.css({color: 'green',fontSize: '24px'}); th.addClass('fa-check-circle'); }else{ //> false th.removeClass('fa-check-circle'); th.removeAttr('style'); th.css({fontSize: '24px'}); th.addClass('fa-times-circle'); } }else{ //> 修改失败 layer.msg(msg.message,{icon:2,time:2000}); } }, error: function () { layer.msg('服务器繁忙,请稍后再试!!!',{icon:3,time:2000}); } }); }); //> 多项绑定删除按钮 $(document).on('click','#sendInfo',function(event){ var evt = event || window.event; var data = []; //> 提示对话框 index = layer.open({ type: 0, content: '是否执行本操作?', icon: 3, title: false, btn: ['执行','取消'], skin: 'demo-class-one', closeBtn: 1, anim:6, yes: function(){ layer.close(index); if( ! $(evt.target).is('button') ){ url = $($(evt.target).closest('button')).data('url'); }else{ url = $(evt.target).data('url'); } destroyIds(url,[].join(';')); return false; }, btn2: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); return false; }, cancel: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); return false; } }); }); //> 多项绑定删除按钮 $(document).on('click','#deleteAll',function(event){ var evt = event || window.event; var th = $(document).find('table tbody tr'); var data = []; th.each(function (index,value) { bool = $(value).is('.selected'); if( bool ){ data.push($(value).data('uniqueid')); } }); if( data.length === 0 ) { layer.msg('请选择删除选项',{icon:3,time:2000}); return false; }else{ //> 提示对话框 index = layer.open({ type: 0, content: '确认是否批量删除操作?', icon: 3, title: false, btn: ['删除','取消'], skin: 'demo-class-one', closeBtn: 1, anim:6, yes: function(){ layer.close(index); if( ! $(evt.target).is('button') ){ url = $($(evt.target).closest('button')).data('url'); }else{ url = $(evt.target).data('url'); } destroyIds(url,data.join(';')); return false; }, btn2: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); return false; }, cancel: function () { //> 阻止事件冒泡 evt.preventDefault(); //> 关闭层 layer.close(index); return false; } }); } }); function destroyIds(url,params) { $.ajax({ url: url, type: 'post', data: {'params':params}, success: function(returnDatum){ if( returnDatum.status ){ layer.msg(returnDatum.message,{icon:2,time:2000}); }else{ layer.msg('操作成功!',{icon:1,time:1500}); refresh(); } }, error: function(){ layer.msg('服务器繁忙,请稍后再试!!!',{icon:3,time:2000}); } }); } //> WeChat刷新缓存 $(document).on('click','#refresh-wx-datum',function (event) { var evt = event || window.event; var url = content = ""; var _this = null; //> 提示对话框 if( ! $(evt.target).is('button') ){ _this = $($(evt.target).closest('button')); url = $($(evt.target).closest('button')).data('url'); }else{ _this = $(evt.target); url = $(evt.target).data('url'); } content = "确认刷新"+_this.data('title')+"!?不建议多次刷新缓存"; var __wx_index = layer.open({ type: 0, title: false, content: content, icon: 4, btn: ['确定','删除'], yes: function () { layer.close( __wx_index ); $.ajax({ type: 'post', url: url, data: {}, dataType: 'json', success: function (msg) { if( msg.status === 0 ){ layer.msg(msg.message,{ icon: 1, time: 2000 }); }else{ layer.msg(msg.message,{ icon: 1, time: 1500 }); } }, error: function () { layer.msg('服务器繁忙,请稍后再试!!!',{icon:3,time:2000}); } }); }, cancel: function () { layer.close( __wx_index ); } }); }); // 绑定复制按钮 $(document).on('click', '.copyNoticeLink', function (event) { var evt = event || window.event; var th = null; if( $(evt.target).is('a') ){ th = $(evt.target); }else{ th = $($(evt.target).closest('a')); } var oInput = document.createElement('input'); oInput.value = th.data('url'); document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 oInput.className = 'oInput'; oInput.style.display='none'; layer.msg("复制成功!"); });