gljClassTree.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. allowContextMenu: false,
  45. allowCopyPasteExcelStyle : false,
  46. allowExtendPasteRange: false,
  47. allowUserDragDrop : false,
  48. allowUserDragFill: false,
  49. scrollbarMaxAlign : true
  50. }
  51. },
  52. isDef: function (v) {
  53. return v !== undefined && v !== null;
  54. },
  55. isFunc: function (v) {
  56. return this.isDef(v) && typeof v === 'function';
  57. },
  58. //sheet things
  59. setOptions: function (workbook, opts) {
  60. for(let opt in opts){
  61. workbook.options[opt] = opts[opt];
  62. }
  63. },
  64. renderFunc: function (sheet, func) {
  65. sheet.suspendPaint();
  66. sheet.suspendEvent();
  67. if(this.isFunc(func)){
  68. func();
  69. }
  70. sheet.resumePaint();
  71. sheet.resumeEvent();
  72. },
  73. buildSheet: function () {
  74. if(!this.isDef(this.workBook)){
  75. this.workBook = new GC.Spread.Sheets.Workbook($('#gljClassSpread')[0], {sheetCount: 1});
  76. sheetCommonObj.spreadDefaultStyle(this.workBook);
  77. this.sheet = this.workBook.getActiveSheet();
  78. this.setOptions(this.workBook, this.setting.options);
  79. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  80. this.bindEvents(this.sheet);
  81. }
  82. },
  83. bindEvents: function (sheet) {
  84. let me = gljClassTreeObj;
  85. const Events = GC.Spread.Sheets.Events;
  86. sheet.bind(Events.SelectionChanging, me.onSelectionChanged);
  87. sheet.bind(Events.EditStarting, me.onEditStarting);
  88. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  89. },
  90. onSelectionChanged: function (sender, info) {
  91. let me = gljClassTreeObj;
  92. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  93. let row = info.newSelections[0].row;
  94. let node = me.cache[row];
  95. me.initSelection(node);
  96. }
  97. },
  98. onEditStarting: function (sender, args) {
  99. args.cancel = true;
  100. },
  101. onClipboardPasting: function (sender, info) {
  102. info.cancel = true;
  103. },
  104. getGljClassTree: function (gljLibId, callback) {
  105. let me = gljClassTreeObj;
  106. let re = repositoryGljObj;
  107. let url = 'complementartGlj/api/getGljTree';
  108. let postData = {gljLibId: gljLibId};
  109. let sucFunc = function (rstData) {
  110. zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
  111. let rootNode = componentOprObj.treeObj.getNodes()[0];
  112. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  113. componentOprObj.rootNode = rootNode;
  114. }
  115. if (rstData && rstData.length > 0) {
  116. me.gljCurTypeId = rstData[0].ID;
  117. }
  118. //init
  119. me.buildSheet();
  120. me.initTree(rstData);
  121. me.cache = me.tree.items;
  122. re.updateParentNodeIds(me.cache, re);
  123. me.initController(me.tree, me.sheet, me.setting.sheet);
  124. me.controller.showTreeData();
  125. me.sheet.setFormatter(-1, 0, '@');
  126. me.initSelection(me.tree.selected);
  127. if(callback){
  128. callback();
  129. }
  130. };
  131. let errFunc = function () {
  132. };
  133. CommonAjax.post(url, postData, sucFunc, errFunc);
  134. },
  135. initTree: function (datas) {
  136. this.tree = idTree.createNew(this.setting.tree);
  137. this.tree.loadDatas(datas);
  138. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  139. },
  140. initController: function (tree, sheet, setting) {
  141. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  142. },
  143. gljClassTreeAjax: function (postData, scFunc, errFunc) {
  144. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  145. },
  146. //模仿默认点击
  147. initSelection: function (node) {
  148. let me = this,
  149. re = repositoryGljObj,
  150. that = gljComponentOprObj;
  151. if(!re.isDef(node)){
  152. return;
  153. }
  154. let gljTypeId = node.data.ID;
  155. re.gljCurTypeId = node.data.ID;
  156. re.addGljObj = null;
  157. sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
  158. if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
  159. re.currentOprParent = 1;
  160. re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
  161. re.workBook.getSheet(0).setRowCount(re.currentCache.length);
  162. } else {
  163. re.currentOprParent = 0;
  164. re.currentCache = re.getCache();
  165. }
  166. re.showGljItems(re.complementaryGljList, gljTypeId);
  167. me.workBook.focus(true);
  168. }
  169. }