mixin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _xeUtils = _interopRequireDefault(require("xe-utils"));
  7. var _util = require("../../src/util");
  8. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  9. function calcMaxHeight($xeTable) {
  10. const $xeGantt = $xeTable.$xeGantt;
  11. const reactData = $xeTable;
  12. const {
  13. customStore
  14. } = reactData;
  15. let wrapperEl = $xeTable.$refs.refElem;
  16. // 判断面板不能大于表格高度
  17. let tableHeight = 0;
  18. if ($xeGantt) {
  19. const ganttContainerElem = $xeGantt.$refs.refGanttContainerElem;
  20. if (ganttContainerElem) {
  21. wrapperEl = ganttContainerElem;
  22. }
  23. }
  24. if (wrapperEl) {
  25. tableHeight = wrapperEl.clientHeight - 28;
  26. }
  27. customStore.maxHeight = Math.max(88, tableHeight);
  28. }
  29. function emitCustomEvent($xeTable, type, evnt) {
  30. const $xeGrid = $xeTable.$xeGrid;
  31. const $xeGantt = $xeTable.$xeGantt;
  32. const comp = $xeGrid || $xeGantt || $xeTable;
  33. comp.dispatchEvent('custom', {
  34. type
  35. }, evnt);
  36. }
  37. var _default = exports.default = {
  38. methods: {
  39. _getCustomVisible() {
  40. const $xeTable = this;
  41. const reactData = $xeTable;
  42. const {
  43. customStore
  44. } = reactData;
  45. return customStore.visible;
  46. },
  47. _openCustom() {
  48. const $xeTable = this;
  49. const reactData = $xeTable;
  50. const {
  51. initStore,
  52. customStore
  53. } = reactData;
  54. customStore.visible = true;
  55. initStore.custom = true;
  56. $xeTable.handleUpdateCustomColumn();
  57. $xeTable.checkCustomStatus();
  58. calcMaxHeight($xeTable);
  59. return $xeTable.$nextTick().then(() => calcMaxHeight($xeTable));
  60. },
  61. _closeCustom() {
  62. const $xeTable = this;
  63. const reactData = $xeTable;
  64. const {
  65. customStore
  66. } = reactData;
  67. const customOpts = $xeTable.computeCustomOpts;
  68. if (customStore.visible) {
  69. customStore.visible = false;
  70. if (!customOpts.immediate) {
  71. $xeTable.handleCustom();
  72. }
  73. }
  74. return $xeTable.$nextTick();
  75. },
  76. _toggleCustom() {
  77. const $xeTable = this;
  78. const reactData = $xeTable;
  79. const {
  80. customStore
  81. } = reactData;
  82. if (customStore.visible) {
  83. return $xeTable.closeCustom();
  84. }
  85. return $xeTable.openCustom();
  86. },
  87. _saveCustom() {
  88. const $xeTable = this;
  89. const reactData = $xeTable;
  90. const internalData = $xeTable;
  91. const {
  92. customColumnList,
  93. aggHandleFields,
  94. rowGroupList
  95. } = reactData;
  96. const customOpts = $xeTable.computeCustomOpts;
  97. const {
  98. allowVisible,
  99. allowSort,
  100. allowFixed,
  101. allowResizable,
  102. allowGroup,
  103. allowValues
  104. } = customOpts;
  105. _xeUtils.default.eachTree(customColumnList, (column, index, items, path, parentColumn) => {
  106. if (parentColumn) {
  107. // 更新子列信息
  108. column.fixed = parentColumn.fixed;
  109. } else {
  110. if (allowSort) {
  111. const sortIndex = index + 1;
  112. column.renderSortNumber = sortIndex;
  113. }
  114. if (allowFixed) {
  115. column.fixed = column.renderFixed;
  116. }
  117. }
  118. if (allowResizable) {
  119. if (column.renderVisible && (!column.children || column.children.length)) {
  120. if (column.renderResizeWidth !== column.renderWidth) {
  121. column.resizeWidth = column.renderResizeWidth;
  122. column.renderWidth = column.renderResizeWidth;
  123. }
  124. }
  125. }
  126. if (allowVisible) {
  127. column.visible = column.renderVisible;
  128. }
  129. if (allowGroup && allowValues) {
  130. column.aggFunc = column.renderAggFn;
  131. }
  132. });
  133. reactData.isCustomStatus = true;
  134. if (allowGroup && allowValues && !!$xeTable.handlePivotTableAggregateData) {
  135. if (rowGroupList.length !== aggHandleFields.length || rowGroupList.some((conf, i) => conf.field !== aggHandleFields[i])) {
  136. // 更新数据分组
  137. if (aggHandleFields.length) {
  138. $xeTable.setRowGroups(aggHandleFields);
  139. } else {
  140. $xeTable.clearRowGroups();
  141. }
  142. } else if (allowValues) {
  143. // 更新聚合函数
  144. $xeTable.handleUpdateAggData();
  145. }
  146. }
  147. if (allowSort) {
  148. internalData.collectColumn = customColumnList;
  149. }
  150. return $xeTable.saveCustomStore('confirm');
  151. },
  152. _cancelCustom() {
  153. const $xeTable = this;
  154. const reactData = $xeTable;
  155. const {
  156. customColumnList,
  157. customStore
  158. } = reactData;
  159. const {
  160. oldSortMaps,
  161. oldFixedMaps,
  162. oldVisibleMaps
  163. } = customStore;
  164. const customOpts = $xeTable.computeCustomOpts;
  165. const {
  166. allowVisible,
  167. allowSort,
  168. allowFixed,
  169. allowResizable
  170. } = customOpts;
  171. _xeUtils.default.eachTree(customColumnList, column => {
  172. const colid = column.getKey();
  173. const visible = !!oldVisibleMaps[colid];
  174. const fixed = oldFixedMaps[colid] || '';
  175. if (allowVisible) {
  176. column.renderVisible = visible;
  177. column.visible = visible;
  178. }
  179. if (allowFixed) {
  180. column.renderFixed = fixed;
  181. column.fixed = fixed;
  182. }
  183. if (allowSort) {
  184. column.renderSortNumber = oldSortMaps[colid] || 0;
  185. }
  186. if (allowResizable) {
  187. column.renderResizeWidth = column.renderWidth;
  188. }
  189. }, {
  190. children: 'children'
  191. });
  192. return $xeTable.$nextTick();
  193. },
  194. _resetCustom(options) {
  195. const $xeTable = this;
  196. const reactData = $xeTable;
  197. const internalData = $xeTable;
  198. const {
  199. rowGroupList
  200. } = reactData;
  201. const {
  202. collectColumn
  203. } = internalData;
  204. const customOpts = $xeTable.computeCustomOpts;
  205. const {
  206. checkMethod
  207. } = customOpts;
  208. const opts = Object.assign({
  209. visible: true,
  210. resizable: options === true,
  211. fixed: options === true,
  212. sort: options === true,
  213. aggFunc: options === true
  214. }, options);
  215. const allCols = [];
  216. _xeUtils.default.eachTree(collectColumn, column => {
  217. if (opts.resizable) {
  218. column.resizeWidth = 0;
  219. }
  220. if (opts.fixed) {
  221. column.fixed = column.defaultFixed;
  222. }
  223. if (opts.sort) {
  224. column.renderSortNumber = column.sortNumber;
  225. column.parentId = column.defaultParentId;
  226. }
  227. if (!checkMethod || checkMethod({
  228. $table: $xeTable,
  229. column
  230. })) {
  231. column.visible = column.defaultVisible;
  232. }
  233. if (opts.aggFunc) {
  234. column.aggFunc = column.defaultAggFunc;
  235. column.renderAggFn = column.defaultAggFunc;
  236. }
  237. column.renderResizeWidth = column.renderWidth;
  238. allCols.push(column);
  239. });
  240. if (opts.sort) {
  241. const newCollectCols = _xeUtils.default.toArrayTree(_xeUtils.default.orderBy(allCols, 'renderSortNumber'), {
  242. key: 'id',
  243. parentKey: 'parentId',
  244. children: 'children'
  245. });
  246. internalData.collectColumn = newCollectCols;
  247. internalData.tableFullColumn = (0, _util.getColumnList)(newCollectCols);
  248. }
  249. reactData.isCustomStatus = false;
  250. return $xeTable.handleCustom().then(() => {
  251. if (opts.aggFunc && $xeTable.handlePivotTableAggregateData) {
  252. const rowGroupFields = $xeTable.computeRowGroupFields;
  253. if (rowGroupFields ? rowGroupFields.length : rowGroupList.length) {
  254. if (rowGroupFields && rowGroupFields.length) {
  255. $xeTable.setRowGroups(rowGroupFields);
  256. } else {
  257. $xeTable.clearRowGroups();
  258. }
  259. } else {
  260. $xeTable.handleUpdateAggData();
  261. }
  262. }
  263. $xeTable.saveCustomStore('reset');
  264. });
  265. },
  266. _toggleCustomAllCheckbox() {
  267. const {
  268. customStore
  269. } = this;
  270. const isAll = !customStore.isAll;
  271. return this.setCustomAllCheckbox(isAll);
  272. },
  273. _setCustomAllCheckbox(checked) {
  274. const $xeTable = this;
  275. const reactData = $xeTable;
  276. const {
  277. customStore
  278. } = reactData;
  279. const {
  280. customColumnList
  281. } = reactData;
  282. const customOpts = $xeTable.computeCustomOpts;
  283. const {
  284. checkMethod,
  285. visibleMethod
  286. } = customOpts;
  287. const isAll = !!checked;
  288. if (customOpts.immediate) {
  289. _xeUtils.default.eachTree(customColumnList, column => {
  290. if (visibleMethod && !visibleMethod({
  291. $table: $xeTable,
  292. column
  293. })) {
  294. return;
  295. }
  296. if (checkMethod && !checkMethod({
  297. $table: $xeTable,
  298. column
  299. })) {
  300. return;
  301. }
  302. column.visible = isAll;
  303. column.renderVisible = isAll;
  304. column.halfVisible = false;
  305. });
  306. customStore.isAll = isAll;
  307. reactData.isCustomStatus = true;
  308. $xeTable.handleCustom();
  309. $xeTable.saveCustomStore('update:visible');
  310. } else {
  311. _xeUtils.default.eachTree(customColumnList, column => {
  312. if (visibleMethod && !visibleMethod({
  313. $table: $xeTable,
  314. column
  315. })) {
  316. return;
  317. }
  318. if (checkMethod && !checkMethod({
  319. $table: $xeTable,
  320. column
  321. })) {
  322. return;
  323. }
  324. column.renderVisible = isAll;
  325. column.halfVisible = false;
  326. });
  327. customStore.isAll = isAll;
  328. }
  329. $xeTable.checkCustomStatus();
  330. },
  331. checkCustomStatus() {
  332. const $xeTable = this;
  333. const reactData = $xeTable;
  334. const internalData = $xeTable;
  335. const {
  336. customStore
  337. } = reactData;
  338. const {
  339. collectColumn
  340. } = internalData;
  341. const customOpts = $xeTable.computeCustomOpts;
  342. const {
  343. checkMethod
  344. } = customOpts;
  345. customStore.isAll = collectColumn.every(column => (checkMethod ? !checkMethod({
  346. $table: $xeTable,
  347. column
  348. }) : false) || column.renderVisible);
  349. customStore.isIndeterminate = !customStore.isAll && collectColumn.some(column => (!checkMethod || checkMethod({
  350. $table: $xeTable,
  351. column
  352. })) && (column.renderVisible || column.halfVisible));
  353. },
  354. emitCustomEvent(type, evnt) {
  355. const $xeTable = this;
  356. const $xeGrid = $xeTable.$xeGrid;
  357. const $xeGantt = $xeTable.$xeGantt;
  358. const comp = $xeGrid || $xeGantt || $xeTable;
  359. comp.dispatchEvent('custom', {
  360. type
  361. }, evnt);
  362. },
  363. triggerCustomEvent(evnt) {
  364. const $xeTable = this;
  365. const reactData = $xeTable;
  366. const {
  367. customStore
  368. } = reactData;
  369. if (customStore.visible) {
  370. this.closeCustom();
  371. emitCustomEvent($xeTable, 'close', evnt);
  372. } else {
  373. customStore.btnEl = evnt.target;
  374. this.openCustom();
  375. emitCustomEvent($xeTable, 'open', evnt);
  376. }
  377. },
  378. customOpenEvent(evnt) {
  379. const $xeTable = this;
  380. const reactData = $xeTable;
  381. const {
  382. customStore
  383. } = reactData;
  384. if (customStore.visible) {
  385. customStore.activeBtn = true;
  386. customStore.btnEl = evnt.target;
  387. $xeTable.openCustom();
  388. emitCustomEvent($xeTable, 'open', evnt);
  389. }
  390. },
  391. customCloseEvent(evnt) {
  392. const $xeTable = this;
  393. const reactData = $xeTable;
  394. const {
  395. customStore
  396. } = reactData;
  397. if (customStore.visible) {
  398. customStore.activeBtn = false;
  399. $xeTable.closeCustom();
  400. emitCustomEvent($xeTable, 'close', evnt);
  401. }
  402. },
  403. handleUpdateCustomColumn() {
  404. const $xeTable = this;
  405. const reactData = $xeTable;
  406. const internalData = $xeTable;
  407. const {
  408. customStore
  409. } = reactData;
  410. const {
  411. collectColumn
  412. } = internalData;
  413. if (customStore.visible) {
  414. const sortMaps = {};
  415. const fixedMaps = {};
  416. const visibleMaps = {};
  417. _xeUtils.default.eachTree(collectColumn, column => {
  418. const colid = column.getKey();
  419. column.renderFixed = column.fixed;
  420. column.renderVisible = column.visible;
  421. column.renderResizeWidth = column.renderWidth;
  422. sortMaps[colid] = column.renderSortNumber;
  423. fixedMaps[colid] = column.fixed;
  424. visibleMaps[colid] = column.visible;
  425. });
  426. customStore.oldSortMaps = sortMaps;
  427. customStore.oldFixedMaps = fixedMaps;
  428. customStore.oldVisibleMaps = visibleMaps;
  429. reactData.customColumnList = collectColumn.slice(0);
  430. }
  431. }
  432. }
  433. };