global.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*全局自适应高度*/
  2. function autoFlashHeight(){
  3. var cHeader = $(".c-header").height();
  4. $(".sjs-height-1").height($(window).height()-cHeader-160);
  5. $(".sjs-height-2").height($(window).height()-cHeader-191);
  6. };
  7. $(window).resize(autoFlashHeight);
  8. /*全局自适应高度结束*/
  9. $(function(){
  10. /*侧滑*/
  11. $(".open-sidebar").click(function(){
  12. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  13. });
  14. $("body").click(function(event){
  15. var e = event || window.event; //浏览器兼容性
  16. if(!$(event.target).is('a')) {
  17. var elem = event.target || e.srcElement;
  18. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  19. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  20. return false;
  21. }
  22. elem = elem.parentNode;
  23. }
  24. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  25. }
  26. });
  27. /*侧滑*/
  28. /*工具提示*/
  29. $(function () {
  30. $('[data-toggle="tooltip"]').tooltip()
  31. });
  32. /*侧栏菜单*/
  33. $(".bg-nav > li > a").click(function() {
  34. var self = $(this);
  35. var subMenu = $(this).siblings('ul.sub-menu');
  36. if(subMenu.length > 0) {
  37. if(subMenu.is(":visible")) {
  38. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  39. subMenu.slideUp('fast');
  40. self.parent().removeClass('active');
  41. }else{
  42. self.parent().addClass('active');
  43. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  44. subMenu.slideDown('fast');
  45. }
  46. }
  47. });
  48. // 数据提交
  49. $("#submit-form").click(function() {
  50. $("#save-form").submit();
  51. });
  52. });
  53. /**
  54. * 提示框
  55. *
  56. * @param string message
  57. * @param string type
  58. * @param string icon
  59. * @return void
  60. */
  61. function toast(message, type, icon)
  62. {
  63. var toast = $(".toast");
  64. toast.addClass(type);
  65. toast.children('.message').html(message);
  66. var iconClass = 'fa-' + icon;
  67. toast.children('.icon').addClass(iconClass);
  68. toast.fadeIn(500);
  69. setTimeout(function() {
  70. toast.fadeOut('fast');
  71. toast.children('.message').text('');
  72. toast.children('.icon').removeClass(iconClass);
  73. }, 3000);
  74. }
  75. /**
  76. * 动态请求数据
  77. * @param {String} url - 请求链接
  78. * @param data - 提交数据
  79. * @param {function} successCallback - 返回成功回调
  80. * @param {function} errorCallBack - 返回失败回调
  81. */
  82. const postData = function (url, data, successCallback, errorCallBack) {
  83. $.ajax({
  84. type:"POST",
  85. url: url,
  86. data: {'data': JSON.stringify(data)},
  87. dataType: 'json',
  88. cache: false,
  89. timeout: 5000,
  90. beforeSend: function(xhr) {
  91. let csrfToken = Cookies.get('csrfToken');
  92. xhr.setRequestHeader('x-csrf-token', csrfToken);
  93. },
  94. success: function(result){
  95. if (result.err === 0) {
  96. if (successCallback) {
  97. successCallback(result.data);
  98. }
  99. } else {
  100. toast('error: ' + result.message, 'error', 'exclamation-circle');
  101. if (errorCallBack) {
  102. errorCallBack();
  103. }
  104. }
  105. },
  106. error: function(jqXHR, textStatus, errorThrown){
  107. toast('error ' + textStatus + " " + errorThrown, 'error', 'exclamation-circle');
  108. if (errorCallBack) {
  109. errorCallBack();
  110. }
  111. }
  112. });
  113. };