global.js 31 KB

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