global.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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+45);
  22. $(".sjs-height-1").height($(window).height()-cHeader-bcontent-90+45);
  23. $(".sjs-height-2").height($(window).height()-cHeader-sBarz-110);
  24. $(".sjs-height-3").height($(window).height()-cHeader-sBar-492+15);/*492*/
  25. $(".sjs-height-4").height($(window).height()-cHeader-pBarz-110+65);
  26. $(".sjs-height-5").height($(window).height()-cHeader-sBar-492+45);/*492*/
  27. $(".sp-wrap").height(bcontent-40);
  28. /*侧栏高度*/
  29. $(".sjs-sh-1").height($(window).height()-cHeader-sBar1-92+45);
  30. $(".sjs-sh-2").height($(window).height()-cHeader-sBar2-92+45);
  31. $(".sjs-sh-3").height($(window).height()-cHeader-sBar3-92+45);
  32. $(".sjs-sh-4").height($(window).height()-cHeader-sBar4-92+45);
  33. $(".sjs-sh-5").height($(window).height()-cHeader-sBar5-92+45);
  34. };
  35. $(window).resize(autoFlashHeight);
  36. /*全局自适应高度结束*/
  37. $(function(){
  38. /*侧滑*/
  39. $(".open-sidebar").click(function(){
  40. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  41. });
  42. $("body").click(function(event){
  43. var e = event || window.event; //浏览器兼容性
  44. if(!$(event.target).is('a')) {
  45. var elem = event.target || e.srcElement;
  46. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  47. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  48. return false;
  49. }
  50. elem = elem.parentNode;
  51. }
  52. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  53. }
  54. });
  55. /*侧滑*/
  56. /*工具提示*/
  57. $(function () {
  58. $('[data-toggle="tooltip"]').tooltip()
  59. });
  60. /*侧栏菜单*/
  61. $(".bg-nav > li > a").click(function() {
  62. var self = $(this);
  63. var subMenu = $(this).siblings('ul.sub-menu');
  64. if(subMenu.length > 0) {
  65. if(subMenu.is(":visible")) {
  66. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  67. subMenu.slideUp('fast');
  68. self.parent().removeClass('active');
  69. }else{
  70. self.parent().addClass('active');
  71. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  72. subMenu.slideDown('fast');
  73. }
  74. }
  75. });
  76. // 数据提交
  77. $("#submit-form").click(function() {
  78. $("#save-form").submit();
  79. });
  80. // modal弹窗拖动
  81. // $(document).on("show.bs.modal", ".modal", function() {
  82. // $(this).draggable({
  83. // handle: ".modal-header" // 只能点击头部拖动
  84. // });
  85. // $(this).css("overflow", "hidden");
  86. // });
  87. // 动态生成datepicker
  88. $('body').on('focus', ".datepicker-here", function (e) {
  89. if ($(this).data("datepicker") != "1") {
  90. $(this).datepicker();
  91. }
  92. $(this).data("datepicker", "1");
  93. });
  94. });
  95. /**
  96. * 提示框
  97. *
  98. * @param string message
  99. * @param string type
  100. * @param string icon
  101. * @return void
  102. */
  103. function toast(message, type, icon) {
  104. var toast = $(".toast");
  105. toast.addClass(type);
  106. toast.children('.message').html(message);
  107. var iconClass = 'fa-' + icon;
  108. toast.children('.icon').addClass(iconClass);
  109. toast.fadeIn(500);
  110. setTimeout(function() {
  111. toast.fadeOut('fast');
  112. toast.children('.message').text('');
  113. toast.children('.icon').removeClass(iconClass);
  114. }, 3000);
  115. }
  116. /**
  117. * 动态请求数据
  118. * @param {String} url - 请求链接
  119. * @param data - 提交数据
  120. * @param {function} successCallback - 返回成功回调
  121. * @param {function} errorCallBack - 返回失败回调
  122. */
  123. const postData = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  124. if (showWaiting) showWaitingView();
  125. $.ajax({
  126. type:"POST",
  127. url: url,
  128. data: {'data': JSON.stringify(data)},
  129. dataType: 'json',
  130. cache: false,
  131. timeout: 40000,
  132. beforeSend: function(xhr) {
  133. let csrfToken = Cookies.get('csrfToken');
  134. xhr.setRequestHeader('x-csrf-token', csrfToken);
  135. },
  136. success: function(result){
  137. if (result.err === 0) {
  138. if (successCallback) {
  139. successCallback(result.data);
  140. }
  141. } else {
  142. toastr.error('error: ' + result.msg);
  143. if (errorCallBack) {
  144. errorCallBack(result.msg);
  145. }
  146. }
  147. if (showWaiting) closeWaitingView();
  148. },
  149. error: function(jqXHR, textStatus, errorThrown){
  150. toastr.error('error: ' + textStatus + " " + errorThrown);
  151. if (errorCallBack) {
  152. errorCallBack();
  153. }
  154. if (showWaiting) closeWaitingView();
  155. }
  156. });
  157. };
  158. /**
  159. * 动态请求数据(压缩数据)
  160. * @param {String} url - 请求链接
  161. * @param data - 提交数据
  162. * @param {function} successCallback - 返回成功回调
  163. * @param {function} errorCallBack - 返回失败回调
  164. */
  165. const postDataCompress = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  166. if (showWaiting) showWaitingView();
  167. $.ajax({
  168. type:"POST",
  169. url: url,
  170. data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
  171. dataType: 'json',
  172. cache: false,
  173. timeout: 60000, // 导入清单Excel(10w行)预计需要时间
  174. beforeSend: function(xhr) {
  175. let csrfToken = Cookies.get('csrfToken');
  176. xhr.setRequestHeader('x-csrf-token', csrfToken);
  177. },
  178. success: function(result){
  179. if (result.err === 0) {
  180. if (successCallback) {
  181. successCallback(result.data);
  182. }
  183. } else {
  184. toastr.error('error: ' + result.msg);
  185. if (errorCallBack) {
  186. errorCallBack(result.msg);
  187. }
  188. }
  189. if (showWaiting) closeWaitingView();
  190. },
  191. error: function(jqXHR, textStatus, errorThrown){
  192. toastr.error('error: ' + textStatus + " " + errorThrown);
  193. if (errorCallBack) {
  194. errorCallBack();
  195. }
  196. if (showWaiting) closeWaitingView();
  197. }
  198. });
  199. };
  200. /**
  201. * 动态请求数据
  202. * @param {String} url - 请求链接
  203. * @param data - 提交数据
  204. * @param {function} successCallback - 返回成功回调
  205. * @param {function} errorCallBack - 返回失败回调
  206. */
  207. const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) {
  208. if (showWaiting) showWaitingView();
  209. $.ajax({
  210. type:"POST",
  211. url: url,
  212. data: formData,
  213. dataType: 'json',
  214. cache: false,
  215. // 告诉jQuery不要去设置Content-Type请求头
  216. contentType: false,
  217. // 告诉jQuery不要去处理发送的数据
  218. processData: false,
  219. timeout: 5000,
  220. beforeSend: function(xhr) {
  221. let csrfToken = Cookies.get('csrfToken');
  222. xhr.setRequestHeader('x-csrf-token', csrfToken);
  223. },
  224. success: function(result){
  225. if (result.err === 0) {
  226. if (successCallback) {
  227. successCallback(result.data);
  228. }
  229. } else {
  230. toastr.error('error: ' + result.msg);
  231. if (errorCallBack) {
  232. errorCallBack();
  233. }
  234. }
  235. if (showWaiting) closeWaitingView();
  236. },
  237. error: function(jqXHR, textStatus, errorThrown){
  238. toastr.error('error: ' + textStatus + " " + errorThrown);
  239. if (errorCallBack) {
  240. errorCallBack();
  241. }
  242. if (showWaiting) closeWaitingView();
  243. }
  244. });
  245. };
  246. /**
  247. * 获取url中参数
  248. * @param variable
  249. * @returns {*}
  250. */
  251. function getQueryVariable(variable) {
  252. var query = window.location.search.substring(1);
  253. var vars = query.split("&");
  254. for (var i=0;i<vars.length;i++) {
  255. var pair = vars[i].split("=");
  256. if(pair[0] == variable){return pair[1];}
  257. }
  258. return(false);
  259. }
  260. const zeroRange = 0.00000001;
  261. function checkZero(value) {
  262. return _.isNumber(value) && Math.abs(value) < zeroRange;
  263. }
  264. function checkFieldChange(o, n) {
  265. return o == n || ((!o || o === '') && (n === ''));
  266. }
  267. var bShowWaiting = false, beginWaitingTime;
  268. //关闭等待窗口
  269. function closeWaitingView() {
  270. bShowWaiting = false;
  271. const time = parseInt(new Date());
  272. setTimeout(function () {
  273. var bgDiv = document.getElementById("bgDiv");
  274. var msgDiv = document.getElementById("msgDiv");
  275. //移除背景遮罩层div
  276. if(bgDiv != null){
  277. document.body.removeChild(bgDiv);
  278. }
  279. //移除中间信息提示层div
  280. if(msgDiv != null){
  281. document.body.removeChild(msgDiv);
  282. }
  283. }, Math.max(beginWaitingTime - time + 1000, 0));
  284. }
  285. //显示等待窗口
  286. function showWaitingView() {
  287. bShowWaiting = true;
  288. setTimeout(function () {
  289. if (!bShowWaiting) return;
  290. beginWaitingTime = parseInt(new Date());
  291. var msgw = 300; //提示窗口的宽度
  292. var msgh = 100; //提示窗口的高度
  293. var sWidth, sHeight;
  294. sWidth = document.body.clientWidth;
  295. sHeight = document.body.clientHeight;
  296. //背景遮罩层div
  297. var bgObj = document.createElement("div");
  298. bgObj.setAttribute('id', 'bgDiv');
  299. bgObj.style.zIndex = '9998';
  300. bgObj.style.position = "absolute";
  301. bgObj.style.top = "0px";
  302. bgObj.style.background = "#888";
  303. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  304. bgObj.style.opacity = "0.6";
  305. bgObj.style.left = "0px";
  306. bgObj.style.width = sWidth + "px";
  307. bgObj.style.height = sHeight + "px";
  308. document.body.appendChild(bgObj);
  309. //信息提示层div
  310. var msgObj = document.createElement("div");
  311. msgObj.style.zIndex = '9999';
  312. msgObj.setAttribute("id", "msgDiv");
  313. msgObj.setAttribute("align", "center");
  314. msgObj.style.position = "absolute";
  315. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  316. msgObj.style.width = msgw + "px";
  317. msgObj.style.height = msgh + "px";
  318. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  319. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  320. document.body.appendChild(msgObj);
  321. //中间等待图标
  322. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  323. }, 1000);
  324. }
  325. /**
  326. * 设置本地缓存
  327. *
  328. * @param {String} key
  329. * @param {String|Number} value
  330. * @return {void}
  331. */
  332. function setLocalCache(key, value) {
  333. const storage = window.localStorage;
  334. if (!storage || key === '' || value === '') {
  335. return;
  336. }
  337. storage.setItem(key, value);
  338. }
  339. /**
  340. * 获取本地缓存
  341. *
  342. * @param {String} key
  343. * @return {String}
  344. */
  345. function getLocalCache(key) {
  346. const storage = window.localStorage;
  347. if (!storage || key === '') {
  348. return null;
  349. }
  350. return storage.getItem(key);
  351. }
  352. /**
  353. * 移除本地缓存
  354. * @param {String} key
  355. * @returns {Boolean}
  356. */
  357. function removeLocalCache(key) {
  358. const storage = window.localStorage;
  359. if (!storage || key === '') {
  360. return null;
  361. }
  362. return storage.removeItem(key);
  363. }
  364. //params: 需要复制的对象(元素)
  365. function copyToClipboard( text ) {
  366. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  367. var aux = document.createElement('textarea');// 创建元素用于复制
  368. // Prevent zooming on iOS
  369. aux.style.fontSize = '12pt';
  370. // Reset box model
  371. aux.style.border = '0';
  372. aux.style.padding = '0';
  373. aux.style.margin = '0';
  374. // Move element out of screen horizontally
  375. aux.style.position = 'absolute';
  376. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  377. // Move element to the same position vertically
  378. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  379. aux.style.top = yPosition + 'px';
  380. aux.setAttribute('readonly', '');
  381. // 设置元素内容
  382. aux.value = text;
  383. // 将元素插入页面进行调用
  384. document.body.appendChild(aux);
  385. // 复制内容
  386. aux.select();
  387. aux.setSelectionRange(0, text.length);
  388. // 将内容复制到剪贴板
  389. document.execCommand("copy", true);
  390. // 删除创建元素
  391. document.body.removeChild(aux);
  392. }
  393. function toastMessageUniq (obj) {
  394. if (!obj.msg || !obj.type) return;
  395. if (!obj.once) {
  396. switch (obj.type) {
  397. case 'error':
  398. toastr.error(obj.msg);
  399. break;
  400. case 'warning':
  401. toastr.warning(obj.msg);
  402. break;
  403. case 'info':
  404. toastr.info(obj.msg);
  405. break;
  406. case 'success':
  407. toastr.success(obj.msg);
  408. break;
  409. }
  410. obj.once = true;
  411. }
  412. }