gljClassTree.js 5.7 KB

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