global.js 32 KB

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