global.js 32 KB

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