export-panel.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _ui = require("../../../ui");
  7. var _xeUtils = _interopRequireDefault(require("xe-utils"));
  8. var _utils = require("../../../ui/src/utils");
  9. var _log = require("../../../ui/src/log");
  10. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  11. const {
  12. getI18n,
  13. getIcon,
  14. globalMixins,
  15. renderEmptyElement
  16. } = _ui.VxeUI;
  17. var _default = exports.default = {
  18. name: 'VxeTableExportPanel',
  19. mixins: [globalMixins.sizeMixin],
  20. props: {
  21. defaultOptions: Object,
  22. storeData: Object
  23. },
  24. components: {
  25. // VxeModal,
  26. // VxeInput,
  27. // VxeCheckbox,
  28. // VxeSelect,
  29. // VxeOption
  30. },
  31. inject: {
  32. $xeTable: {
  33. default: null
  34. }
  35. },
  36. data() {
  37. return {
  38. isAll: false,
  39. isIndeterminate: false,
  40. loading: false
  41. };
  42. },
  43. computed: {
  44. checkedAll() {
  45. return this.storeData.columns.every(column => column.checked);
  46. },
  47. showSheet() {
  48. return ['html', 'xml', 'xlsx', 'pdf'].indexOf(this.defaultOptions.type) > -1;
  49. },
  50. supportMerge() {
  51. const {
  52. storeData,
  53. defaultOptions
  54. } = this;
  55. return !defaultOptions.original && defaultOptions.mode === 'current' && (storeData.isPrint || ['html', 'xlsx'].indexOf(defaultOptions.type) > -1);
  56. },
  57. // computeSupportGroup () {
  58. // const { defaultOptions } = this
  59. // return ['html', 'xlsx', 'csv', 'txt'].indexOf(defaultOptions.type) > -1
  60. // },
  61. supportStyle() {
  62. const {
  63. defaultOptions
  64. } = this;
  65. return !defaultOptions.original && ['xlsx'].indexOf(defaultOptions.type) > -1;
  66. }
  67. },
  68. created() {
  69. const $xeTableExportPanel = this;
  70. const VxeUIModalComponent = _ui.VxeUI.getComponent('VxeModal');
  71. const VxeUIButtonComponent = _ui.VxeUI.getComponent('VxeButton');
  72. const VxeUISelectComponent = _ui.VxeUI.getComponent('VxeSelect');
  73. const VxeUIInputComponent = _ui.VxeUI.getComponent('VxeInput');
  74. const VxeUICheckboxComponent = _ui.VxeUI.getComponent('VxeCheckbox');
  75. $xeTableExportPanel.$nextTick(() => {
  76. if (!VxeUIModalComponent) {
  77. (0, _log.errLog)('vxe.error.reqComp', ['vxe-modal']);
  78. }
  79. if (!VxeUIButtonComponent) {
  80. (0, _log.errLog)('vxe.error.reqComp', ['vxe-button']);
  81. }
  82. if (!VxeUISelectComponent) {
  83. (0, _log.errLog)('vxe.error.reqComp', ['vxe-select']);
  84. }
  85. if (!VxeUIInputComponent) {
  86. (0, _log.errLog)('vxe.error.reqComp', ['vxe-input']);
  87. }
  88. if (!VxeUICheckboxComponent) {
  89. (0, _log.errLog)('vxe.error.reqComp', ['vxe-checkbox']);
  90. }
  91. });
  92. },
  93. render(h) {
  94. const $xeTable = this.$xeTable;
  95. const $xeGrid = $xeTable.$xeGrid;
  96. const $xeGantt = $xeTable.$xeGantt;
  97. const {
  98. _e,
  99. checkedAll,
  100. isAll: isAllChecked,
  101. isIndeterminate: isAllIndeterminate,
  102. showSheet,
  103. supportMerge,
  104. supportStyle,
  105. defaultOptions,
  106. storeData
  107. } = this;
  108. const {
  109. hasTree,
  110. hasMerge,
  111. isPrint,
  112. hasColgroup,
  113. columns
  114. } = storeData;
  115. const {
  116. isHeader
  117. } = defaultOptions;
  118. // const supportGroup = this.computeSupportGroup
  119. const slots = defaultOptions.slots || {};
  120. const topSlot = slots.top;
  121. const bottomSlot = slots.bottom;
  122. const defaultSlot = slots.default;
  123. const footerSlot = slots.footer;
  124. const parameterSlot = slots.parameter;
  125. const cols = [];
  126. _xeUtils.default.eachTree(columns, column => {
  127. const colTitle = (0, _utils.formatText)(column.getTitle(), 1);
  128. const isColGroup = column.children && column.children.length;
  129. const isChecked = column.checked;
  130. const indeterminate = column.halfChecked;
  131. const isHtml = column.type === 'html';
  132. cols.push(h('li', {
  133. class: ['vxe-table-export--panel-column-option', `level--${column.level}`, {
  134. 'is--group': isColGroup,
  135. 'is--checked': isChecked,
  136. 'is--indeterminate': indeterminate,
  137. 'is--disabled': column.disabled
  138. }],
  139. attrs: {
  140. title: colTitle
  141. },
  142. on: {
  143. click: () => {
  144. if (!column.disabled) {
  145. this.changeOption(column);
  146. }
  147. }
  148. }
  149. }, [h('span', {
  150. class: ['vxe-checkbox--icon', indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  151. }), isHtml ? h('span', {
  152. key: '1',
  153. class: 'vxe-checkbox--label',
  154. domProps: {
  155. innerHTML: colTitle
  156. }
  157. }) : h('span', {
  158. key: '0',
  159. class: 'vxe-checkbox--label'
  160. }, colTitle)]));
  161. });
  162. return h('vxe-modal', {
  163. ref: 'modal',
  164. props: {
  165. id: 'VXE_EXPORT_MODAL',
  166. value: storeData.visible,
  167. title: getI18n(isPrint ? 'vxe.export.printTitle' : 'vxe.export.expTitle'),
  168. width: 660,
  169. minWidth: 500,
  170. minHeight: 400,
  171. mask: true,
  172. lockView: true,
  173. showFooter: true,
  174. escClosable: true,
  175. maskClosable: true,
  176. showMaximize: true,
  177. resize: true,
  178. loading: this.loading
  179. },
  180. on: {
  181. input(value) {
  182. storeData.visible = value;
  183. },
  184. show: this.showEvent
  185. },
  186. scopedSlots: {
  187. default: () => {
  188. const params = {
  189. $table: $xeTable,
  190. $grid: $xeGrid,
  191. $gantt: $xeGantt,
  192. options: defaultOptions,
  193. columns,
  194. params: defaultOptions.params
  195. };
  196. const hasEmptyData = defaultOptions.mode === 'empty';
  197. return h('div', {
  198. class: 'vxe-table-export--panel'
  199. }, [topSlot ? h('div', {
  200. class: 'vxe-table-export--panel-top'
  201. }, $xeTable.callSlot(topSlot, params, h)) : renderEmptyElement(this), h('div', {
  202. class: 'vxe-table-export--panel-body'
  203. }, defaultSlot ? $xeTable.callSlot(defaultSlot, params, h) : [h('table', {
  204. attrs: {
  205. class: 'vxe-table-export--panel-table',
  206. cellspacing: 0,
  207. cellpadding: 0,
  208. border: 0
  209. }
  210. }, [h('tbody', [[isPrint ? _e() : h('tr', [h('td', getI18n('vxe.export.expName')), h('td', [h('vxe-input', {
  211. ref: 'filename',
  212. props: {
  213. value: defaultOptions.filename,
  214. type: 'text',
  215. clearable: true,
  216. placeholder: getI18n('vxe.export.expNamePlaceholder')
  217. },
  218. on: {
  219. modelValue(value) {
  220. defaultOptions.filename = value;
  221. }
  222. }
  223. })])]), isPrint ? _e() : h('tr', [h('td', getI18n('vxe.export.expType')), h('td', [h('vxe-select', {
  224. props: {
  225. value: defaultOptions.type,
  226. options: storeData.typeList
  227. },
  228. on: {
  229. modelValue(value) {
  230. defaultOptions.type = value;
  231. }
  232. }
  233. })])]), isPrint || showSheet ? h('tr', [h('td', getI18n('vxe.export.expSheetName')), h('td', [h('vxe-input', {
  234. ref: 'sheetname',
  235. props: {
  236. value: defaultOptions.sheetName,
  237. type: 'text',
  238. clearable: true,
  239. placeholder: getI18n('vxe.export.expSheetNamePlaceholder')
  240. },
  241. on: {
  242. modelValue(value) {
  243. defaultOptions.sheetName = value;
  244. }
  245. }
  246. })])]) : _e(), h('tr', [h('td', getI18n('vxe.export.expMode')), h('td', [h('vxe-select', {
  247. props: {
  248. value: defaultOptions.mode,
  249. options: storeData.modeList
  250. },
  251. on: {
  252. modelValue(value) {
  253. defaultOptions.mode = value;
  254. }
  255. }
  256. })])]), h('tr', [h('td', [getI18n('vxe.export.expColumn')]), h('td', [h('div', {
  257. class: 'vxe-table-export--panel-column'
  258. }, [h('ul', {
  259. class: 'vxe-table-export--panel-column-header'
  260. }, [h('li', {
  261. class: ['vxe-table-export--panel-column-option', {
  262. 'is--checked': isAllChecked,
  263. 'is--indeterminate': isAllIndeterminate
  264. }],
  265. attrs: {
  266. title: getI18n('vxe.table.allTitle')
  267. },
  268. on: {
  269. click: this.allColumnEvent
  270. }
  271. }, [h('span', {
  272. class: ['vxe-checkbox--icon', isAllIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isAllChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
  273. }), h('span', {
  274. class: 'vxe-checkbox--label'
  275. }, getI18n('vxe.export.expCurrentColumn'))])]), h('ul', {
  276. class: 'vxe-table-export--panel-column-body'
  277. }, cols)])])]), h('tr', [h('td', getI18n('vxe.export.expOpts')), parameterSlot ? h('td', [h('div', {
  278. class: 'vxe-table-export--panel-option-row'
  279. }, $xeTable.callSlot(parameterSlot, params, h))]) : h('td', [h('div', {
  280. class: 'vxe-table-export--panel-option-row'
  281. }, [h('vxe-checkbox', {
  282. props: {
  283. value: hasEmptyData || isHeader,
  284. disabled: hasEmptyData,
  285. title: getI18n('vxe.export.expHeaderTitle'),
  286. content: getI18n('vxe.export.expOptHeader')
  287. },
  288. on: {
  289. input(value) {
  290. defaultOptions.isHeader = value;
  291. }
  292. }
  293. }), h('vxe-checkbox', {
  294. props: {
  295. value: isHeader ? defaultOptions.isTitle : false,
  296. disabled: !isHeader,
  297. title: getI18n('vxe.export.expTitleTitle'),
  298. content: getI18n('vxe.export.expOptTitle')
  299. },
  300. on: {
  301. input(value) {
  302. defaultOptions.isTitle = value;
  303. }
  304. }
  305. }), h('vxe-checkbox', {
  306. props: {
  307. value: isHeader && hasColgroup && supportMerge ? defaultOptions.isColgroup : false,
  308. disabled: !isHeader || !hasColgroup || !supportMerge,
  309. title: getI18n('vxe.export.expColgroupTitle'),
  310. content: getI18n('vxe.export.expOptColgroup')
  311. },
  312. on: {
  313. input(value) {
  314. defaultOptions.isColgroup = value;
  315. }
  316. }
  317. })]), h('div', {
  318. class: 'vxe-table-export--panel-option-row'
  319. }, [h('vxe-checkbox', {
  320. props: {
  321. value: hasEmptyData ? false : defaultOptions.original,
  322. disabled: hasEmptyData,
  323. title: getI18n('vxe.export.expOriginalTitle'),
  324. content: getI18n('vxe.export.expOptOriginal')
  325. },
  326. on: {
  327. input(value) {
  328. defaultOptions.original = value;
  329. }
  330. }
  331. }), h('vxe-checkbox', {
  332. props: {
  333. value: hasMerge && supportMerge && checkedAll ? defaultOptions.isMerge : false,
  334. disabled: hasEmptyData || !hasMerge || !supportMerge || !checkedAll,
  335. title: getI18n('vxe.export.expMergeTitle'),
  336. content: getI18n('vxe.export.expOptMerge')
  337. },
  338. on: {
  339. input(value) {
  340. defaultOptions.isMerge = value;
  341. }
  342. }
  343. }), isPrint ? _e() : h('vxe-checkbox', {
  344. props: {
  345. value: supportStyle ? defaultOptions.useStyle : false,
  346. disabled: !supportStyle,
  347. title: getI18n('vxe.export.expUseStyleTitle'),
  348. content: getI18n('vxe.export.expOptUseStyle')
  349. },
  350. on: {
  351. input(value) {
  352. defaultOptions.useStyle = value;
  353. }
  354. }
  355. }), h('vxe-checkbox', {
  356. props: {
  357. value: hasTree ? defaultOptions.isAllExpand : false,
  358. disabled: hasEmptyData || !hasTree,
  359. title: getI18n('vxe.export.expAllExpandTitle'),
  360. content: getI18n('vxe.export.expOptAllExpand')
  361. },
  362. on: {
  363. input(value) {
  364. defaultOptions.isAllExpand = value;
  365. }
  366. }
  367. })]), h('div', {
  368. class: 'vxe-table-export--panel-option-row'
  369. }, [h('vxe-checkbox', {
  370. props: {
  371. value: defaultOptions.isFooter,
  372. disabled: !storeData.hasFooter,
  373. title: getI18n('vxe.export.expFooterTitle'),
  374. content: getI18n('vxe.export.expOptFooter')
  375. },
  376. on: {
  377. input(value) {
  378. defaultOptions.isFooter = value;
  379. }
  380. }
  381. })])])])]])])]), bottomSlot ? h('div', {
  382. class: 'vxe-table-export--panel-bottom'
  383. }, $xeTable.callSlot(bottomSlot, params, h)) : renderEmptyElement(this)]);
  384. },
  385. footer: () => {
  386. const params = {
  387. $table: $xeTable,
  388. $grid: $xeGrid,
  389. $gantt: $xeGantt,
  390. options: defaultOptions,
  391. columns,
  392. params: defaultOptions.params
  393. };
  394. return h('div', {
  395. class: 'vxe-table-export--panel-footer'
  396. }, footerSlot ? $xeTable.callSlot(footerSlot, params, h) : [h('div', {
  397. class: 'vxe-table-export--panel-btns'
  398. }, [h('vxe-button', {
  399. props: {
  400. content: getI18n('vxe.export.expCancel')
  401. },
  402. on: {
  403. click: this.cancelEvent
  404. }
  405. }), h('vxe-button', {
  406. ref: 'confirmBtn',
  407. props: {
  408. status: 'primary',
  409. content: getI18n(isPrint ? 'vxe.export.expPrint' : 'vxe.export.expConfirm')
  410. },
  411. on: {
  412. click: this.confirmEvent
  413. }
  414. })])]);
  415. }
  416. }
  417. });
  418. },
  419. methods: {
  420. changeOption(column) {
  421. const isChecked = !column.checked;
  422. _xeUtils.default.eachTree([column], item => {
  423. item.checked = isChecked;
  424. item.halfChecked = false;
  425. });
  426. this.handleOptionCheck(column);
  427. this.checkStatus();
  428. },
  429. handleOptionCheck(column) {
  430. const matchObj = _xeUtils.default.findTree(this.storeData.columns, item => item === column);
  431. if (matchObj && matchObj.parent) {
  432. const {
  433. parent
  434. } = matchObj;
  435. if (parent.children && parent.children.length) {
  436. parent.checked = parent.children.every(column => column.checked);
  437. parent.halfChecked = !parent.checked && parent.children.some(column => column.checked || column.halfChecked);
  438. this.handleOptionCheck(parent);
  439. }
  440. }
  441. },
  442. checkStatus() {
  443. const columns = this.storeData.columns;
  444. this.isAll = columns.every(column => column.disabled || column.checked);
  445. this.isIndeterminate = !this.isAll && columns.some(column => !column.disabled && (column.checked || column.halfChecked));
  446. },
  447. allColumnEvent() {
  448. const isAll = !this.isAll;
  449. _xeUtils.default.eachTree(this.storeData.columns, column => {
  450. if (!column.disabled) {
  451. column.checked = isAll;
  452. column.halfChecked = false;
  453. }
  454. });
  455. this.isAll = isAll;
  456. this.checkStatus();
  457. },
  458. showEvent() {
  459. this.$nextTick(() => {
  460. const {
  461. $refs
  462. } = this;
  463. const targetElem = $refs.filename || $refs.sheetname || $refs.confirmBtn;
  464. if (targetElem) {
  465. targetElem.focus();
  466. }
  467. });
  468. this.checkStatus();
  469. },
  470. getExportOption() {
  471. const {
  472. checkedAll,
  473. storeData,
  474. defaultOptions,
  475. supportMerge
  476. } = this;
  477. const {
  478. hasMerge,
  479. columns
  480. } = storeData;
  481. const expColumns = _xeUtils.default.searchTree(columns, column => column.checked, {
  482. children: 'children',
  483. mapChildren: 'childNodes',
  484. original: true
  485. });
  486. return Object.assign({}, defaultOptions, {
  487. columns: expColumns,
  488. isMerge: hasMerge && supportMerge && checkedAll ? defaultOptions.isMerge : false
  489. });
  490. },
  491. cancelEvent() {
  492. this.storeData.visible = false;
  493. },
  494. confirmEvent(evnt) {
  495. if (this.storeData.isPrint) {
  496. this.printEvent(evnt);
  497. } else {
  498. this.exportEvent(evnt);
  499. }
  500. },
  501. printEvent() {
  502. const $xeTable = this.$parent;
  503. this.storeData.visible = false;
  504. $xeTable.print(Object.assign({}, $xeTable.printOpts, this.getExportOption()));
  505. },
  506. exportEvent() {
  507. const $xeTable = this.$xeTable;
  508. const exportOpts = $xeTable.exportOpts;
  509. this.loading = true;
  510. $xeTable.exportData(Object.assign({}, exportOpts, this.getExportOption())).then(() => {
  511. this.loading = false;
  512. this.storeData.visible = false;
  513. }).catch(() => {
  514. this.loading = false;
  515. });
  516. }
  517. }
  518. };