/*!
* 搴旂敤閫氱敤鍔熻兘
* 绫虫嫇浼佷笟寤虹珯绯荤粺 Copyright (C) 闀挎矙绫虫嫇淇℃伅鎶€鏈湁闄愬叕鍙 (https://www.metinfo.cn). All rights reserved.
*/
// 鍒ゆ柇鍦板潃鏍忔槸鍚︽湁lang鍙傛暟锛屾病鏈夊垯璺宠浆鍒板甫lang鍙傛暟鐨勫湴鍧€
if(typeof MET !='undefined' && MET['url']['basepath'] !='undefined'){
try {
if(window.parent){
var str=window.parent.document.URL,
s=str.indexOf("lang="+M['lang']),
z=str.indexOf("lang");
if (s=='-1' && z!='-1') {
var s1=str.indexOf('#');
if (s1=='-1') {
str=str.replace(/(lang=[^#]*)/g, "lang="+M['lang']+"#");
}
str=str.replace(/(lang=[^#]*#)/g, "lang="+lang+"#");
parent.location.href=str;
}
}
} catch (err) {}
}
// 鑾峰彇鍦板潃鏍忓弬鏁
function getQueryString(name) {
var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)", "i");
var r=window.location.search.substr(1).match(reg);
if (r!=null) return unescape(decodeURIComponent(r[2]));
return null;
}
// 淇敼銆佹坊鍔犮€佸垹闄ゅ湴鍧€鏍忓弬鏁
function replaceParamVal(param,value) {
var url=location.href,
match_url=window.location.search.substr(1) || window.location.hash.split('?')[1]||'',
param=$.isArray(param)?param:[param],
value=$.isArray(value)?value:[value];
$.each(param, function(index, val) {
var param1='&' + val + '=',
param2='?' + val + '=',
re = match_url.match(new RegExp("(^|&)"+val+"=([^&]*)(&|$)", "i"));
if(!re && (url.indexOf(param1)>0 || url.indexOf(param2)>0)) re=[val + '='];
re && (re[0]=re[0].replace(/&/g,''));
value[index]=String(value[index]);
if(value[index]){
if(re){
if(url.indexOf(param1)>0){
url = url.replace('&'+re[0], param1 + value[index]);
}else if(url.indexOf(param2)>0){
url = url.replace('?'+re[0], param2 + value[index]);
}
}else{
if(url.indexOf('?')>0){
var laststr=url.substr(-1),
urls=url.split('?');
if(urls[urls.length-1].indexOf('#')>0 && laststr!='/'){
url+='/?';
laststr=url.substr(-1);
}
url = url+((laststr=='?'||laststr=='&')?(val + '='):param1) + value[index];
}else{
if((url+'/')==M.weburl) url+='/';
var laststr=url.substr(url.lastIndexOf('/')+1);
if(laststr.length?laststr.indexOf('.')>0:1){
url=url+param2 + value[index];
}else{
url=url+'/'+param2 + value[index];
}
}
}
}else if(re){
url = url.replace('&'+re[0], '').replace(re[0], '');
}
})
history.pushState('','',url);
}
try {
if(window.parent){
// 鍙鍖栧脊妗嗕腑椤甸潰闅愯棌澶撮儴
if (parent.window.location.search.indexOf('pageset=1') >= 0) $('.metadmin-head').hide();
// 鎿嶄綔鎴愬姛銆佸け璐ユ彁绀轰俊鎭
if(top.location!=location) $("html",parent.document).find('.turnovertext').remove();
}
} catch (err) {}
// 寮瑰嚭鎻愮ず淇℃伅
function metAlert(text,delay,bg_ok,type){
delay=typeof delay != 'undefined'?delay:2000;
bg_ok=bg_ok?'bgshow':'';
if(bg_ok){
$('.metalert-text').remove();
}else{
$('.metalert-wrapper').remove();
}
if(text!=' '){
text=text||METLANG.jsok;
text='
鏆傛棤鍙€夋嫨鍥剧墖锛岃涓婁紶鍥剧墖
';
$loader.hide();
$list.html(html).find('[data-original]').metLazyLoad({container:'.img-library-body'});
$('.img-library-modal').removeAttr('data-update');
}
}
});
}else{
$('.img-library-modal .img-library-list li a').removeClass('active');
}
});
// 鍥剧墖搴?閫夋嫨鍥剧墖
$(document).on('click', '.img-library-modal .img-library-list li a', function(event) {
var multiple=$('.file-input #'+$('.img-library-modal button[type="submit"]').attr('data-id')).attr('multiple')?true:false;
$(this).toggleClass('active');
if(!multiple) $(this).parents('li').siblings('li').find('a').removeClass('active');
})
// 鍥剧墖搴?鎻愪氦
$(document).on('click', '.img-library-modal button[type="submit"]', function(event) {
var $self=$(this),
$img_library_modal=$('.img-library-modal'),
img_url='';
$img_library_modal.find('.img-library-list li a.active img').each(function(index, el) {
img_url+=(index?',':'')+$(this).attr('src');
});
metAlertifyLoadFun(function(){
if(img_url){
$('.file-input #'+$self.attr('data-id')).metFileInputChange(img_url);
$img_library_modal.modal('hide');
alertify.success('鍥剧墖閫夋嫨鎴愬姛');
}else{
alertify.error('璇烽€夋嫨鍥剧墖');
}
});
});
// 澶栭儴鍥剧墖-寮规
$(document).on('click', '.file-input .fileinput-file-other', function(event) {
if(!$('.img-other-modal').length){
var html='
';
$('body').append(html);
$('.img-other-modal').modal();
}
$('.img-other-modal [name="img_url"]').val('');
$('.img-other-modal button[type="submit"]').attr({'data-id':$(this).parents('.file-input').find('input[type="file"]').attr('id')});
});
// 澶栭儴鍥剧墖-鎻愪氦
$(document).on('click', '.img-other-modal button[type="submit"]', function(event) {
var $self=$(this),
$img_other_modal=$('.img-other-modal'),
img_url=$img_other_modal.find('[name="img_url"]').val();
metAlertifyLoadFun(function(){
if(img_url){
$('.file-input #'+$self.attr('data-id')).metFileInputChange(img_url);
$img_other_modal.modal('hide');
alertify.success('鍥剧墖娣诲姞鎴愬姛');
}else{
alertify.error('璇疯緭鍏ュ閮ㄥ浘鐗囬摼鎺?);
$img_other_modal.find('[name="img_url"]').focus();
}
});
});
}
},
// 涓婁紶鍥剧墖缁勪欢鏀瑰彉鍊
metFileInputChange:function(img_url){
var $file_input=$(this).parents('.file-input'),
name=$(this).attr('name'),
html='',
img_urls=img_url.indexOf(',')>=0?img_url.split(','):[img_url];
if($(this).attr('multiple')){
var old_val=$file_input.find('input[type="hidden"][name="'+name+'"]').val();
if(old_val){
old_val=old_val.indexOf(',')>=0?old_val.split(','):[old_val];
img_url=old_val+','+img_url;
}else{
old_val=[];
}
if(old_val!=img_urls) img_urls=old_val.concat(img_urls);
}
$.each(img_urls, function(index, val) {
html+='
'
+'
'
+''
+'
';
});
if(html && $file_input.hasClass('file-input-new')) $file_input.removeClass('file-input-new');
$file_input.find('.file-drop-zone .file-drop-zone-title').remove();
$file_input.find('.file-preview-thumbnails').html(html);
$file_input.find('.input-group .file-caption-name').html('
'+img_url).attr({title:img_url});
$file_input.find('input[type="hidden"][name="'+name+'"]').val(img_url).trigger('change');
},
// 鍗曢€夈€佸閫夐粯璁ら€変腑
metRadioCheckboxChecked:function(){
if(!$(this).length) return;
$(this).each(function(index, el) {
var checked=String($(this).attr('data-checked')),
delimiter=$(this).data('delimiter')||'#@met@#';
if(checked !='undefined'){
checked=checked.indexOf(delimiter)>=0?checked.split(delimiter):[checked];
var name=$(this).attr('name');
$(this).parents('form').find('input[name="'+name+'"]').removeAttr('checked');
for (var i=0; i < checked.length; i++) {
$(this).parents('form').find('input[name="'+name+'"][value="'+checked[i]+'"]').attr('checked', true).prop({checked:true});
}
}
});
},
// 涓嬫媺鑿滃崟榛樿閫変腑
metSelectChecked:function(){
if(!$(this).length) return;
$(this).each(function(index, el) {
$('option[value="'+$(this).attr('data-checked')+'"]',this).attr({selected:true});
});
},
// 鍥剧墖寤惰繜鍔犺浇
metLazyLoad:function(options){
if(!$(this).length) return;
var $self=$(this);
metFileLoadFun(M['plugin']['lazyload'],function(){
return typeof $.fn.lazyload=='function';
},function(){
$self.lazyload(options);
});
},
// 琛ㄥ崟鍒犻櫎鎸夐挳ajax鎻愪氦
metFormAjaxDel:function(url){
var $form=$(this).parents('form'),
del_id=$form.find('[name="all_id"]')?$form.find('[name="all_id"]').val():'';
if(del_id!=''){
$.ajax({
url: $(this).data('url')||$form.attr('action'),
type: "POST",
dataType:'json',
data:{del_id:del_id},
success: function(result){
metAjaxFun({result:result});
}
});
}else{
metAlert(METLANG.jslang3,'','bgshow',0);
}
},
// 琛ㄥ崟涓ょ绫诲瀷鎻愪氦鍓嶇殑澶勭悊锛堜繚瀛樸€佸垹闄わ級
metSubmit:function(type){
// 鎻掑叆submit_type瀛楁
var type=typeof type!='undefined'?type:1,
type_str=type?'save':'delet';
if($(this).find('[name="submit_type"]').length){
$(this).find('[name="submit_type"]').val(type_str);
}else $(this).append('
');
// 鎻掑叆琛ㄦ牸鐨刟ll_id瀛楁
if($(this).find('table').length){
var $table=$(this).find('table'),
checked_str=type?'':':checked',
$checkbox=$table.find('tbody input[type="checkbox"][name="id"]'+checked_str),
all_id='';
$checkbox.each(function(index, el) {
all_id+=all_id?','+$(this).val():$(this).val();
})
if(!$(this).find('[name="all_id"]').length) $(this).append('
');
$(this).find('[name="all_id"]').val(all_id);
}
},
// 琛ㄥ崟鏇存柊楠岃瘉
metFormAddField:function(name){
var $form=$(this)[0].tagName=='FORM'?$(this):$(this).parents('form');
if($form.length){
if(name){
if(!$.isArray(name)){
if(name.indexOf(',')>=0){
name=name.split(',');
}else name=[name];
}
$.each(name, function(index, val) {
$form.data('formValidation').addField(val);
})
}else{
var name_array=[];
$('[name]',this).each(function(index, el) {
var name=$(this).attr('name');
if($.inArray(name, name_array)<=0){
name_array.push(name);
if(typeof $(this).attr('required') !='undefined'){
$form.data('formValidation').addField(name);
}else{
$.each($(this).data(), function(index, val) {
var third_str=index.substr(2,1);
if(index.substr(0,2)=='fv' && index.length>2 && third_str >= 'A' && third_str <= 'Z'){
$form.data('formValidation').addField(name);
return false;
}
});
}
}
});
}
}
},
// 鐐瑰嚮ajax璇锋眰寮瑰嚭纭妗嗗悗浠ュ強杩斿洖缁撴灉閫氱敤澶勭悊
metClickConfirmAjax:function(default_options){
var default_options = $.extend({
ajax_data:'',
true_text:METLANG.confirm,
false_text:METLANG.cancel,
confirm_text:METLANG.delete_information,
true_fun:function(){
var url=typeof this.url=='function'?this.url():this.url,
ajax_data=typeof this.ajax_data=='function'?this.ajax_data():this.ajax_data,
options_this=this;
$.ajax({
url: url,
type: ajax_data?'POST':'GET',
dataType: 'json',
data:ajax_data,
success:function(result){
options_this.ajax_fun(result);
}
});
},
false_fun:'',
ajax_fun:function(result){
metAjaxFun({result:result});
}
},default_options);
$(document).on('click', this.selector, function(event) {
var options = $.extend({
el:$(this),
url:$(this).data('url')
},default_options);
metAlertifyLoadFun(function(){
var confirm_text=typeof options.confirm_text=='function'?options.confirm_text():options.confirm_text;
alertify.okBtn(options.true_text).cancelBtn(options.false_text).confirm(confirm_text, function (ev) {
options.true_fun();
},function(){
if(typeof options.false_fun=='function') options.false_fun();
});
})
});
},
// 閫氱敤鍔熻兘寮€鍚
metCommon:function(){
var dom=this;
// 琛ㄥ崟楠岃瘉
if($('form',dom).length){
if(typeof validate =='undefined'){
$.include(M['plugin']['formvalidation']);
}else{
$(dom).metValidate();
}
}
// ajax琛ㄦ牸
if($('.dataTable',dom).length){
if(typeof datatable =='undefined'){
$.include(M['plugin']['datatables']);
}else{
$(dom).metDataTable();
}
}
// 缂栬緫鍣
if($('textarea[data-plugin="editor"]',dom).length && typeof MET['url']['basepath']!='undefined') $('textarea[data-plugin="editor"]',dom).metEditor();
// 棰滆壊閫夋嫨鍣
if($('input[data-plugin="minicolors"]',dom).length) $.include(M['plugin']['minicolors'],function(){
$('input[data-plugin="minicolors"]',dom).minicolors();
});
// 鏍囩
if($('input[data-plugin="tokenfield"]',dom).length) $.include(M['plugin']['tokenfield'],'','siterun');
// 婊戝潡
if($('input[type="text"][data-plugin="ionRangeSlider"]',dom).length) $.include(M['plugin']['ionrangeslider'],'','siterun');
// 鏃ユ湡閫夋嫨鍣
if($('input[data-plugin="datetimepicker"]',dom).length) $.include(M['plugin']['datetimepicker'],function(){
$('input[data-plugin="datetimepicker"]',dom).metDatetimepicker();
});
// 鑱斿姩鑿滃崟
if($('[data-plugin="select-linkage"]',dom).length) $.include(M['plugin']['select-linkage'],function(){
$('[data-plugin="select-linkage"]',dom).metCitySelect();
});
// 妯℃€佸璇濇
if($('[data-plugin="alertify"]',dom).length) $.include(M['plugin']['alertify'],'','siterun');
// 鍏ㄩ€夈€佸叏涓嶉€
if($('[data-plugin="selectable"]',dom).length) $.include(M['plugin']['selectable'],'','siterun');
// 涓婁紶鏂囦欢
if($('input[type="file"][data-plugin="fileinput"]',dom).length) $.include(M['plugin']['fileinput'],function(){
$('input[type="file"][data-plugin="fileinput"]',dom).metFileInput();
})
// 婊氬姩鏉
if($('[data-plugin="scrollable"]',dom).length) $.include(M['plugin']['asscrollable'],'','siterun');
// 鍗曢€夈€佸閫夐粯璁ら€変腑
if($('input[data-checked]',dom).length) $('input[data-checked]',dom).metRadioCheckboxChecked();
// 涓嬫媺鑿滃崟榛樿閫変腑
if($('select[data-checked]',dom).length) $('select[data-checked]',dom).metSelectChecked();
// 鏁伴噺鏀瑰彉
if($('[data-plugin="touchSpin"]',dom).length && typeof $.fn.TouchSpin =='undefined') $.include(M['plugin']['touchspin'],function(){
$('[data-plugin="touchSpin"]',dom).TouchSpin();
});
// 鍥剧墖寤惰繜鍔犺浇
if($('[data-original]',dom).length && dom!=document) $('[data-original]',dom).metLazyLoad();
}
});
// 閫氱敤鍔熻兘寮€鍚
$(document).metCommon();
// 鍕鹃€夊紑鍏
$(document).on('change', 'input[type="checkbox"][data-plugin="switchery"]', function(event) {
var val=$(this).is(':checked')?1:0;
$(this).val(val);
});
// tokenfield鎻掍欢杈撳叆妗嗗€兼洿鏂板悗
$(document).on('change', '.tokenfield .token-input', function(event) {
$(this).parents('.tokenfield').find('[name][data-fv-field]').trigger('change');
});
$(function(){
// 闈炲墠鍙版ā鏉块〉闈?鍏煎鑰佹ā鏉
if(M['url']['basepath'] || $('script[src*="js/basic_web.js"]').length){
// 杩斿洖椤堕儴
$(".met-scroll-top").click(function(){
$('html,body').animate({scrollTop:0},300);
});
// 杩斿洖椤堕儴鎸夐挳鏄剧ず/闅愯棌
var wh=$(window).height();
$(window).scroll(function(){
if($(this).scrollTop()>wh){
$(".met-scroll-top").removeAttr('hidden').addClass("animation-slide-bottom");
}else{
$(".met-scroll-top").attr({hidden:''}).removeClass('animation-slide-bottom');
}
});
}
// 浼氬憳渚ф爮鎵嬫満绔綋鍓嶉〉闈㈡爣棰樻樉绀哄湪瀵艰埅寰掓
Breakpoints.on('xs sm',{
enter:function(){
if($('.met-sidebar-nav-active-name').length) $('.met-sidebar-nav-active-name').html($('.met-sidebar-nav-mobile .dropdown-menu .dropdown-item.active').text());
}
})
// 鍦?pageset=1寮圭獥涓椂锛岄〉闈㈢殑琛ㄥ崟鎻愪氦鍦板潃娣诲姞鍙傛暟pageset=1
if(getQueryString('pageset')) $('form').each(function(index, el) {
if($(this).attr('action')) $(this).attr({action:$(this).attr('action')+'&pageset=1'});
});
// 涓嬫媺灞曞紑鏃朵笅鎷夊浘鏍囨棆杞
$(document).on('click', '[data-toggle="collapse"]', function(event) {
var $icon=$('.icon[class*="fa-angle-"]',this);
if($icon.length){
if(!$icon.hasClass('transition500')) $icon.addClass('transition500');
if($($(this).data('target')).height()){
$icon.removeClass('fa-rotate-90');
}else{
$icon.addClass('fa-rotate-90');
}
}
});
// 琛ㄥ崟鍔熻兘
// 娣诲姞椤
$(document).on('click', '[table-addlist]', function(event) {
var $self=$(this),
$table=$(this).parents('table').length?$(this).parents('table'):$($(this).data('table-id')),
addlist=function(data){
$table.find('tbody').append(data);
var $new_tr=$table.find('tbody tr:last-child');
if(!$new_tr.find('[table-cancel]').length && typeof $self.data('nocancel')=='undefined') $new_tr.find('td:last-child').append('
');
// 娣诲姞琛ㄥ崟楠岃瘉
$new_tr.metFormAddField();
};
if($table.find('[table-addlist-data]').length){
var html=$table.find('[table-addlist-data]').val();
addlist(html);
}else{
if(typeof datatable_option=='undefined') window.datatable_option=[];
var datatable_index=$table.index('.dataTable');
if(typeof datatable_option[datatable_index]=='undefined') datatable_option[datatable_index]=[];
if(typeof datatable_option[datatable_index]['new_id']=='undefined'){
datatable_option[datatable_index]['new_id']=0;
}else{
datatable_option[datatable_index]['new_id']++;
}
$.ajax({
url: $(this).data('url'),
type: 'POST',
data:{new_id:datatable_option[datatable_index]['new_id']},
success:function(result){
addlist(result);
}
});
}
});
// 鎾ら攢椤
$(document).on('click', '[table-cancel]', function(event) {
$(this).parents('tr').remove();
})
// 鍒犻櫎椤?涓嶆彁浜
$(document).on('click', '[table-del]', function(event) {
var $self=$(this),
remove=function(){
alertify.theme('bootstrap').okBtn(METLANG.confirm).cancelBtn(METLANG.cancel).confirm(METLANG.delete_information, function (ev) {
$self.parents('tr').remove();
})
};
metAlertifyLoadFun(function(){
remove();
});
})
// 鐐瑰嚮淇濆瓨鎸夐挳
$(document).on('click', 'form .btn[type="submit"]', function(event) {
if($(this).data('plugin')=='alertify' && $(this).data('type')=='confirm') event.preventDefault();
$(this).parents('form').metSubmit();
})
// 鍒犻櫎澶氶」鎻愪氦
$(document).on('click', '[table-delet]', function(event) {
event.preventDefault();
var $form=$(this).parents('form');
$form.metSubmit(0);
if($(this).data('plugin')!='alertify'){
if($(this).data('url')){
$(this).metFormAjaxDel();
}else $form.submit();
}
})
// 琛ㄥ崟杈撳叆妗嗗洖杞︽椂锛岃Е鍙戞彁浜ゆ寜閽
$(document).on('keydown', 'form input[type="text"]', function(event) {
if(event.keyCode==13){
event.preventDefault();
$(this).parents('form').find('[type="submit"]:not(.fv-hidden-submit)').click();
}
});
// 琛ㄥ崟鎻愪氦
$(document).on('submit', 'form', function(event) {
// 鎻愪氦鍒犻櫎鏃舵病鏈夊嬀閫夋椂鎻愮ず
if($(this).find('[name="submit_type"]').length && $(this).find('[name="submit_type"]').val()=='delet' && $(this).find('[name="all_id"]').val()==''){
event.preventDefault();
metAlert(METLANG.jslang3,'','bgshow',0);
}
});
});
// 鍒ゆ柇鏄惁鍔犺浇浜唂ormvalidation鍚庡洖璋
function metFormvalidationLoadFun(fun){
metFileLoadFun(M['plugin']['formvalidation'],function(){
return typeof $.fn.metValidate=='function';
},function(){
if(typeof fun=='function') fun();
});
}
// 鍒ゆ柇鏄惁鍔犺浇浜哸lertify鍚庡洖璋
function metAlertifyLoadFun(fun){
metFileLoadFun(M['plugin']['alertify'],function(){
return typeof alertify!='undefined';
},function(){
if(typeof fun=='function') fun();
});
}
// ajax璇锋眰杩斿洖鍚庨€氱敤澶勭悊
function metAjaxFun(options){
options = $.extend({
result:'',
false_fun:'',
true_fun:'',
status_key:'status',
msg_key:'msg',
true_val:function(){
return parseInt(options.result[options.status_key]);
}
},options);
metAlertifyLoadFun(function(){
if(options.true_val()){
if(typeof options.result[options.msg_key]!='undefined' && options.result[options.msg_key]!='') alertify.success(options.result[options.msg_key]);
if(typeof options.true_fun=='function'){
options.true_fun();
}else{
setTimeout(function(){
location.reload();
},1000);
}
}else{
if(typeof options.result[options.msg_key]!='undefined' && options.result[options.msg_key]!='') alertify.error(options.result[options.msg_key]);
if(typeof options.false_fun=='function') options.false_fun();
}
});
}
// 璁剧疆cookie
function setCookie(name,value,path,term){
var exp = new Date(),
terms =term||30,
paths =path||'/';
exp.setTime(exp.getTime() + terms*24*60*60*1000);
document.cookie = name + "="+ value + ";path="+paths+";expires=" + exp.toGMTString();
}
// 鑾峰彇鎸囧畾鍚嶇О鐨刢ookie鐨勫€
function getCookie(name) {
var cookie_str = document.cookie.split(";");
for (var i = 0; i < cookie_str.length; i++) {
cookie_str[i]=$.trim(cookie_str[i]);
var index = cookie_str[i].indexOf("="),
cookie_name = cookie_str[i].substring(0, index);
if (cookie_name == name) {
var temp = cookie_str[i].substring(index + 1);
return decodeURIComponent(temp);
}
}
}