$(function () { $('a').on('click', function () { if ($(this).hasClass('show-loading')) { showWaitingView(); } }); $('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="popover"]').popover(); }) /** * 动态请求数据 * @param {String} url - 请求链接 * @param data - 提交数据 * @param {function} successCallback - 返回成功回调 * @param {function} errorCallBack - 返回失败回调 */ const postData = function (url, data, successCallback, errorCallBack, showWaiting = true) { if (showWaiting) showWaitingView(); $.ajax({ type:"POST", url: url, data: {'data': JSON.stringify(data)}, dataType: 'json', cache: false, timeout: 60000, beforeSend: function(xhr) { let csrfToken = Cookies.get('csrfToken_j'); xhr.setRequestHeader('x-csrf-token', csrfToken); }, success: function(result){ if (result.err === 0) { if (successCallback) { successCallback(result.data); } } else if (result.err === 2) { toastr.error('error: ' + result.msg); setTimeout(function () { window.location.href = '/wap/login'; },1000); } else { toastr.error('error: ' + result.msg); if (errorCallBack) { errorCallBack(result.msg); } } if (showWaiting) closeWaitingView(); }, error: function(jqXHR, textStatus, errorThrown){ toastr.error('error: ' + textStatus + " " + errorThrown); if (errorCallBack) { errorCallBack(); } if (showWaiting) closeWaitingView(); } }); }; /** * 动态请求数据 * @param {String} url - 请求链接 * @param data - 提交数据 * @param {function} successCallback - 返回成功回调 * @param {function} errorCallBack - 返回失败回调 */ const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) { if (showWaiting) showWaitingView(); if (formData.getAll('file[]').length > 10) { toastr.error('文件数量不能多于10个'); if (showWaiting) closeWaitingView(); return } $.ajax({ type:"POST", url: url, data: formData, dataType: 'json', cache: false, // 告诉jQuery不要去设置Content-Type请求头 contentType: false, // 告诉jQuery不要去处理发送的数据 processData: false, timeout: 60000, beforeSend: function(xhr) { let csrfToken = Cookies.get('csrfToken_j'); xhr.setRequestHeader('x-csrf-token', csrfToken); }, success: function(result){ if (result.err === 0) { if (successCallback) { successCallback(result.data); } } else if (result.err === 2) { toastr.error('error: ' + result.msg); setTimeout(function () { window.location.href = '/wap/login'; },1000); } else { toastr.error('error: ' + result.msg); if (errorCallBack) { errorCallBack(); } } if (showWaiting) closeWaitingView(); }, error: function(jqXHR, textStatus, errorThrown){ toastr.error('error: ' + textStatus + " " + errorThrown); if (errorCallBack) { errorCallBack(); } if (showWaiting) closeWaitingView(); } }); }; /** * 提示框 * * @param string message * @param string type * @param string icon * @return void */ function toast(message, type, icon) { var toast = $(".toast"); toast.addClass(type); toast.children('.message').html(message); var iconClass = 'fa-' + icon; toast.children('.icon').addClass(iconClass); toast.fadeIn(500); setTimeout(function() { toast.fadeOut('fast'); toast.children('.message').text(''); toast.children('.icon').removeClass(iconClass); }, 3000); } /** * 获取url中参数 * @param variable * @returns {*} */ function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i