global.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*全局自适应高度*/
  2. function autoFlashHeight(){
  3. var cHeader = $(".c-header").height();
  4. var toptitle = $(".top-title").height();
  5. var bottomtitle = $(".bottom-title").height();
  6. var sjsbottom = $(".sjs-bottom-2").height();
  7. $(".sjs-height-1").height($(window).height()-cHeader-162);
  8. $(".sjs-height-3").height($(window).height()-cHeader-toptitle-bottomtitle-sjsbottom-192);
  9. };
  10. $(window).resize(autoFlashHeight);
  11. /*全局自适应高度结束*/
  12. $(function(){
  13. /*侧滑*/
  14. $(".open-sidebar").click(function(){
  15. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  16. });
  17. $("body").click(function(event){
  18. var e = event || window.event; //浏览器兼容性
  19. if(!$(event.target).is('a')) {
  20. var elem = event.target || e.srcElement;
  21. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  22. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  23. return false;
  24. }
  25. elem = elem.parentNode;
  26. }
  27. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  28. }
  29. });
  30. /*侧滑*/
  31. /*工具提示*/
  32. $(function () {
  33. $('[data-toggle="tooltip"]').tooltip();
  34. $('[data-toggle="popover"]').popover()
  35. });
  36. /*侧栏菜单*/
  37. $(".bg-nav > li > a").click(function() {
  38. var self = $(this);
  39. var subMenu = $(this).siblings('ul.sub-menu');
  40. if(subMenu.length > 0) {
  41. if(subMenu.is(":visible")) {
  42. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  43. subMenu.slideUp('fast');
  44. self.parent().removeClass('active');
  45. }else{
  46. self.parent().addClass('active');
  47. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  48. subMenu.slideDown('fast');
  49. }
  50. }
  51. });
  52. });
  53. /**
  54. * 动态请求数据
  55. * @param {String} url - 请求链接
  56. * @param data - 提交数据
  57. * @param {function} successCallback - 返回成功回调
  58. * @param {function} errorCallBack - 返回失败回调
  59. */
  60. const postData = function (url, data, successCallback, errorCallBack) {
  61. $.ajax({
  62. type:"POST",
  63. url: url,
  64. data: {'data': JSON.stringify(data)},
  65. dataType: 'json',
  66. cache: false,
  67. timeout: 25000,
  68. beforeSend: function(xhr) {
  69. let csrfToken = Cookies.get('csrfToken');
  70. xhr.setRequestHeader('x-csrf-token', csrfToken);
  71. },
  72. success: function(result){
  73. if (result.err === 0) {
  74. if (successCallback) {
  75. successCallback(result.data);
  76. }
  77. } else {
  78. if (errorCallBack) {
  79. errorCallBack(result.data);
  80. }
  81. }
  82. },
  83. error: function(jqXHR, textStatus, errorThrown){
  84. if (errorCallBack) {
  85. errorCallBack();
  86. }
  87. }
  88. });
  89. };
  90. GetUrlQueryString = function (name) {
  91. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  92. var r = window.location.search.substr(1).match(reg);
  93. return r ? unescape(r[2]) : null;
  94. };
  95. // 对Date的扩展,将 Date 转化为指定格式的String
  96. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  97. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  98. // 例子:
  99. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  100. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  101. Date.prototype.Format = function (fmt) { //author: meizz
  102. var o = {
  103. "M+": this.getMonth() + 1, //月份
  104. "d+": this.getDate(), //日
  105. "h+": this.getHours(), //小时
  106. "m+": this.getMinutes(), //分
  107. "s+": this.getSeconds(), //秒
  108. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  109. "S": this.getMilliseconds() //毫秒
  110. };
  111. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  112. for (var k in o)
  113. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  114. return fmt;
  115. }