123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- $(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<vars.length;i++) {
- var pair = vars[i].split("=");
- if(pair[0] == variable){return pair[1];}
- }
- return(false);
- }
- const zeroRange = 0.00000001;
- function checkZero(value) {
- return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
- }
- function checkFieldChange(o, n) {
- return o == n || ((!o || o === '') && (n === ''));
- }
- /**
- * 设置本地缓存
- *
- * @param {String} key
- * @param {String|Number} value
- * @return {void}
- */
- function setLocalCache(key, value) {
- const storage = window.localStorage;
- if (!storage || key === '' || value === '') {
- return;
- }
- storage.setItem(key, value);
- }
- /**
- * 获取本地缓存
- *
- * @param {String} key
- * @return {String}
- */
- function getLocalCache(key) {
- const storage = window.localStorage;
- if (!storage || key === '') {
- return null;
- }
- return storage.getItem(key);
- }
- /**
- * 移除本地缓存
- * @param {String} key
- * @returns {Boolean}
- */
- function removeLocalCache(key) {
- const storage = window.localStorage;
- if (!storage || key === '') {
- return null;
- }
- return storage.removeItem(key);
- }
- function trimInvalidChar(str) {
- return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
- }
- function cleanSymbols(str) {
- return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
- }
- //关闭等待窗口
- function closeWaitingView() {
- bShowWaiting = false;
- const time = parseInt(new Date());
- setTimeout(function () {
- var bgDiv = document.getElementById("bgDiv");
- var msgDiv = document.getElementById("msgDiv");
- //移除背景遮罩层div
- if(bgDiv != null){
- document.body.removeChild(bgDiv);
- }
- //移除中间信息提示层div
- if(msgDiv != null){
- document.body.removeChild(msgDiv);
- }
- }, Math.max(beginWaitingTime - time + 500, 0));
- }
- //显示等待窗口
- function showWaitingView() {
- // bShowWaiting = true;
- // setTimeout(function () {
- // if (!bShowWaiting) return;
- // beginWaitingTime = parseInt(new Date());
- // var msgw = 300; //提示窗口的宽度
- // var msgh = 100; //提示窗口的高度
- //
- // var sWidth, sHeight;
- // sWidth = document.body.clientWidth;
- // sHeight = document.body.clientHeight;
- //
- // //背景遮罩层div
- // var bgObj = document.createElement("div");
- // bgObj.setAttribute('id', 'bgDiv');
- // bgObj.style.zIndex = '9998';
- // bgObj.style.position = "absolute";
- // bgObj.style.top = "0px";
- // bgObj.style.background = "#888";
- // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
- // bgObj.style.opacity = "0.6";
- // bgObj.style.left = "0px";
- // bgObj.style.width = sWidth + "px";
- // bgObj.style.height = sHeight + "px";
- // document.body.appendChild(bgObj);
- //
- // //信息提示层div
- // var msgObj = document.createElement("div");
- // msgObj.style.zIndex = '9999';
- // msgObj.setAttribute("id", "msgDiv");
- // msgObj.setAttribute("align", "center");
- // msgObj.style.position = "absolute";
- // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
- // msgObj.style.width = msgw + "px";
- // msgObj.style.height = msgh + "px";
- // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
- // msgObj.style.left = (sWidth - msgw) / 2 + "px";
- // document.body.appendChild(msgObj);
- //
- // //中间等待图标
- // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
- // }, 1000);
- beginWaitingTime = parseInt(new Date());
- var msgw = 300; //提示窗口的宽度
- var msgh = 100; //提示窗口的高度
- var sWidth, sHeight;
- sWidth = document.body.clientWidth;
- sHeight = document.body.clientHeight;
- //背景遮罩层div
- var bgObj = document.createElement("div");
- bgObj.setAttribute('id', 'bgDiv');
- bgObj.style.zIndex = '9998';
- bgObj.style.position = "absolute";
- bgObj.style.top = "0px";
- // bgObj.style.background = "#888";
- bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
- bgObj.style.opacity = "0.6";
- bgObj.style.left = "0px";
- bgObj.style.width = sWidth + "px";
- bgObj.style.height = sHeight + "px";
- document.body.appendChild(bgObj);
- //信息提示层div
- var msgObj = document.createElement("div");
- msgObj.style.zIndex = '9999';
- msgObj.setAttribute("id", "msgDiv");
- msgObj.setAttribute("align", "center");
- msgObj.style.position = "fixed";
- msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
- msgObj.style.width = msgw + "px";
- msgObj.style.height = msgh + "px";
- // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
- msgObj.style.top = "50%";
- msgObj.style.left = (sWidth - msgw) / 2 + "px";
- document.body.appendChild(msgObj);
- //中间等待图标
- document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
- }
|