global.js 29 KB

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