main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. slideResize($("#main"), function() {
  19. projectObj.mainSpread.refresh();
  20. refreshSubSpread();
  21. });
  22. });
  23. /**
  24. * 拖动更改div大小
  25. *
  26. * @param {Object} rootElement - 最顶层div
  27. * @param {function} callback - 成功后执行
  28. * @return {void}
  29. */
  30. function slideResize(rootElement, callback) {
  31. let startY = 0;
  32. let drag = false;
  33. const element = rootElement.find('.resize-line');
  34. const topContentEle = rootElement.find(".top-content");
  35. const bottomContentEle = rootElement.find(".bottom-content");
  36. let topContentHeight = 0;
  37. let bottomContentHeight = 0;
  38. let navHeight = 0;
  39. let topChangeHeight = 0;
  40. let bottomChangeHeight = 0;
  41. // 鼠标点下时
  42. element.mousedown(function(e) {
  43. drag = true;
  44. startY = e.clientY;
  45. // 获取上部分的高度
  46. topContentHeight = topContentEle.height();
  47. // 获取下部分的高度
  48. bottomContentHeight = bottomContentEle.height();
  49. // nav高度部分
  50. navHeight = bottomContentEle.children('ul.nav').height();
  51. });
  52. // 鼠标移动
  53. $("body").mousemove(function(e) {
  54. if (drag) {
  55. let moveHeight = e.clientY - startY;
  56. // 判断拖动范围不能超出
  57. topChangeHeight = topContentHeight + moveHeight;
  58. topChangeHeight = topChangeHeight < 150 ? 150 : topChangeHeight;
  59. topChangeHeight = topChangeHeight > 700 ? 700 : topChangeHeight;
  60. topContentEle.children(".main-data-top").height(topChangeHeight);
  61. bottomChangeHeight = bottomContentHeight - moveHeight;
  62. bottomChangeHeight = bottomChangeHeight < 150 ? 150 : bottomChangeHeight;
  63. bottomChangeHeight = bottomChangeHeight > 700 ? 700 : bottomChangeHeight;
  64. bottomContentEle.children().find(".main-data-bottom").height(bottomChangeHeight - navHeight);
  65. }
  66. });
  67. // 鼠标弹起
  68. $("body").mouseup(function(e) {
  69. if (drag) {
  70. callback();
  71. drag = false;
  72. // 存入本地缓存
  73. const storage = window.localStorage;
  74. if (storage) {
  75. const id = rootElement.attr('id');
  76. storage.setItem('topHeight:' + id, topChangeHeight);
  77. storage.setItem('bottomHeight:' + id, bottomChangeHeight);
  78. }
  79. }
  80. });
  81. }
  82. /**
  83. * 读取设置的高度
  84. *
  85. * @param {String} tag - 顶层div的id
  86. * @param {function} callback - 回调函数
  87. * @return {void}
  88. */
  89. function loadSize(tag, callback) {
  90. const storage = window.localStorage;
  91. if (!storage || tag === '') {
  92. return;
  93. }
  94. const topHeight = storage.getItem('topHeight:' + tag);
  95. const bottomHeight = storage.getItem('bottomHeight:' + tag);
  96. const navHeight = $("#"+ tag +" .bottom-content").children('ul.nav').height();
  97. $("#"+ tag +" .main-data-top").height(topHeight);
  98. $("#"+ tag +" .main-data-bottom").height(bottomHeight - navHeight);
  99. $("#"+ tag +" .bottom-content").height(bottomHeight);
  100. callback();
  101. }