main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Created by Mai on 2017/3/10.
  3. */
  4. $(function () {
  5. // 读取本地存储的高度(必须放在载入spread之前)
  6. loadSize("main", function() {
  7. refreshSubSpread();
  8. });
  9. $("#header-menu").removeAttr('style');
  10. projectInfoObj.showProjectInfo();
  11. projectObj.checkMainSpread();
  12. projectObj.loadProjectData();
  13. $('#tab_baobiao').on('shown.bs.tab', function (e) {
  14. $(e.relatedTarget.hash).removeClass('active');
  15. // do something
  16. });
  17. $('#tab_zaojiashu').on('shown.bs.tab', function (e) {
  18. $(e.relatedTarget.hash).removeClass('active');
  19. $("#subItems").addClass('active');
  20. $(gljOprObj.activeTab).addClass('active');
  21. loadSize("main", function() {
  22. projectObj.refreshMainSpread();
  23. refreshSubSpread();
  24. });
  25. });
  26. slideResize($("#main"), function() {
  27. projectObj.mainSpread.refresh();
  28. refreshSubSpread();
  29. });
  30. const projectId = scUrlUtil.GetQueryString('project');
  31. // 绑定点击事件
  32. projectObj.mainSpread.bind(GC.Spread.Sheets.Events.CellClick, function(sender, info) {
  33. if (info.row !== undefined && projectId !== undefined) {
  34. setLocalCache('lastRow:' + projectId, info.row);
  35. setLocalCache('lastCol:' + projectId, info.col);
  36. }
  37. });
  38. });
  39. /**
  40. * 拖动更改div大小
  41. *
  42. * @param {Object} rootElement - 最顶层div
  43. * @param {function} callback - 成功后执行
  44. * @return {void}
  45. */
  46. function slideResize(rootElement, callback) {
  47. let startY = 0;
  48. let drag = false;
  49. const element = rootElement.find('.resize');
  50. const topContentEle = rootElement.find(".top-content");
  51. const bottomContentEle = rootElement.find(".bottom-content");
  52. let topContentHeight = 0;
  53. let bottomContentHeight = 0;
  54. let navHeight = 0;
  55. let topChangeHeight = 0;
  56. let bottomChangeHeight = 0;
  57. // 鼠标点下时
  58. element.mousedown(function(e) {
  59. drag = true;
  60. startY = e.clientY;
  61. // 获取上部分的高度
  62. topContentHeight = topContentEle.height();
  63. // 获取下部分的高度
  64. bottomContentHeight = bottomContentEle.height();
  65. // nav高度部分
  66. navHeight = bottomContentEle.children('ul.nav').height() + 4;
  67. element.tooltip('hide');
  68. });
  69. // 鼠标移动
  70. $("body").mousemove(function(e) {
  71. if (drag) {
  72. let moveHeight = e.clientY - startY;
  73. // 判断拖动范围不能超出
  74. topChangeHeight = topContentHeight + moveHeight;
  75. topChangeHeight = topChangeHeight < 170 ? 170 : topChangeHeight;
  76. topChangeHeight = topChangeHeight > 700 ? 709 : topChangeHeight;
  77. topContentEle.children(".main-data-top").height(topChangeHeight);
  78. bottomChangeHeight = bottomContentHeight - moveHeight;
  79. bottomChangeHeight = bottomChangeHeight < 170 ? 170 : bottomChangeHeight;
  80. bottomChangeHeight = bottomChangeHeight > 700 ? 709 : bottomChangeHeight;
  81. bottomContentEle.children().find(".main-data-bottom").height(bottomChangeHeight - navHeight);
  82. }
  83. });
  84. // 鼠标弹起
  85. $("body").mouseup(function(e) {
  86. if (drag) {
  87. callback();
  88. drag = false;
  89. // 存入本地缓存
  90. const id = rootElement.attr('id');
  91. topChangeHeight = topChangeHeight >= 700 ? 709 : topChangeHeight;
  92. bottomChangeHeight = bottomChangeHeight >= 700 ? 709 : bottomChangeHeight;
  93. setLocalCache('topHeight:' + id, topChangeHeight);
  94. setLocalCache('bottomHeight:' + id, bottomChangeHeight);
  95. }
  96. });
  97. }
  98. /**
  99. * 读取设置的高度
  100. *
  101. * @param {String} tag - 顶层div的id
  102. * @param {function} callback - 回调函数
  103. * @return {void}
  104. */
  105. function loadSize(tag, callback) {
  106. if (tag === '') {
  107. return;
  108. }
  109. let o_topHeight = $("#"+ tag +" .main-data-top").height();
  110. let o_bottomHeight = $("#"+ tag +" .main-data-bottom").height();
  111. let topHeight = getLocalCache('topHeight:' + tag);
  112. let bottomHeight = getLocalCache('bottomHeight:' + tag);
  113. if (topHeight === null || bottomHeight === null) {
  114. $("#"+ tag +" .main-data-top").height(o_topHeight);
  115. $("#"+ tag +" .main-data-bottom").height(o_bottomHeight);
  116. }else {
  117. const navHeight = $("#"+ tag +" .bottom-content").children('ul.nav').height() + 4;
  118. topHeight = parseFloat(topHeight);
  119. bottomHeight = parseFloat(bottomHeight);
  120. console.log(topHeight);
  121. console.log(bottomHeight);
  122. $("#"+ tag +" .main-data-top").height(topHeight);
  123. $("#"+ tag +" .main-data-bottom").height(bottomHeight - navHeight);
  124. }
  125. // $("#"+ tag +" .bottom-content").height(bottomHeight);
  126. callback();
  127. }