12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- /**
- * 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: '<b>锁屏</b>',
- 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('<img src="'+$(this).data('img')+'" style="width:100%;" />', 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('<img class="del_img" src="'+$(this).data('img')+'" style="width:100%;" />', 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:'<img class="del_img" src="'+$(this).data('img')+'" style="width:100%;" />',
- // 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 = '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <strong>'+title_name?title_name:新增+'</strong>';
- var area_width=th.data('area-width')?th.data('area-width'):'60%';
- }else if( th.data('title') == 'group' ){
- title = '<span class="glyphicon glyphicon-list" aria-hidden="true"></span> <strong>'+(title_name?title_name:列表)+'</strong>';
- var area_width='100%';
- }else{
- //> 编辑
- title = '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span> <strong>'+(title_name?title_name:编辑)+'</strong>';
- 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: '<div id="createForm"></div><script>var load = layer.load();$.ajax({url:window.createUrl,type:"get",async:true,dataType:"html",data:{},success:function(data){layer.close(load);$("#createForm").html(data)},error:function(){layer.close(load);$("#createForm").html("<div class=\'text-center\' style=\'margin-top:150px;\'>加载失败...</div>")}});</script>',
- 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: '<div id="createForm" style="width:'+th.data('max-width')+'px;height:'+th.data('max-width')+'px;"></div><script>var load = layer.load();$.ajax({url:window.createUrl,type:"get",async:true,dataType:"html",data:{},success:function(data){layer.close(load);$("#createForm").html(data)},error:function(){layer.close(load);$("#createForm").html("<div class=\'text-center\' style=\'margin-top:150px;\'>加载失败...</div>")}});</script>',
- 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: '<div id="createForm" style="width:700px;height:400px;"></div><script>var load = layer.load();$.ajax({url:window.createUrl,type:"get",async:true,dataType:"html",data:{},success:function(data){layer.close(load);$("#createForm").html(data)},error:function(){layer.close(load);$("#createForm").html("<div class=\'text-center\' style=\'margin-top:150px;\'>加载失败...</div>")}});</script>',
- 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: '<span class="glyphicon glyphicon-list" aria-hidden="true"></span> <strong>消息列表</strong>',
- 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: "确认执行 <span style='color: orangered;'>"+th.html()+"</span> ?",
- 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 '<i class="fa fa-check-circle checkJ '+(bool_datum.class?bool_datum.class:'')+'" data-field='+(this.field)+(bool_datum.url?' data-url='+bool_datum.url:'')+(bool_datum.table?' data-table='+bool_datum.table:'')+(bool_datum.pk?' data-pk='+bool_datum.pk:'')+' data-id='+row.id+' data-bool="true" style="color: green;font-size: 24px;"></i>';
- }else{
- return '<i class="fa fa-times-circle checkJ '+(bool_datum.class?bool_datum.class:'')+'" data-field='+(this.field)+(bool_datum.url?' data-url='+bool_datum.url:'')+(bool_datum.table?' data-table='+bool_datum.table:'')+(bool_datum.pk?' data-pk='+bool_datum.pk:'')+' data-id='+row.id+' data-bool="false" style="font-size: 24px;"></i>';
- }
- }
- function yesOrNoTwo(value,row,index) {
- bool_datum = this.bool_data;
- //> value 当前字段值
- //> row 当前tr行元素对象
- //> index 当前行索引 0,1,2~...
- if( value > 0 ){
- return '<i class="fa fa-check-circle '+(bool_datum.class?bool_datum.class:'')+'" data-field='+(this.field)+(bool_datum.url?' data-url='+bool_datum.url:'')+(bool_datum.table?' data-table='+bool_datum.table:'')+(bool_datum.pk?' data-pk='+bool_datum.pk:'')+' data-id='+row.id+' data-bool="true" style="color: green;font-size: 24px;"></i>';
- }else{
- return '<i class="fa fa-times-circle '+(bool_datum.class?bool_datum.class:'')+'" data-field='+(this.field)+(bool_datum.url?' data-url='+bool_datum.url:'')+(bool_datum.table?' data-table='+bool_datum.table:'')+(bool_datum.pk?' data-pk='+bool_datum.pk:'')+' data-id='+row.id+' data-bool="false" style="font-size: 24px;"></i>';
- }
- }
- //> 使用规则
- // 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 = '<input type="text" min="1" max="100" data-field="'+(this.field)+'" data-id="'+row.id+'" data-old="'+value+'" class="text-center classJ input-data '+(input_datum.class?input_datum.class:'')+'" value="'+value+'" '+(input_datum.url?' data-url='+input_datum.url:'')+(input_datum.pk?' data-pk='+input_datum.pk:'')+(input_datum.table?' data-table='+input_datum.table:'')+'>';
- 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 = '<i class="fa fa-picture-o thumbHover" style="font-size:21px;" data-img="'+value+'"></i>';
- }
- return html;
- }
- function cthumbFormatter(value, row, index) {
- var html = '';
- if (value) {
- html = '<i class="fa fa-picture-o t_thumbHover" style="font-size:21px;" data-img="'+value+'"></i>';
- // for (var img_key in value){
- // html += '<i class="fa fa-picture-o t_thumbHover" style="font-size:21px;" data-img="'+value[img_key]+'"></i> ';
- // }
- }
- return html;
- }
- function thumbFormatterNum(value, row, index) {
- var html = '';
- console.log(value);
- if (value) {
- for (var img_key in value){
- html += '<i class="fa fa-picture-o thumbHover" style="font-size:21px;" data-img="'+value[img_key]+'"></i> ';
- }
- }
- return html;
- }
- function operateFormatterSH(value, row, index) {
- if( row.status == 1 ){
- if (this.btn_group) {
- var html = '<div class="btn-group">';
- 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 += '<a href="'+url+'" class="btn btn-sm '+(item.class?item.class:'btn-white')+'" data-index="'+index+'"'+(item.target?' target="'+item.target+'"':'"')+(confirm_url?' data-url="'+confirm_url+'"':'')+(name?' data-name="'+name+'"':'')+(title?' data-title="'+title+'"':'')+'>'+item.name+'</a>';
- }
- html += '</div>';
- }
- 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 = '<div class="btn-group">';
- 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 += '<a href="'+url+'" class="btn btn-sm '+(item.class?item.class:'btn-white')+'" data-index="'+index+'"'+(item.target?' target="'+item.target+'"':'"')+(confirm_url?' data-url="'+confirm_url+'"':'')+(zIndex?' data-zIndex="'+zIndex+'"':'99')+(name?' data-name="'+name+'"':'')+(title?' data-title="'+title+'"':'')+(item.areaWidth?' data-area-width="'+item.areaWidth+'"':'')+(item.areaHeight?' data-area-height="'+item.areaHeight+'"':'')+(item.maxWidth?' data-max-width="'+item.maxWidth+'"':'')+(item.maxHeight?' data-max-height="'+item.maxHeight+'"':'')+'>'+item.name+'</a>';
- }
- if( html == '<div class="btn-group">' ){
- html += '--</div>';
- }else{
- html += '</div>';
- }
- }
- return html;
- }
- //> a标签
- function aHttp(value, row, index) {
- var a = '';
- if( value ){
- a = '<a href="'+value+'" target="_blank">'+value+'</a>';
- }
- return a;
- }
- function aHttpAddress(value, row, index) {
- var a = '';
- if( value ){
- str = value.substring(0,9) + '...';
- a = '<a class="moveR" data-stringr="'+value+'" href="https://www.yitaifang.com/accounts/'+value+'" target="_blank">'+str+'</a>';
- }
- return a;
- }
- function aHttpHash(value, row, index) {
- var a = '';
- if( value ){
- str = value.substring(0,9) + '...';
- a = '<a class="moveR" data-stringr="'+value+'" href="https://www.yitaifang.com/txs/'+value+'" target="_blank">'+str+'</a>';
- }
- return a;
- }
- //> 字段剪切
- function qString(value, row, index) {
- var str = '';
- if( value && value.length > 9 ){
- str = value.substring(0,9) + '...';
- return '<span class="moveR" data-stringr="'+value+'">'+str+'</span>';
- }
- return '<span>'+value+'</span>';
- }
- function qStringOrTrim(value, row, index) {
- var str = '';
- if( value && value.length > 9 ){
- str = value.substring(0,9) + '...';
- return '<span class="moveR" data-stringr="'+value+'">'+str+'</span>';
- }else if( value === null ){
- return '<span>-</span>';
- }
- return '<span>'+value+'</span>';
- }
- // 发货字段
- function quantityOne(value, row, index){
- return '<span>'+(value - 4)+'</span>';
- }
- //> 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("复制成功!");
- });
|