global.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*全局自适应高度*/
  2. /*全局自适应高度*/
  3. function autoFlashHeight(){
  4. function getObjHeight(select) {
  5. return select.length > 0 ? select.height() : 0;
  6. }
  7. /*侧栏高度*/
  8. var sBar1 = getObjHeight($(".sjs-bar-1"));
  9. var sBar2 = getObjHeight($(".sjs-bar-2"));
  10. var sBar3 = getObjHeight($(".sjs-bar-3"));
  11. var sBar4 = getObjHeight($(".sjs-bar-4"));
  12. var sBar5 = getObjHeight($(".sjs-bar-5"));
  13. /*侧栏高度*/
  14. var cHeader = getObjHeight($(".c-header"));
  15. var sBar = getObjHeight($(".sjs-bar"));
  16. var sBart = getObjHeight($(".sjs-bart"));
  17. var sBarz = getObjHeight($(".side-bar"));
  18. var pBarz = getObjHeight($(".toolsbar-f"));
  19. var bdtopc = getObjHeight($(".body-height-top"));
  20. var bcontent = getObjHeight($(".bcontent-wrap"));
  21. $(".sjs-height-0").height($(window).height()-cHeader-90+53);
  22. $(".sjs-height-1").height($(window).height()-cHeader-bcontent-90+53);
  23. $(".sjs-height-2").height($(window).height()-cHeader-sBarz-120);
  24. $(".sjs-height-3").height($(window).height()-cHeader-sBar-492+25);/*492*/
  25. $(".sjs-height-4").height($(window).height()-cHeader-pBarz-110+75);
  26. $(".sjs-height-5").height($(window).height()-cHeader-sBar-492+55);/*492*/
  27. $(".sp-wrap").height(bcontent-30);
  28. /*侧栏高度*/
  29. $(".sjs-sh-1").height($(window).height()-cHeader-sBar1-92+55);
  30. $(".sjs-sh-2").height($(window).height()-cHeader-sBar2-92+55);
  31. $(".sjs-sh-3").height($(window).height()-cHeader-sBar3-92+55);
  32. $(".sjs-sh-4").height($(window).height()-cHeader-sBar4-92+55);
  33. $(".sjs-sh-5").height($(window).height()-cHeader-sBar5-92+55);
  34. for (const sh of $('.sjs-sh')) {
  35. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parent))-92+55);
  36. }
  37. };
  38. $(window).resize(autoFlashHeight);
  39. /*全局自适应高度结束*/
  40. $(function(){
  41. /*侧滑*/
  42. $(".open-sidebar").click(function(){
  43. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  44. });
  45. $("body").click(function(event){
  46. var e = event || window.event; //浏览器兼容性
  47. if(!$(event.target).is('a')) {
  48. var elem = event.target || e.srcElement;
  49. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  50. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  51. return false;
  52. }
  53. elem = elem.parentNode;
  54. }
  55. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  56. }
  57. });
  58. /*侧滑*/
  59. /*工具提示*/
  60. $(function () {
  61. $('[data-toggle="tooltip"]').tooltip()
  62. });
  63. /*侧栏菜单*/
  64. $(".bg-nav > li > a").click(function() {
  65. var self = $(this);
  66. var subMenu = $(this).siblings('ul.sub-menu');
  67. if(subMenu.length > 0) {
  68. if(subMenu.is(":visible")) {
  69. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  70. subMenu.slideUp('fast');
  71. self.parent().removeClass('active');
  72. }else{
  73. self.parent().addClass('active');
  74. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  75. subMenu.slideDown('fast');
  76. }
  77. }
  78. });
  79. // 数据提交
  80. $("#submit-form").click(function() {
  81. $("#save-form").submit();
  82. });
  83. // modal弹窗拖动
  84. // $(document).on("show.bs.modal", ".modal", function() {
  85. // $(this).draggable({
  86. // handle: ".modal-header" // 只能点击头部拖动
  87. // });
  88. // $(this).css("overflow", "hidden");
  89. // });
  90. // 动态生成datepicker
  91. $('body').on('focus', ".datepicker-here", function (e) {
  92. if ($(this).data("datepicker") != "1") {
  93. $(this).datepicker();
  94. }
  95. $(this).data("datepicker", "1");
  96. });
  97. });
  98. /**
  99. * 提示框
  100. *
  101. * @param string message
  102. * @param string type
  103. * @param string icon
  104. * @return void
  105. */
  106. function toast(message, type, icon) {
  107. var toast = $(".toast");
  108. toast.addClass(type);
  109. toast.children('.message').html(message);
  110. var iconClass = 'fa-' + icon;
  111. toast.children('.icon').addClass(iconClass);
  112. toast.fadeIn(500);
  113. setTimeout(function() {
  114. toast.fadeOut('fast');
  115. toast.children('.message').text('');
  116. toast.children('.icon').removeClass(iconClass);
  117. }, 3000);
  118. }
  119. /**
  120. * 动态请求数据
  121. * @param {String} url - 请求链接
  122. * @param data - 提交数据
  123. * @param {function} successCallback - 返回成功回调
  124. * @param {function} errorCallBack - 返回失败回调
  125. */
  126. const postData = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  127. if (showWaiting) showWaitingView();
  128. $.ajax({
  129. type:"POST",
  130. url: url,
  131. data: {'data': JSON.stringify(data)},
  132. dataType: 'json',
  133. cache: false,
  134. timeout: 60000,
  135. beforeSend: function(xhr) {
  136. let csrfToken = Cookies.get('csrfToken');
  137. xhr.setRequestHeader('x-csrf-token', csrfToken);
  138. },
  139. success: function(result){
  140. if (result.err === 0) {
  141. if (successCallback) {
  142. successCallback(result.data);
  143. }
  144. } else {
  145. toastr.error('error: ' + result.msg);
  146. if (errorCallBack) {
  147. errorCallBack(result.msg);
  148. }
  149. }
  150. if (showWaiting) closeWaitingView();
  151. },
  152. error: function(jqXHR, textStatus, errorThrown){
  153. toastr.error('error: ' + textStatus + " " + errorThrown);
  154. if (errorCallBack) {
  155. errorCallBack();
  156. }
  157. if (showWaiting) closeWaitingView();
  158. }
  159. });
  160. };
  161. /**
  162. * 动态请求数据(压缩数据)
  163. * @param {String} url - 请求链接
  164. * @param data - 提交数据
  165. * @param {function} successCallback - 返回成功回调
  166. * @param {function} errorCallBack - 返回失败回调
  167. */
  168. const postDataCompress = function (url, data, successCallback, errorCallBack, htype = 'progress') {
  169. if (htype === 'wait') showWaitingView();
  170. if (htype === 'progress') showProgress();
  171. $.ajax({
  172. type:"POST",
  173. url: url,
  174. data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
  175. dataType: 'json',
  176. cache: false,
  177. timeout: 80000, // 导入清单Excel(10w行)预计需要时间
  178. beforeSend: function(xhr) {
  179. let csrfToken = Cookies.get('csrfToken');
  180. xhr.setRequestHeader('x-csrf-token', csrfToken);
  181. },
  182. success: function(result){
  183. if (htype === 'progress') doneProgress();
  184. if (result.err === 0) {
  185. if (successCallback) {
  186. successCallback(result.data);
  187. }
  188. } else {
  189. toastr.error('error: ' + result.msg);
  190. if (errorCallBack) {
  191. errorCallBack(result.msg);
  192. }
  193. }
  194. if (htype === 'wait') closeWaitingView();
  195. if (htype === 'progress') closeProgress();
  196. },
  197. error: function(jqXHR, textStatus, errorThrown){
  198. toastr.error('error: ' + textStatus + " " + errorThrown);
  199. if (errorCallBack) {
  200. errorCallBack();
  201. }
  202. if (htype === 'wait') closeWaitingView();
  203. if (htype === 'progress') closeProgress();
  204. }
  205. });
  206. };
  207. /**
  208. * 动态请求数据
  209. * @param {String} url - 请求链接
  210. * @param data - 提交数据
  211. * @param {function} successCallback - 返回成功回调
  212. * @param {function} errorCallBack - 返回失败回调
  213. */
  214. const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) {
  215. if (showWaiting) showWaitingView();
  216. $.ajax({
  217. type:"POST",
  218. url: url,
  219. data: formData,
  220. dataType: 'json',
  221. cache: false,
  222. // 告诉jQuery不要去设置Content-Type请求头
  223. contentType: false,
  224. // 告诉jQuery不要去处理发送的数据
  225. processData: false,
  226. timeout: 5000,
  227. beforeSend: function(xhr) {
  228. let csrfToken = Cookies.get('csrfToken');
  229. xhr.setRequestHeader('x-csrf-token', csrfToken);
  230. },
  231. success: function(result){
  232. if (result.err === 0) {
  233. if (successCallback) {
  234. successCallback(result.data);
  235. }
  236. } else {
  237. toastr.error('error: ' + result.msg);
  238. if (errorCallBack) {
  239. errorCallBack();
  240. }
  241. }
  242. if (showWaiting) closeWaitingView();
  243. },
  244. error: function(jqXHR, textStatus, errorThrown){
  245. toastr.error('error: ' + textStatus + " " + errorThrown);
  246. if (errorCallBack) {
  247. errorCallBack();
  248. }
  249. if (showWaiting) closeWaitingView();
  250. }
  251. });
  252. };
  253. /**
  254. * 获取url中参数
  255. * @param variable
  256. * @returns {*}
  257. */
  258. function getQueryVariable(variable) {
  259. var query = window.location.search.substring(1);
  260. var vars = query.split("&");
  261. for (var i=0;i<vars.length;i++) {
  262. var pair = vars[i].split("=");
  263. if(pair[0] == variable){return pair[1];}
  264. }
  265. return(false);
  266. }
  267. const zeroRange = 0.00000001;
  268. function checkZero(value) {
  269. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  270. }
  271. function checkFieldChange(o, n) {
  272. return o == n || ((!o || o === '') && (n === ''));
  273. }
  274. var bShowWaiting = false, beginWaitingTime;
  275. //关闭等待窗口
  276. function closeWaitingView() {
  277. bShowWaiting = false;
  278. const time = parseInt(new Date());
  279. setTimeout(function () {
  280. var bgDiv = document.getElementById("bgDiv");
  281. var msgDiv = document.getElementById("msgDiv");
  282. //移除背景遮罩层div
  283. if(bgDiv != null){
  284. document.body.removeChild(bgDiv);
  285. }
  286. //移除中间信息提示层div
  287. if(msgDiv != null){
  288. document.body.removeChild(msgDiv);
  289. }
  290. }, Math.max(beginWaitingTime - time + 500, 0));
  291. }
  292. //显示等待窗口
  293. function showWaitingView() {
  294. // bShowWaiting = true;
  295. // setTimeout(function () {
  296. // if (!bShowWaiting) return;
  297. // beginWaitingTime = parseInt(new Date());
  298. // var msgw = 300; //提示窗口的宽度
  299. // var msgh = 100; //提示窗口的高度
  300. //
  301. // var sWidth, sHeight;
  302. // sWidth = document.body.clientWidth;
  303. // sHeight = document.body.clientHeight;
  304. //
  305. // //背景遮罩层div
  306. // var bgObj = document.createElement("div");
  307. // bgObj.setAttribute('id', 'bgDiv');
  308. // bgObj.style.zIndex = '9998';
  309. // bgObj.style.position = "absolute";
  310. // bgObj.style.top = "0px";
  311. // bgObj.style.background = "#888";
  312. // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  313. // bgObj.style.opacity = "0.6";
  314. // bgObj.style.left = "0px";
  315. // bgObj.style.width = sWidth + "px";
  316. // bgObj.style.height = sHeight + "px";
  317. // document.body.appendChild(bgObj);
  318. //
  319. // //信息提示层div
  320. // var msgObj = document.createElement("div");
  321. // msgObj.style.zIndex = '9999';
  322. // msgObj.setAttribute("id", "msgDiv");
  323. // msgObj.setAttribute("align", "center");
  324. // msgObj.style.position = "absolute";
  325. // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  326. // msgObj.style.width = msgw + "px";
  327. // msgObj.style.height = msgh + "px";
  328. // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  329. // msgObj.style.left = (sWidth - msgw) / 2 + "px";
  330. // document.body.appendChild(msgObj);
  331. //
  332. // //中间等待图标
  333. // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  334. // }, 1000);
  335. beginWaitingTime = parseInt(new Date());
  336. var msgw = 300; //提示窗口的宽度
  337. var msgh = 100; //提示窗口的高度
  338. var sWidth, sHeight;
  339. sWidth = document.body.clientWidth;
  340. sHeight = document.body.clientHeight;
  341. //背景遮罩层div
  342. var bgObj = document.createElement("div");
  343. bgObj.setAttribute('id', 'bgDiv');
  344. bgObj.style.zIndex = '9998';
  345. bgObj.style.position = "absolute";
  346. bgObj.style.top = "0px";
  347. // bgObj.style.background = "#888";
  348. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  349. bgObj.style.opacity = "0.6";
  350. bgObj.style.left = "0px";
  351. bgObj.style.width = sWidth + "px";
  352. bgObj.style.height = sHeight + "px";
  353. document.body.appendChild(bgObj);
  354. //信息提示层div
  355. var msgObj = document.createElement("div");
  356. msgObj.style.zIndex = '9999';
  357. msgObj.setAttribute("id", "msgDiv");
  358. msgObj.setAttribute("align", "center");
  359. msgObj.style.position = "absolute";
  360. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  361. msgObj.style.width = msgw + "px";
  362. msgObj.style.height = msgh + "px";
  363. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  364. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  365. document.body.appendChild(msgObj);
  366. //中间等待图标
  367. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  368. }
  369. let progressInterval;
  370. function showProgress() {
  371. var sWidth, sHeight;
  372. sWidth = document.body.clientWidth;
  373. sHeight = document.body.clientHeight;
  374. //背景遮罩层div
  375. var bgObj = document.createElement("div");
  376. bgObj.setAttribute('id', 'bgDiv');
  377. bgObj.style.zIndex = '9998';
  378. bgObj.style.position = "absolute";
  379. bgObj.style.top = "0px";
  380. bgObj.style.background = "#888";
  381. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  382. bgObj.style.opacity = "0.6";
  383. bgObj.style.left = "0px";
  384. bgObj.style.width = sWidth + "px";
  385. bgObj.style.height = sHeight + "px";
  386. document.body.appendChild(bgObj);
  387. //信息提示层div
  388. var msgObj = document.createElement("div");
  389. msgObj.classList.add('progress');
  390. msgObj.style.zIndex = '9999';
  391. msgObj.style.position = "absolute";
  392. msgObj.setAttribute("id", "progressDiv");
  393. msgObj.style.height = "2px";
  394. msgObj.style.width = "600px";
  395. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  396. msgObj.style.left = (sWidth - 600) / 2 + "px";
  397. document.body.appendChild(msgObj);
  398. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  399. const processObj = $('.progress-bar');
  400. let count = 0;
  401. progressInterval = setInterval(function () {
  402. const pos = parseInt(processObj.attr('aria-valuenow'));
  403. if (pos < 20) { // 1
  404. processObj.attr('aria-valuenow', pos + 2);
  405. processObj.width((pos + 2) + '%');
  406. } else if (pos < 40) { // 2
  407. processObj.attr('aria-valuenow', pos + 1);
  408. processObj.width((pos + 1) + '%');
  409. } else if (pos < 60) { // 4
  410. count += 1;
  411. if (count % 2 === 0) {
  412. processObj.attr('aria-valuenow', pos + 1);
  413. processObj.width((pos + 1) + '%');
  414. }
  415. } else if (pos < 80) { // 10
  416. count += 1;
  417. if (count % 5 === 0) {
  418. processObj.attr('aria-valuenow', pos + 1);
  419. processObj.width((pos + 1) + '%');
  420. }
  421. } else if (pos < 90) { // 15
  422. count += 1;
  423. if (count % 15 === 0) {
  424. processObj.attr('aria-valuenow', pos + 1);
  425. processObj.width((pos + 1) + '%');
  426. }
  427. } else if (pos < 95) { // 20
  428. count += 1;
  429. if (count % 40 === 0) {
  430. processObj.attr('aria-valuenow', pos + 1);
  431. processObj.width((pos + 1) + '%');
  432. }
  433. } else if (pos < 100) { // 30
  434. count += 1;
  435. if (count % 60 === 0) {
  436. processObj.attr('aria-valuenow', pos + 1);
  437. }
  438. }
  439. }, 100);
  440. }
  441. function doneProgress() {
  442. clearInterval(progressInterval);
  443. $('.progress-bar').attr('aria-valuenow', 100).width('100%');
  444. }
  445. function closeProgress() {
  446. setTimeout(function () {
  447. var bgDiv = document.getElementById("bgDiv");
  448. var msgDiv = document.getElementById("progressDiv");
  449. //移除背景遮罩层div
  450. if(bgDiv != null){
  451. document.body.removeChild(bgDiv);
  452. }
  453. //移除中间信息提示层div
  454. if(msgDiv != null){
  455. document.body.removeChild(msgDiv);
  456. }
  457. }, 500);
  458. }
  459. /**
  460. * 设置本地缓存
  461. *
  462. * @param {String} key
  463. * @param {String|Number} value
  464. * @return {void}
  465. */
  466. function setLocalCache(key, value) {
  467. const storage = window.localStorage;
  468. if (!storage || key === '' || value === '') {
  469. return;
  470. }
  471. storage.setItem(key, value);
  472. }
  473. /**
  474. * 获取本地缓存
  475. *
  476. * @param {String} key
  477. * @return {String}
  478. */
  479. function getLocalCache(key) {
  480. const storage = window.localStorage;
  481. if (!storage || key === '') {
  482. return null;
  483. }
  484. return storage.getItem(key);
  485. }
  486. /**
  487. * 移除本地缓存
  488. * @param {String} key
  489. * @returns {Boolean}
  490. */
  491. function removeLocalCache(key) {
  492. const storage = window.localStorage;
  493. if (!storage || key === '') {
  494. return null;
  495. }
  496. return storage.removeItem(key);
  497. }
  498. //params: 需要复制的对象(元素)
  499. function copyToClipboard( text ) {
  500. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  501. var aux = document.createElement('textarea');// 创建元素用于复制
  502. // Prevent zooming on iOS
  503. aux.style.fontSize = '12pt';
  504. // Reset box model
  505. aux.style.border = '0';
  506. aux.style.padding = '0';
  507. aux.style.margin = '0';
  508. // Move element out of screen horizontally
  509. aux.style.position = 'absolute';
  510. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  511. // Move element to the same position vertically
  512. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  513. aux.style.top = yPosition + 'px';
  514. aux.setAttribute('readonly', '');
  515. // 设置元素内容
  516. aux.value = text;
  517. // 将元素插入页面进行调用
  518. document.body.appendChild(aux);
  519. // 复制内容
  520. aux.select();
  521. aux.setSelectionRange(0, text.length);
  522. // 将内容复制到剪贴板
  523. document.execCommand("copy", true);
  524. // 删除创建元素
  525. document.body.removeChild(aux);
  526. }
  527. function toastMessageUniq (obj) {
  528. if (!obj.msg || !obj.type) return;
  529. if (!obj.once) {
  530. switch (obj.type) {
  531. case 'error':
  532. toastr.error(obj.msg);
  533. break;
  534. case 'warning':
  535. toastr.warning(obj.msg);
  536. break;
  537. case 'info':
  538. toastr.info(obj.msg);
  539. break;
  540. case 'success':
  541. toastr.success(obj.msg);
  542. break;
  543. }
  544. obj.once = true;
  545. }
  546. }
  547. function trimInvalidChar(str) {
  548. return $.trim(str).replace('\n', '').replace('\r', '').replace('\t', '');
  549. }
  550. jQuery.bootstrapLoading = {
  551. isLoading: function () {
  552. return $('#loadingPage').is(':visible');
  553. },
  554. start: function (options) {
  555. if(this.isLoading()){
  556. return;
  557. }
  558. var defaults = {
  559. opacity: 0.5,
  560. //loading页面透明度
  561. // backgroundColor: "#FFFFFF",
  562. //loading页面背景色
  563. borderColor: "#bbb",
  564. //提示边框颜色
  565. borderWidth: 1,
  566. //提示边框宽度
  567. borderStyle: "solid",
  568. //提示边框样式
  569. loadingTips: "Loading, please wait...",
  570. //提示文本
  571. TipsColor: "#fff",
  572. //提示颜色
  573. delayTime: 500,
  574. //页面加载完成后,加载页面渐出速度
  575. zindex: 2000,
  576. //loading页面层次
  577. sleep: 0
  578. //设置挂起,等于0时则无需挂起
  579. }
  580. var options = $.extend(defaults, options);
  581. //获取页面宽高
  582. var _PageHeight = document.documentElement.clientHeight,
  583. _PageWidth = document.documentElement.clientWidth;
  584. //在页面未加载完毕之前显示的loading Html自定义内容
  585. //var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;border-color:' + options.borderColor + ';border-style:' + options.borderStyle + ';border-width:' + options.borderWidth + 'px; height:80px; line-height:80px; padding-left:80px; padding-right: 5px;border-radius:10px; background: ' + options.backgroundColor + ' url(/Content/bootstrap-loading/images/loading.gif) no-repeat 5px center; color:' + options.TipsColor + ';font-size:20px;">' + options.loadingTips + '</div></div>';
  586. var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;">' +'<div class="text-green"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i> <span class="sr-only">Loading...</span> </div> </div></div>';
  587. //呈现loading效果
  588. $("body").append(_LoadingHtml);
  589. //获取loading提示框宽高
  590. var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
  591. _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
  592. //计算距离,让loading提示框保持在屏幕上下左右居中
  593. var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
  594. _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
  595. $("#loadingTips").css({
  596. "left": _LoadingLeft + "px",
  597. "top": _LoadingTop + "px"
  598. });
  599. //监听页面加载状态
  600. document.onreadystatechange = PageLoaded;
  601. //当页面加载完成后执行
  602. function PageLoaded() {
  603. if (document.readyState == "complete") {
  604. var loadingMask = $('#loadingPage');
  605. setTimeout(function () {
  606. loadingMask.animate({
  607. "opacity": 0
  608. },
  609. options.delayTime,
  610. function () {
  611. $(this).hide();
  612. });
  613. },
  614. options.sleep);
  615. }
  616. }
  617. },
  618. end: function () {
  619. $("#loadingPage").remove();
  620. },
  621. progressStop:true,
  622. progressStart:async function(title="导出文件",autoBar = false){
  623. if($("#progressModal").length == 0){
  624. let phtml = `<div class="modal fade" id="progressModal" data-backdrop="static">
  625. <div class="modal-dialog" role="document">
  626. <div class="modal-content">
  627. <div class="modal-header">
  628. <h5 class="modal-title" id="progress_modal_title">${title}</h5>
  629. </div>
  630. <div class="modal-body">
  631. <!--正在生成-->
  632. <h5 class="my-3" id="progress_modal_body">正在${title}</h5>
  633. <div class="progress mb-3">
  634. <div id="progress_modal_bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 10%"></div>
  635. </div>
  636. </div>
  637. </div>
  638. </div>
  639. </div>`;
  640. $("body").append(phtml);
  641. }else {
  642. $("#progress_modal_title").text(title);
  643. $("#progress_modal_body").text(`正在${title}`);
  644. }
  645. $("#progress_modal_bar").css('width','0%');
  646. $("#progressModal").modal('show');
  647. if(autoBar == true){//假的进度条
  648. $.bootstrapLoading.progressStop = false;
  649. let width = 0;
  650. while ($.bootstrapLoading.progressStop == false){
  651. await setTimeoutSync(null,1000);
  652. width += 5;
  653. if(width > 90) width -= 50;
  654. $("#progress_modal_bar").css('width',`${width}%`);
  655. }
  656. }
  657. },
  658. progressEnd:function () {
  659. $("#progress_modal_bar").css('width','100%');
  660. $.bootstrapLoading.progressStop = true;
  661. $("#progressModal").modal('hide');
  662. }
  663. };