347 lines
16 KiB
JavaScript
347 lines
16 KiB
JavaScript
/*!
|
||
* M['weburl'] 网站网址
|
||
* M['lang'] 网站语言
|
||
* M['tem'] 模板目录路径
|
||
* M['user_name'] 页面登录用户名
|
||
* met_prevarrow,
|
||
met_nextarrow slick插件翻页按钮自定义html
|
||
* M['device_type'] 客户端判断(d:PC端,t:平板端,m:手机端)
|
||
* M['n'] 当前模块名称
|
||
* M['c'] 当前类
|
||
* M['a'] 当前方法
|
||
* M['langtxt'] 当前语言文字
|
||
* M['langset'] 当前后台语言
|
||
* M['anyid'] 当前模块id
|
||
* M['met_editor'] 当前系统编辑器名称
|
||
* M['met_keywords'] 页面关键词
|
||
* M['url']['admin'] 后台文件夹路径
|
||
* M['url']['static']
|
||
* M['url']['static_vendor']
|
||
* M['url']['static2']
|
||
* M['url']['static2_vendor']
|
||
* M['url']['static2_plugin']
|
||
* M['url']['uiv2'] 模板框架v2路径
|
||
* M['url']['uiv2_css']
|
||
* M['url']['uiv2_js']
|
||
* M['url']['app'] 应用文件夹路径
|
||
* M['url']['pub'] 后台模块公用文件夹路径
|
||
* M['url']['epl'] 后台模块公用示例文件夹路径
|
||
* M['url']['ui'] 应用前后台公用UI文件app/system/include/piblic/ui/里面
|
||
* M['url']['own_form'] 当前页面程序地址
|
||
* M['url']['own_name'] 当前模块地址
|
||
* M['url']['own'] 当前模块后台路径
|
||
* M['url']['own_tem'] 当前页面模板路径
|
||
* M['url']['api'] app站点地址
|
||
* M['url']['editor'] 当前编辑器应用文件夹路径
|
||
*/
|
||
$(function () {
|
||
var myDate = new Date().getTime()
|
||
$.include(M.url.own_tem + 'js/appcheck.min.js?' + myDate);
|
||
|
||
$.ajax({
|
||
type : "GET",
|
||
url : M.url.own_name + 'c=ajax&a=doajaxcl&lang=' + M['langset'],
|
||
dataType: "jsonp",
|
||
async : false
|
||
}).done(function (data) {
|
||
CL = data;
|
||
});
|
||
|
||
var appfun = function () {
|
||
var $self = this;
|
||
//有序表处理
|
||
$.getJSON(M.url.own_name + 'c=ajax&a=dosequence&lang=' + M['langset'], {}, function (json) {});
|
||
//select2
|
||
if ($('[data-plugin="select2"]').length) $self.select2(true);
|
||
//排期广告位选择
|
||
if ($('.add_ap_list').length) $.include(M.url.own_tem + 'js/applan.js?' + myDate);
|
||
//表格重绘后回调
|
||
$('#tableslist').on('draw.dt', function (e, settings) {
|
||
if ($('[data-plugin="alertify"]').length) $self.select2(false);
|
||
})
|
||
// 表格数据加载状态
|
||
$('#tableslist').on('processing.dt', function (e, settings, processing) {
|
||
if (processing) {
|
||
$self.tableProcessing(this)
|
||
}
|
||
})
|
||
$('#tables-list').on('processing.dt', function (e, settings, processing) {
|
||
if (processing) {
|
||
$self.tableProcessing(this)
|
||
}
|
||
})
|
||
//单个时间初始化
|
||
if ($('[data-plugin="alonetime"]').length) $self.alonetime();
|
||
//时间区段选择
|
||
if ($('[data-plugin="datetosearch"]').length) $self.datepicker();
|
||
//导出功能
|
||
$(document).on('click', '.backups', function (event) {
|
||
var my = $(this);
|
||
event.preventDefault();
|
||
my.parents('form').metSubmit(0);
|
||
var obj = my.parents("form").serialize(),
|
||
href = my.data('url'),
|
||
veaps = $('select[name="veaps"]').val(),
|
||
vtype = $('select[name="vtype"]').val();
|
||
// 单独给get传递增加veaps的值
|
||
if (!$self.isEmpty(veaps)) obj += '&jsadd_veaps=' + veaps.join(',');
|
||
if (!$self.isEmpty(vtype)) obj += '&jsadd_vtype=' + vtype.join(',');
|
||
window.location.href = href + '&' + obj;
|
||
})
|
||
//表格底部自定义按钮
|
||
$(document).on('click', '[table-zdybtn]', function (event) {
|
||
var my = $(this),
|
||
$form = my.parents('form'),
|
||
typestr = my.data('submit_type');
|
||
event.preventDefault();
|
||
$self.ownsubmit($form, typestr);
|
||
if (my.data('plugin') != 'alertify') {
|
||
$form.submit();
|
||
return true;
|
||
}
|
||
})
|
||
//排序功能
|
||
if ($('a.orderby-link').length) $self.orders();
|
||
//状态更改
|
||
// http://bsify.admui.com/alertify/ 中文说明
|
||
$(document).on('click', '.btn-cursor-pointer', function () {
|
||
var self = $(this);
|
||
$.include(M['url']['static2_vendor'] + 'alertify/alertify.js', function () {
|
||
alertify
|
||
.okBtn("确定")
|
||
.cancelBtn("取消")
|
||
.confirm('确定更改状态吗?', function () {
|
||
$.getJSON(self.data('href'), function (json) {
|
||
window.location.reload();
|
||
})
|
||
})
|
||
})
|
||
});
|
||
};
|
||
|
||
appfun.prototype = {
|
||
isEmpty : function (val) {
|
||
switch (typeof val) {
|
||
case 'undefined':
|
||
return true;
|
||
case 'string':
|
||
if (val.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0)
|
||
return true;
|
||
break;
|
||
case 'boolean':
|
||
if (!val)
|
||
return true;
|
||
break;
|
||
case 'number':
|
||
if (0 === val || isNaN(val))
|
||
return true;
|
||
break;
|
||
case 'object':
|
||
if (null === val || val.length === 0)
|
||
return true;
|
||
for (var i in val) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
},
|
||
select2 : function (drawdt) {
|
||
// drawdt true 执行默认操作 false 不执行
|
||
var $self = this,
|
||
select = [];
|
||
//选择器
|
||
M['plugin']['select2'] = [
|
||
M['url']['static2_vendor'] + 'select2/select2.min.css',
|
||
M['url']['static2_vendor'] + 'select2/select2.full.min.js',
|
||
M['url']['static2_vendor'] + 'select2/i18n/zh-CN.js',
|
||
];
|
||
$.include(M['plugin']['select2'], function () {
|
||
$('[data-plugin="select2"]').each(function (indexs, item) {
|
||
var _self = $(this),
|
||
defaults = _self.data('default'),
|
||
select2url = _self.data('select2-url') + '&' + myDate;
|
||
|
||
select[indexs] = _self.select2({
|
||
placeholder: '输入搜索内容', //提示语
|
||
ajax : {
|
||
url : select2url,
|
||
dataType: 'jsonp',
|
||
delay : 500,
|
||
data : function (params) {
|
||
return {
|
||
querys : params.term, //search term
|
||
tname : _self.data('tname'), //指定简短表
|
||
fiend : _self.data('fiend'), //指定字段值
|
||
allnone : _self.data('allnone'), //是否只显示应用的值
|
||
source : _self.data('source'), //查看来源标记
|
||
condition: _self.data('condition') //查询限制条件
|
||
};
|
||
},
|
||
results : function (data, page) {
|
||
return {results: data.results};
|
||
}
|
||
}
|
||
});
|
||
|
||
//默认值处理
|
||
if (!$self.isEmpty(defaults) && drawdt == true) {
|
||
$.getJSON(
|
||
select2url,
|
||
{
|
||
tname : _self.data('tname'), //指定简短表
|
||
fiend : _self.data('fiend'), //指定字段值
|
||
allnone : _self.data('allnone'), //是否只显示应用的值
|
||
source : _self.data('source'), //查看来源标记
|
||
condition: _self.data('condition'), //查询限制条件
|
||
default : defaults, //默认值
|
||
division : _self.data('division') //默认值分隔符
|
||
},
|
||
function (obj) {
|
||
$.each(obj.results, function (index, ele) {
|
||
$.each(ele.children, function (indexop, eleop) {
|
||
var option = new Option(eleop.text, eleop.id, true, true);
|
||
select[indexs].append(option).trigger('change');
|
||
})
|
||
});
|
||
}
|
||
)
|
||
}
|
||
|
||
});
|
||
});
|
||
},
|
||
datepicker : function () {
|
||
var $self = this;
|
||
M['plugin']['datetimepicker'] = [
|
||
M['url']['epl'] + 'time/jquery.datetimepicker.css',
|
||
M['url']['epl'] + 'time/jquery.datetimepicker.js'
|
||
];
|
||
$.include(M['plugin']['datetimepicker'], function () {
|
||
var starttime = $('#date_timepicker_start'),
|
||
endtime = $('#date_timepicker_end');
|
||
starttime.datetimepicker({
|
||
lang : M.synchronous == 'cn' ? 'ch' : 'en',
|
||
timepicker : starttime.attr("data-day-type") == 2 ? true : false,
|
||
format : starttime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
|
||
// value:starttime.val()?starttime.val():'',
|
||
// onShow:function( ct ){
|
||
// this.setOptions({
|
||
// maxDate:endtime.val()?endtime.val():false
|
||
// })
|
||
// },
|
||
onSelectDate: function (ct, $i) {
|
||
$self.tableaajx(starttime);
|
||
}
|
||
});
|
||
endtime.datetimepicker({
|
||
lang : M.synchronous == 'cn' ? 'ch' : 'en',
|
||
timepicker : endtime.attr("data-day-type") == 2 ? true : false,
|
||
format : endtime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
|
||
// value:endtime.val()?endtime.val():'',
|
||
// onShow:function( ct ){
|
||
// this.setOptions({
|
||
// minDate:starttime.val()?starttime.val():false
|
||
// })
|
||
// },
|
||
onSelectDate: function (ct, $i) {
|
||
$self.tableaajx(endtime);
|
||
}
|
||
});
|
||
})
|
||
},
|
||
alonetime : function () {
|
||
var $self = this;
|
||
M['plugin']['datetimepicker'] = [
|
||
M['url']['epl'] + 'time/jquery.datetimepicker.css',
|
||
M['url']['epl'] + 'time/jquery.datetimepicker.js'
|
||
];
|
||
$.include(M['plugin']['datetimepicker'], function () {
|
||
var alonetime = $('[data-plugin="alonetime"]');
|
||
alonetime.datetimepicker({
|
||
lang : M.synchronous == 'cn' ? 'ch' : 'en',
|
||
timepicker : alonetime.attr("data-day-type") == 2 ? true : false,
|
||
format : alonetime.attr("data-day-type") == 2 ? 'Y-m-d H:i:s' : 'Y-m-d',
|
||
onSelectDate: function (ct, $i) {
|
||
$self.tableaajx(alonetime);
|
||
}
|
||
});
|
||
});
|
||
},
|
||
tableaajx : function (timedom) {
|
||
if (typeof datatable != 'undefined') {
|
||
var $this_datatable = timedom.parents('.dataTable'),
|
||
datatable_index = $this_datatable.index('.dataTable');
|
||
if (datatable_index < 0) datatable_index = 0;
|
||
datatable[datatable_index].ajax.reload();
|
||
}
|
||
},
|
||
orders : function () {
|
||
var $self = this;
|
||
$(document).on('click', 'a.orderby-link', function (event) {
|
||
var $this = $(this),
|
||
arrow = $this.find(".orderby-arrow");
|
||
if (arrow.length) {
|
||
if ($this.find(".desc").length) {
|
||
$self.orderby($this, 'asc');
|
||
} else {
|
||
//还原
|
||
$self.orderby($this, '');
|
||
}
|
||
} else {
|
||
$self.orderby($this, 'desc');
|
||
}
|
||
});
|
||
},
|
||
orderby(dom, type) {
|
||
var $self = this;
|
||
//清楚所有排序
|
||
$("a.orderby-link").find(".orderby-arrow").remove();
|
||
$("a.orderby-link").next().val('');
|
||
//操作当前排序
|
||
if (type) dom.append('<span class="orderby-arrow ' + type + '"></span>');
|
||
dom.next().val(type);
|
||
$self.tableaajx(dom);
|
||
},
|
||
ownsubmit : function ($form, typestr) {
|
||
// 插入submit_type字段
|
||
if ($form.find('[name="submit_type"]').length) $form.append('<input type="hidden" name="submit_type" value=""/>');
|
||
$form.find('[name="submit_type"]').val(typestr);
|
||
// 插入表格的all_id字段
|
||
if ($form.find('.dataTable').length) {
|
||
var $table = $form.find('.dataTable'),
|
||
$checkbox = $table.find('tbody input[type="checkbox"][name="id"]:checked'),
|
||
all_id = '';
|
||
$checkbox.each(function (index, el) {
|
||
all_id += all_id ? ',' + $(this).val() : $(this).val();
|
||
})
|
||
if (!$form.find('[name="all_id"]').length) $form.append('<input type="hidden" name="all_id"/>');
|
||
$form.find('[name="all_id"]').val(all_id);
|
||
}
|
||
},
|
||
tableProcessing: function (_this_) {
|
||
// 表格数据加载状态
|
||
var tbody = $(_this_).find('tbody')
|
||
var colspan = tbody.data('colspan')
|
||
var html = `<tr>
|
||
<td colspan="${colspan}">
|
||
<div class="h-50 vertical-align text-xs-center"><div class="loader vertical-align-middle loader-default"></div></div>
|
||
</td>
|
||
</tr>`
|
||
tbody.html(html)
|
||
}
|
||
};
|
||
|
||
APPFUN = new appfun();
|
||
|
||
//地图
|
||
if ($('#showmap').length || $('#modalmap').length || $('#selectMap').length) {
|
||
$.include(M.url.own_tem + 'js/bmaps.js?' + myDate, function () {
|
||
APPMAP.bmaps();
|
||
});
|
||
}
|
||
|
||
//缓存
|
||
$.ajaxSetup({cache: false});
|
||
});
|