panel.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _ui = require("../../../ui");
  7. var _utils = require("../../../ui/src/utils");
  8. var _dom = require("../../../ui/src/dom");
  9. var _log = require("../../../ui/src/log");
  10. var _xeUtils = _interopRequireDefault(require("xe-utils"));
  11. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  12. const {
  13. getI18n,
  14. getIcon,
  15. renderEmptyElement
  16. } = _ui.VxeUI;
  17. function showDropTip($xeTableCustomPanel, evnt, optEl, showLine, dragPos) {
  18. const customPanelInternalData = $xeTableCustomPanel.internalData;
  19. const bodyWrapperElem = $xeTableCustomPanel.$refs.refBodyWrapperElem;
  20. if (!bodyWrapperElem) {
  21. return;
  22. }
  23. const customBodyElem = $xeTableCustomPanel.$refs.refCustomBodyElem;
  24. if (!customBodyElem) {
  25. return;
  26. }
  27. const {
  28. prevDragToChild
  29. } = customPanelInternalData;
  30. const bodyWrapperRect = bodyWrapperElem.getBoundingClientRect();
  31. const customBodyRect = customBodyElem.getBoundingClientRect();
  32. const dragLineEl = $xeTableCustomPanel.$refs.refDragLineElem;
  33. if (optEl) {
  34. if (dragLineEl) {
  35. if (showLine) {
  36. const optRect = optEl.getBoundingClientRect();
  37. dragLineEl.style.display = 'block';
  38. dragLineEl.style.left = `${Math.max(0, customBodyRect.x - bodyWrapperRect.x)}px`;
  39. dragLineEl.style.top = `${Math.max(1, optRect.y + bodyWrapperElem.scrollTop - bodyWrapperRect.y)}px`;
  40. dragLineEl.style.height = `${optRect.height}px`;
  41. dragLineEl.style.width = `${optRect.width}px`;
  42. dragLineEl.setAttribute('drag-pos', dragPos);
  43. dragLineEl.setAttribute('drag-to-child', prevDragToChild ? 'y' : 'n');
  44. } else {
  45. dragLineEl.style.display = '';
  46. }
  47. }
  48. } else {
  49. if (dragLineEl) {
  50. dragLineEl.style.display = 'node';
  51. }
  52. }
  53. const dragTipEl = $xeTableCustomPanel.$refs.refDragTipElem;
  54. if (dragTipEl) {
  55. dragTipEl.style.display = 'block';
  56. dragTipEl.style.top = `${Math.min(bodyWrapperElem.clientHeight + bodyWrapperElem.scrollTop - dragTipEl.clientHeight, evnt.clientY + bodyWrapperElem.scrollTop - bodyWrapperRect.y)}px`;
  57. dragTipEl.style.left = `${Math.min(bodyWrapperElem.clientWidth + bodyWrapperElem.scrollLeft - dragTipEl.clientWidth, evnt.clientX + bodyWrapperElem.scrollLeft - bodyWrapperRect.x)}px`;
  58. dragTipEl.setAttribute('drag-status', showLine ? prevDragToChild ? 'sub' : 'normal' : 'disabled');
  59. }
  60. }
  61. function hideDropTip($xeTableCustomPanel) {
  62. const dragTipEl = $xeTableCustomPanel.$refs.refDragTipElem;
  63. const dragLineEl = $xeTableCustomPanel.$refs.refDragLineElem;
  64. if (dragTipEl) {
  65. dragTipEl.style.display = '';
  66. }
  67. if (dragLineEl) {
  68. dragLineEl.style.display = '';
  69. }
  70. }
  71. const renderDragTip = (h, $xeTableCustomPanel) => {
  72. const $xeTable = $xeTableCustomPanel.$xeTable;
  73. const customPanelReactData = $xeTableCustomPanel.reactData;
  74. const {
  75. dragTipText
  76. } = customPanelReactData;
  77. const columnDragOpts = $xeTable.computeColumnDragOpts;
  78. return h('div', {}, [h('div', {
  79. ref: 'refDragLineElem',
  80. class: ['vxe-table-custom-popup--drag-line', {
  81. 'is--guides': columnDragOpts.showGuidesStatus
  82. }]
  83. }), h('div', {
  84. ref: 'refDragTipElem',
  85. class: 'vxe-table-custom-popup--drag-tip'
  86. }, [h('div', {
  87. class: 'vxe-table-custom-popup--drag-tip-wrapper'
  88. }, [h('div', {
  89. class: 'vxe-table-custom-popup--drag-tip-status'
  90. }, [h('span', {
  91. class: ['vxe-table-custom-popup--drag-tip-normal-status', getIcon().TABLE_DRAG_STATUS_ROW]
  92. }), h('span', {
  93. class: ['vxe-table-custom-popup--drag-tip-sub-status', getIcon().TABLE_DRAG_STATUS_SUB_ROW]
  94. }), h('span', {
  95. class: ['vxe-table-custom-popup--drag-tip-group-status', getIcon().TABLE_DRAG_STATUS_AGG_GROUP]
  96. }), h('span', {
  97. class: ['vxe-table-custom-popup--drag-tip-values-status', getIcon().TABLE_DRAG_STATUS_AGG_VALUES]
  98. }), h('span', {
  99. class: ['vxe-table-custom-popup--drag-tip-disabled-status', getIcon().TABLE_DRAG_DISABLED]
  100. })]), h('div', {
  101. class: 'vxe-table-custom-popup--drag-tip-content'
  102. }, `${dragTipText || ''}`)])])]);
  103. };
  104. const renderSimplePanel = (h, _vm) => {
  105. const VxeUIButtonComponent = _ui.VxeUI.getComponent('VxeButton');
  106. const props = _vm;
  107. const $xeTable = _vm.$xeTable;
  108. const tableProps = $xeTable;
  109. const tableReactData = $xeTable;
  110. const $xeGrid = $xeTable.$xeGrid;
  111. const $xeGantt = $xeTable.$xeGantt;
  112. const {
  113. customStore
  114. } = props;
  115. const {
  116. treeConfig,
  117. rowGroupConfig,
  118. aggregateConfig
  119. } = tableProps;
  120. const {
  121. isCustomStatus,
  122. customColumnList
  123. } = tableReactData;
  124. const customOpts = $xeTable.computeCustomOpts;
  125. const {
  126. immediate
  127. } = customOpts;
  128. const columnDragOpts = $xeTable.computeColumnDragOpts;
  129. const {
  130. maxHeight
  131. } = customStore;
  132. const {
  133. checkMethod,
  134. visibleMethod,
  135. allowVisible,
  136. allowSort,
  137. allowFixed,
  138. trigger,
  139. placement
  140. } = customOpts;
  141. const isMaxFixedColumn = $xeTable.computeIsMaxFixedColumn;
  142. const {
  143. isCrossDrag
  144. } = columnDragOpts;
  145. const slots = customOpts.slots || {};
  146. const headerSlot = slots.header;
  147. const topSlot = slots.top;
  148. const bottomSlot = slots.bottom;
  149. const defaultSlot = slots.default;
  150. const footerSlot = slots.footer;
  151. const colVNs = [];
  152. const customWrapperOns = {};
  153. const isAllChecked = customStore.isAll;
  154. const isAllIndeterminate = customStore.isIndeterminate;
  155. // hover 触发
  156. if (trigger === 'hover') {
  157. customWrapperOns.mouseenter = _vm.handleWrapperMouseenterEvent;
  158. customWrapperOns.mouseleave = _vm.handleWrapperMouseleaveEvent;
  159. }
  160. const params = {
  161. $table: $xeTable,
  162. $grid: $xeGrid,
  163. $gantt: $xeGantt,
  164. columns: customColumnList,
  165. isAllChecked,
  166. isAllIndeterminate,
  167. isCustomStatus
  168. };
  169. _xeUtils.default.eachTree(customColumnList, (column, index, items, path, parent) => {
  170. const isVisible = visibleMethod ? visibleMethod({
  171. $table: $xeTable,
  172. column
  173. }) : true;
  174. if (isVisible) {
  175. const isChecked = column.renderVisible;
  176. const isIndeterminate = column.halfVisible;
  177. const isColGroup = column.children && column.children.length;
  178. const colTitle = (0, _utils.formatText)(column.getTitle(), 1);
  179. const isDisabled = checkMethod ? !checkMethod({
  180. $table: $xeTable,
  181. column
  182. }) : false;
  183. const isHidden = !isChecked;
  184. colVNs.push(h('li', {
  185. key: column.id,
  186. attrs: {
  187. colid: column.id
  188. },
  189. class: ['vxe-table-custom--option', `level--${column.level}`, {
  190. 'is--hidden': isDisabled || isHidden,
  191. 'is--group': isColGroup
  192. }],
  193. on: {
  194. dragstart: _vm.sortDragstartEvent,
  195. dragend: _vm.sortDragendEvent,
  196. dragover: _vm.sortDragoverEvent
  197. }
  198. }, [allowVisible ? h('div', {
  199. class: ['vxe-table-custom--checkbox-option', {
  200. 'is--checked': isChecked,
  201. 'is--indeterminate': isIndeterminate,
  202. 'is--disabled': isDisabled
  203. }],
  204. attrs: {
  205. title: getI18n('vxe.custom.setting.colVisible')
  206. },
  207. on: {
  208. click: evnt => {
  209. if (!isDisabled) {
  210. _vm.changeCheckboxOption(column, evnt);
  211. }
  212. }
  213. }
  214. }, [h('span', {
  215. class: ['vxe-checkbox--icon', isIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  216. })]) : renderEmptyElement($xeTable), h('div', {
  217. class: 'vxe-table-custom--name-option'
  218. }, [allowSort && ((isCrossDrag ? immediate : false) || column.level === 1) ? h('div', {
  219. class: 'vxe-table-custom--sort-option'
  220. }, [h('span', {
  221. class: ['vxe-table-custom--sort-btn', {
  222. 'is--disabled': isDisabled || isHidden
  223. }],
  224. attrs: {
  225. title: getI18n('vxe.custom.setting.sortHelpTip')
  226. },
  227. on: isDisabled || isHidden ? {} : {
  228. mousedown: _vm.sortMousedownEvent,
  229. mouseup: _vm.sortMouseupEvent
  230. }
  231. }, [h('i', {
  232. class: getIcon().TABLE_CUSTOM_SORT
  233. })])]) : renderEmptyElement($xeTable), column.type === 'html' ? h('div', {
  234. key: '1',
  235. class: 'vxe-table-custom--checkbox-label',
  236. domProps: {
  237. innerHTML: colTitle
  238. }
  239. }) : h('div', {
  240. key: '0',
  241. class: 'vxe-table-custom--checkbox-label',
  242. attrs: {
  243. title: colTitle
  244. }
  245. }, colTitle)]), !parent && allowFixed ? h('div', {
  246. class: 'vxe-table-custom--fixed-option'
  247. }, [h(VxeUIButtonComponent, {
  248. props: {
  249. mode: 'text',
  250. icon: column.renderFixed === 'left' ? getIcon().TOOLBAR_TOOLS_FIXED_LEFT_ACTIVE : getIcon().TOOLBAR_TOOLS_FIXED_LEFT,
  251. status: column.renderFixed === 'left' ? 'primary' : '',
  252. disabled: isDisabled || isHidden || isMaxFixedColumn && !column.renderFixed,
  253. title: getI18n(column.renderFixed === 'left' ? 'vxe.toolbar.cancelFixed' : 'vxe.toolbar.fixedLeft')
  254. },
  255. on: {
  256. click: ({
  257. $event
  258. }) => {
  259. _vm.changeFixedOption(column, 'left', $event);
  260. }
  261. }
  262. }), h(VxeUIButtonComponent, {
  263. props: {
  264. mode: 'text',
  265. icon: column.renderFixed === 'right' ? getIcon().TOOLBAR_TOOLS_FIXED_RIGHT_ACTIVE : getIcon().TOOLBAR_TOOLS_FIXED_RIGHT,
  266. status: column.renderFixed === 'right' ? 'primary' : '',
  267. disabled: isDisabled || isHidden || isMaxFixedColumn && !column.renderFixed,
  268. title: getI18n(column.renderFixed === 'right' ? 'vxe.toolbar.cancelFixed' : 'vxe.toolbar.fixedRight')
  269. },
  270. on: {
  271. click: ({
  272. $event
  273. }) => {
  274. _vm.changeFixedOption(column, 'right', $event);
  275. }
  276. }
  277. })]) : renderEmptyElement($xeTable)]));
  278. }
  279. });
  280. return h('div', {
  281. ref: 'refElem',
  282. key: 'simple',
  283. class: ['vxe-table-custom-wrapper', `placement--${placement}`, {
  284. 'is--active': customStore.visible
  285. }],
  286. style: maxHeight && !['left', 'right'].includes(placement || '') ? {
  287. maxHeight: `${maxHeight}px`
  288. } : {}
  289. }, customStore.visible ? [h('div', {
  290. ref: 'refBodyWrapperElem',
  291. class: 'vxe-table-custom-simple--body-wrapper'
  292. }, [!treeConfig && (aggregateConfig || rowGroupConfig) && $xeTable.getPivotTableAggregateSimplePanel ? h($xeTable.getPivotTableAggregateSimplePanel(), {
  293. props: {
  294. customStore
  295. }
  296. }) : renderEmptyElement($xeTable), h('div', {
  297. ref: 'refCustomBodyElem',
  298. class: 'vxe-table-custom--handle-wrapper'
  299. }, [h('div', {
  300. class: 'vxe-table-custom--header'
  301. }, headerSlot ? $xeTable.callSlot(headerSlot, params, h) : [h('ul', {
  302. class: 'vxe-table-custom--panel-list'
  303. }, [h('li', {
  304. class: 'vxe-table-custom--option'
  305. }, [allowVisible ? h('div', {
  306. class: ['vxe-table-custom--checkbox-option', {
  307. 'is--checked': isAllChecked,
  308. 'is--indeterminate': isAllIndeterminate
  309. }],
  310. attrs: {
  311. title: getI18n('vxe.table.allTitle')
  312. },
  313. on: {
  314. click: _vm.allOptionEvent
  315. }
  316. }, [h('span', {
  317. class: ['vxe-checkbox--icon', isAllIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isAllChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  318. }), h('span', {
  319. class: 'vxe-checkbox--label'
  320. }, getI18n('vxe.toolbar.customAll'))]) : h('span', {
  321. class: 'vxe-checkbox--label'
  322. }, getI18n('vxe.table.customTitle'))])])]), h('div', {
  323. class: 'vxe-table-custom--body'
  324. }, [topSlot ? h('div', {
  325. class: 'vxe-table-custom--panel-top'
  326. }, $xeTable.callSlot(topSlot, params, h)) : renderEmptyElement($xeTable), defaultSlot ? h('div', {
  327. class: 'vxe-table-custom--panel-body'
  328. }, $xeTable.callSlot(defaultSlot, params, h)) : h('transition-group', {
  329. class: 'vxe-table-custom--panel-list',
  330. props: {
  331. name: 'vxe-table-custom--list',
  332. tag: 'ul'
  333. },
  334. on: customWrapperOns
  335. }, colVNs), bottomSlot ? h('div', {
  336. class: 'vxe-table-custom--panel-bottom'
  337. }, $xeTable.callSlot(bottomSlot, params, h)) : renderEmptyElement($xeTable)]), customOpts.showFooter ? h('div', {
  338. class: 'vxe-table-custom--footer'
  339. }, footerSlot ? $xeTable.callSlot(footerSlot, params, h) : [h('div', {
  340. class: 'vxe-table-custom--footer-buttons'
  341. }, [h(VxeUIButtonComponent, {
  342. props: {
  343. mode: 'text',
  344. content: customOpts.resetButtonText || getI18n('vxe.table.customRestore'),
  345. disabled: !isCustomStatus
  346. },
  347. on: {
  348. click: _vm.resetCustomEvent
  349. }
  350. }), immediate ? h(VxeUIButtonComponent, {
  351. props: {
  352. mode: 'text',
  353. content: customOpts.closeButtonText || getI18n('vxe.table.customClose')
  354. },
  355. on: {
  356. click: _vm.cancelCloseEvent
  357. }
  358. }) : h(VxeUIButtonComponent, {
  359. props: {
  360. mode: 'text',
  361. content: customOpts.resetButtonText || getI18n('vxe.table.customCancel')
  362. },
  363. on: {
  364. click: _vm.cancelCustomEvent
  365. }
  366. }), immediate ? renderEmptyElement($xeTable) : h(VxeUIButtonComponent, {
  367. props: {
  368. mode: 'text',
  369. status: 'primary',
  370. content: customOpts.confirmButtonText || getI18n('vxe.table.customConfirm')
  371. },
  372. on: {
  373. click: _vm.confirmCustomEvent
  374. }
  375. })])]) : null]), renderDragTip(h, _vm)])] : []);
  376. };
  377. const renderPopupPanel = (h, $xeTableCustomPanel) => {
  378. const VxeUIModalComponent = _ui.VxeUI.getComponent('VxeModal');
  379. const VxeUIDrawerComponent = _ui.VxeUI.getComponent('VxeDrawer');
  380. const VxeUIButtonComponent = _ui.VxeUI.getComponent('VxeButton');
  381. const VxeUINumberInputComponent = _ui.VxeUI.getComponent('VxeNumberInput');
  382. const _vm = $xeTableCustomPanel;
  383. const props = $xeTableCustomPanel;
  384. const $xeTable = $xeTableCustomPanel.$xeTable;
  385. const tableProps = $xeTable;
  386. const tableReactData = $xeTable;
  387. const $xeGrid = $xeTable.$xeGrid;
  388. const $xeGantt = $xeTable.$xeGantt;
  389. const {
  390. customStore
  391. } = props;
  392. const {
  393. treeConfig,
  394. rowGroupConfig,
  395. aggregateConfig,
  396. resizable: allResizable
  397. } = tableProps;
  398. const {
  399. isCustomStatus,
  400. customColumnList
  401. } = tableReactData;
  402. const customOpts = $xeTable.computeCustomOpts;
  403. const {
  404. immediate
  405. } = customOpts;
  406. const columnDragOpts = $xeTable.computeColumnDragOpts;
  407. const {
  408. mode,
  409. modalOptions,
  410. drawerOptions,
  411. allowVisible,
  412. allowSort,
  413. allowFixed,
  414. allowResizable,
  415. checkMethod,
  416. visibleMethod
  417. } = customOpts;
  418. const columnOpts = $xeTable.computeColumnOpts;
  419. const {
  420. maxFixedSize
  421. } = columnOpts;
  422. const resizableOpts = $xeTable.computeResizableOpts;
  423. const {
  424. minWidth: reMinWidth,
  425. maxWidth: reMaxWidth
  426. } = resizableOpts;
  427. const modalOpts = Object.assign({}, modalOptions);
  428. const drawerOpts = Object.assign({}, drawerOptions);
  429. const isMaxFixedColumn = $xeTable.computeIsMaxFixedColumn;
  430. const {
  431. isCrossDrag
  432. } = columnDragOpts;
  433. const slots = customOpts.slots || {};
  434. const headerSlot = slots.header;
  435. const topSlot = slots.top;
  436. const bottomSlot = slots.bottom;
  437. const defaultSlot = slots.default;
  438. const footerSlot = slots.footer;
  439. const trVNs = [];
  440. const isAllChecked = customStore.isAll;
  441. const isAllIndeterminate = customStore.isIndeterminate;
  442. const params = {
  443. $table: $xeTable,
  444. $grid: $xeGrid,
  445. $gantt: $xeGantt,
  446. columns: customColumnList,
  447. isAllChecked,
  448. isAllIndeterminate,
  449. isCustomStatus
  450. };
  451. _xeUtils.default.eachTree(customColumnList, (column, index, items, path, parent) => {
  452. const isVisible = visibleMethod ? visibleMethod({
  453. $table: $xeTable,
  454. column
  455. }) : true;
  456. if (isVisible) {
  457. // 默认继承调整宽度
  458. let customMinWidth = 0;
  459. let customMaxWidth = 0;
  460. if (allowResizable) {
  461. const resizeParams = {
  462. $table: $xeTable,
  463. column,
  464. columnIndex: index,
  465. $columnIndex: index,
  466. $rowIndex: -1
  467. };
  468. if (reMinWidth) {
  469. customMinWidth = _xeUtils.default.toNumber(_xeUtils.default.isFunction(reMinWidth) ? reMinWidth(resizeParams) : reMinWidth);
  470. }
  471. if (reMaxWidth) {
  472. customMaxWidth = _xeUtils.default.toNumber(_xeUtils.default.isFunction(reMaxWidth) ? reMaxWidth(resizeParams) : reMaxWidth);
  473. }
  474. }
  475. const isChecked = column.renderVisible;
  476. const isIndeterminate = column.halfVisible;
  477. const colTitle = (0, _utils.formatText)(column.getTitle(), 1);
  478. const isColGroup = column.children && column.children.length;
  479. const isDisabled = checkMethod ? !checkMethod({
  480. $table: $xeTable,
  481. column
  482. }) : false;
  483. const isHidden = !isChecked;
  484. trVNs.push(h('tr', {
  485. key: column.id,
  486. attrs: {
  487. colid: column.id
  488. },
  489. class: [`vxe-table-custom-popup--row level--${column.level}`, {
  490. 'is--group': isColGroup
  491. }],
  492. on: {
  493. dragstart: _vm.sortDragstartEvent,
  494. dragend: _vm.sortDragendEvent,
  495. dragover: _vm.sortDragoverEvent
  496. }
  497. }, [allowVisible ? h('td', {
  498. class: 'vxe-table-custom-popup--column-item col--visible'
  499. }, [h('div', {
  500. class: ['vxe-table-custom--checkbox-option', {
  501. 'is--checked': isChecked,
  502. 'is--indeterminate': isIndeterminate,
  503. 'is--disabled': isDisabled
  504. }],
  505. attrs: {
  506. title: getI18n('vxe.custom.setting.colVisible')
  507. },
  508. on: {
  509. click: evnt => {
  510. if (!isDisabled) {
  511. _vm.changeCheckboxOption(column, evnt);
  512. }
  513. }
  514. }
  515. }, [h('span', {
  516. class: ['vxe-checkbox--icon', isIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  517. })])]) : renderEmptyElement($xeTable), h('td', {
  518. class: 'vxe-table-custom-popup--column-item col--name'
  519. }, [h('div', {
  520. class: 'vxe-table-custom-popup--name'
  521. }, [allowSort ? (isCrossDrag ? immediate : false) || column.level === 1 ? h('div', {
  522. class: ['vxe-table-custom-popup--column-sort-btn', {
  523. 'is--disabled': isDisabled || isHidden
  524. }],
  525. attrs: {
  526. title: getI18n('vxe.custom.setting.sortHelpTip')
  527. },
  528. on: isDisabled || isHidden ? {} : {
  529. mousedown: _vm.sortMousedownEvent,
  530. mouseup: _vm.sortMouseupEvent
  531. }
  532. }, [h('i', {
  533. class: getIcon().TABLE_CUSTOM_SORT
  534. })]) : h('div', {
  535. class: 'vxe-table-custom-popup--column-sort-placeholder'
  536. }) : renderEmptyElement($xeTable), column.type === 'html' ? h('div', {
  537. key: '1',
  538. class: 'vxe-table-custom-popup--title',
  539. domProps: {
  540. innerHTML: colTitle
  541. }
  542. }) : h('div', {
  543. key: '0',
  544. class: 'vxe-table-custom-popup--title',
  545. attrs: {
  546. title: colTitle
  547. }
  548. }, colTitle)])]), allowResizable ? h('td', {
  549. class: 'vxe-table-custom-popup--column-item col--resizable'
  550. }, [column.children && column.children.length || !(_xeUtils.default.isBoolean(column.resizable) ? column.resizable : columnOpts.resizable || allResizable) ? h('span', '-') : VxeUINumberInputComponent ? h(VxeUINumberInputComponent, {
  551. props: {
  552. type: 'integer',
  553. immediate: false,
  554. disabled: isDisabled || isHidden,
  555. value: column.renderResizeWidth,
  556. min: customMinWidth || undefined,
  557. max: customMaxWidth || undefined
  558. },
  559. on: {
  560. modelValue(value) {
  561. column.renderResizeWidth = Math.max(0, Number(value));
  562. },
  563. change() {
  564. _vm.changeColumnWidth(column);
  565. }
  566. }
  567. }) : renderEmptyElement($xeTableCustomPanel)]) : renderEmptyElement($xeTable), allowFixed ? h('td', {
  568. class: 'vxe-table-custom-popup--column-item col--fixed'
  569. }, [parent ? h('span', '-') : h('vxe-radio-group', {
  570. props: {
  571. value: column.renderFixed || '',
  572. type: 'button',
  573. size: 'mini',
  574. disabled: isDisabled || isHidden,
  575. options: [{
  576. label: getI18n('vxe.custom.setting.fixedLeft'),
  577. value: 'left',
  578. disabled: isDisabled || isHidden || isMaxFixedColumn
  579. }, {
  580. label: getI18n('vxe.custom.setting.fixedUnset'),
  581. value: '',
  582. disabled: isDisabled || isHidden
  583. }, {
  584. label: getI18n('vxe.custom.setting.fixedRight'),
  585. value: 'right',
  586. disabled: isDisabled || isHidden || isMaxFixedColumn
  587. }]
  588. },
  589. on: {
  590. change({
  591. label,
  592. $event
  593. }) {
  594. _vm.changeFixedOption(column, label, $event);
  595. }
  596. }
  597. })]) : renderEmptyElement($xeTable)]));
  598. }
  599. });
  600. const scopedSlots = {
  601. default: () => {
  602. return h('div', {
  603. ref: 'refBodyWrapperElem',
  604. class: 'vxe-table-custom-popup--body-wrapper'
  605. }, defaultSlot ? $xeTable.callSlot(defaultSlot, params, h) : [h('div', {
  606. ref: 'refCustomBodyElem',
  607. class: 'vxe-table-custom-popup--handle-wrapper'
  608. }, [topSlot ? h('div', {
  609. class: 'vxe-table-custom-popup--table-top'
  610. }, $xeTable.callSlot(topSlot, params, h)) : renderEmptyElement($xeTable), h('div', {
  611. class: 'vxe-table-custom-popup--table-wrapper'
  612. }, [h('table', {}, [h('colgroup', {}, [allowVisible ? h('col', {
  613. class: 'vxe-table-custom-popup--table-col-seq'
  614. }) : renderEmptyElement($xeTable), h('col', {
  615. class: 'vxe-table-custom-popup--table-col-title'
  616. }), allowResizable ? h('col', {
  617. class: 'vxe-table-custom-popup--table-col-width'
  618. }) : renderEmptyElement($xeTable), allowFixed ? h('col', {
  619. class: 'vxe-table-custom-popup--table-col-fixed'
  620. }) : renderEmptyElement($xeTable)]), h('thead', {}, [h('tr', {}, [allowVisible ? h('th', {}, [h('div', {
  621. class: ['vxe-table-custom--checkbox-option', {
  622. 'is--checked': isAllChecked,
  623. 'is--indeterminate': isAllIndeterminate
  624. }],
  625. attrs: {
  626. title: getI18n('vxe.table.allTitle')
  627. },
  628. on: {
  629. click: _vm.allOptionEvent
  630. }
  631. }, [h('span', {
  632. class: ['vxe-checkbox--icon', isAllIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isAllChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  633. }), h('span', {
  634. class: 'vxe-checkbox--label'
  635. }, getI18n('vxe.toolbar.customAll'))])]) : renderEmptyElement($xeTable), h('th', {}, getI18n('vxe.custom.setting.colTitle')), allowResizable ? h('th', {}, getI18n('vxe.custom.setting.colResizable')) : renderEmptyElement($xeTable), allowFixed ? h('th', {}, getI18n(`vxe.custom.setting.${maxFixedSize ? 'colFixedMax' : 'colFixed'}`, [maxFixedSize])) : renderEmptyElement($xeTable)])]), h('transition-group', {
  636. class: 'vxe-table-custom--panel-list',
  637. props: {
  638. tag: 'tbody',
  639. name: 'vxe-table-custom--list'
  640. }
  641. }, trVNs)])]), bottomSlot ? h('div', {
  642. class: 'vxe-table-custom-popup--table-bottom'
  643. }, $xeTable.callSlot(bottomSlot, params, h)) : renderEmptyElement($xeTable), renderDragTip(h, _vm)]), !treeConfig && (aggregateConfig || rowGroupConfig) && $xeTable.getPivotTableAggregatePopupPanel ? h($xeTable.getPivotTableAggregatePopupPanel(), {
  644. props: {
  645. customStore
  646. }
  647. }) : renderEmptyElement($xeTable)]);
  648. },
  649. footer: () => {
  650. if (footerSlot) {
  651. return $xeTable.callSlot(footerSlot, params, h);
  652. }
  653. return h('div', {
  654. class: 'vxe-table-custom-popup--footer'
  655. }, [h(VxeUIButtonComponent, {
  656. props: {
  657. content: customOpts.resetButtonText || getI18n('vxe.custom.cstmRestore'),
  658. disabled: !isCustomStatus
  659. },
  660. on: {
  661. click: _vm.resetCustomEvent
  662. }
  663. }), immediate ? h(VxeUIButtonComponent, {
  664. props: {
  665. content: customOpts.resetButtonText || getI18n('vxe.table.customClose')
  666. },
  667. on: {
  668. click: _vm.cancelCloseEvent
  669. }
  670. }) : h(VxeUIButtonComponent, {
  671. props: {
  672. content: customOpts.resetButtonText || getI18n('vxe.custom.cstmCancel')
  673. },
  674. on: {
  675. click: _vm.cancelCustomEvent
  676. }
  677. }), immediate ? renderEmptyElement($xeTable) : h(VxeUIButtonComponent, {
  678. props: {
  679. status: 'primary',
  680. content: customOpts.confirmButtonText || getI18n('vxe.custom.cstmConfirm')
  681. },
  682. on: {
  683. click: _vm.confirmCustomEvent
  684. }
  685. })]);
  686. }
  687. };
  688. if (headerSlot) {
  689. scopedSlots.header = () => $xeTable.callSlot(headerSlot, params, h);
  690. }
  691. if (mode === 'drawer') {
  692. return VxeUIDrawerComponent ? h(VxeUIDrawerComponent, {
  693. key: 'drawer',
  694. props: {
  695. className: ['vxe-table-custom-drawer-wrapper', 'vxe-table--ignore-clear', drawerOpts.className || ''].join(' '),
  696. value: customStore.visible,
  697. title: drawerOpts.title || getI18n('vxe.custom.cstmTitle'),
  698. width: drawerOpts.width || Math.min(880, Math.floor(document.documentElement.clientWidth * 0.6)),
  699. position: drawerOpts.position,
  700. resize: !!drawerOpts.resize,
  701. escClosable: !!drawerOpts.escClosable,
  702. maskClosable: !!drawerOpts.maskClosable,
  703. destroyOnClose: true,
  704. showFooter: true
  705. },
  706. on: {
  707. input(value) {
  708. customStore.visible = value;
  709. }
  710. },
  711. scopedSlots
  712. }) : renderEmptyElement($xeTableCustomPanel);
  713. }
  714. return VxeUIModalComponent ? h(VxeUIModalComponent, {
  715. key: 'modal',
  716. props: {
  717. className: ['vxe-table-custom-popup-wrapper', 'vxe-table--ignore-clear', modalOpts.className || ''].join(' '),
  718. value: customStore.visible,
  719. title: modalOpts.title || getI18n('vxe.custom.cstmTitle'),
  720. width: modalOpts.width || Math.min(880, document.documentElement.clientWidth),
  721. minWidth: modalOpts.minWidth || 700,
  722. height: modalOpts.height || Math.min(680, document.documentElement.clientHeight),
  723. minHeight: modalOpts.minHeight || 400,
  724. showZoom: modalOpts.showZoom,
  725. showMaximize: modalOpts.showMaximize,
  726. showMinimize: modalOpts.showMinimize,
  727. mask: modalOpts.mask,
  728. lockView: modalOpts.lockView,
  729. resize: modalOpts.resize,
  730. escClosable: !!modalOpts.escClosable,
  731. maskClosable: !!modalOpts.maskClosable,
  732. destroyOnClose: true,
  733. showFooter: true
  734. },
  735. on: {
  736. input(value) {
  737. customStore.visible = value;
  738. }
  739. },
  740. scopedSlots
  741. }) : renderEmptyElement($xeTableCustomPanel);
  742. };
  743. var _default = exports.default = {
  744. name: 'VxeTableCustomPanel',
  745. props: {
  746. customStore: {
  747. type: Object,
  748. default: () => ({})
  749. }
  750. },
  751. provide() {
  752. const $xeTableCustomPanel = this;
  753. return {
  754. $xeTableCustomPanel
  755. };
  756. },
  757. inject: {
  758. $xeTable: {
  759. default: null
  760. }
  761. },
  762. data() {
  763. const reactData = {
  764. dragCol: null,
  765. dragGroupField: null,
  766. dragAggFnCol: null,
  767. dragTipText: ''
  768. };
  769. const internalData = {
  770. // prevDragCol: undefined,
  771. // prevDragGroupField: undefined,
  772. // prevDragAggFnColid: undefined,
  773. // prevDragToChild: false,
  774. // prevDragPos: null
  775. };
  776. return {
  777. reactData,
  778. internalData
  779. };
  780. },
  781. computed: {},
  782. created() {
  783. const $xeTableCustomPanel = this;
  784. const VxeUIModalComponent = _ui.VxeUI.getComponent('VxeModal');
  785. const VxeUIDrawerComponent = _ui.VxeUI.getComponent('VxeDrawer');
  786. const VxeUIButtonComponent = _ui.VxeUI.getComponent('VxeButton');
  787. const VxeUINumberInputComponent = _ui.VxeUI.getComponent('VxeNumberInput');
  788. const VxeUIRadioGroupComponent = _ui.VxeUI.getComponent('VxeRadioGroup');
  789. $xeTableCustomPanel.$nextTick(() => {
  790. const $xeTable = $xeTableCustomPanel.$xeTable;
  791. const {
  792. customOpts
  793. } = $xeTable;
  794. const {
  795. mode
  796. } = customOpts;
  797. if (!VxeUIModalComponent && mode === 'modal') {
  798. (0, _log.errLog)('vxe.error.reqComp', ['vxe-modal']);
  799. }
  800. if (!VxeUIDrawerComponent && mode === 'drawer') {
  801. (0, _log.errLog)('vxe.error.reqComp', ['vxe-drawer']);
  802. }
  803. if (!VxeUIButtonComponent) {
  804. (0, _log.errLog)('vxe.error.reqComp', ['vxe-button']);
  805. }
  806. if (!VxeUINumberInputComponent) {
  807. (0, _log.errLog)('vxe.error.reqComp', ['vxe-number-input']);
  808. }
  809. if (!VxeUIRadioGroupComponent) {
  810. (0, _log.errLog)('vxe.error.reqComp', ['vxe-radio-group']);
  811. }
  812. });
  813. },
  814. render(h) {
  815. const $xeTableCustomPanel = this;
  816. const $xeTable = $xeTableCustomPanel.$xeTable;
  817. const customOpts = $xeTable.computeCustomOpts;
  818. if (['modal', 'drawer', 'popup'].includes(`${customOpts.mode}`)) {
  819. return renderPopupPanel(h, $xeTableCustomPanel);
  820. }
  821. return renderSimplePanel(h, $xeTableCustomPanel);
  822. },
  823. methods: {
  824. handleWrapperMouseenterEvent(evnt) {
  825. const $xeTableCustomPanel = this;
  826. const $xeTable = $xeTableCustomPanel.$xeTable;
  827. const {
  828. customStore
  829. } = this;
  830. customStore.activeWrapper = true;
  831. $xeTable.customOpenEvent(evnt);
  832. },
  833. handleWrapperMouseleaveEvent(evnt) {
  834. const $xeTableCustomPanel = this;
  835. const $xeTable = $xeTableCustomPanel.$xeTable;
  836. const props = $xeTableCustomPanel;
  837. const {
  838. customStore
  839. } = props;
  840. customStore.activeWrapper = false;
  841. setTimeout(() => {
  842. if (!customStore.activeBtn && !customStore.activeWrapper) {
  843. $xeTable.customCloseEvent(evnt);
  844. }
  845. }, 300);
  846. },
  847. getStoreData() {
  848. return {};
  849. },
  850. confirmCustomEvent({
  851. $event
  852. }) {
  853. const $xeTableCustomPanel = this;
  854. const $xeTable = $xeTableCustomPanel.$xeTable;
  855. const tableReactData = $xeTable;
  856. tableReactData.isCustomStatus = true;
  857. $xeTable.saveCustom();
  858. $xeTable.closeCustom();
  859. $xeTable.emitCustomEvent('confirm', $event);
  860. },
  861. cancelCloseEvent({
  862. $event
  863. }) {
  864. const $xeTableCustomPanel = this;
  865. const $xeTable = $xeTableCustomPanel.$xeTable;
  866. $xeTable.closeCustom();
  867. $xeTable.emitCustomEvent('close', $event);
  868. },
  869. cancelCustomEvent({
  870. $event
  871. }) {
  872. const $xeTableCustomPanel = this;
  873. const $xeTable = $xeTableCustomPanel.$xeTable;
  874. $xeTable.cancelCustom();
  875. $xeTable.closeCustom();
  876. $xeTable.emitCustomEvent('cancel', $event);
  877. },
  878. handleResetCustomEvent(evnt) {
  879. const $xeTableCustomPanel = this;
  880. const $xeTable = $xeTableCustomPanel.$xeTable;
  881. $xeTable.resetCustom(true);
  882. $xeTable.closeCustom();
  883. $xeTable.emitCustomEvent('reset', evnt);
  884. },
  885. resetCustomEvent(evnt) {
  886. if (_ui.VxeUI.modal) {
  887. _ui.VxeUI.modal.confirm({
  888. content: getI18n('vxe.custom.cstmConfirmRestore'),
  889. className: 'vxe-table--ignore-clear',
  890. escClosable: true
  891. }).then(type => {
  892. if (type === 'confirm') {
  893. this.handleResetCustomEvent(evnt);
  894. }
  895. });
  896. } else {
  897. this.handleResetCustomEvent(evnt);
  898. }
  899. },
  900. handleOptionCheck(column) {
  901. const $xeTableCustomPanel = this;
  902. const $xeTable = $xeTableCustomPanel.$xeTable;
  903. const tableReactData = $xeTable;
  904. const {
  905. customColumnList
  906. } = tableReactData;
  907. const matchObj = _xeUtils.default.findTree(customColumnList, item => item === column);
  908. if (matchObj && matchObj.parent) {
  909. const {
  910. parent
  911. } = matchObj;
  912. if (parent.children && parent.children.length) {
  913. parent.renderVisible = parent.children.every(column => column.renderVisible);
  914. parent.halfVisible = !parent.renderVisible && parent.children.some(column => column.renderVisible || column.halfVisible);
  915. this.handleOptionCheck(parent);
  916. }
  917. }
  918. },
  919. changeCheckboxOption(column, evnt) {
  920. const $xeTableCustomPanel = this;
  921. const $xeTable = $xeTableCustomPanel.$xeTable;
  922. const tableReactData = $xeTable;
  923. const isChecked = !column.renderVisible;
  924. const customOpts = $xeTable.computeCustomOpts;
  925. if (customOpts.immediate) {
  926. _xeUtils.default.eachTree([column], item => {
  927. item.visible = isChecked;
  928. item.renderVisible = isChecked;
  929. item.halfVisible = false;
  930. });
  931. tableReactData.isCustomStatus = true;
  932. $xeTable.handleCustom();
  933. $xeTable.saveCustomStore('update:visible');
  934. } else {
  935. _xeUtils.default.eachTree([column], item => {
  936. item.renderVisible = isChecked;
  937. item.halfVisible = false;
  938. });
  939. }
  940. this.handleOptionCheck(column);
  941. $xeTable.checkCustomStatus();
  942. $xeTable.dispatchEvent('custom-visible-change', {
  943. column,
  944. checked: isChecked
  945. }, evnt);
  946. },
  947. changeColumnWidth(column) {
  948. const $xeTableCustomPanel = this;
  949. const $xeTable = $xeTableCustomPanel.$xeTable;
  950. const tableReactData = $xeTable;
  951. const customOpts = $xeTable.computeCustomOpts;
  952. if (customOpts.immediate) {
  953. if (column.renderResizeWidth !== column.renderWidth) {
  954. column.resizeWidth = column.renderResizeWidth;
  955. column.renderWidth = column.renderResizeWidth;
  956. tableReactData.isCustomStatus = true;
  957. $xeTable.handleCustom();
  958. $xeTable.saveCustomStore('update:width');
  959. }
  960. }
  961. },
  962. changeFixedOption(column, colFixed, evnt) {
  963. const $xeTableCustomPanel = this;
  964. const $xeTable = $xeTableCustomPanel.$xeTable;
  965. const tableReactData = $xeTable;
  966. const isMaxFixedColumn = $xeTable.computeIsMaxFixedColumn;
  967. const customOpts = $xeTable.computeCustomOpts;
  968. let targetFixed = null;
  969. if (customOpts.immediate) {
  970. if (column.renderFixed === colFixed) {
  971. targetFixed = '';
  972. _xeUtils.default.eachTree([column], col => {
  973. col.fixed = '';
  974. col.renderFixed = '';
  975. });
  976. } else {
  977. if (!isMaxFixedColumn || column.renderFixed) {
  978. targetFixed = colFixed;
  979. _xeUtils.default.eachTree([column], col => {
  980. col.fixed = colFixed;
  981. col.renderFixed = colFixed;
  982. });
  983. }
  984. }
  985. tableReactData.isCustomStatus = true;
  986. $xeTable.handleCustom();
  987. $xeTable.saveCustomStore('update:fixed');
  988. } else {
  989. if (column.renderFixed === colFixed) {
  990. targetFixed = '';
  991. _xeUtils.default.eachTree([column], col => {
  992. col.renderFixed = '';
  993. });
  994. } else {
  995. if (!isMaxFixedColumn || column.renderFixed) {
  996. targetFixed = colFixed;
  997. _xeUtils.default.eachTree([column], col => {
  998. col.renderFixed = colFixed;
  999. });
  1000. }
  1001. }
  1002. }
  1003. if (targetFixed !== null) {
  1004. $xeTable.dispatchEvent('custom-fixed-change', {
  1005. column,
  1006. fixed: targetFixed
  1007. }, evnt);
  1008. }
  1009. },
  1010. allOptionEvent(evnt) {
  1011. const $xeTableCustomPanel = this;
  1012. const $xeTable = $xeTableCustomPanel.$xeTable;
  1013. const tableReactData = $xeTable;
  1014. const {
  1015. customStore
  1016. } = tableReactData;
  1017. const isAll = !customStore.isAll;
  1018. $xeTable.toggleCustomAllCheckbox();
  1019. $xeTable.dispatchEvent('custom-visible-all', {
  1020. checked: isAll
  1021. }, evnt);
  1022. },
  1023. updateColDropTipContent() {
  1024. const $xeTableCustomPanel = this;
  1025. const $xeTable = $xeTableCustomPanel.$xeTable;
  1026. const customPanelReactData = $xeTableCustomPanel.reactData;
  1027. const {
  1028. dragCol
  1029. } = customPanelReactData;
  1030. const columnDragOpts = $xeTable.computeColumnDragOpts;
  1031. const {
  1032. tooltipMethod
  1033. } = columnDragOpts;
  1034. let tipContent = '';
  1035. if (tooltipMethod) {
  1036. const dtParams = {
  1037. $table: $xeTable,
  1038. column: dragCol
  1039. };
  1040. tipContent = `${tooltipMethod(dtParams) || ''}`;
  1041. } else {
  1042. tipContent = getI18n('vxe.custom.cstmDragTarget', [dragCol && dragCol.type !== 'html' ? dragCol.getTitle() : '']);
  1043. }
  1044. customPanelReactData.dragTipText = tipContent;
  1045. },
  1046. sortMousedownEvent(evnt) {
  1047. const $xeTableCustomPanel = this;
  1048. const $xeTable = $xeTableCustomPanel.$xeTable;
  1049. const customPanelReactData = $xeTableCustomPanel.reactData;
  1050. const btnEl = evnt.currentTarget;
  1051. const cellEl = btnEl.parentElement;
  1052. const tdEl = cellEl.parentElement;
  1053. const trEl = tdEl.parentElement;
  1054. const colid = trEl.getAttribute('colid');
  1055. const column = $xeTable.getColumnById(colid);
  1056. trEl.draggable = true;
  1057. customPanelReactData.dragCol = column;
  1058. customPanelReactData.dragGroupField = null;
  1059. customPanelReactData.dragAggFnCol = null;
  1060. this.updateColDropTipContent();
  1061. (0, _dom.addClass)(trEl, 'active--drag-origin');
  1062. },
  1063. sortMouseupEvent(evnt) {
  1064. const $xeTableCustomPanel = this;
  1065. const customPanelReactData = $xeTableCustomPanel.reactData;
  1066. const btnEl = evnt.currentTarget;
  1067. const cellEl = btnEl.parentElement;
  1068. const tdEl = cellEl.parentElement;
  1069. const trEl = tdEl.parentElement;
  1070. hideDropTip($xeTableCustomPanel);
  1071. trEl.draggable = false;
  1072. customPanelReactData.dragCol = null;
  1073. customPanelReactData.dragGroupField = null;
  1074. customPanelReactData.dragAggFnCol = null;
  1075. (0, _dom.removeClass)(trEl, 'active--drag-origin');
  1076. },
  1077. sortDragstartEvent(evnt) {
  1078. const $xeTableCustomPanel = this;
  1079. const customPanelInternalData = $xeTableCustomPanel.internalData;
  1080. if (evnt.dataTransfer) {
  1081. evnt.dataTransfer.setDragImage((0, _dom.getTpImg)(), 0, 0);
  1082. }
  1083. customPanelInternalData.prevDragGroupField = null;
  1084. customPanelInternalData.prevDragAggFnColid = null;
  1085. },
  1086. sortDragendEvent(evnt) {
  1087. const $xeTableCustomPanel = this;
  1088. const $xeTable = $xeTableCustomPanel.$xeTable;
  1089. const tableProps = $xeTable;
  1090. const tableReactData = $xeTable;
  1091. const tableInternalData = $xeTable;
  1092. const customPanelReactData = $xeTableCustomPanel.reactData;
  1093. const customPanelInternalData = $xeTableCustomPanel.internalData;
  1094. const {
  1095. mouseConfig
  1096. } = tableProps;
  1097. const {
  1098. customColumnList
  1099. } = tableReactData;
  1100. const {
  1101. collectColumn
  1102. } = tableInternalData;
  1103. const customOpts = $xeTable.computeCustomOpts;
  1104. const {
  1105. immediate
  1106. } = customOpts;
  1107. const trEl = evnt.currentTarget;
  1108. const columnDragOpts = $xeTable.computeColumnDragOpts;
  1109. const {
  1110. isCrossDrag,
  1111. isSelfToChildDrag,
  1112. isToChildDrag,
  1113. dragEndMethod
  1114. } = columnDragOpts;
  1115. const {
  1116. dragCol
  1117. } = customPanelReactData;
  1118. const {
  1119. prevDragCol,
  1120. prevDragGroupField,
  1121. prevDragAggFnColid,
  1122. prevDragPos,
  1123. prevDragToChild
  1124. } = customPanelInternalData;
  1125. const dragOffsetIndex = prevDragPos === 'bottom' ? 1 : 0;
  1126. if (prevDragGroupField || prevDragAggFnColid) {
  1127. if ($xeTable.handlePivotTableAggregatePanelDragendEvent) {
  1128. $xeTable.handlePivotTableAggregatePanelDragendEvent(evnt);
  1129. }
  1130. } else if (prevDragCol && dragCol) {
  1131. // 判断是否有拖动
  1132. if (prevDragCol !== dragCol) {
  1133. const dragColumn = dragCol;
  1134. const newColumn = prevDragCol;
  1135. Promise.resolve(dragEndMethod ? dragEndMethod({
  1136. oldColumn: dragColumn,
  1137. newColumn,
  1138. dragColumn,
  1139. dragPos: prevDragPos,
  1140. dragToChild: !!prevDragToChild,
  1141. offsetIndex: dragOffsetIndex
  1142. }) : true).then(status => {
  1143. if (!status) {
  1144. return;
  1145. }
  1146. let oafIndex = -1;
  1147. let nafIndex = -1;
  1148. const oldAllMaps = {};
  1149. _xeUtils.default.eachTree([dragColumn], column => {
  1150. oldAllMaps[column.id] = column;
  1151. });
  1152. let isSelfToChildStatus = false;
  1153. // 只有实时拖拽支持跨层级
  1154. if (immediate) {
  1155. if (dragColumn.parentId && newColumn.parentId) {
  1156. // 子到子
  1157. if (!isCrossDrag) {
  1158. return;
  1159. }
  1160. if (oldAllMaps[newColumn.id]) {
  1161. isSelfToChildStatus = true;
  1162. if (!(isCrossDrag && isSelfToChildDrag)) {
  1163. if (_ui.VxeUI.modal) {
  1164. _ui.VxeUI.modal.message({
  1165. status: 'error',
  1166. content: getI18n('vxe.error.treeDragChild')
  1167. });
  1168. }
  1169. return;
  1170. }
  1171. }
  1172. } else if (dragColumn.parentId) {
  1173. // 子到根
  1174. if (!isCrossDrag) {
  1175. return;
  1176. }
  1177. } else if (newColumn.parentId) {
  1178. // 根到子
  1179. if (!isCrossDrag) {
  1180. return;
  1181. }
  1182. if (oldAllMaps[newColumn.id]) {
  1183. isSelfToChildStatus = true;
  1184. if (!(isCrossDrag && isSelfToChildDrag)) {
  1185. if (_ui.VxeUI.modal) {
  1186. _ui.VxeUI.modal.message({
  1187. status: 'error',
  1188. content: getI18n('vxe.error.treeDragChild')
  1189. });
  1190. }
  1191. return;
  1192. }
  1193. }
  1194. } else {
  1195. // 根到根
  1196. }
  1197. const oldewMatchRest = _xeUtils.default.findTree(collectColumn, item => item.id === dragColumn.id);
  1198. // 改变层级
  1199. if (isSelfToChildStatus && isCrossDrag && isSelfToChildDrag) {
  1200. if (oldewMatchRest) {
  1201. const {
  1202. items: oCols,
  1203. index: oIndex
  1204. } = oldewMatchRest;
  1205. const childList = dragColumn.children || [];
  1206. childList.forEach(column => {
  1207. column.parentId = dragColumn.parentId;
  1208. });
  1209. oCols.splice(oIndex, 1, ...childList);
  1210. dragColumn.children = [];
  1211. }
  1212. } else {
  1213. if (oldewMatchRest) {
  1214. const {
  1215. items: oCols,
  1216. index: oIndex,
  1217. parent: oParent
  1218. } = oldewMatchRest;
  1219. oCols.splice(oIndex, 1);
  1220. if (!oParent) {
  1221. oafIndex = oIndex;
  1222. }
  1223. }
  1224. }
  1225. const newMatchRest = _xeUtils.default.findTree(collectColumn, item => item.id === newColumn.id);
  1226. if (newMatchRest) {
  1227. const {
  1228. items: nCols,
  1229. index: nIndex,
  1230. parent: nParent
  1231. } = newMatchRest;
  1232. // 转子级
  1233. if (isCrossDrag && isToChildDrag && prevDragToChild) {
  1234. dragColumn.parentId = newColumn.id;
  1235. newColumn.children = (newColumn.children || []).concat([dragColumn]);
  1236. } else {
  1237. dragColumn.parentId = newColumn.parentId;
  1238. nCols.splice(nIndex + dragOffsetIndex, 0, dragColumn);
  1239. }
  1240. if (!nParent) {
  1241. nafIndex = nIndex;
  1242. }
  1243. }
  1244. _xeUtils.default.eachTree(collectColumn, (column, index, items, path, parent) => {
  1245. if (!parent) {
  1246. const sortIndex = index + 1;
  1247. column.renderSortNumber = sortIndex;
  1248. }
  1249. });
  1250. } else {
  1251. oafIndex = _xeUtils.default.findIndexOf(customColumnList, item => item.id === dragColumn.id);
  1252. customColumnList.splice(oafIndex, 1);
  1253. nafIndex = _xeUtils.default.findIndexOf(customColumnList, item => item.id === newColumn.id);
  1254. customColumnList.splice(nafIndex + dragOffsetIndex, 0, dragColumn);
  1255. }
  1256. if (mouseConfig) {
  1257. if ($xeTable.clearSelected) {
  1258. $xeTable.clearSelected();
  1259. }
  1260. if ($xeTable.clearCellAreas) {
  1261. $xeTable.clearCellAreas();
  1262. $xeTable.clearCopyCellArea();
  1263. }
  1264. }
  1265. const csParams = {
  1266. oldColumn: dragColumn,
  1267. newColumn,
  1268. dragColumn,
  1269. dragPos: prevDragPos,
  1270. offsetIndex: dragOffsetIndex,
  1271. _index: {
  1272. newIndex: nafIndex,
  1273. oldIndex: oafIndex
  1274. }
  1275. };
  1276. $xeTable.dispatchEvent('custom-sort-change', csParams, evnt);
  1277. $xeTable.dispatchEvent('column-dragend', csParams, evnt);
  1278. if (immediate) {
  1279. tableReactData.customColumnList = collectColumn.slice(0);
  1280. $xeTable.handleColDragSwapColumn();
  1281. }
  1282. }).catch(() => {});
  1283. }
  1284. }
  1285. hideDropTip($xeTableCustomPanel);
  1286. customPanelReactData.dragCol = null;
  1287. customPanelReactData.dragGroupField = null;
  1288. customPanelReactData.dragAggFnCol = null;
  1289. customPanelInternalData.prevDragGroupField = null;
  1290. customPanelInternalData.prevDragAggFnColid = null;
  1291. trEl.draggable = false;
  1292. trEl.removeAttribute('drag-pos');
  1293. (0, _dom.removeClass)(trEl, 'active--drag-target');
  1294. (0, _dom.removeClass)(trEl, 'active--drag-origin');
  1295. },
  1296. sortDragoverEvent(evnt) {
  1297. const $xeTableCustomPanel = this;
  1298. const $xeTable = $xeTableCustomPanel.$xeTable;
  1299. const customPanelReactData = $xeTableCustomPanel.reactData;
  1300. const customPanelInternalData = $xeTableCustomPanel.internalData;
  1301. const {
  1302. dragCol
  1303. } = customPanelReactData;
  1304. const customOpts = $xeTable.computeCustomOpts;
  1305. const {
  1306. immediate
  1307. } = customOpts;
  1308. const columnDragOpts = $xeTable.computeColumnDragOpts;
  1309. const {
  1310. isCrossDrag,
  1311. isToChildDrag
  1312. } = columnDragOpts;
  1313. const optEl = evnt.currentTarget;
  1314. const isControlKey = (0, _dom.hasControlKey)(evnt);
  1315. const colid = optEl.getAttribute('colid');
  1316. const column = $xeTable.getColumnById(colid);
  1317. customPanelInternalData.prevDragGroupField = null;
  1318. customPanelInternalData.prevDragAggFnColid = null;
  1319. // 是否移入有效列
  1320. if (column && (isCrossDrag || column.level === 1)) {
  1321. evnt.preventDefault();
  1322. const offsetY = evnt.clientY - optEl.getBoundingClientRect().y;
  1323. const dragPos = offsetY < optEl.clientHeight / 2 ? 'top' : 'bottom';
  1324. if (!dragCol || dragCol && dragCol.id === column.id || !isCrossDrag && column.level > 1 || !immediate && column.level > 1) {
  1325. showDropTip($xeTableCustomPanel, evnt, optEl, false, dragPos);
  1326. return;
  1327. }
  1328. customPanelInternalData.prevDragToChild = !!(isCrossDrag && isToChildDrag && isControlKey && immediate);
  1329. customPanelInternalData.prevDragCol = column;
  1330. customPanelInternalData.prevDragPos = dragPos;
  1331. showDropTip($xeTableCustomPanel, evnt, optEl, true, dragPos);
  1332. }
  1333. }
  1334. }
  1335. };