main.js 4.3 KB

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