global.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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.parentNode))-92+55);
  36. }
  37. /*工程变更添加清单高度*/
  38. $(".sjs-biangeng-height").height($(window).height()/3.3);
  39. };
  40. $(window).resize(autoFlashHeight);
  41. /*全局自适应高度结束*/
  42. $(function(){
  43. /*侧滑*/
  44. $(".open-sidebar").click(function(){
  45. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  46. });
  47. $("body").click(function(event){
  48. var e = event || window.event; //浏览器兼容性
  49. if(!$(event.target).is('a')) {
  50. var elem = event.target || e.srcElement;
  51. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  52. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  53. return false;
  54. }
  55. elem = elem.parentNode;
  56. }
  57. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  58. }
  59. });
  60. /*侧滑*/
  61. /*工具提示*/
  62. $(function () {
  63. $('[data-toggle="tooltip"]').tooltip()
  64. });
  65. /*侧栏菜单*/
  66. $(".bg-nav > li > a").click(function() {
  67. var self = $(this);
  68. var subMenu = $(this).siblings('ul.sub-menu');
  69. if(subMenu.length > 0) {
  70. if(subMenu.is(":visible")) {
  71. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  72. subMenu.slideUp('fast');
  73. self.parent().removeClass('active');
  74. }else{
  75. self.parent().addClass('active');
  76. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  77. subMenu.slideDown('fast');
  78. }
  79. }
  80. });
  81. // 数据提交
  82. $("#submit-form").click(function() {
  83. $("#save-form").submit();
  84. });
  85. // modal弹窗拖动
  86. // $(document).on("show.bs.modal", ".modal", function() {
  87. // $(this).draggable({
  88. // handle: ".modal-header" // 只能点击头部拖动
  89. // });
  90. // $(this).css("overflow", "hidden");
  91. // });
  92. // 动态生成datepicker
  93. $('body').on('focus', ".datepicker-here", function (e) {
  94. if ($(this).data("datepicker") != "1") {
  95. $(this).datepicker();
  96. }
  97. $(this).data("datepicker", "1");
  98. });
  99. });
  100. /**
  101. * 提示框
  102. *
  103. * @param string message
  104. * @param string type
  105. * @param string icon
  106. * @return void
  107. */
  108. function toast(message, type, icon) {
  109. var toast = $(".toast");
  110. toast.addClass(type);
  111. toast.children('.message').html(message);
  112. var iconClass = 'fa-' + icon;
  113. toast.children('.icon').addClass(iconClass);
  114. toast.fadeIn(500);
  115. setTimeout(function() {
  116. toast.fadeOut('fast');
  117. toast.children('.message').text('');
  118. toast.children('.icon').removeClass(iconClass);
  119. }, 3000);
  120. }
  121. /**
  122. * 动态请求数据
  123. * @param {String} url - 请求链接
  124. * @param data - 提交数据
  125. * @param {function} successCallback - 返回成功回调
  126. * @param {function} errorCallBack - 返回失败回调
  127. */
  128. const postData = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  129. if (showWaiting) showWaitingView();
  130. $.ajax({
  131. type:"POST",
  132. url: url,
  133. data: {'data': JSON.stringify(data)},
  134. dataType: 'json',
  135. cache: false,
  136. timeout: 60000,
  137. beforeSend: function(xhr) {
  138. let csrfToken = Cookies.get('csrfToken');
  139. xhr.setRequestHeader('x-csrf-token', csrfToken);
  140. },
  141. success: function(result){
  142. if (result.err === 0) {
  143. if (successCallback) {
  144. successCallback(result.data);
  145. }
  146. } else if (result.err === 2) {
  147. toastr.error('error: ' + result.msg);
  148. setTimeout(function () {
  149. window.location.href = '/login';
  150. },1000);
  151. } else {
  152. toastr.error('error: ' + result.msg);
  153. if (errorCallBack) {
  154. errorCallBack(result.msg);
  155. }
  156. }
  157. if (showWaiting) closeWaitingView();
  158. },
  159. error: function(jqXHR, textStatus, errorThrown){
  160. toastr.error('error: ' + textStatus + " " + errorThrown);
  161. if (errorCallBack) {
  162. errorCallBack();
  163. }
  164. if (showWaiting) closeWaitingView();
  165. }
  166. });
  167. };
  168. /**
  169. * 动态请求数据(压缩数据)
  170. * @param {String} url - 请求链接
  171. * @param data - 提交数据
  172. * @param {function} successCallback - 返回成功回调
  173. * @param {function} errorCallBack - 返回失败回调
  174. */
  175. const postDataCompress = function (url, data, successCallback, errorCallBack, htype = 'progress') {
  176. if (htype === 'wait') showWaitingView();
  177. if (htype === 'progress') showProgress();
  178. $.ajax({
  179. type:"POST",
  180. url: url,
  181. data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
  182. dataType: 'json',
  183. cache: false,
  184. timeout: 80000, // 导入清单Excel(10w行)预计需要时间
  185. beforeSend: function(xhr) {
  186. let csrfToken = Cookies.get('csrfToken');
  187. xhr.setRequestHeader('x-csrf-token', csrfToken);
  188. },
  189. success: function(result){
  190. if (htype === 'progress') doneProgress();
  191. if (result.err === 0) {
  192. if (successCallback) {
  193. successCallback(result.data);
  194. }
  195. } else if (result.err === 2) {
  196. toastr.error('error: ' + result.msg);
  197. setTimeout(function () {
  198. window.location.href = '/login';
  199. },1000);
  200. } else {
  201. toastr.error('error: ' + result.msg);
  202. if (errorCallBack) {
  203. errorCallBack(result.msg);
  204. }
  205. }
  206. if (htype === 'wait') closeWaitingView();
  207. if (htype === 'progress') closeProgress();
  208. },
  209. error: function(jqXHR, textStatus, errorThrown){
  210. toastr.error('error: ' + textStatus + " " + errorThrown);
  211. if (errorCallBack) {
  212. errorCallBack();
  213. }
  214. if (htype === 'wait') closeWaitingView();
  215. if (htype === 'progress') closeProgress();
  216. }
  217. });
  218. };
  219. /**
  220. * 动态请求数据
  221. * @param {String} url - 请求链接
  222. * @param data - 提交数据
  223. * @param {function} successCallback - 返回成功回调
  224. * @param {function} errorCallBack - 返回失败回调
  225. */
  226. const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) {
  227. if (showWaiting) showWaitingView();
  228. if (formData.getAll('file[]').length > 10) {
  229. toastr.error('文件数量不能多于10个');
  230. if (showWaiting) closeWaitingView();
  231. return
  232. }
  233. $.ajax({
  234. type:"POST",
  235. url: url,
  236. data: formData,
  237. dataType: 'json',
  238. cache: false,
  239. // 告诉jQuery不要去设置Content-Type请求头
  240. contentType: false,
  241. // 告诉jQuery不要去处理发送的数据
  242. processData: false,
  243. timeout: 60000,
  244. beforeSend: function(xhr) {
  245. let csrfToken = Cookies.get('csrfToken');
  246. xhr.setRequestHeader('x-csrf-token', csrfToken);
  247. },
  248. success: function(result){
  249. if (result.err === 0) {
  250. if (successCallback) {
  251. successCallback(result.data);
  252. }
  253. } else if (result.err === 2) {
  254. toastr.error('error: ' + result.msg);
  255. setTimeout(function () {
  256. window.location.href = '/login';
  257. },1000);
  258. } else {
  259. toastr.error('error: ' + result.msg);
  260. if (errorCallBack) {
  261. errorCallBack();
  262. }
  263. }
  264. if (showWaiting) closeWaitingView();
  265. },
  266. error: function(jqXHR, textStatus, errorThrown){
  267. toastr.error('error: ' + textStatus + " " + errorThrown);
  268. if (errorCallBack) {
  269. errorCallBack();
  270. }
  271. if (showWaiting) closeWaitingView();
  272. }
  273. });
  274. };
  275. const postDataWithFileProgress = function (url, formData, successCallback, errorCallBack) {
  276. showUploadFileProgress();
  277. $.ajax({
  278. type:"POST",
  279. url: url,
  280. data: formData,
  281. dataType: 'json',
  282. cache: false,
  283. // 告诉jQuery不要去设置Content-Type请求头
  284. contentType: false,
  285. // 告诉jQuery不要去处理发送的数据
  286. processData: false,
  287. beforeSend: function(xhr) {
  288. let csrfToken = Cookies.get('csrfToken');
  289. xhr.setRequestHeader('x-csrf-token', csrfToken);
  290. },
  291. success: function(result){
  292. doneProgress();
  293. if (result.err === 0) {
  294. if (successCallback) {
  295. successCallback(result.data);
  296. }
  297. } else if (result.err === 2) {
  298. toastr.error('error: ' + result.msg);
  299. setTimeout(function () {
  300. window.location.href = '/login';
  301. },1000);
  302. } else {
  303. toastr.error('error: ' + result.msg);
  304. if (errorCallBack) {
  305. errorCallBack();
  306. }
  307. }
  308. closeProgress();
  309. },
  310. error: function(jqXHR, textStatus, errorThrown){
  311. toastr.error('error: ' + textStatus + " " + errorThrown);
  312. if (errorCallBack) {
  313. errorCallBack();
  314. }
  315. closeProgress();
  316. },
  317. xhr: function() {
  318. var xhr = new XMLHttpRequest();
  319. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  320. xhr.upload.addEventListener('progress', function (e) {
  321. console.log(e);
  322. //loaded代表上传了多少
  323. //total代表总数为多少
  324. var progressRate = (e.loaded / e.total) * 95;
  325. //通过设置进度条的宽度达到效果
  326. setUploadFileProgress(progressRate);
  327. })
  328. return xhr;
  329. }
  330. });
  331. }
  332. /**
  333. * 获取url中参数
  334. * @param variable
  335. * @returns {*}
  336. */
  337. function getQueryVariable(variable) {
  338. var query = window.location.search.substring(1);
  339. var vars = query.split("&");
  340. for (var i=0;i<vars.length;i++) {
  341. var pair = vars[i].split("=");
  342. if(pair[0] == variable){return pair[1];}
  343. }
  344. return(false);
  345. }
  346. const zeroRange = 0.00000001;
  347. function checkZero(value) {
  348. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  349. }
  350. function checkFieldChange(o, n) {
  351. return o == n || ((!o || o === '') && (n === ''));
  352. }
  353. var bShowWaiting = false, beginWaitingTime;
  354. //关闭等待窗口
  355. function closeWaitingView() {
  356. bShowWaiting = false;
  357. const time = parseInt(new Date());
  358. setTimeout(function () {
  359. var bgDiv = document.getElementById("bgDiv");
  360. var msgDiv = document.getElementById("msgDiv");
  361. //移除背景遮罩层div
  362. if(bgDiv != null){
  363. document.body.removeChild(bgDiv);
  364. }
  365. //移除中间信息提示层div
  366. if(msgDiv != null){
  367. document.body.removeChild(msgDiv);
  368. }
  369. }, Math.max(beginWaitingTime - time + 500, 0));
  370. }
  371. //显示等待窗口
  372. function showWaitingView() {
  373. // bShowWaiting = true;
  374. // setTimeout(function () {
  375. // if (!bShowWaiting) return;
  376. // beginWaitingTime = parseInt(new Date());
  377. // var msgw = 300; //提示窗口的宽度
  378. // var msgh = 100; //提示窗口的高度
  379. //
  380. // var sWidth, sHeight;
  381. // sWidth = document.body.clientWidth;
  382. // sHeight = document.body.clientHeight;
  383. //
  384. // //背景遮罩层div
  385. // var bgObj = document.createElement("div");
  386. // bgObj.setAttribute('id', 'bgDiv');
  387. // bgObj.style.zIndex = '9998';
  388. // bgObj.style.position = "absolute";
  389. // bgObj.style.top = "0px";
  390. // bgObj.style.background = "#888";
  391. // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  392. // bgObj.style.opacity = "0.6";
  393. // bgObj.style.left = "0px";
  394. // bgObj.style.width = sWidth + "px";
  395. // bgObj.style.height = sHeight + "px";
  396. // document.body.appendChild(bgObj);
  397. //
  398. // //信息提示层div
  399. // var msgObj = document.createElement("div");
  400. // msgObj.style.zIndex = '9999';
  401. // msgObj.setAttribute("id", "msgDiv");
  402. // msgObj.setAttribute("align", "center");
  403. // msgObj.style.position = "absolute";
  404. // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  405. // msgObj.style.width = msgw + "px";
  406. // msgObj.style.height = msgh + "px";
  407. // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  408. // msgObj.style.left = (sWidth - msgw) / 2 + "px";
  409. // document.body.appendChild(msgObj);
  410. //
  411. // //中间等待图标
  412. // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  413. // }, 1000);
  414. beginWaitingTime = parseInt(new Date());
  415. var msgw = 300; //提示窗口的宽度
  416. var msgh = 100; //提示窗口的高度
  417. var sWidth, sHeight;
  418. sWidth = document.body.clientWidth;
  419. sHeight = document.body.clientHeight;
  420. //背景遮罩层div
  421. var bgObj = document.createElement("div");
  422. bgObj.setAttribute('id', 'bgDiv');
  423. bgObj.style.zIndex = '9998';
  424. bgObj.style.position = "absolute";
  425. bgObj.style.top = "0px";
  426. // bgObj.style.background = "#888";
  427. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  428. bgObj.style.opacity = "0.6";
  429. bgObj.style.left = "0px";
  430. bgObj.style.width = sWidth + "px";
  431. bgObj.style.height = sHeight + "px";
  432. document.body.appendChild(bgObj);
  433. //信息提示层div
  434. var msgObj = document.createElement("div");
  435. msgObj.style.zIndex = '9999';
  436. msgObj.setAttribute("id", "msgDiv");
  437. msgObj.setAttribute("align", "center");
  438. msgObj.style.position = "absolute";
  439. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  440. msgObj.style.width = msgw + "px";
  441. msgObj.style.height = msgh + "px";
  442. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  443. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  444. document.body.appendChild(msgObj);
  445. //中间等待图标
  446. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  447. }
  448. let progressInterval;
  449. function showProgress() {
  450. var sWidth, sHeight;
  451. sWidth = document.body.clientWidth;
  452. sHeight = document.body.clientHeight;
  453. //背景遮罩层div
  454. var bgObj = document.createElement("div");
  455. bgObj.setAttribute('id', 'bgDiv');
  456. bgObj.style.zIndex = '9998';
  457. bgObj.style.position = "absolute";
  458. bgObj.style.top = "0px";
  459. bgObj.style.background = "#888";
  460. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  461. bgObj.style.opacity = "0.6";
  462. bgObj.style.left = "0px";
  463. bgObj.style.width = sWidth + "px";
  464. bgObj.style.height = sHeight + "px";
  465. document.body.appendChild(bgObj);
  466. //信息提示层div
  467. var msgObj = document.createElement("div");
  468. msgObj.classList.add('progress');
  469. msgObj.style.zIndex = '9999';
  470. msgObj.style.position = "absolute";
  471. msgObj.setAttribute("id", "progressDiv");
  472. msgObj.style.height = "2px";
  473. msgObj.style.width = "600px";
  474. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  475. msgObj.style.left = (sWidth - 600) / 2 + "px";
  476. document.body.appendChild(msgObj);
  477. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  478. const processObj = $('.progress-bar');
  479. let count = 0;
  480. progressInterval = setInterval(function () {
  481. const pos = parseInt(processObj.attr('aria-valuenow'));
  482. if (pos < 20) { // 1
  483. processObj.attr('aria-valuenow', pos + 2);
  484. processObj.width((pos + 2) + '%');
  485. } else if (pos < 40) { // 2
  486. processObj.attr('aria-valuenow', pos + 1);
  487. processObj.width((pos + 1) + '%');
  488. } else if (pos < 60) { // 4
  489. count += 1;
  490. if (count % 2 === 0) {
  491. processObj.attr('aria-valuenow', pos + 1);
  492. processObj.width((pos + 1) + '%');
  493. }
  494. } else if (pos < 80) { // 10
  495. count += 1;
  496. if (count % 5 === 0) {
  497. processObj.attr('aria-valuenow', pos + 1);
  498. processObj.width((pos + 1) + '%');
  499. }
  500. } else if (pos < 90) { // 15
  501. count += 1;
  502. if (count % 15 === 0) {
  503. processObj.attr('aria-valuenow', pos + 1);
  504. processObj.width((pos + 1) + '%');
  505. }
  506. } else if (pos < 95) { // 20
  507. count += 1;
  508. if (count % 40 === 0) {
  509. processObj.attr('aria-valuenow', pos + 1);
  510. processObj.width((pos + 1) + '%');
  511. }
  512. } else if (pos < 100) { // 30
  513. count += 1;
  514. if (count % 60 === 0) {
  515. processObj.attr('aria-valuenow', pos + 1);
  516. }
  517. }
  518. }, 100);
  519. }
  520. function doneProgress() {
  521. clearInterval(progressInterval);
  522. $('.progress-bar').attr('aria-valuenow', 100).width('100%');
  523. }
  524. function closeProgress() {
  525. setTimeout(function () {
  526. var bgDiv = document.getElementById("bgDiv");
  527. var msgDiv = document.getElementById("progressDiv");
  528. //移除背景遮罩层div
  529. if(bgDiv != null){
  530. document.body.removeChild(bgDiv);
  531. }
  532. //移除中间信息提示层div
  533. if(msgDiv != null){
  534. document.body.removeChild(msgDiv);
  535. }
  536. }, 500);
  537. }
  538. function showUploadFileProgress() {
  539. var sWidth, sHeight;
  540. sWidth = document.body.clientWidth;
  541. sHeight = document.body.clientHeight;
  542. //背景遮罩层div
  543. var bgObj = document.createElement("div");
  544. bgObj.setAttribute('id', 'bgDiv');
  545. bgObj.style.zIndex = '9998';
  546. bgObj.style.position = "absolute";
  547. bgObj.style.top = "0px";
  548. bgObj.style.background = "#888";
  549. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  550. bgObj.style.opacity = "0.6";
  551. bgObj.style.left = "0px";
  552. bgObj.style.width = sWidth + "px";
  553. bgObj.style.height = sHeight + "px";
  554. document.body.appendChild(bgObj);
  555. //信息提示层div
  556. var msgObj = document.createElement("div");
  557. msgObj.classList.add('progress');
  558. msgObj.style.zIndex = '9999';
  559. msgObj.style.position = "absolute";
  560. msgObj.setAttribute("id", "progressDiv");
  561. msgObj.style.height = "2px";
  562. msgObj.style.width = "600px";
  563. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  564. msgObj.style.left = (sWidth - 600) / 2 + "px";
  565. document.body.appendChild(msgObj);
  566. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  567. }
  568. function setUploadFileProgress(pos) {
  569. const processObj = $('.progress-bar');
  570. processObj.attr('aria-valuenow', pos);
  571. processObj.width(pos + '%');
  572. }
  573. /**
  574. * 设置本地缓存
  575. *
  576. * @param {String} key
  577. * @param {String|Number} value
  578. * @return {void}
  579. */
  580. function setLocalCache(key, value) {
  581. const storage = window.localStorage;
  582. if (!storage || key === '' || value === '') {
  583. return;
  584. }
  585. storage.setItem(key, value);
  586. }
  587. /**
  588. * 获取本地缓存
  589. *
  590. * @param {String} key
  591. * @return {String}
  592. */
  593. function getLocalCache(key) {
  594. const storage = window.localStorage;
  595. if (!storage || key === '') {
  596. return null;
  597. }
  598. return storage.getItem(key);
  599. }
  600. /**
  601. * 移除本地缓存
  602. * @param {String} key
  603. * @returns {Boolean}
  604. */
  605. function removeLocalCache(key) {
  606. const storage = window.localStorage;
  607. if (!storage || key === '') {
  608. return null;
  609. }
  610. return storage.removeItem(key);
  611. }
  612. //params: 需要复制的对象(元素)
  613. function copyToClipboard( text ) {
  614. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  615. var aux = document.createElement('textarea');// 创建元素用于复制
  616. // Prevent zooming on iOS
  617. aux.style.fontSize = '12pt';
  618. // Reset box model
  619. aux.style.border = '0';
  620. aux.style.padding = '0';
  621. aux.style.margin = '0';
  622. // Move element out of screen horizontally
  623. aux.style.position = 'absolute';
  624. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  625. // Move element to the same position vertically
  626. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  627. aux.style.top = yPosition + 'px';
  628. aux.setAttribute('readonly', '');
  629. // 设置元素内容
  630. aux.value = text;
  631. // 将元素插入页面进行调用
  632. document.body.appendChild(aux);
  633. // 复制内容
  634. aux.select();
  635. aux.setSelectionRange(0, text.length);
  636. // 将内容复制到剪贴板
  637. document.execCommand("copy", true);
  638. // 删除创建元素
  639. document.body.removeChild(aux);
  640. }
  641. function toastMessageUniq (obj) {
  642. if (!obj.msg || !obj.type) return;
  643. if (!obj.once) {
  644. switch (obj.type) {
  645. case 'error':
  646. toastr.error(obj.msg);
  647. break;
  648. case 'warning':
  649. toastr.warning(obj.msg);
  650. break;
  651. case 'info':
  652. toastr.info(obj.msg);
  653. break;
  654. case 'success':
  655. toastr.success(obj.msg);
  656. break;
  657. }
  658. obj.once = true;
  659. }
  660. }
  661. function trimInvalidChar(str) {
  662. return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
  663. }
  664. function cleanSymbols(str) {
  665. return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
  666. }
  667. jQuery.bootstrapLoading = {
  668. isLoading: function () {
  669. return $('#loadingPage').is(':visible');
  670. },
  671. start: function (options) {
  672. if(this.isLoading()){
  673. return;
  674. }
  675. var defaults = {
  676. opacity: 0.5,
  677. //loading页面透明度
  678. // backgroundColor: "#FFFFFF",
  679. //loading页面背景色
  680. borderColor: "#bbb",
  681. //提示边框颜色
  682. borderWidth: 1,
  683. //提示边框宽度
  684. borderStyle: "solid",
  685. //提示边框样式
  686. loadingTips: "Loading, please wait...",
  687. //提示文本
  688. TipsColor: "#fff",
  689. //提示颜色
  690. delayTime: 500,
  691. //页面加载完成后,加载页面渐出速度
  692. zindex: 2000,
  693. //loading页面层次
  694. sleep: 0
  695. //设置挂起,等于0时则无需挂起
  696. }
  697. var options = $.extend(defaults, options);
  698. //获取页面宽高
  699. var _PageHeight = document.documentElement.clientHeight,
  700. _PageWidth = document.documentElement.clientWidth;
  701. //在页面未加载完毕之前显示的loading Html自定义内容
  702. //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>';
  703. 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>';
  704. //呈现loading效果
  705. $("body").append(_LoadingHtml);
  706. //获取loading提示框宽高
  707. var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
  708. _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
  709. //计算距离,让loading提示框保持在屏幕上下左右居中
  710. var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
  711. _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
  712. $("#loadingTips").css({
  713. "left": _LoadingLeft + "px",
  714. "top": _LoadingTop + "px"
  715. });
  716. //监听页面加载状态
  717. document.onreadystatechange = PageLoaded;
  718. //当页面加载完成后执行
  719. function PageLoaded() {
  720. if (document.readyState == "complete") {
  721. var loadingMask = $('#loadingPage');
  722. setTimeout(function () {
  723. loadingMask.animate({
  724. "opacity": 0
  725. },
  726. options.delayTime,
  727. function () {
  728. $(this).hide();
  729. });
  730. },
  731. options.sleep);
  732. }
  733. }
  734. },
  735. end: function () {
  736. $("#loadingPage").remove();
  737. },
  738. progressStop:true,
  739. progressStart:async function(title="导出文件",autoBar = false){
  740. if($("#progressModal").length == 0){
  741. let phtml = `<div class="modal fade" id="progressModal" data-backdrop="static">
  742. <div class="modal-dialog" role="document">
  743. <div class="modal-content">
  744. <div class="modal-header">
  745. <h5 class="modal-title" id="progress_modal_title">${title}</h5>
  746. </div>
  747. <div class="modal-body">
  748. <!--正在生成-->
  749. <h5 class="my-3" id="progress_modal_body">正在${title}</h5>
  750. <div class="progress mb-3">
  751. <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>
  752. </div>
  753. </div>
  754. </div>
  755. </div>
  756. </div>`;
  757. $("body").append(phtml);
  758. }else {
  759. $("#progress_modal_title").text(title);
  760. $("#progress_modal_body").text(`正在${title}`);
  761. }
  762. $("#progress_modal_bar").css('width','0%');
  763. $("#progressModal").modal('show');
  764. if(autoBar == true){//假的进度条
  765. $.bootstrapLoading.progressStop = false;
  766. let width = 0;
  767. while ($.bootstrapLoading.progressStop == false){
  768. await setTimeoutSync(null,1000);
  769. width += 5;
  770. if(width > 90) width -= 50;
  771. $("#progress_modal_bar").css('width',`${width}%`);
  772. }
  773. }
  774. },
  775. progressEnd:function () {
  776. $("#progress_modal_bar").css('width','100%');
  777. $.bootstrapLoading.progressStop = true;
  778. $("#progressModal").modal('hide');
  779. }
  780. };
  781. // 光标插入button内容
  782. $.fn.extend({
  783. insertAtCaret: function(myValue){
  784. var $t=$(this)[0];
  785. if (document.selection) {
  786. this.focus();
  787. sel = document.selection.createRange();
  788. sel.text = myValue;
  789. this.focus();
  790. }
  791. else
  792. if ($t.selectionStart || $t.selectionStart == '0') {
  793. var startPos = $t.selectionStart;
  794. var endPos = $t.selectionEnd;
  795. var scrollTop = $t.scrollTop;
  796. $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
  797. this.focus();
  798. $t.selectionStart = startPos + myValue.length;
  799. $t.selectionEnd = startPos + myValue.length;
  800. $t.scrollTop = scrollTop;
  801. }
  802. else {
  803. this.value += myValue;
  804. this.focus();
  805. }
  806. }
  807. });
  808. Number.prototype.format2Str = function (pattern) {
  809. var strarr = this?this.toString().split('.'):['0'];
  810. var fmtarr = pattern?pattern.split('.'):[''];
  811. var retstr='';
  812. // 整数部分
  813. var str = strarr[0];
  814. var fmt = fmtarr[0];
  815. var i = str.length-1;
  816. var comma = false;
  817. for(var f=fmt.length-1;f>=0;f--){
  818. switch(fmt.substr(f,1)){
  819. case '#':
  820. if(i>=0 ) retstr = str.substr(i--,1) + retstr;
  821. break;
  822. case '0':
  823. if(i>=0) retstr = str.substr(i--,1) + retstr;
  824. else retstr = '0' + retstr;
  825. break;
  826. case ',':
  827. comma = true;
  828. retstr=','+retstr;
  829. break;
  830. }
  831. }
  832. if(i>=0){
  833. if(comma){
  834. var l = str.length;
  835. for(;i>=0;i--){
  836. retstr = str.substr(i,1) + retstr;
  837. if(i>0 && ((l-i)%3)==0) retstr = ',' + retstr;
  838. }
  839. }
  840. else retstr = str.substr(0,i+1) + retstr;
  841. }
  842. retstr = retstr+'.';
  843. // 处理小数部分
  844. str=strarr.length>1?strarr[1]:'';
  845. fmt=fmtarr.length>1?fmtarr[1]:'';
  846. i=0;
  847. for(var f=0;f<fmt.length;f++){
  848. switch(fmt.substr(f,1)){
  849. case '#':
  850. if(i<str.length) retstr+=str.substr(i++,1);
  851. break;
  852. case '0':
  853. if(i<str.length) retstr+= str.substr(i++,1);
  854. else retstr+='0';
  855. break;
  856. }
  857. }
  858. return retstr.replace(/^,+/,'').replace(/\.$/,'');
  859. };