main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Created by Mai on 2017/3/10.
  3. */
  4. $(function () {
  5. projectInfoObj.showProjectInfo();
  6. projectObj.checkMainSpread();
  7. projectObj.loadProjectData();
  8. $('#tab_baobiao').on('shown.bs.tab', function (e) {
  9. $(e.relatedTarget.hash).removeClass('active');
  10. // do something
  11. });
  12. $('#tab_zaojiashu').on('shown.bs.tab', function (e) {
  13. $(e.relatedTarget.hash).removeClass('active');
  14. $("#subItems").addClass('active');
  15. $(gljOprObj.activeTab).addClass('active');
  16. // do something
  17. });
  18. // 读取本地存储的高度
  19. loadSize("main", function() {
  20. refreshSubSpread();
  21. });
  22. slideResize($("#main"), function() {
  23. projectObj.mainSpread.refresh();
  24. refreshSubSpread();
  25. });
  26. });
  27. /**
  28. * 拖动更改div大小
  29. *
  30. * @param {Object} rootElement - 最顶层div
  31. * @param {function} callback - 成功后执行
  32. * @return {void}
  33. */
  34. function slideResize(rootElement, callback) {
  35. let startY = 0;
  36. let drag = false;
  37. const element = rootElement.find('.resize');
  38. const topContentEle = rootElement.find(".top-content");
  39. const bottomContentEle = rootElement.find(".bottom-content");
  40. let topContentHeight = 0;
  41. let bottomContentHeight = 0;
  42. let navHeight = 0;
  43. let topChangeHeight = 0;
  44. let bottomChangeHeight = 0;
  45. // 鼠标点下时
  46. element.mousedown(function(e) {
  47. drag = true;
  48. startY = e.clientY;
  49. // 获取上部分的高度
  50. topContentHeight = topContentEle.height();
  51. // 获取下部分的高度
  52. bottomContentHeight = bottomContentEle.height();
  53. // nav高度部分
  54. navHeight = bottomContentEle.children('ul.nav').height();
  55. element.tooltip('hide');
  56. });
  57. // 鼠标移动
  58. $("body").mousemove(function(e) {
  59. if (drag) {
  60. let moveHeight = e.clientY - startY;
  61. // 判断拖动范围不能超出
  62. topChangeHeight = topContentHeight + moveHeight;
  63. topChangeHeight = topChangeHeight < 170 ? 170 : topChangeHeight;
  64. topChangeHeight = topChangeHeight > 700 ? 700 : topChangeHeight;
  65. topContentEle.children(".main-data-top").height(topChangeHeight);
  66. bottomChangeHeight = bottomContentHeight - moveHeight;
  67. bottomChangeHeight = bottomChangeHeight < 170 ? 170 : bottomChangeHeight;
  68. bottomChangeHeight = bottomChangeHeight > 700 ? 700 : bottomChangeHeight;
  69. bottomContentEle.children().find(".main-data-bottom").height(bottomChangeHeight - navHeight);
  70. }
  71. });
  72. // 鼠标弹起
  73. $("body").mouseup(function(e) {
  74. if (drag) {
  75. callback();
  76. drag = false;
  77. // 存入本地缓存
  78. const storage = window.localStorage;
  79. if (storage) {
  80. const id = rootElement.attr('id');
  81. storage.setItem('topHeight:' + id, topChangeHeight);
  82. storage.setItem('bottomHeight:' + id, bottomChangeHeight);
  83. }
  84. }
  85. });
  86. }
  87. /**
  88. * 读取设置的高度
  89. *
  90. * @param {String} tag - 顶层div的id
  91. * @param {function} callback - 回调函数
  92. * @return {void}
  93. */
  94. function loadSize(tag, callback) {
  95. const storage = window.localStorage;
  96. if (!storage || tag === '') {
  97. return;
  98. }
  99. const topHeight = storage.getItem('topHeight:' + tag);
  100. const bottomHeight = storage.getItem('bottomHeight:' + tag);
  101. if (topHeight === null || bottomHeight === null) {
  102. return;
  103. }
  104. const navHeight = $("#"+ tag +" .bottom-content").children('ul.nav').height();
  105. $("#"+ tag +" .main-data-top").height(topHeight);
  106. $("#"+ tag +" .main-data-bottom").height(bottomHeight - navHeight);
  107. $("#"+ tag +" .bottom-content").height(bottomHeight);
  108. callback();
  109. }