panel.js 65 KB

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