123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- /*全局自适应高度*/
- /*全局自适应高度*/
- function autoFlashHeight(){
- function getObjHeight(select) {
- return select.length > 0 ? select.height() : 0;
- }
- /*侧栏高度*/
- var sBar1 = getObjHeight($(".sjs-bar-1"));
- var sBar2 = getObjHeight($(".sjs-bar-2"));
- var sBar3 = getObjHeight($(".sjs-bar-3"));
- var sBar4 = getObjHeight($(".sjs-bar-4"));
- var sBar5 = getObjHeight($(".sjs-bar-5"));
- /*侧栏高度*/
- var cHeader = getObjHeight($(".c-header"));
- var sBar = getObjHeight($(".sjs-bar"));
- var sBart = getObjHeight($(".sjs-bart"));
- var sBarz = getObjHeight($(".side-bar"));
- var pBarz = getObjHeight($(".toolsbar-f"));
- var bdtopc = getObjHeight($(".body-height-top"));
- var bcontent = getObjHeight($(".bcontent-wrap"));
- $(".sjs-height-0").height($(window).height()-cHeader-90+53);
- $(".sjs-height-1").height($(window).height()-cHeader-bcontent-90+53);
- $(".sjs-height-2").height($(window).height()-cHeader-sBarz-120);
- $(".sjs-height-3").height($(window).height()-cHeader-sBar-492+25);/*492*/
- $(".sjs-height-4").height($(window).height()-cHeader-pBarz-110+75);
- $(".sjs-height-5").height($(window).height()-cHeader-sBar-492+55);/*492*/
- $(".sp-wrap").height(bcontent-30);
- /*侧栏高度*/
- $(".sjs-sh-1").height($(window).height()-cHeader-sBar1-92+55);
- $(".sjs-sh-2").height($(window).height()-cHeader-sBar2-92+55);
- $(".sjs-sh-3").height($(window).height()-cHeader-sBar3-92+55);
- $(".sjs-sh-4").height($(window).height()-cHeader-sBar4-92+55);
- $(".sjs-sh-5").height($(window).height()-cHeader-sBar5-92+55);
- };
- $(window).resize(autoFlashHeight);
- /*全局自适应高度结束*/
- $(function(){
- /*侧滑*/
- $(".open-sidebar").click(function(){
- $(".slide-sidebar").animate({width:"800"}).addClass("open");
- });
- $("body").click(function(event){
- var e = event || window.event; //浏览器兼容性
- if(!$(event.target).is('a')) {
- var elem = event.target || e.srcElement;
- while (elem) { //循环判断至跟节点,防止点击的是div子元素
- if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
- return false;
- }
- elem = elem.parentNode;
- }
- $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
- }
- });
- /*侧滑*/
- /*工具提示*/
- $(function () {
- $('[data-toggle="tooltip"]').tooltip()
- });
- /*侧栏菜单*/
- $(".bg-nav > li > a").click(function() {
- var self = $(this);
- var subMenu = $(this).siblings('ul.sub-menu');
- if(subMenu.length > 0) {
- if(subMenu.is(":visible")) {
- self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
- subMenu.slideUp('fast');
- self.parent().removeClass('active');
- }else{
- self.parent().addClass('active');
- self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
- subMenu.slideDown('fast');
- }
- }
- });
- // 数据提交
- $("#submit-form").click(function() {
- $("#save-form").submit();
- });
- // modal弹窗拖动
- // $(document).on("show.bs.modal", ".modal", function() {
- // $(this).draggable({
- // handle: ".modal-header" // 只能点击头部拖动
- // });
- // $(this).css("overflow", "hidden");
- // });
- // 动态生成datepicker
- $('body').on('focus', ".datepicker-here", function (e) {
- if ($(this).data("datepicker") != "1") {
- $(this).datepicker();
- }
- $(this).data("datepicker", "1");
- });
- });
- /**
- * 提示框
- *
- * @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);
- }
- /**
- * 动态请求数据
- * @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');
- xhr.setRequestHeader('x-csrf-token', csrfToken);
- },
- success: function(result){
- if (result.err === 0) {
- if (successCallback) {
- successCallback(result.data);
- }
- } 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 postDataCompress = function (url, data, successCallback, errorCallBack, htype = 'progress') {
- if (htype === 'wait') showWaitingView();
- if (htype === 'progress') showProgress();
- $.ajax({
- type:"POST",
- url: url,
- data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
- dataType: 'json',
- cache: false,
- timeout: 80000, // 导入清单Excel(10w行)预计需要时间
- beforeSend: function(xhr) {
- let csrfToken = Cookies.get('csrfToken');
- xhr.setRequestHeader('x-csrf-token', csrfToken);
- },
- success: function(result){
- if (htype === 'progress') doneProgress();
- if (result.err === 0) {
- if (successCallback) {
- successCallback(result.data);
- }
- } else {
- toastr.error('error: ' + result.msg);
- if (errorCallBack) {
- errorCallBack(result.msg);
- }
- }
- if (htype === 'wait') closeWaitingView();
- if (htype === 'progress') closeProgress();
- },
- error: function(jqXHR, textStatus, errorThrown){
- toastr.error('error: ' + textStatus + " " + errorThrown);
- if (errorCallBack) {
- errorCallBack();
- }
- if (htype === 'wait') closeWaitingView();
- if (htype === 'progress') closeProgress();
- }
- });
- };
- /**
- * 动态请求数据
- * @param {String} url - 请求链接
- * @param data - 提交数据
- * @param {function} successCallback - 返回成功回调
- * @param {function} errorCallBack - 返回失败回调
- */
- const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) {
- if (showWaiting) showWaitingView();
- $.ajax({
- type:"POST",
- url: url,
- data: formData,
- dataType: 'json',
- cache: false,
- // 告诉jQuery不要去设置Content-Type请求头
- contentType: false,
- // 告诉jQuery不要去处理发送的数据
- processData: false,
- timeout: 5000,
- beforeSend: function(xhr) {
- let csrfToken = Cookies.get('csrfToken');
- xhr.setRequestHeader('x-csrf-token', csrfToken);
- },
- success: function(result){
- if (result.err === 0) {
- if (successCallback) {
- successCallback(result.data);
- }
- } 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();
- }
- });
- };
- /**
- * 获取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 === ''));
- }
- var bShowWaiting = false, beginWaitingTime;
- //关闭等待窗口
- 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 + 1000, 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);
- }
- let progressInterval;
- function showProgress() {
- 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.classList.add('progress');
- msgObj.style.zIndex = '9999';
- msgObj.style.position = "absolute";
- msgObj.setAttribute("id", "progressDiv");
- msgObj.style.height = "2px";
- msgObj.style.width = "600px";
- msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
- msgObj.style.left = (sWidth - 600) / 2 + "px";
- document.body.appendChild(msgObj);
- msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
- const processObj = $('.progress-bar');
- let count = 0;
- progressInterval = setInterval(function () {
- const pos = parseInt(processObj.attr('aria-valuenow'));
- if (pos < 20) { // 1
- processObj.attr('aria-valuenow', pos + 2);
- processObj.width((pos + 2) + '%');
- } else if (pos < 40) { // 2
- processObj.attr('aria-valuenow', pos + 1);
- processObj.width((pos + 1) + '%');
- } else if (pos < 60) { // 4
- count += 1;
- if (count % 2 === 0) {
- processObj.attr('aria-valuenow', pos + 1);
- processObj.width((pos + 1) + '%');
- }
- } else if (pos < 80) { // 10
- count += 1;
- if (count % 5 === 0) {
- processObj.attr('aria-valuenow', pos + 1);
- processObj.width((pos + 1) + '%');
- }
- } else if (pos < 90) { // 15
- count += 1;
- if (count % 15 === 0) {
- processObj.attr('aria-valuenow', pos + 1);
- processObj.width((pos + 1) + '%');
- }
- } else if (pos < 95) { // 20
- count += 1;
- if (count % 40 === 0) {
- processObj.attr('aria-valuenow', pos + 1);
- processObj.width((pos + 1) + '%');
- }
- } else if (pos < 100) { // 30
- count += 1;
- if (count % 60 === 0) {
- processObj.attr('aria-valuenow', pos + 1);
- }
- }
- }, 100);
- }
- function doneProgress() {
- clearInterval(progressInterval);
- $('.progress-bar').attr('aria-valuenow', 100).width('100%');
- }
- function closeProgress() {
- setTimeout(function () {
- var bgDiv = document.getElementById("bgDiv");
- var msgDiv = document.getElementById("progressDiv");
- //移除背景遮罩层div
- if(bgDiv != null){
- document.body.removeChild(bgDiv);
- }
- //移除中间信息提示层div
- if(msgDiv != null){
- document.body.removeChild(msgDiv);
- }
- }, 500);
- }
- /**
- * 设置本地缓存
- *
- * @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);
- }
- //params: 需要复制的对象(元素)
- function copyToClipboard( text ) {
- var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
- var aux = document.createElement('textarea');// 创建元素用于复制
- // Prevent zooming on iOS
- aux.style.fontSize = '12pt';
- // Reset box model
- aux.style.border = '0';
- aux.style.padding = '0';
- aux.style.margin = '0';
- // Move element out of screen horizontally
- aux.style.position = 'absolute';
- aux.style[isRTL ? 'right' : 'left'] = '-9999px';
- // Move element to the same position vertically
- var yPosition = window.pageYOffset || document.documentElement.scrollTop;
- aux.style.top = yPosition + 'px';
- aux.setAttribute('readonly', '');
- // 设置元素内容
- aux.value = text;
- // 将元素插入页面进行调用
- document.body.appendChild(aux);
- // 复制内容
- aux.select();
- aux.setSelectionRange(0, text.length);
- // 将内容复制到剪贴板
- document.execCommand("copy", true);
- // 删除创建元素
- document.body.removeChild(aux);
- }
- function toastMessageUniq (obj) {
- if (!obj.msg || !obj.type) return;
- if (!obj.once) {
- switch (obj.type) {
- case 'error':
- toastr.error(obj.msg);
- break;
- case 'warning':
- toastr.warning(obj.msg);
- break;
- case 'info':
- toastr.info(obj.msg);
- break;
- case 'success':
- toastr.success(obj.msg);
- break;
- }
- obj.once = true;
- }
- }
- function trimInvalidChar(str) {
- return $.trim(str).replace('\n', '').replace('\r', '').replace('\t', '');
- }
|