global.js 35 KB

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