gljClassTree.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. this.sheet = this.workBook.getActiveSheet();
  77. this.setOptions(this.workBook, this.setting.options);
  78. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  79. this.bindEvents(this.sheet);
  80. }
  81. },
  82. bindEvents: function (sheet) {
  83. let me = gljClassTreeObj;
  84. const Events = GC.Spread.Sheets.Events;
  85. sheet.bind(Events.SelectionChanging, me.onSelectionChanged);
  86. sheet.bind(Events.EditStarting, me.onEditStarting);
  87. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  88. },
  89. onSelectionChanged: function (sender, info) {
  90. let me = gljClassTreeObj;
  91. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  92. let row = info.newSelections[0].row;
  93. let node = me.cache[row];
  94. me.initSelection(node);
  95. }
  96. },
  97. onEditStarting: function (sender, args) {
  98. args.cancel = true;
  99. },
  100. onClipboardPasting: function (sender, info) {
  101. info.cancel = true;
  102. },
  103. getGljClassTree: function (gljLibId, callback) {
  104. let me = gljClassTreeObj;
  105. let re = repositoryGljObj;
  106. let url = 'complementartGlj/api/getGljTree';
  107. let postData = {gljLibId: gljLibId};
  108. let sucFunc = function (rstData) {
  109. zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
  110. let rootNode = componentOprObj.treeObj.getNodes()[0];
  111. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  112. componentOprObj.rootNode = rootNode;
  113. }
  114. if (rstData && rstData.length > 0) {
  115. me.gljCurTypeId = rstData[0].ID;
  116. }
  117. //init
  118. me.buildSheet();
  119. me.initTree(rstData);
  120. me.cache = me.tree.items;
  121. re.updateParentNodeIds(me.cache, re);
  122. me.initController(me.tree, me.sheet, me.setting.sheet);
  123. me.controller.showTreeData();
  124. me.sheet.setFormatter(-1, 0, '@');
  125. me.initSelection(me.tree.selected);
  126. if(callback){
  127. callback();
  128. }
  129. };
  130. let errFunc = function () {
  131. };
  132. CommonAjax.post(url, postData, sucFunc, errFunc);
  133. },
  134. initTree: function (datas) {
  135. this.tree = idTree.createNew(this.setting.tree);
  136. this.tree.loadDatas(datas);
  137. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  138. },
  139. initController: function (tree, sheet, setting) {
  140. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  141. },
  142. gljClassTreeAjax: function (postData, scFunc, errFunc) {
  143. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  144. },
  145. //模仿默认点击
  146. initSelection: function (node) {
  147. let me = this,
  148. re = repositoryGljObj,
  149. that = gljComponentOprObj;
  150. if(!re.isDef(node)){
  151. return;
  152. }
  153. let gljTypeId = node.data.ID;
  154. re.gljCurTypeId = node.data.ID;
  155. re.addGljObj = null;
  156. sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
  157. if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
  158. re.currentOprParent = 1;
  159. re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
  160. re.workBook.getSheet(0).setRowCount(re.currentCache.length);
  161. } else {
  162. re.currentOprParent = 0;
  163. re.currentCache = re.getCache();
  164. }
  165. re.showGljItems(re.complementaryGljList, gljTypeId);
  166. me.workBook.focus(true);
  167. }
  168. }