main.js 4.1 KB

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