global.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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: 60000,
  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. const postDataWithFileProgress = function (url, formData, successCallback, errorCallBack) {
  254. showUploadFileProgress();
  255. $.ajax({
  256. type:"POST",
  257. url: url,
  258. data: formData,
  259. dataType: 'json',
  260. cache: false,
  261. // 告诉jQuery不要去设置Content-Type请求头
  262. contentType: false,
  263. // 告诉jQuery不要去处理发送的数据
  264. processData: false,
  265. beforeSend: function(xhr) {
  266. let csrfToken = Cookies.get('csrfToken');
  267. xhr.setRequestHeader('x-csrf-token', csrfToken);
  268. },
  269. success: function(result){
  270. doneProgress();
  271. if (result.err === 0) {
  272. if (successCallback) {
  273. successCallback(result.data);
  274. }
  275. } else {
  276. toastr.error('error: ' + result.msg);
  277. if (errorCallBack) {
  278. errorCallBack();
  279. }
  280. }
  281. closeProgress();
  282. },
  283. error: function(jqXHR, textStatus, errorThrown){
  284. toastr.error('error: ' + textStatus + " " + errorThrown);
  285. if (errorCallBack) {
  286. errorCallBack();
  287. }
  288. closeProgress();
  289. },
  290. xhr: function() {
  291. var xhr = new XMLHttpRequest();
  292. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  293. xhr.upload.addEventListener('progress', function (e) {
  294. console.log(e);
  295. //loaded代表上传了多少
  296. //total代表总数为多少
  297. var progressRate = (e.loaded / e.total) * 95;
  298. //通过设置进度条的宽度达到效果
  299. setUploadFileProgress(progressRate);
  300. })
  301. return xhr;
  302. }
  303. });
  304. }
  305. /**
  306. * 获取url中参数
  307. * @param variable
  308. * @returns {*}
  309. */
  310. function getQueryVariable(variable) {
  311. var query = window.location.search.substring(1);
  312. var vars = query.split("&");
  313. for (var i=0;i<vars.length;i++) {
  314. var pair = vars[i].split("=");
  315. if(pair[0] == variable){return pair[1];}
  316. }
  317. return(false);
  318. }
  319. const zeroRange = 0.00000001;
  320. function checkZero(value) {
  321. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  322. }
  323. function checkFieldChange(o, n) {
  324. return o == n || ((!o || o === '') && (n === ''));
  325. }
  326. var bShowWaiting = false, beginWaitingTime;
  327. //关闭等待窗口
  328. function closeWaitingView() {
  329. bShowWaiting = false;
  330. const time = parseInt(new Date());
  331. setTimeout(function () {
  332. var bgDiv = document.getElementById("bgDiv");
  333. var msgDiv = document.getElementById("msgDiv");
  334. //移除背景遮罩层div
  335. if(bgDiv != null){
  336. document.body.removeChild(bgDiv);
  337. }
  338. //移除中间信息提示层div
  339. if(msgDiv != null){
  340. document.body.removeChild(msgDiv);
  341. }
  342. }, Math.max(beginWaitingTime - time + 500, 0));
  343. }
  344. //显示等待窗口
  345. function showWaitingView() {
  346. // bShowWaiting = true;
  347. // setTimeout(function () {
  348. // if (!bShowWaiting) return;
  349. // beginWaitingTime = parseInt(new Date());
  350. // var msgw = 300; //提示窗口的宽度
  351. // var msgh = 100; //提示窗口的高度
  352. //
  353. // var sWidth, sHeight;
  354. // sWidth = document.body.clientWidth;
  355. // sHeight = document.body.clientHeight;
  356. //
  357. // //背景遮罩层div
  358. // var bgObj = document.createElement("div");
  359. // bgObj.setAttribute('id', 'bgDiv');
  360. // bgObj.style.zIndex = '9998';
  361. // bgObj.style.position = "absolute";
  362. // bgObj.style.top = "0px";
  363. // bgObj.style.background = "#888";
  364. // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  365. // bgObj.style.opacity = "0.6";
  366. // bgObj.style.left = "0px";
  367. // bgObj.style.width = sWidth + "px";
  368. // bgObj.style.height = sHeight + "px";
  369. // document.body.appendChild(bgObj);
  370. //
  371. // //信息提示层div
  372. // var msgObj = document.createElement("div");
  373. // msgObj.style.zIndex = '9999';
  374. // msgObj.setAttribute("id", "msgDiv");
  375. // msgObj.setAttribute("align", "center");
  376. // msgObj.style.position = "absolute";
  377. // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  378. // msgObj.style.width = msgw + "px";
  379. // msgObj.style.height = msgh + "px";
  380. // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  381. // msgObj.style.left = (sWidth - msgw) / 2 + "px";
  382. // document.body.appendChild(msgObj);
  383. //
  384. // //中间等待图标
  385. // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  386. // }, 1000);
  387. beginWaitingTime = parseInt(new Date());
  388. var msgw = 300; //提示窗口的宽度
  389. var msgh = 100; //提示窗口的高度
  390. var sWidth, sHeight;
  391. sWidth = document.body.clientWidth;
  392. sHeight = document.body.clientHeight;
  393. //背景遮罩层div
  394. var bgObj = document.createElement("div");
  395. bgObj.setAttribute('id', 'bgDiv');
  396. bgObj.style.zIndex = '9998';
  397. bgObj.style.position = "absolute";
  398. bgObj.style.top = "0px";
  399. // bgObj.style.background = "#888";
  400. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  401. bgObj.style.opacity = "0.6";
  402. bgObj.style.left = "0px";
  403. bgObj.style.width = sWidth + "px";
  404. bgObj.style.height = sHeight + "px";
  405. document.body.appendChild(bgObj);
  406. //信息提示层div
  407. var msgObj = document.createElement("div");
  408. msgObj.style.zIndex = '9999';
  409. msgObj.setAttribute("id", "msgDiv");
  410. msgObj.setAttribute("align", "center");
  411. msgObj.style.position = "absolute";
  412. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  413. msgObj.style.width = msgw + "px";
  414. msgObj.style.height = msgh + "px";
  415. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  416. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  417. document.body.appendChild(msgObj);
  418. //中间等待图标
  419. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  420. }
  421. let progressInterval;
  422. function showProgress() {
  423. var sWidth, sHeight;
  424. sWidth = document.body.clientWidth;
  425. sHeight = document.body.clientHeight;
  426. //背景遮罩层div
  427. var bgObj = document.createElement("div");
  428. bgObj.setAttribute('id', 'bgDiv');
  429. bgObj.style.zIndex = '9998';
  430. bgObj.style.position = "absolute";
  431. bgObj.style.top = "0px";
  432. bgObj.style.background = "#888";
  433. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  434. bgObj.style.opacity = "0.6";
  435. bgObj.style.left = "0px";
  436. bgObj.style.width = sWidth + "px";
  437. bgObj.style.height = sHeight + "px";
  438. document.body.appendChild(bgObj);
  439. //信息提示层div
  440. var msgObj = document.createElement("div");
  441. msgObj.classList.add('progress');
  442. msgObj.style.zIndex = '9999';
  443. msgObj.style.position = "absolute";
  444. msgObj.setAttribute("id", "progressDiv");
  445. msgObj.style.height = "2px";
  446. msgObj.style.width = "600px";
  447. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  448. msgObj.style.left = (sWidth - 600) / 2 + "px";
  449. document.body.appendChild(msgObj);
  450. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  451. const processObj = $('.progress-bar');
  452. let count = 0;
  453. progressInterval = setInterval(function () {
  454. const pos = parseInt(processObj.attr('aria-valuenow'));
  455. if (pos < 20) { // 1
  456. processObj.attr('aria-valuenow', pos + 2);
  457. processObj.width((pos + 2) + '%');
  458. } else if (pos < 40) { // 2
  459. processObj.attr('aria-valuenow', pos + 1);
  460. processObj.width((pos + 1) + '%');
  461. } else if (pos < 60) { // 4
  462. count += 1;
  463. if (count % 2 === 0) {
  464. processObj.attr('aria-valuenow', pos + 1);
  465. processObj.width((pos + 1) + '%');
  466. }
  467. } else if (pos < 80) { // 10
  468. count += 1;
  469. if (count % 5 === 0) {
  470. processObj.attr('aria-valuenow', pos + 1);
  471. processObj.width((pos + 1) + '%');
  472. }
  473. } else if (pos < 90) { // 15
  474. count += 1;
  475. if (count % 15 === 0) {
  476. processObj.attr('aria-valuenow', pos + 1);
  477. processObj.width((pos + 1) + '%');
  478. }
  479. } else if (pos < 95) { // 20
  480. count += 1;
  481. if (count % 40 === 0) {
  482. processObj.attr('aria-valuenow', pos + 1);
  483. processObj.width((pos + 1) + '%');
  484. }
  485. } else if (pos < 100) { // 30
  486. count += 1;
  487. if (count % 60 === 0) {
  488. processObj.attr('aria-valuenow', pos + 1);
  489. }
  490. }
  491. }, 100);
  492. }
  493. function doneProgress() {
  494. clearInterval(progressInterval);
  495. $('.progress-bar').attr('aria-valuenow', 100).width('100%');
  496. }
  497. function closeProgress() {
  498. setTimeout(function () {
  499. var bgDiv = document.getElementById("bgDiv");
  500. var msgDiv = document.getElementById("progressDiv");
  501. //移除背景遮罩层div
  502. if(bgDiv != null){
  503. document.body.removeChild(bgDiv);
  504. }
  505. //移除中间信息提示层div
  506. if(msgDiv != null){
  507. document.body.removeChild(msgDiv);
  508. }
  509. }, 500);
  510. }
  511. function showUploadFileProgress() {
  512. var sWidth, sHeight;
  513. sWidth = document.body.clientWidth;
  514. sHeight = document.body.clientHeight;
  515. //背景遮罩层div
  516. var bgObj = document.createElement("div");
  517. bgObj.setAttribute('id', 'bgDiv');
  518. bgObj.style.zIndex = '9998';
  519. bgObj.style.position = "absolute";
  520. bgObj.style.top = "0px";
  521. bgObj.style.background = "#888";
  522. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  523. bgObj.style.opacity = "0.6";
  524. bgObj.style.left = "0px";
  525. bgObj.style.width = sWidth + "px";
  526. bgObj.style.height = sHeight + "px";
  527. document.body.appendChild(bgObj);
  528. //信息提示层div
  529. var msgObj = document.createElement("div");
  530. msgObj.classList.add('progress');
  531. msgObj.style.zIndex = '9999';
  532. msgObj.style.position = "absolute";
  533. msgObj.setAttribute("id", "progressDiv");
  534. msgObj.style.height = "2px";
  535. msgObj.style.width = "600px";
  536. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  537. msgObj.style.left = (sWidth - 600) / 2 + "px";
  538. document.body.appendChild(msgObj);
  539. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  540. }
  541. function setUploadFileProgress(pos) {
  542. const processObj = $('.progress-bar');
  543. processObj.attr('aria-valuenow', pos);
  544. processObj.width(pos + '%');
  545. }
  546. /**
  547. * 设置本地缓存
  548. *
  549. * @param {String} key
  550. * @param {String|Number} value
  551. * @return {void}
  552. */
  553. function setLocalCache(key, value) {
  554. const storage = window.localStorage;
  555. if (!storage || key === '' || value === '') {
  556. return;
  557. }
  558. storage.setItem(key, value);
  559. }
  560. /**
  561. * 获取本地缓存
  562. *
  563. * @param {String} key
  564. * @return {String}
  565. */
  566. function getLocalCache(key) {
  567. const storage = window.localStorage;
  568. if (!storage || key === '') {
  569. return null;
  570. }
  571. return storage.getItem(key);
  572. }
  573. /**
  574. * 移除本地缓存
  575. * @param {String} key
  576. * @returns {Boolean}
  577. */
  578. function removeLocalCache(key) {
  579. const storage = window.localStorage;
  580. if (!storage || key === '') {
  581. return null;
  582. }
  583. return storage.removeItem(key);
  584. }
  585. //params: 需要复制的对象(元素)
  586. function copyToClipboard( text ) {
  587. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  588. var aux = document.createElement('textarea');// 创建元素用于复制
  589. // Prevent zooming on iOS
  590. aux.style.fontSize = '12pt';
  591. // Reset box model
  592. aux.style.border = '0';
  593. aux.style.padding = '0';
  594. aux.style.margin = '0';
  595. // Move element out of screen horizontally
  596. aux.style.position = 'absolute';
  597. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  598. // Move element to the same position vertically
  599. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  600. aux.style.top = yPosition + 'px';
  601. aux.setAttribute('readonly', '');
  602. // 设置元素内容
  603. aux.value = text;
  604. // 将元素插入页面进行调用
  605. document.body.appendChild(aux);
  606. // 复制内容
  607. aux.select();
  608. aux.setSelectionRange(0, text.length);
  609. // 将内容复制到剪贴板
  610. document.execCommand("copy", true);
  611. // 删除创建元素
  612. document.body.removeChild(aux);
  613. }
  614. function toastMessageUniq (obj) {
  615. if (!obj.msg || !obj.type) return;
  616. if (!obj.once) {
  617. switch (obj.type) {
  618. case 'error':
  619. toastr.error(obj.msg);
  620. break;
  621. case 'warning':
  622. toastr.warning(obj.msg);
  623. break;
  624. case 'info':
  625. toastr.info(obj.msg);
  626. break;
  627. case 'success':
  628. toastr.success(obj.msg);
  629. break;
  630. }
  631. obj.once = true;
  632. }
  633. }
  634. function trimInvalidChar(str) {
  635. return $.trim(str).replace('\n', '').replace('\r', '').replace('\t', '');
  636. }
  637. jQuery.bootstrapLoading = {
  638. isLoading: function () {
  639. return $('#loadingPage').is(':visible');
  640. },
  641. start: function (options) {
  642. if(this.isLoading()){
  643. return;
  644. }
  645. var defaults = {
  646. opacity: 0.5,
  647. //loading页面透明度
  648. // backgroundColor: "#FFFFFF",
  649. //loading页面背景色
  650. borderColor: "#bbb",
  651. //提示边框颜色
  652. borderWidth: 1,
  653. //提示边框宽度
  654. borderStyle: "solid",
  655. //提示边框样式
  656. loadingTips: "Loading, please wait...",
  657. //提示文本
  658. TipsColor: "#fff",
  659. //提示颜色
  660. delayTime: 500,
  661. //页面加载完成后,加载页面渐出速度
  662. zindex: 2000,
  663. //loading页面层次
  664. sleep: 0
  665. //设置挂起,等于0时则无需挂起
  666. }
  667. var options = $.extend(defaults, options);
  668. //获取页面宽高
  669. var _PageHeight = document.documentElement.clientHeight,
  670. _PageWidth = document.documentElement.clientWidth;
  671. //在页面未加载完毕之前显示的loading Html自定义内容
  672. //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>';
  673. 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>';
  674. //呈现loading效果
  675. $("body").append(_LoadingHtml);
  676. //获取loading提示框宽高
  677. var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
  678. _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
  679. //计算距离,让loading提示框保持在屏幕上下左右居中
  680. var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
  681. _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
  682. $("#loadingTips").css({
  683. "left": _LoadingLeft + "px",
  684. "top": _LoadingTop + "px"
  685. });
  686. //监听页面加载状态
  687. document.onreadystatechange = PageLoaded;
  688. //当页面加载完成后执行
  689. function PageLoaded() {
  690. if (document.readyState == "complete") {
  691. var loadingMask = $('#loadingPage');
  692. setTimeout(function () {
  693. loadingMask.animate({
  694. "opacity": 0
  695. },
  696. options.delayTime,
  697. function () {
  698. $(this).hide();
  699. });
  700. },
  701. options.sleep);
  702. }
  703. }
  704. },
  705. end: function () {
  706. $("#loadingPage").remove();
  707. },
  708. progressStop:true,
  709. progressStart:async function(title="导出文件",autoBar = false){
  710. if($("#progressModal").length == 0){
  711. let phtml = `<div class="modal fade" id="progressModal" data-backdrop="static">
  712. <div class="modal-dialog" role="document">
  713. <div class="modal-content">
  714. <div class="modal-header">
  715. <h5 class="modal-title" id="progress_modal_title">${title}</h5>
  716. </div>
  717. <div class="modal-body">
  718. <!--正在生成-->
  719. <h5 class="my-3" id="progress_modal_body">正在${title}</h5>
  720. <div class="progress mb-3">
  721. <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>
  722. </div>
  723. </div>
  724. </div>
  725. </div>
  726. </div>`;
  727. $("body").append(phtml);
  728. }else {
  729. $("#progress_modal_title").text(title);
  730. $("#progress_modal_body").text(`正在${title}`);
  731. }
  732. $("#progress_modal_bar").css('width','0%');
  733. $("#progressModal").modal('show');
  734. if(autoBar == true){//假的进度条
  735. $.bootstrapLoading.progressStop = false;
  736. let width = 0;
  737. while ($.bootstrapLoading.progressStop == false){
  738. await setTimeoutSync(null,1000);
  739. width += 5;
  740. if(width > 90) width -= 50;
  741. $("#progress_modal_bar").css('width',`${width}%`);
  742. }
  743. }
  744. },
  745. progressEnd:function () {
  746. $("#progress_modal_bar").css('width','100%');
  747. $.bootstrapLoading.progressStop = true;
  748. $("#progressModal").modal('hide');
  749. }
  750. };