gljClassTree.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * Created by Zhong on 2018/1/16.
  3. */
  4. let gljClassTreeObj = {
  5. treeData: null,
  6. cache: null,//ref to tree.items
  7. tree: null,
  8. controller: null,
  9. workBook: null,
  10. sheet: null,
  11. setting: {
  12. sheet: {
  13. cols:[
  14. {
  15. head: {
  16. titleNames: ['名称'],
  17. spanCols: [1],
  18. spanRows: [2],
  19. vAlign: [1, 1],
  20. hAlign: [1, 1],
  21. font: 'Arial'
  22. },
  23. data: {
  24. field: 'Name',
  25. vAlign: 1,
  26. hAlign: 0,
  27. font: 'Arial'
  28. },
  29. width: 400
  30. }
  31. ],
  32. headRows: 1,
  33. headRowHeight: [47],
  34. emptyRows: 0,
  35. treeCol: 0
  36. },
  37. tree: {
  38. id: 'ID',
  39. pid: 'ParentID',
  40. nid: 'NextSiblingID',
  41. rootId: -1
  42. },
  43. options: {
  44. tabStripVisible: false,
  45. allowContextMenu: false,
  46. allowCopyPasteExcelStyle : false,
  47. allowExtendPasteRange: false,
  48. allowUserDragDrop : false,
  49. allowUserDragFill: false,
  50. scrollbarMaxAlign : true
  51. }
  52. },
  53. isDef: function (v) {
  54. return v !== undefined && v !== null;
  55. },
  56. isFunc: function (v) {
  57. return this.isDef(v) && typeof v === 'function';
  58. },
  59. //sheet things
  60. setOptions: function (workbook, opts) {
  61. for(let opt in opts){
  62. workbook.options[opt] = opts[opt];
  63. }
  64. },
  65. renderFunc: function (sheet, func) {
  66. sheet.suspendPaint();
  67. sheet.suspendEvent();
  68. if(this.isFunc(func)){
  69. func();
  70. }
  71. sheet.resumePaint();
  72. sheet.resumeEvent();
  73. },
  74. buildSheet: function () {
  75. if(!this.isDef(this.workBook)){
  76. this.workBook = new GC.Spread.Sheets.Workbook($('#gljClassSpread')[0], {sheetCount: 1});
  77. sheetCommonObj.spreadDefaultStyle(this.workBook);
  78. this.sheet = this.workBook.getActiveSheet();
  79. this.setOptions(this.workBook, this.setting.options);
  80. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  81. this.bindEvents(this.sheet);
  82. }
  83. },
  84. bindEvents: function (sheet) {
  85. let me = gljClassTreeObj;
  86. const Events = GC.Spread.Sheets.Events;
  87. sheet.bind(Events.SelectionChanging, me.onSelectionChanged);
  88. sheet.bind(Events.EditStarting, me.onEditStarting);
  89. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  90. },
  91. onSelectionChanged: function (sender, info) {
  92. let me = gljClassTreeObj;
  93. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  94. let row = info.newSelections[0].row;
  95. let node = me.cache[row];
  96. me.initSelection(node);
  97. }
  98. },
  99. onEditStarting: function (sender, args) {
  100. args.cancel = true;
  101. },
  102. onClipboardPasting: function (sender, info) {
  103. info.cancel = true;
  104. },
  105. getGljClassTree: function (gljLibId, callback) {
  106. let me = gljClassTreeObj;
  107. let re = repositoryGljObj;
  108. let url = '/complementartGlj/api/getMixedTree';
  109. let postData = {gljLibId: gljLibId};
  110. let sucFunc = function (rstData) {
  111. me.treeData = rstData;
  112. let compleTreeData = me.treeData.comple;
  113. if (compleTreeData && compleTreeData.length > 0) {
  114. me.gljCurTypeId = compleTreeData[0].ID;
  115. }
  116. //init
  117. me.buildSheet();
  118. me.initTree(compleTreeData);
  119. me.cache = me.tree.items;
  120. re.updateParentNodeIds(me.cache, re);
  121. me.initController(me.tree, me.sheet, me.setting.sheet);
  122. me.controller.showTreeData();
  123. me.sheet.setFormatter(-1, 0, '@');
  124. if(callback){
  125. callback();
  126. }
  127. };
  128. CommonAjax.post(url, postData, sucFunc);
  129. },
  130. initTree: function (datas) {
  131. this.tree = idTree.createNew(this.setting.tree);
  132. this.tree.loadDatas(datas);
  133. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  134. },
  135. initController: function (tree, sheet, setting) {
  136. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  137. },
  138. //模仿默认点击
  139. initSelection: function (node) {
  140. let me = this,
  141. re = repositoryGljObj,
  142. that = gljComponentOprObj;
  143. if(!re.isDef(node)){
  144. return;
  145. }
  146. let gljTypeId = node.data.ID;
  147. re.gljCurTypeId = node.data.ID;
  148. re.addGljObj = null;
  149. sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
  150. if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
  151. re.currentOprParent = 1;
  152. re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
  153. re.workBook.getSheet(0).setRowCount(re.currentCache.length);
  154. } else {
  155. re.currentOprParent = 0;
  156. re.currentCache = re.getCache();
  157. }
  158. re.showGljItems(re.complementaryGljList, gljTypeId);
  159. re.initSel(re.workBook.getSheet(0).getActiveRowIndex());
  160. me.workBook.focus(true);
  161. }
  162. }