;(function () { //鍏ㄥ眬ajax澶勭悊 $.ajaxSetup({ complete: function (jqXHR) { }, data: {}, error: function (jqXHR, textStatus, errorThrown) { //璇锋眰澶辫触澶勭悊 } }); if ($.browser && $.browser.msie) { //ie 閮戒笉缂撳瓨 $.ajaxSetup({ cache: false }); } //涓嶆敮鎸乸laceholder娴忚鍣ㄤ笅瀵筽laceholder杩涜澶勭悊 if (document.createElement('input').placeholder !== '') { $('[placeholder]').focus(function () { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function () { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur().parents('form').submit(function () { $(this).find('[placeholder]').each(function () { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }); }); } //鎵€鏈夊姞浜哾ialog绫诲悕鐨刟閾炬帴锛岃嚜鍔ㄥ脊鍑哄畠鐨刪ref if ($('a.js-dialog').length) { Wind.use('artDialog', 'iframeTools', function () { $('.js-dialog').on('click', function (e) { e.preventDefault(); var $_this = this, _this = $($_this); art.dialog.open($(this).prop('href'), { close: function () { $_this.focus(); //鍏抽棴鏃惰瑙﹀彂寮圭獥鐨勫厓绱犺幏鍙栫劍鐐 return true; }, title: _this.prop('title') }); }).attr('role', 'button'); }); } //鎵€鏈夌殑ajax form鎻愪氦,鐢变簬澶у涓氬姟閫昏緫閮芥槸涓€鏍风殑锛屾晠缁熶竴澶勭悊 var ajaxForm_list = $('form.js-ajax-form'); if (ajaxForm_list.length) { Wind.use('ajaxForm', 'noty', 'validate', function () { //var form = btn.parents('form.js-ajax-form'); var $btn; $('button.js-ajax-submit').on('click', function (e) { //e.preventDefault(); /*var btn = $(this).find('button.js-ajax-submit'), form = $(this);*/ var btn = $(this), form = btn.parents('form.js-ajax-form'); $btn = btn; if (btn.data("loading")) { return false; } //鎵归噺鎿嶄綔 鍒ゆ柇閫夐」 if (btn.data('subcheck')) { btn.parent().find('span').remove(); if (form.find('input.js-check:checked').length) { var msg = btn.data('msg'); if (msg) { noty({ text: msg, type: 'confirm', layout: "center", timeout: false, modal: true, buttons: [ { addClass: 'btn btn-primary', text: '纭畾', onClick: function ($noty) { $noty.close(); btn.data('subcheck', false); btn.click(); } }, { addClass: 'btn btn-danger', text: '鍙栨秷', onClick: function ($noty) { $noty.close(); } } ] }); } else { btn.data('subcheck', false); btn.click(); } } else { noty({ text: "璇疯嚦灏戦€夋嫨涓€椤?, type: 'error', layout: 'center' }); } return false; } //ie澶勭悊placeholder鎻愪氦闂 if ($.browser && $.browser.msie) { form.find('[placeholder]').each(function () { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }); } }); ajaxForm_list.each(function () { $(this).validate({ //鏄惁鍦ㄨ幏鍙栫劍鐐规椂楠岃瘉 //onfocusout : false, //鏄惁鍦ㄦ暡鍑婚敭鐩樻椂楠岃瘉 //onkeyup : false, //褰撻紶鏍囩偣鍑绘椂楠岃瘉 //onclick : false, //缁欐湭閫氳繃楠岃瘉鐨勫厓绱犲姞鏁堟灉,闂儊绛 highlight: function (element, errorClass, validClass) { if (element.type === "radio") { this.findByName(element.name).addClass(errorClass).removeClass(validClass); } else { var $element = $(element); $element.addClass(errorClass).removeClass(validClass); $element.parent().addClass("has-error");//bootstrap3琛ㄥ崟 $element.parents('.control-group').addClass("error");//bootstrap2琛ㄥ崟 } }, unhighlight: function (element, errorClass, validClass) { if (element.type === "radio") { this.findByName(element.name).removeClass(errorClass).addClass(validClass); } else { var $element = $(element); $element.removeClass(errorClass).addClass(validClass); $element.parent().removeClass("has-error");//bootstrap3琛ㄥ崟 $element.parents('.control-group').removeClass("error");//bootstrap2琛ㄥ崟 } }, showErrors: function (errorMap, errorArr) { var i, elements, error; for (i = 0; this.errorList[i]; i++) { error = this.errorList[i]; if (this.settings.highlight) { this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass); } //this.showLabel( error.element, error.message ); } if (this.errorList.length) { //this.toShow = this.toShow.add( this.containers ); } if (this.settings.success) { for (i = 0; this.successList[i]; i++) { //this.showLabel( this.successList[ i ] ); } } if (this.settings.unhighlight) { for (i = 0, elements = this.validElements(); elements[i]; i++) { this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass); } } this.toHide = this.toHide.not(this.toShow); this.hideErrors(); this.addWrapper(this.toShow).show(); }, submitHandler: function (form) { var $form = $(form); if(!$btn){ $btn=$form.find('button.js-ajax-submit'); } $form.ajaxSubmit({ url: $btn && $btn.data('action') ? $btn.data('action') : $form.attr('action'), //鎸夐挳涓婃槸鍚﹁嚜瀹氫箟鎻愪氦鍦板潃(澶氭寜閽儏鍐? dataType: 'json', beforeSubmit: function (arr, $form, options) { if($btn){ $btn.data("loading", true); var text = $btn.text(); //鎸夐挳鏂囨銆佺姸鎬佷慨鏀 $btn.text(text + '...').prop('disabled', true).addClass('disabled'); } }, success: function (data, statusText, xhr, $form) { function _refresh() { if (data.url) { if (window.parent.art) { //iframe寮瑰嚭椤 window.parent.location.href = data.url; } else { window.location.href = data.url; } } else { if (data.code == 1) { var wait = $btn.data("wait"); if (window.parent.art) { reloadPage(window.parent); } else { //鍒锋柊褰撳墠椤 reloadPage(window); } } } } var text = $btn.text(); //鎸夐挳鏂囨銆佺姸鎬佷慨鏀 $btn.removeClass('disabled').prop('disabled', false).text(text.replace('...', '')).parent().find('span').remove(); if (data.code == 1) { if ($btn.data('success')) { var successCallback = $btn.data('success'); window[successCallback](data, statusText, xhr, $form); return; } noty({ text: data.msg, type: 'success', layout: 'center', modal: true, callback: { afterClose: function () { _refresh(); } } }); } else if (data.code == 0) { if ($btn.data('error')) { var errorCallback = $btn.data('error'); window[errorCallback](data, statusText, xhr, $form); return; } var $verify_img = $form.find(".verify_img"); if ($verify_img.length) { $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random()); } var $verify_input = $form.find("[name='verify']"); $verify_input.val(""); noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { _refresh(); } } }); } }, error: function (xhr, e, statusText) { noty({ text: statusText, type: 'error', layout: 'center', callback: { // afterClose: function () { // if (window.parent.art) { // reloadPage(window.parent); // } else { // //鍒锋柊褰撳墠椤 // reloadPage(window); // } // } } }); }, complete: function () { $btn.data("loading", false); } }); } }); }); }); } //dialog寮圭獥鍐呯殑鍏抽棴鏂规硶 $('#js-dialog-close').on('click', function (e) { e.preventDefault(); try { art.dialog.close(); } catch (err) { Wind.use('artDialog', 'iframeTools', function () { art.dialog.close(); }); } ; }); //鎵€鏈夌殑鍒犻櫎鎿嶄綔锛屽垹闄ゆ暟鎹悗鍒锋柊椤甸潰 if ($('a.js-ajax-delete').length) { Wind.use('noty', function () { $('.js-ajax-delete').on('click', function (e) { e.preventDefault(); var $_this = this, $this = $($_this), href = $this.data('href'), refresh = $this.data('refresh'), msg = $this.data('msg'); okBtnText = $this.data('ok-btn'); cancelBtnText = $this.data('cancel-btn'); href = href ? href : $this.attr('href'); noty({ text: msg ? msg : '纭畾瑕佸垹闄ゅ悧锛?, type: 'confirm', layout: "center", timeout: false, modal: true, buttons: [ { addClass: 'btn btn-primary', text: okBtnText ? okBtnText : '纭畾', onClick: function ($noty) { $noty.close(); $.getJSON(href).done(function (data) { if (data.code == 1) { if (data.url) { location.href = data.url; } else if (refresh || refresh == undefined) { reloadPage(window); } } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }); } }, { addClass: 'btn btn-danger', text: cancelBtnText ? cancelBtnText : '鍙栨秷', onClick: function ($noty) { $noty.close(); } } ] }); }); }); } if ($('a.js-ajax-dialog-btn').length) { Wind.use('noty', function () { $('.js-ajax-dialog-btn').on('click', function (e) { e.preventDefault(); var $_this = this, $this = $($_this), href = $this.data('href'), refresh = $this.data('refresh'), msg = $this.data('msg'); href = href ? href : $this.attr('href'); noty({ text: msg, type: 'confirm', layout: "center", timeout: false, modal: true, buttons: [ { addClass: 'btn btn-primary', text: '纭畾', onClick: function ($noty) { $noty.close(); $.getJSON(href).done(function (data) { if (data.code == 1) { if (data.url) { location.href = data.url; } else if (refresh || refresh == undefined) { reloadPage(window); } } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }); } }, { addClass: 'btn btn-danger', text: '鍙栨秷', onClick: function ($noty) { $noty.close(); } } ] }); }); }); } if ($('a.js-ajax-btn').length) { Wind.use('noty', function () { $('.js-ajax-btn').on('click', function (e) { e.preventDefault(); var $_this = this, $this = $($_this), href = $this.data('href'), msg = $this.data('msg'); refresh = $this.data('refresh'); href = href ? href : $this.attr('href'); refresh = refresh == undefined ? 1 : refresh; $.getJSON(href).done(function (data) { if (data.code == 1) { noty({ text: data.msg, type: 'success', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; return; } if (refresh || refresh == undefined) { reloadPage(window); } } } }); } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }); }); }); } //鎵€鏈夌殑璇锋眰鍒锋柊鎿嶄綔 var ajax_refresh = $('a.js-ajax-refresh'), refresh_lock = false; if (ajax_refresh.length) { ajax_refresh.on('click', function (e) { e.preventDefault(); if (refresh_lock) { return false; } refresh_lock = true; $.post(this.href, function (data) { refresh_lock = false; if (data.code == 1) { if (data.url) { location.href = data.url; } else { reloadPage(window); } } else if (data.code == 0) { Wind.art.dialog.alert(data.msg); } }, 'json'); }); } //鐭俊楠岃瘉鐮 var $js_get_mobile_code = $('.js-get-mobile-code'); if ($js_get_mobile_code.length > 0) { Wind.use('noty', function () { $js_get_mobile_code.on('click', function () { var $this = $(this); if ($this.data('loading')) return; if ($this.data('sending')) return; var $mobile_input = $($this.data('mobile-input')); var mobile = $mobile_input.val(); if (mobile == '') { $mobile_input.focus(); return; } var $form = $this.parents('form'); var $captchaInput = $("input[name='captcha']", $form); var $captchaIdInput = $("input[name='_captcha_id']", $form); var captcha = $captchaInput.val(); var captchaId = $captchaIdInput.val(); if (!captcha) { $captchaInput.focus(); return; } $this.data('loading', true); $this.data('sending', true); var url = $this.data('url'); var init_secode_left = parseInt($this.data('init-second-left')); init_secode_left = init_secode_left > 0 ? init_secode_left : 60; var init_text = $this.text(); $this.data('second-left', init_secode_left); var wait_msg = $this.data('wait-msg'); var codeType = $this.data('type'); $.ajax({ url: url, type: 'POST', dataType: 'json', data: {username: mobile, captcha: captcha, captcha_id: captchaId, type: codeType}, success: function (data) { if (data.code == 1) { noty({ text: data.msg, type: 'success', layout: 'center' }); $this.text(wait_msg.replace('[second]', init_secode_left)); var mtimer = setInterval(function () { if (init_secode_left > 0) { init_secode_left--; $this.text(wait_msg.replace('[second]', init_secode_left)); } else { clearInterval(mtimer); $this.text(init_text); $this.data('sending', false); } }, 1000); } else { $captchaInput.val(''); var $verify_img = $form.find(".verify_img"); if ($verify_img.length) { $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random()); } noty({ text: data.msg, type: 'error', layout: 'center' }); $this.data('sending', false); } }, error: function () { $this.data('sending', false); }, complete: function () { $this.data('loading', false); } }); }); }); } //閭欢楠岃瘉鐮 var $js_get_email_code = $('.js-get-email-code'); if ($js_get_email_code.length > 0) { Wind.use('noty', function () { $js_get_email_code.on('click', function () { var $this = $(this); if ($this.data('loading')) return; if ($this.data('sending')) return; var $email_input = $($this.data('email-input')); var email = $email_input.val(); if (email == '') { $email_input.focus(); return; } var $form = $this.parents('form'); var $captchaInput = $("input[name='captcha']", $form); var $captchaIdInput = $("input[name='_captcha_id']", $form); var captcha = $captchaInput.val(); var captchaId = $captchaIdInput.val(); if (!captcha) { $captchaInput.focus(); return; } $this.data('loading', true); $this.data('sending', true); var url = $this.data('url'); var init_secode_left = parseInt($this.data('init-second-left')); init_secode_left = init_secode_left > 0 ? init_secode_left : 60; var init_text = $this.text(); $this.data('second-left', init_secode_left); var wait_msg = $this.data('wait-msg'); var codeType = $this.data('type'); $.ajax({ url: url, type: 'POST', dataType: 'json', data: {username: email, captcha: captcha, captcha_id: captchaId, type: codeType}, success: function (data) { if (data.code == 1) { noty({ text: data.msg, type: 'success', layout: 'center' }); $this.text(wait_msg.replace('[second]', init_secode_left)); var mtimer = setInterval(function () { if (init_secode_left > 0) { init_secode_left--; $this.text(wait_msg.replace('[second]', init_secode_left)); } else { clearInterval(mtimer); $this.text(init_text); $this.data('sending', false); } }, 1000); } else { $captchaInput.val(''); var $verify_img = $form.find(".verify_img"); if ($verify_img.length) { $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random()); } noty({ text: data.msg, type: 'error', layout: 'center' }); $this.data('sending', false); } }, error: function () { $this.data('sending', false); }, complete: function () { $this.data('loading', false); } }); }); }); } /*澶嶉€夋鍏ㄩ€?鏀寔澶氫釜锛岀旱妯弻鎺у叏閫?銆 *瀹炰緥锛氱増鍧楃紪杈?鏉冮檺鐩稿叧锛堝弻鎺э級锛岄獙璇佹満鍒?楠岃瘉绛栫暐锛堝崟鎺э級 *璇存槑锛 * "js-check"鐨?data-xid"瀵瑰簲鍏跺乏渚?js-check-all"鐨?data-checklist"锛 * "js-check"鐨?data-yid"瀵瑰簲鍏朵笂鏂?js-check-all"鐨?data-checklist"锛 * 鍏ㄩ€夋鐨?data-direction"浠h〃鍏舵帶鍒剁殑鍏ㄩ€夋柟鍚?x鎴杫)锛 * "js-check-wrap"鍚屼竴鍧楀叏閫夋搷浣滃尯鍩熺殑鐖舵爣绛綾lass锛屽涓皟鐢ㄨ€冭檻 */ if ($('.js-check-wrap').length) { var total_check_all = $('input.js-check-all'); //閬嶅巻鎵€鏈夊叏閫夋 $.each(total_check_all, function () { var check_all = $(this), check_items; //鍒嗙粍鍚勭旱妯」 var check_all_direction = check_all.data('direction'); check_items = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled"); //鐐瑰嚮鍏ㄩ€夋 check_all.change(function (e) { var check_wrap = check_all.parents('.js-check-wrap'); //褰撳墠鎿嶄綔鍖哄煙鎵€鏈夊閫夋鐨勭埗鏍囩锛堥噸鐢ㄨ€冭檻锛 if ($(this).prop('checked')) { //鍏ㄩ€夌姸鎬 check_items.prop('checked', true); //鎵€鏈夐」閮借閫変腑 if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) { check_wrap.find(total_check_all).prop('checked', true); } } else { //闈炲叏閫夌姸鎬 check_items.removeProp('checked'); check_wrap.find(total_check_all).removeProp('checked'); //鍙︿竴鏂瑰悜鐨勫叏閫夋鍙栨秷鍏ㄩ€夌姸鎬 var direction_invert = check_all_direction === 'x' ? 'y' : 'x'; check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked'); } }); //鐐瑰嚮闈炲叏閫夋椂鍒ゆ柇鏄惁鍏ㄩ儴鍕鹃€ check_items.change(function () { if ($(this).prop('checked')) { if (check_items.filter(':checked').length === check_items.length) { //宸查€夋嫨鍜屾湭閫夋嫨鐨勫閫夋鏁扮浉绛 check_all.prop('checked', true); } } else { check_all.removeProp('checked'); } }); }); } //鏃ユ湡閫夋嫨鍣 var dateInput = $("input.js-date"); if (dateInput.length) { Wind.use('datePicker', function () { dateInput.datePicker(); }); } //鏃ユ湡+鏃堕棿閫夋嫨鍣 var dateTimeInput = $("input.js-datetime"); if (dateTimeInput.length) { Wind.use('datePicker', function () { dateTimeInput.datePicker({ time: true }); }); } // bootstrap骞撮€夋嫨鍣 var bootstrapYearInput = $("input.js-bootstrap-year") if (bootstrapYearInput.length) { Wind.css('bootstrapDatetimePicker'); Wind.use('bootstrapDatetimePicker', function () { bootstrapYearInput.datetimepicker({ language: 'zh-CN', format: 'yyyy', minView: 'decade', startView: 'decade', todayBtn: 1, autoclose: true }); }); } // bootstrap鏃ユ湡閫夋嫨鍣 var bootstrapDateInput = $("input.js-bootstrap-date") if (bootstrapDateInput.length) { Wind.css('bootstrapDatetimePicker'); Wind.use('bootstrapDatetimePicker', function () { bootstrapDateInput.datetimepicker({ language: 'zh-CN', format: 'yyyy-mm-dd', minView: 'month', todayBtn: 1, autoclose: true }); }); } // bootstrap鏃ユ湡閫夋嫨鍣ㄦ棩鏈?鏃堕棿閫夋嫨鍣 var bootstrapDateTimeInput = $("input.js-bootstrap-datetime"); if (bootstrapDateTimeInput.length) { Wind.css('bootstrapDatetimePicker'); Wind.use('bootstrapDatetimePicker', function () { bootstrapDateTimeInput.datetimepicker({ language: 'zh-CN', format: 'yyyy-mm-dd hh:ii', todayBtn: 1, autoclose: true }); }); } //璧烇紝鎷嶇瓑锛屾湁鏁伴噺鎿嶄綔鐨勬寜閽 var $js_count_btn = $('a.js-count-btn'); if ($js_count_btn.length) { Wind.use('noty', function () { $js_count_btn.on('click', function (e) { e.preventDefault(); var $this = $(this), href = $this.prop('href'); $.post(href, {}, function (data) { if (data.code == 1) { var $count = $this.find(".count"); var count = parseInt($count.text()); $count.text(count + 1); if (data.msg) { noty({ text: data.msg, type: 'success', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }, "json"); }); }); } //鍦板潃鑱斿姩 var $js_address_select = $('.js-address-select'); if ($js_address_select.length > 0) { $('.js-address-province-select,.js-address-city-select').change(function () { var $this = $(this); var id = $this.val(); var $child_area_select; var $this_js_address_select = $this.parents('.js-address-select'); if ($this.is('.js-address-province-select')) { $child_area_select = $this_js_address_select.find('.js-address-city-select'); $this_js_address_select.find('.js-address-district-select').hide(); } else { $child_area_select = $this_js_address_select.find('.js-address-district-select'); } var empty_option = ''; $child_area_select.html(empty_option); var child_area_html = $this.data('childarea' + id); if (child_area_html) { $child_area_select.show(); $child_area_select.html(child_area_html); return; } $.ajax({ url: $this_js_address_select.data('url'), type: 'POST', dataType: 'JSON', data: {id: id}, success: function (data) { if (data.code == 1) { if (data.data.areas.length > 0) { var html = [empty_option]; $.each(data.data.areas, function (i, area) { var area_html = ''; area_html = area_html.replace('[name]', area.name); area_html = area_html.replace('[id]', area.id); html.push(area_html); }); html = html.join('', html); $this.data('childarea' + id, html); $child_area_select.html(html); $child_area_select.show(); } else { $child_area_select.hide(); } } }, error: function () { }, complete: function () { } }); }); } //鍦板潃鑱斿姩end // var $js_action_btn = $('a.js-action-btn'); if ($js_action_btn.length) { Wind.use('noty', function () { $js_action_btn.on('click', function (e) { e.preventDefault(); var $this = $(this), href = $this.prop('href'); $.post(href, {}, function (data) { if (data.code == '1') { if (data.msg) { noty({ text: data.msg, type: 'success', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }, "json"); }); }); } var $js_favorite_btn = $('a.js-favorite-btn'); if ($js_favorite_btn.length) { Wind.use('noty', function () { $js_favorite_btn.on('click', function (e) { e.preventDefault(); var $this = $(this), href = $this.prop('href'), url = $this.data("url"), id = $this.data("id"), table = $this.data('table'), title = $this.data("title"), description = $this.data("description"); $.post(href, { id: id, table: table, url: url, title: title, description: description }, function (data) { if (data.code == 1) { if (data.msg) { noty({ text: data.msg, type: 'success', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } } else if (data.code == 0) { noty({ text: data.msg, type: 'error', layout: 'center', callback: { afterClose: function () { if (data.url) { location.href = data.url; } } } }); } }, "json"); }); }); } })(); //閲嶆柊鍒锋柊椤甸潰锛屼娇鐢╨ocation.reload()鏈夊彲鑳藉鑷撮噸鏂版彁浜 function reloadPage(win) { if (win) { } else { win = window; } var location = win.location; location.href = location.pathname + location.search; } //椤甸潰璺宠浆 function redirect(url) { location.href = url; } /** * 璇诲彇cookie * @param name * @returns */ function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } /** * 璁剧疆cookie */ function setCookie(name, value, options) { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } var path = options.path ? '; path=' + options.path : ''; var domain = options.domain ? '; domain=' + options.domain : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } function openIframeDialog(url, title, options) { var params = { title: title, lock: true, opacity: 0, width: "95%" }; params = options ? $.extend(params, options) : params; Wind.use('artDialog', 'iframeTools', function () { art.dialog.open(url, params); }); } /** * 鎵撳紑鍦板浘瀵硅瘽妗 * * @param url * @param title * @param options * @param callback */ function openMapDialog(url, title, options, callback) { Wind.css('artDialog'); var params = { title: title, lock: true, opacity: 0, width: "95%", height: 400, ok: function () { if (callback) { var d = this.iframe.contentWindow; var lng = $("#lng_input", d.document).val(); var lat = $("#lat_input", d.document).val(); var address = {}; address.address = $("#address_input", d.document).val(); address.province = $("#province_input", d.document).val(); address.city = $("#city_input", d.document).val(); address.district = $("#district_input", d.document).val(); callback.apply(this, [lng, lat, address]); } } }; params = options ? $.extend(params, options) : params; Wind.use('artDialog', 'iframeTools', function () { art.dialog.open(url, params); }); } /** * 鎵撳紑鏂囦欢涓婁紶瀵硅瘽妗 * @param dialog_title 瀵硅瘽妗嗘爣棰 * @param callback 鍥炶皟鏂规硶锛屽弬鏁版湁锛堝綋鍓峝ialog瀵硅薄锛岄€夋嫨鐨勬枃浠舵暟缁勶紝浣犺缃殑extra_params锛 * @param extra_params 棰濆鍙傛暟锛宱bject * @param multi 鏄惁鍙互澶氶€ * @param filetype 鏂囦欢绫诲瀷锛宨mage,video,audio,file * @param app 搴旂敤鍚嶏紝CMF鐨勫簲鐢ㄥ悕 */ function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) { Wind.css('artDialog'); multi = multi ? 1 : 0; filetype = filetype ? filetype : 'image'; app = app ? app : GV.APP; var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app; Wind.use("artDialog", "iframeTools", function () { art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, { title: dialog_title, id: new Date().getTime(), width: '600px', height: '350px', lock: true, fixed: true, background: "#CCCCCC", opacity: 0, ok: function () { if (typeof callback == 'function') { var iframewindow = this.iframe.contentWindow; var files = iframewindow.get_selected_files(); console.log(files); if (files && files.length > 0) { callback.apply(this, [this, files, extra_params]); } else { return false; } } }, cancel: true }); }); } /** * 鍗曚釜鏂囦欢涓婁紶 * @param dialog_title 涓婁紶瀵硅瘽妗嗘爣棰 * @param input_selector 鍥剧墖瀹瑰櫒 * @param filetype 鏂囦欢绫诲瀷锛宨mage,video,audio,file * @param extra_params 棰濆鍙傛暟锛宱bject * @param app 搴旂敤鍚?CMF鐨勫簲鐢ㄥ悕 */ function uploadOne(dialog_title, input_selector, filetype, extra_params, app) { filetype = filetype ? filetype : 'file'; openUploadDialog(dialog_title, function (dialog, files) { $(input_selector).val(files[0].filepath); $(input_selector + '-preview').attr('href', files[0].preview_url); $(input_selector + '-name').val(files[0].name); $(input_selector + '-name-text').text(files[0].name); }, extra_params, 0, filetype, app); } /** * 鍗曚釜鍥剧墖涓婁紶 * @param dialog_title 涓婁紶瀵硅瘽妗嗘爣棰 * @param input_selector 鍥剧墖瀹瑰櫒 * @param extra_params 棰濆鍙傛暟锛宱bject * @param app 搴旂敤鍚?CMF鐨勫簲鐢ㄥ悕 */ function uploadOneImage(dialog_title, input_selector, extra_params, app) { openUploadDialog(dialog_title, function (dialog, files) { $(input_selector).val(files[0].filepath); $(input_selector + '-preview').attr('src', files[0].preview_url); $(input_selector + '-name').val(files[0].name); $(input_selector + '-name-text').text(files[0].name); }, extra_params, 0, 'image', app); } /** * 澶氬浘涓婁紶 * @param dialog_title 涓婁紶瀵硅瘽妗嗘爣棰 * @param container_selector 鍥剧墖瀹瑰櫒 * @param item_tpl_wrapper_id 鍗曚釜鍥剧墖html妯℃澘瀹瑰櫒id * @param extra_params 棰濆鍙傛暟锛宱bject * @param app 搴旂敤鍚?CMF 鐨勫簲鐢ㄥ悕 */ function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) { openUploadDialog(dialog_title, function (dialog, files) { var tpl = $('#' + item_tpl_wrapper_id).html(); var html = ''; $.each(files, function (i, item) { var itemtpl = tpl; itemtpl = itemtpl.replace(/\{id\}/g, item.id); itemtpl = itemtpl.replace(/\{url\}/g, item.url); itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url); itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath); itemtpl = itemtpl.replace(/\{name\}/g, item.name); html += itemtpl; }); $(container_selector).append(html); }, extra_params, 1, 'image', app); } /** * 澶氭枃浠朵笂浼 * @param dialog_title 涓婁紶瀵硅瘽妗嗘爣棰 * @param container_selector 鍥剧墖瀹瑰櫒 * @param item_tpl_wrapper_id 鍗曚釜鍥剧墖html妯℃澘瀹瑰櫒id * @param filetype 鏂囦欢绫诲瀷锛宨mage,video,audio,file * @param extra_params 棰濆鍙傛暟锛宱bject * @param app 搴旂敤鍚?CMF 鐨勫簲鐢ㄥ悕 */ function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) { filetype = filetype ? filetype : 'file'; openUploadDialog(dialog_title, function (dialog, files) { var tpl = $('#' + item_tpl_wrapper_id).html(); var html = ''; $.each(files, function (i, item) { var itemtpl = tpl; itemtpl = itemtpl.replace(/\{id\}/g, item.id); itemtpl = itemtpl.replace(/\{url\}/g, item.url); itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url); itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath); itemtpl = itemtpl.replace(/\{name\}/g, item.name); html += itemtpl; }); $(container_selector).append(html); }, extra_params, 1, filetype, app); } function openIframeLayer(url, title, options) { var params = { type: 2, title: title, shadeClose: true, // skin: 'layui-layer-nobg', shade: [0.001, '#000000'], shadeClose: true, area: ['95%', '90%'], move: false, content: url, yes: function (index, layero) { //do something layer.close(index); //濡傛灉璁惧畾浜唝es鍥炶皟锛岄渶杩涜鎵嬪伐鍏抽棴 } }; params = options ? $.extend(params, options) : params; Wind.css('layer'); Wind.use("layer", function () { layer.open(params); }); }