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. autoFlashHeight();
  22. projectObj.refreshMainSpread();
  23. /*loadSize("main", function() {
  24. projectObj.refreshMainSpread();
  25. refreshSubSpread();
  26. });*/
  27. });
  28. slideResize($("#main"), function() {
  29. projectObj.mainSpread.refresh();
  30. refreshSubSpread();
  31. });
  32. const projectId = scUrlUtil.GetQueryString('project');
  33. // 绑定点击事件
  34. projectObj.mainSpread.bind(GC.Spread.Sheets.Events.CellClick, function(sender, info) {
  35. if (info.row !== undefined && projectId !== undefined) {
  36. setLocalCache('lastRow:' + projectId, info.row);
  37. setLocalCache('lastCol:' + projectId, info.col);
  38. }
  39. });
  40. });
  41. /**
  42. * 拖动更改div大小
  43. *
  44. * @param {Object} rootElement - 最顶层div
  45. * @param {function} callback - 成功后执行
  46. * @return {void}
  47. */
  48. function slideResize(rootElement, callback) {
  49. let startY = 0;
  50. let drag = false;
  51. const element = rootElement.find('.resize');
  52. const topContentEle = rootElement.find(".top-content");
  53. const bottomContentEle = rootElement.find(".bottom-content");
  54. let topContentHeight = 0;
  55. let bottomContentHeight = 0;
  56. let navHeight = 0;
  57. let topChangeHeight = 0;
  58. let bottomChangeHeight = 0;
  59. // 鼠标点下时
  60. element.mousedown(function(e) {
  61. drag = true;
  62. startY = e.clientY;
  63. // 获取上部分的高度
  64. topContentHeight = topContentEle.height();
  65. // 获取下部分的高度
  66. bottomContentHeight = bottomContentEle.height();
  67. // nav高度部分
  68. navHeight = bottomContentEle.children('ul.nav').height() + 4;
  69. element.tooltip('hide');
  70. });
  71. // 鼠标移动
  72. $("body").mousemove(function(e) {
  73. if (drag) {
  74. let moveHeight = e.clientY - startY;
  75. // 判断拖动范围不能超出
  76. topChangeHeight = topContentHeight + moveHeight;
  77. topChangeHeight = topChangeHeight < 170 ? 170 : topChangeHeight;
  78. topChangeHeight = topChangeHeight > 700 ? 709 : topChangeHeight;
  79. topContentEle.children(".main-data-top").height(topChangeHeight);
  80. bottomChangeHeight = bottomContentHeight - moveHeight;
  81. bottomChangeHeight = bottomChangeHeight < 170 ? 170 : bottomChangeHeight;
  82. bottomChangeHeight = bottomChangeHeight > 700 ? 709 : bottomChangeHeight;
  83. bottomContentEle.children().find(".main-data-bottom").height(bottomChangeHeight - navHeight);
  84. }
  85. });
  86. // 鼠标弹起
  87. $("body").mouseup(function(e) {
  88. if (drag) {
  89. callback();
  90. drag = false;
  91. // 存入本地缓存
  92. const id = rootElement.attr('id');
  93. topChangeHeight = topChangeHeight >= 700 ? 709 : topChangeHeight;
  94. bottomChangeHeight = bottomChangeHeight >= 700 ? 709 : bottomChangeHeight;
  95. setLocalCache('topHeight:' + id, topChangeHeight);
  96. setLocalCache('bottomHeight:' + id, bottomChangeHeight);
  97. }
  98. });
  99. }
  100. /**
  101. * 读取设置的高度
  102. *
  103. * @param {String} tag - 顶层div的id
  104. * @param {function} callback - 回调函数
  105. * @return {void}
  106. */
  107. function loadSize(tag, callback) {
  108. if (tag === '') {
  109. return;
  110. }
  111. let o_topHeight = $("#"+ tag +" .main-data-top").height();
  112. let o_bottomHeight = $("#"+ tag +" .main-data-bottom").height();
  113. let topHeight = getLocalCache('topHeight:' + tag);
  114. let bottomHeight = getLocalCache('bottomHeight:' + tag);
  115. if (topHeight === null || bottomHeight === null) {
  116. $("#"+ tag +" .main-data-top").height(o_topHeight);
  117. $("#"+ tag +" .main-data-bottom").height(o_bottomHeight);
  118. }else {
  119. const navHeight = $("#"+ tag +" .bottom-content").children('ul.nav').height() + 4;
  120. topHeight = parseFloat(topHeight);
  121. bottomHeight = parseFloat(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. }