mixin.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _xeUtils = _interopRequireDefault(require("xe-utils"));
  7. var _ui = require("../../../ui");
  8. var _util = require("../../src/util");
  9. var _utils = require("../../../ui/src/utils");
  10. var _dom = require("../../../ui/src/dom");
  11. var _util2 = require("./util");
  12. var _log = require("../../../ui/src/log");
  13. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  14. const {
  15. getI18n,
  16. renderer
  17. } = _ui.VxeUI;
  18. let htmlCellElem;
  19. const csvBOM = '\ufeff';
  20. const enterSymbol = '\r\n';
  21. function hasTreeChildren($xeTable, row) {
  22. const treeOpts = $xeTable.computeTreeOpts;
  23. const childrenField = treeOpts.children || treeOpts.childrenField;
  24. return row[childrenField] && row[childrenField].length;
  25. }
  26. function getSeq($xeTable, cellValue, row, $rowIndex, column, $columnIndex) {
  27. const seqOpts = $xeTable.computeSeqOpts;
  28. const seqMethod = seqOpts.seqMethod || column.seqMethod;
  29. if (seqMethod) {
  30. return seqMethod({
  31. $table: $xeTable,
  32. row,
  33. rowIndex: $xeTable.getRowIndex(row),
  34. $rowIndex,
  35. column,
  36. columnIndex: $xeTable.getColumnIndex(column),
  37. $columnIndex
  38. });
  39. }
  40. return cellValue;
  41. }
  42. function defaultFilterExportColumn(column) {
  43. return !!column.field || ['seq', 'checkbox', 'radio'].indexOf(column.type || '') === -1;
  44. }
  45. function toTableBorder(border) {
  46. if (border === true) {
  47. return 'full';
  48. }
  49. if (border) {
  50. return border;
  51. }
  52. return 'default';
  53. }
  54. function toBooleanValue(cellValue) {
  55. return _xeUtils.default.isBoolean(cellValue) ? cellValue ? 'TRUE' : 'FALSE' : cellValue;
  56. }
  57. const toStringValue = cellValue => {
  58. return (0, _utils.eqEmptyValue)(cellValue) ? '' : `${cellValue}`;
  59. };
  60. function getBodyLabelData($xeTable, opts, columns, datas) {
  61. const props = $xeTable;
  62. const {
  63. isAllExpand,
  64. mode
  65. } = opts;
  66. const {
  67. treeConfig
  68. } = props;
  69. const radioOpts = $xeTable.computeRadioOpts;
  70. const checkboxOpts = $xeTable.computeCheckboxOpts;
  71. const treeOpts = $xeTable.computeTreeOpts;
  72. const columnOpts = $xeTable.computeColumnOpts;
  73. if (!htmlCellElem) {
  74. htmlCellElem = document.createElement('div');
  75. }
  76. if (treeConfig) {
  77. const childrenField = treeOpts.children || treeOpts.childrenField;
  78. // 如果是树表格只允许导出数据源
  79. const rest = [];
  80. const expandMaps = {};
  81. const useMaps = {};
  82. const {
  83. handleGetRowId
  84. } = (0, _util.createHandleGetRowId)($xeTable);
  85. _xeUtils.default.eachTree(datas, (item, $rowIndex, items, path, parent, nodes) => {
  86. const row = item._row || item;
  87. const rowid = handleGetRowId(row);
  88. if (useMaps[rowid]) {
  89. return;
  90. }
  91. const parentRow = parent && parent._row ? parent._row : parent;
  92. const pRowid = parentRow ? handleGetRowId(parentRow) : '';
  93. if (isAllExpand || !parentRow || expandMaps[pRowid] && $xeTable.isTreeExpandByRow(parentRow)) {
  94. const hasRowChild = hasTreeChildren($xeTable, row);
  95. const item = {
  96. _row: row,
  97. _level: nodes.length - 1,
  98. _hasChild: hasRowChild,
  99. _expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
  100. };
  101. columns.forEach((column, $columnIndex) => {
  102. let cellValue = '';
  103. const renderOpts = column.editRender || column.cellRender;
  104. let bodyExportMethod = column.exportMethod || columnOpts.exportMethod;
  105. if (!bodyExportMethod && renderOpts && renderOpts.name) {
  106. const compConf = renderer.get(renderOpts.name);
  107. if (compConf) {
  108. bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod;
  109. }
  110. }
  111. if (!bodyExportMethod) {
  112. bodyExportMethod = columnOpts.exportMethod;
  113. }
  114. if (bodyExportMethod) {
  115. cellValue = bodyExportMethod({
  116. $table: $xeTable,
  117. row,
  118. column,
  119. options: opts
  120. });
  121. } else {
  122. switch (column.type) {
  123. case 'seq':
  124. {
  125. const seqVal = path.map((num, i) => i % 2 === 0 ? Number(num) + 1 : '.').join('');
  126. cellValue = mode === 'all' ? seqVal : getSeq($xeTable, seqVal, row, $rowIndex, column, $columnIndex);
  127. break;
  128. }
  129. case 'checkbox':
  130. cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row));
  131. item._checkboxLabel = checkboxOpts.labelField ? _xeUtils.default.get(row, checkboxOpts.labelField) : '';
  132. item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({
  133. $table: $xeTable,
  134. row
  135. });
  136. break;
  137. case 'radio':
  138. cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row));
  139. item._radioLabel = radioOpts.labelField ? _xeUtils.default.get(row, radioOpts.labelField) : '';
  140. item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({
  141. $table: $xeTable,
  142. row
  143. });
  144. break;
  145. default:
  146. if (opts.original) {
  147. cellValue = (0, _util.getCellValue)(row, column);
  148. } else {
  149. cellValue = $xeTable.getCellLabel(row, column);
  150. if (column.type === 'html') {
  151. htmlCellElem.innerHTML = cellValue;
  152. cellValue = htmlCellElem.innerText.trim();
  153. } else {
  154. const cell = $xeTable.getCellElement(row, column);
  155. if (cell && !(0, _dom.hasClass)(cell, 'is--progress')) {
  156. cellValue = cell.innerText.trim();
  157. }
  158. }
  159. }
  160. }
  161. }
  162. item[column.id] = toStringValue(cellValue);
  163. });
  164. useMaps[rowid] = true;
  165. if (pRowid) {
  166. expandMaps[pRowid] = true;
  167. }
  168. rest.push(Object.assign(item, row));
  169. }
  170. }, {
  171. children: childrenField
  172. });
  173. return rest;
  174. }
  175. return datas.map((row, $rowIndex) => {
  176. const item = {
  177. _row: row
  178. };
  179. columns.forEach((column, $columnIndex) => {
  180. let cellValue = '';
  181. const renderOpts = column.editRender || column.cellRender;
  182. let bodyExportMethod = column.exportMethod || columnOpts.exportMethod;
  183. if (!bodyExportMethod && renderOpts && renderOpts.name) {
  184. const compConf = renderer.get(renderOpts.name);
  185. if (compConf) {
  186. bodyExportMethod = compConf.tableExportMethod || compConf.exportMethod;
  187. }
  188. }
  189. if (bodyExportMethod) {
  190. cellValue = bodyExportMethod({
  191. $table: $xeTable,
  192. row,
  193. column,
  194. options: opts
  195. });
  196. } else {
  197. switch (column.type) {
  198. case 'seq':
  199. {
  200. const seqValue = $rowIndex + 1;
  201. cellValue = mode === 'all' ? seqValue : getSeq($xeTable, seqValue, row, $rowIndex, column, $columnIndex);
  202. break;
  203. }
  204. case 'checkbox':
  205. cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row));
  206. item._checkboxLabel = checkboxOpts.labelField ? _xeUtils.default.get(row, checkboxOpts.labelField) : '';
  207. item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({
  208. $table: $xeTable,
  209. row
  210. });
  211. break;
  212. case 'radio':
  213. cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row));
  214. item._radioLabel = radioOpts.labelField ? _xeUtils.default.get(row, radioOpts.labelField) : '';
  215. item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({
  216. $table: $xeTable,
  217. row
  218. });
  219. break;
  220. default:
  221. if (opts.original) {
  222. cellValue = (0, _util.getCellValue)(row, column);
  223. } else {
  224. cellValue = $xeTable.getCellLabel(row, column);
  225. if (column.type === 'html') {
  226. htmlCellElem.innerHTML = cellValue;
  227. cellValue = htmlCellElem.innerText.trim();
  228. } else {
  229. const cell = $xeTable.getCellElement(row, column);
  230. if (cell && !(0, _dom.hasClass)(cell, 'is--progress')) {
  231. cellValue = cell.innerText.trim();
  232. }
  233. }
  234. }
  235. }
  236. }
  237. item[column.id] = toStringValue(cellValue);
  238. });
  239. return item;
  240. });
  241. }
  242. function getExportData($xeTable, opts) {
  243. const $xeGrid = $xeTable.$xeGrid;
  244. const $xeGantt = $xeTable.$xeGantt;
  245. const {
  246. columns,
  247. dataFilterMethod
  248. } = opts;
  249. let datas = opts.data;
  250. if (dataFilterMethod) {
  251. datas = datas.filter((row, index) => dataFilterMethod({
  252. $table: $xeTable,
  253. $grid: $xeGrid,
  254. $gantt: $xeGantt,
  255. row,
  256. $rowIndex: index
  257. }));
  258. }
  259. return getBodyLabelData($xeTable, opts, columns, datas);
  260. }
  261. function getBooleanValue(cellValue) {
  262. return cellValue === 'TRUE' || cellValue === 'true' || cellValue === true;
  263. }
  264. function getHeaderTitle($xeTable, opts, column) {
  265. const columnOpts = $xeTable.computeColumnOpts;
  266. const headExportMethod = column.headerExportMethod || columnOpts.headerExportMethod;
  267. return headExportMethod ? headExportMethod({
  268. column,
  269. options: opts,
  270. $table: $xeTable
  271. }) : (opts.isTitle ? column.getTitle() : column.field) || '';
  272. }
  273. function getFooterCellValue($xeTable, opts, row, column) {
  274. const columnOpts = $xeTable.computeColumnOpts;
  275. const renderOpts = column.editRender || column.cellRender;
  276. let footLabelMethod = column.footerExportMethod;
  277. if (!footLabelMethod && renderOpts && renderOpts.name) {
  278. const compConf = renderer.get(renderOpts.name);
  279. if (compConf) {
  280. footLabelMethod = compConf.tableFooterExportMethod || compConf.footerExportMethod || compConf.footerCellExportMethod;
  281. }
  282. }
  283. if (!footLabelMethod) {
  284. footLabelMethod = columnOpts.footerExportMethod;
  285. }
  286. const _columnIndex = $xeTable.getVTColumnIndex(column);
  287. if (footLabelMethod) {
  288. return footLabelMethod({
  289. $table: $xeTable,
  290. items: row,
  291. itemIndex: _columnIndex,
  292. row,
  293. _columnIndex,
  294. column,
  295. options: opts
  296. });
  297. }
  298. // 兼容老模式
  299. if (_xeUtils.default.isArray(row)) {
  300. return _xeUtils.default.toValueString(row[_columnIndex]);
  301. }
  302. return _xeUtils.default.get(row, column.field);
  303. }
  304. function getFooterData($xeTable, opts, footerTableData) {
  305. const $xeGrid = $xeTable.$xeGrid;
  306. const $xeGantt = $xeTable.$xeGantt;
  307. const {
  308. footerFilterMethod
  309. } = opts;
  310. return footerFilterMethod ? footerTableData.filter((items, index) => footerFilterMethod({
  311. $table: $xeTable,
  312. $grid: $xeGrid,
  313. $gantt: $xeGantt,
  314. items,
  315. $rowIndex: index
  316. })) : footerTableData;
  317. }
  318. function getCsvCellTypeLabel(column, cellValue) {
  319. if (cellValue) {
  320. if (column.type === 'seq') {
  321. return `\t${cellValue}`;
  322. }
  323. switch (column.cellType) {
  324. case 'string':
  325. if (!isNaN(cellValue)) {
  326. return `\t${cellValue}`;
  327. }
  328. break;
  329. case 'number':
  330. break;
  331. default:
  332. if (cellValue.length >= 12 && !isNaN(cellValue)) {
  333. return `\t${cellValue}`;
  334. }
  335. break;
  336. }
  337. }
  338. return cellValue;
  339. }
  340. function toTxtCellLabel(val) {
  341. if (/[",\s\n]/.test(val)) {
  342. return `"${val.replace(/"/g, '""')}"`;
  343. }
  344. return val;
  345. }
  346. function toCsv($xeTable, opts, columns, datas) {
  347. const reactData = $xeTable;
  348. let content = csvBOM;
  349. if (opts.isHeader) {
  350. content += columns.map(column => toTxtCellLabel(getHeaderTitle($xeTable, opts, column))).join(',') + enterSymbol;
  351. }
  352. datas.forEach(row => {
  353. content += columns.map(column => toTxtCellLabel(getCsvCellTypeLabel(column, row[column.id]))).join(',') + enterSymbol;
  354. });
  355. if (opts.isFooter) {
  356. const {
  357. footerTableData
  358. } = reactData;
  359. const footers = getFooterData($xeTable, opts, footerTableData);
  360. footers.forEach(row => {
  361. content += columns.map(column => toTxtCellLabel(getFooterCellValue($xeTable, opts, row, column))).join(',') + enterSymbol;
  362. });
  363. }
  364. return content;
  365. }
  366. function toTxt($xeTable, opts, columns, datas) {
  367. const reactData = $xeTable;
  368. let content = '';
  369. if (opts.isHeader) {
  370. content += columns.map(column => toTxtCellLabel(getHeaderTitle($xeTable, opts, column))).join('\t') + enterSymbol;
  371. }
  372. datas.forEach(row => {
  373. content += columns.map(column => toTxtCellLabel(row[column.id])).join('\t') + enterSymbol;
  374. });
  375. if (opts.isFooter) {
  376. const {
  377. footerTableData
  378. } = reactData;
  379. const footers = getFooterData($xeTable, opts, footerTableData);
  380. footers.forEach(row => {
  381. content += columns.map(column => toTxtCellLabel(getFooterCellValue($xeTable, opts, row, column))).join('\t') + enterSymbol;
  382. });
  383. }
  384. return content;
  385. }
  386. function hasEllipsis($xeTable, column, property, allColumnOverflow) {
  387. const reactData = $xeTable;
  388. const columnOverflow = column[property];
  389. const headOverflow = _xeUtils.default.isUndefined(columnOverflow) || _xeUtils.default.isNull(columnOverflow) ? allColumnOverflow : columnOverflow;
  390. const showEllipsis = headOverflow === 'ellipsis';
  391. const showTitle = headOverflow === 'title';
  392. const showTooltip = headOverflow === true || headOverflow === 'tooltip';
  393. let isEllipsis = showTitle || showTooltip || showEllipsis;
  394. // 虚拟滚动不支持动态高度
  395. const {
  396. scrollXLoad,
  397. scrollYLoad
  398. } = reactData;
  399. if ((scrollXLoad || scrollYLoad) && !isEllipsis) {
  400. isEllipsis = true;
  401. }
  402. return isEllipsis;
  403. }
  404. function toHtml($xeTable, opts, columns, datas) {
  405. const props = $xeTable;
  406. const reactData = $xeTable;
  407. const internalData = $xeTable;
  408. const {
  409. id,
  410. border,
  411. treeConfig,
  412. headerAlign: allHeaderAlign,
  413. align: allAlign,
  414. footerAlign: allFooterAlign,
  415. showOverflow: allColumnOverflow,
  416. showHeaderOverflow: allColumnHeaderOverflow
  417. } = props;
  418. const {
  419. isAllSelected,
  420. isIndeterminate
  421. } = reactData;
  422. const {
  423. mergeBodyCellMaps
  424. } = internalData;
  425. const treeOpts = $xeTable.computeTreeOpts;
  426. const {
  427. print: isPrint,
  428. isHeader,
  429. isFooter,
  430. isColgroup,
  431. isMerge,
  432. colgroups,
  433. original
  434. } = opts;
  435. const allCls = 'check-all';
  436. const clss = ['vxe-table', `border--${toTableBorder(border)}`, isPrint ? 'is--print' : '', isHeader ? 'is--header' : ''].filter(cls => cls);
  437. const tables = [`<table class="${clss.join(' ')}" border="0" cellspacing="0" cellpadding="0">`, `<colgroup>${columns.map(column => `<col style="width:${column.renderWidth}px">`).join('')}</colgroup>`];
  438. if (isHeader) {
  439. tables.push('<thead>');
  440. if (isColgroup && !original) {
  441. colgroups.forEach(cols => {
  442. tables.push(`<tr>${cols.map(column => {
  443. const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign;
  444. const classNames = hasEllipsis($xeTable, column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : [];
  445. const cellTitle = getHeaderTitle($xeTable, opts, column);
  446. let childWidth = 0;
  447. let countChild = 0;
  448. _xeUtils.default.eachTree([column], item => {
  449. if (!item.childNodes || !column.childNodes.length) {
  450. countChild++;
  451. }
  452. childWidth += item.renderWidth;
  453. }, {
  454. children: 'childNodes'
  455. });
  456. const cellWidth = childWidth - countChild;
  457. if (headAlign) {
  458. classNames.push(`col--${headAlign}`);
  459. }
  460. if (column.type === 'checkbox') {
  461. return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}"><div ${isPrint ? '' : `style="width: ${cellWidth}px"`}><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`;
  462. }
  463. return `<th class="${classNames.join(' ')}" colspan="${column._colSpan}" rowspan="${column._rowSpan}" title="${cellTitle}"><div ${isPrint ? '' : `style="width: ${cellWidth}px"`}><span>${(0, _utils.formatText)(cellTitle, true)}</span></div></th>`;
  464. }).join('')}</tr>`);
  465. });
  466. } else {
  467. tables.push(`<tr>${columns.map(column => {
  468. const headAlign = column.headerAlign || column.align || allHeaderAlign || allAlign;
  469. const classNames = hasEllipsis($xeTable, column, 'showHeaderOverflow', allColumnHeaderOverflow) ? ['col--ellipsis'] : [];
  470. const cellTitle = getHeaderTitle($xeTable, opts, column);
  471. if (headAlign) {
  472. classNames.push(`col--${headAlign}`);
  473. }
  474. if (column.type === 'checkbox') {
  475. return `<th class="${classNames.join(' ')}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><input type="checkbox" class="${allCls}" ${isAllSelected ? 'checked' : ''}><span>${cellTitle}</span></div></th>`;
  476. }
  477. return `<th class="${classNames.join(' ')}" title="${cellTitle}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><span>${(0, _utils.formatText)(cellTitle, true)}</span></div></th>`;
  478. }).join('')}</tr>`);
  479. }
  480. tables.push('</thead>');
  481. }
  482. if (datas.length) {
  483. tables.push('<tbody>');
  484. if (treeConfig) {
  485. datas.forEach(item => {
  486. tables.push('<tr>' + columns.map(column => {
  487. const cellAlign = column.align || allAlign;
  488. const classNames = hasEllipsis($xeTable, column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : [];
  489. const cellValue = item[column.id];
  490. if (cellAlign) {
  491. classNames.push(`col--${cellAlign}`);
  492. }
  493. if (column.treeNode) {
  494. let treeIcon = '';
  495. if (item._hasChild) {
  496. treeIcon = `<i class="${item._expand ? 'vxe-table--tree-fold-icon' : 'vxe-table--tree-unfold-icon'}"></i>`;
  497. }
  498. classNames.push('vxe-table--tree-node');
  499. if (column.type === 'radio') {
  500. return `<td class="${classNames.join(' ')}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></div></div></td>`;
  501. } else if (column.type === 'checkbox') {
  502. return `<td class="${classNames.join(' ')}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell"><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></div></div></td>`;
  503. }
  504. return `<td class="${classNames.join(' ')}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><div class="vxe-table--tree-node-wrapper" style="padding-left: ${item._level * treeOpts.indent}px"><div class="vxe-table--tree-icon-wrapper">${treeIcon}</div><div class="vxe-table--tree-cell">${cellValue}</div></div></div></td>`;
  505. }
  506. if (column.type === 'radio') {
  507. return `<td class="${classNames.join(' ')}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`;
  508. } else if (column.type === 'checkbox') {
  509. return `<td class="${classNames.join(' ')}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`;
  510. }
  511. return `<td class="${classNames.join(' ')}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}>${(0, _utils.formatText)(cellValue, true)}</div></td>`;
  512. }).join('') + '</tr>');
  513. });
  514. } else {
  515. datas.forEach(item => {
  516. tables.push('<tr>' + columns.map(column => {
  517. const colid = column.id;
  518. const cellAlign = column.align || allAlign;
  519. const classNames = hasEllipsis($xeTable, column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : [];
  520. const cellValue = item[colid];
  521. let rowSpan = 1;
  522. let colSpan = 1;
  523. if (isMerge) {
  524. const _rowIndex = $xeTable.getVTRowIndex(item._row);
  525. const _columnIndex = $xeTable.getVTColumnIndex(column);
  526. const spanRest = mergeBodyCellMaps[`${_rowIndex}:${_columnIndex}`];
  527. if (spanRest) {
  528. const {
  529. rowspan,
  530. colspan
  531. } = spanRest;
  532. if (!rowspan || !colspan) {
  533. return '';
  534. }
  535. if (rowspan > 1) {
  536. rowSpan = rowspan;
  537. }
  538. if (colspan > 1) {
  539. colSpan = colspan;
  540. }
  541. }
  542. }
  543. if (cellAlign) {
  544. classNames.push(`col--${cellAlign}`);
  545. }
  546. if (column.type === 'radio') {
  547. return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><input type="radio" name="radio_${id}" ${item._radioDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._radioLabel}</span></div></td>`;
  548. } else if (column.type === 'checkbox') {
  549. return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}><input type="checkbox" ${item._checkboxDisabled ? 'disabled ' : ''}${getBooleanValue(cellValue) ? 'checked' : ''}><span>${item._checkboxLabel}</span></div></td>`;
  550. }
  551. return `<td class="${classNames.join(' ')}" rowspan="${rowSpan}" colspan="${colSpan}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}>${(0, _utils.formatText)(cellValue, true)}</div></td>`;
  552. }).join('') + '</tr>');
  553. });
  554. }
  555. tables.push('</tbody>');
  556. }
  557. if (isFooter) {
  558. const {
  559. footerTableData
  560. } = reactData;
  561. const footers = getFooterData($xeTable, opts, footerTableData);
  562. if (footers.length) {
  563. tables.push('<tfoot>');
  564. footers.forEach(row => {
  565. tables.push(`<tr>${columns.map(column => {
  566. const footAlign = column.footerAlign || column.align || allFooterAlign || allAlign;
  567. const classNames = hasEllipsis($xeTable, column, 'showOverflow', allColumnOverflow) ? ['col--ellipsis'] : [];
  568. const cellValue = getFooterCellValue($xeTable, opts, row, column);
  569. if (footAlign) {
  570. classNames.push(`col--${footAlign}`);
  571. }
  572. return `<td class="${classNames.join(' ')}" title="${cellValue}"><div ${isPrint ? '' : `style="width: ${column.renderWidth}px"`}>${(0, _utils.formatText)(cellValue, true)}</div></td>`;
  573. }).join('')}</tr>`);
  574. });
  575. tables.push('</tfoot>');
  576. }
  577. }
  578. // 是否半选状态
  579. const script = !isAllSelected && isIndeterminate ? `<script>(function(){var a=document.querySelector(".${allCls}");if(a){a.indeterminate=true}})()</script>` : '';
  580. tables.push('</table>', script);
  581. return isPrint ? tables.join('') : (0, _util2.createHtmlPage)(opts, tables.join(''));
  582. }
  583. function toXML($xeTable, opts, columns, datas) {
  584. const reactData = $xeTable;
  585. let xml = ['<?xml version="1.0"?>', '<?mso-application progid="Excel.Sheet"?>', '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">', '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">', '<Version>16.00</Version>', '</DocumentProperties>', '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">', '<WindowHeight>7920</WindowHeight>', '<WindowWidth>21570</WindowWidth>', '<WindowTopX>32767</WindowTopX>', '<WindowTopY>32767</WindowTopY>', '<ProtectStructure>False</ProtectStructure>', '<ProtectWindows>False</ProtectWindows>', '</ExcelWorkbook>', `<Worksheet ss:Name="${opts.sheetName}">`, '<Table>', columns.map(column => `<Column ss:Width="${column.renderWidth}"/>`).join('')].join('');
  586. if (opts.isHeader) {
  587. xml += `<Row>${columns.map(column => `<Cell><Data ss:Type="String">${getHeaderTitle($xeTable, opts, column)}</Data></Cell>`).join('')}</Row>`;
  588. }
  589. datas.forEach(row => {
  590. xml += '<Row>' + columns.map(column => `<Cell><Data ss:Type="String">${row[column.id]}</Data></Cell>`).join('') + '</Row>';
  591. });
  592. if (opts.isFooter) {
  593. const {
  594. footerTableData
  595. } = reactData;
  596. const footers = getFooterData($xeTable, opts, footerTableData);
  597. footers.forEach(row => {
  598. xml += `<Row>${columns.map(column => `<Cell><Data ss:Type="String">${getFooterCellValue($xeTable, opts, row, column)}</Data></Cell>`).join('')}</Row>`;
  599. });
  600. }
  601. return `${xml}</Table></Worksheet></Workbook>`;
  602. }
  603. function getContent($xeTable, opts, columns, datas) {
  604. if (columns.length) {
  605. switch (opts.type) {
  606. case 'csv':
  607. return toCsv($xeTable, opts, columns, datas);
  608. case 'txt':
  609. return toTxt($xeTable, opts, columns, datas);
  610. case 'html':
  611. return toHtml($xeTable, opts, columns, datas);
  612. case 'xml':
  613. return toXML($xeTable, opts, columns, datas);
  614. }
  615. }
  616. return '';
  617. }
  618. function downloadFile($xeTable, opts, content) {
  619. const {
  620. filename,
  621. type,
  622. download
  623. } = opts;
  624. if (!download) {
  625. const blob = (0, _util2.getExportBlobByContent)(content, opts);
  626. return Promise.resolve({
  627. type,
  628. content,
  629. blob
  630. });
  631. }
  632. if (_ui.VxeUI.saveFile) {
  633. _ui.VxeUI.saveFile({
  634. filename,
  635. type,
  636. content
  637. }).then(() => {
  638. if (opts.message !== false) {
  639. if (_ui.VxeUI.modal) {
  640. _ui.VxeUI.modal.message({
  641. content: getI18n('vxe.table.expSuccess'),
  642. status: 'success'
  643. });
  644. }
  645. }
  646. });
  647. }
  648. }
  649. function clearColumnConvert(columns) {
  650. _xeUtils.default.eachTree(columns, column => {
  651. delete column._level;
  652. delete column._colSpan;
  653. delete column._rowSpan;
  654. delete column._children;
  655. delete column.childNodes;
  656. }, {
  657. children: 'children'
  658. });
  659. }
  660. function handleExport($xeTable, opts) {
  661. const $xeGrid = $xeTable.$xeGrid;
  662. const $xeGantt = $xeTable.$xeGantt;
  663. const {
  664. remote,
  665. columns,
  666. colgroups,
  667. exportMethod,
  668. afterExportMethod
  669. } = opts;
  670. return new Promise(resolve => {
  671. if (remote) {
  672. const params = {
  673. options: opts,
  674. $table: $xeTable,
  675. $grid: $xeGrid,
  676. $gantt: $xeGantt
  677. };
  678. resolve(exportMethod ? exportMethod(params) : params);
  679. } else {
  680. const datas = getExportData($xeTable, opts);
  681. resolve($xeTable.preventEvent(null, 'event.export', {
  682. options: opts,
  683. columns,
  684. colgroups,
  685. datas
  686. }, () => {
  687. return downloadFile($xeTable, opts, getContent($xeTable, opts, columns, datas));
  688. }));
  689. }
  690. }).then(params => {
  691. clearColumnConvert(columns);
  692. if (!opts.print) {
  693. if (afterExportMethod) {
  694. afterExportMethod({
  695. status: true,
  696. options: opts,
  697. $table: $xeTable,
  698. $grid: $xeGrid,
  699. $gantt: $xeGantt
  700. });
  701. }
  702. }
  703. return Object.assign({
  704. status: true
  705. }, params);
  706. }).catch(() => {
  707. clearColumnConvert(columns);
  708. if (!opts.print) {
  709. if (afterExportMethod) {
  710. afterExportMethod({
  711. status: false,
  712. options: opts,
  713. $table: $xeTable,
  714. $grid: $xeGrid,
  715. $gantt: $xeGantt
  716. });
  717. }
  718. }
  719. const params = {
  720. status: false
  721. };
  722. return Promise.reject(params);
  723. });
  724. }
  725. function getElementsByTagName(elem, qualifiedName) {
  726. return elem.getElementsByTagName(qualifiedName);
  727. }
  728. function getTxtCellKey(now) {
  729. return `#${now}@${_xeUtils.default.uniqueId()}`;
  730. }
  731. function replaceTxtCell(cell, vMaps) {
  732. return cell.replace(/#\d+@\d+/g, key => _xeUtils.default.hasOwnProp(vMaps, key) ? vMaps[key] : key);
  733. }
  734. function getTxtCellValue(val, vMaps) {
  735. const rest = replaceTxtCell(val, vMaps);
  736. return rest.replace(/^"+$/g, qVal => '"'.repeat(Math.ceil(qVal.length / 2)));
  737. }
  738. function toExportField(tableConf, field) {
  739. const {
  740. fieldMaps,
  741. titleMaps
  742. } = tableConf;
  743. // title 转 field
  744. if (!fieldMaps[field]) {
  745. const teCol = titleMaps[field];
  746. if (teCol && teCol.field) {
  747. field = teCol.field;
  748. }
  749. }
  750. return field;
  751. }
  752. function parseCsvAndTxt(tableConf, content, cellSeparator) {
  753. const list = content.split(enterSymbol);
  754. const rows = [];
  755. let fields = [];
  756. if (list.length) {
  757. const vMaps = {};
  758. const now = Date.now();
  759. list.forEach(rVal => {
  760. if (rVal) {
  761. const item = {};
  762. rVal = rVal.replace(/("")|(\n)/g, (text, dVal) => {
  763. const key = getTxtCellKey(now);
  764. vMaps[key] = dVal ? '"' : '\n';
  765. return key;
  766. }).replace(/"(.*?)"/g, (text, cVal) => {
  767. const key = getTxtCellKey(now);
  768. vMaps[key] = replaceTxtCell(cVal, vMaps);
  769. return key;
  770. });
  771. const cells = rVal.split(cellSeparator);
  772. if (!fields.length) {
  773. fields = cells.map(val => toExportField(tableConf, getTxtCellValue(val.trim(), vMaps)));
  774. } else {
  775. cells.forEach((val, colIndex) => {
  776. if (colIndex < fields.length) {
  777. item[fields[colIndex]] = getTxtCellValue(val.trim(), vMaps);
  778. }
  779. });
  780. rows.push(item);
  781. }
  782. }
  783. });
  784. }
  785. return {
  786. fields,
  787. rows
  788. };
  789. }
  790. function parseCsv(tableConf, content) {
  791. return parseCsvAndTxt(tableConf, content, ',');
  792. }
  793. function parseTxt(tableConf, content) {
  794. return parseCsvAndTxt(tableConf, content, '\t');
  795. }
  796. function parseHTML(tableConf, content) {
  797. const domParser = new DOMParser();
  798. const xmlDoc = domParser.parseFromString(content, 'text/html');
  799. const bodyNodes = getElementsByTagName(xmlDoc, 'body');
  800. const rows = [];
  801. const fields = [];
  802. if (bodyNodes.length) {
  803. const tableNodes = getElementsByTagName(bodyNodes[0], 'table');
  804. if (tableNodes.length) {
  805. const theadNodes = getElementsByTagName(tableNodes[0], 'thead');
  806. if (theadNodes.length) {
  807. _xeUtils.default.arrayEach(getElementsByTagName(theadNodes[0], 'tr'), rowNode => {
  808. _xeUtils.default.arrayEach(getElementsByTagName(rowNode, 'th'), cellNode => {
  809. fields.push(toExportField(tableConf, cellNode.textContent || ''));
  810. });
  811. });
  812. const tbodyNodes = getElementsByTagName(tableNodes[0], 'tbody');
  813. if (tbodyNodes.length) {
  814. _xeUtils.default.arrayEach(getElementsByTagName(tbodyNodes[0], 'tr'), rowNode => {
  815. const item = {};
  816. _xeUtils.default.arrayEach(getElementsByTagName(rowNode, 'td'), (cellNode, colIndex) => {
  817. if (fields[colIndex]) {
  818. item[fields[colIndex]] = cellNode.textContent || '';
  819. }
  820. });
  821. rows.push(item);
  822. });
  823. }
  824. }
  825. }
  826. }
  827. return {
  828. fields,
  829. rows
  830. };
  831. }
  832. function parseXML(tableConf, content) {
  833. const domParser = new DOMParser();
  834. const xmlDoc = domParser.parseFromString(content, 'application/xml');
  835. const sheetNodes = getElementsByTagName(xmlDoc, 'Worksheet');
  836. const rows = [];
  837. const fields = [];
  838. if (sheetNodes.length) {
  839. const tableNodes = getElementsByTagName(sheetNodes[0], 'Table');
  840. if (tableNodes.length) {
  841. const rowNodes = getElementsByTagName(tableNodes[0], 'Row');
  842. if (rowNodes.length) {
  843. _xeUtils.default.arrayEach(getElementsByTagName(rowNodes[0], 'Cell'), cellNode => {
  844. fields.push(toExportField(tableConf, cellNode.textContent || ''));
  845. });
  846. _xeUtils.default.arrayEach(rowNodes, (rowNode, index) => {
  847. if (index) {
  848. const item = {};
  849. const cellNodes = getElementsByTagName(rowNode, 'Cell');
  850. _xeUtils.default.arrayEach(cellNodes, (cellNode, colIndex) => {
  851. if (fields[colIndex]) {
  852. item[fields[colIndex]] = cellNode.textContent;
  853. }
  854. });
  855. rows.push(item);
  856. }
  857. });
  858. }
  859. }
  860. }
  861. return {
  862. fields,
  863. rows
  864. };
  865. }
  866. function handleImport($xeTable, content, opts) {
  867. const internalData = $xeTable;
  868. const {
  869. tableFullColumn,
  870. _importResolve,
  871. _importReject
  872. } = internalData;
  873. let rest = {
  874. fields: [],
  875. rows: []
  876. };
  877. const tableFieldMaps = {};
  878. const tableTitleMaps = {};
  879. tableFullColumn.forEach(column => {
  880. const field = column.field;
  881. const title = column.getTitle();
  882. if (field) {
  883. tableFieldMaps[field] = column;
  884. }
  885. if (title) {
  886. tableTitleMaps[column.getTitle()] = column;
  887. }
  888. });
  889. const tableConf = {
  890. fieldMaps: tableFieldMaps,
  891. titleMaps: tableTitleMaps
  892. };
  893. switch (opts.type) {
  894. case 'csv':
  895. rest = parseCsv(tableConf, content);
  896. break;
  897. case 'txt':
  898. rest = parseTxt(tableConf, content);
  899. break;
  900. case 'html':
  901. rest = parseHTML(tableConf, content);
  902. break;
  903. case 'xml':
  904. rest = parseXML(tableConf, content);
  905. break;
  906. }
  907. const {
  908. fields,
  909. rows
  910. } = rest;
  911. const status = fields.some(field => tableFieldMaps[field] || tableTitleMaps[field]);
  912. if (status) {
  913. $xeTable.createData(rows).then(data => {
  914. let loadRest;
  915. if (opts.mode === 'insert' || opts.mode === 'insertBottom') {
  916. loadRest = $xeTable.insertAt(data, -1);
  917. }
  918. if (opts.mode === 'insertTop') {
  919. loadRest = $xeTable.insert(data);
  920. } else {
  921. loadRest = $xeTable.reloadData(data);
  922. }
  923. if (opts.message !== false) {
  924. // 检测弹窗模块
  925. if (!_ui.VxeUI.modal) {
  926. (0, _log.errLog)('vxe.error.reqModule', ['Modal']);
  927. }
  928. _ui.VxeUI.modal.message({
  929. content: getI18n('vxe.table.impSuccess', [rows.length]),
  930. status: 'success'
  931. });
  932. }
  933. return loadRest.then(() => {
  934. if (_importResolve) {
  935. _importResolve({
  936. status: true
  937. });
  938. }
  939. });
  940. });
  941. } else if (opts.message !== false) {
  942. // 检测弹窗模块
  943. if (!_ui.VxeUI.modal) {
  944. (0, _log.errLog)('vxe.error.reqModule', ['Modal']);
  945. }
  946. _ui.VxeUI.modal.message({
  947. content: getI18n('vxe.error.impFields'),
  948. status: 'error'
  949. });
  950. if (_importReject) {
  951. _importReject({
  952. status: false
  953. });
  954. }
  955. }
  956. }
  957. function handleFileImport($xeTable, file, opts) {
  958. const internalData = $xeTable;
  959. const importOpts = $xeTable.computeImportOpts;
  960. const {
  961. importMethod,
  962. afterImportMethod
  963. } = opts;
  964. const {
  965. type,
  966. filename
  967. } = (0, _utils.parseFile)(file);
  968. // 检查类型,如果为自定义导出,则不需要校验类型
  969. if (!importMethod && !_xeUtils.default.includes(_xeUtils.default.keys(importOpts._typeMaps), type)) {
  970. if (opts.message !== false) {
  971. // 检测弹窗模块
  972. if (!_ui.VxeUI.modal) {
  973. (0, _log.errLog)('vxe.error.reqModule', ['Modal']);
  974. }
  975. _ui.VxeUI.modal.message({
  976. content: getI18n('vxe.error.notType', [type]),
  977. status: 'error'
  978. });
  979. }
  980. const params = {
  981. status: false
  982. };
  983. return Promise.reject(params);
  984. }
  985. const rest = new Promise((resolve, reject) => {
  986. const _importResolve = params => {
  987. resolve(params);
  988. $xeTable._importResolve = null;
  989. $xeTable._importReject = null;
  990. };
  991. const _importReject = params => {
  992. reject(params);
  993. $xeTable._importResolve = null;
  994. $xeTable._importReject = null;
  995. };
  996. $xeTable._importResolve = _importResolve;
  997. $xeTable._importReject = _importReject;
  998. if (window.FileReader) {
  999. const options = Object.assign({
  1000. mode: 'insertTop'
  1001. }, opts, {
  1002. type,
  1003. filename
  1004. });
  1005. if (options.remote) {
  1006. if (importMethod) {
  1007. Promise.resolve(importMethod({
  1008. file,
  1009. options,
  1010. $table: $xeTable
  1011. })).then(() => {
  1012. _importResolve({
  1013. status: true
  1014. });
  1015. }).catch(() => {
  1016. _importResolve({
  1017. status: true
  1018. });
  1019. });
  1020. } else {
  1021. _importResolve({
  1022. status: true
  1023. });
  1024. }
  1025. } else {
  1026. const {
  1027. tableFullColumn
  1028. } = internalData;
  1029. $xeTable.preventEvent(null, 'event.import', {
  1030. file,
  1031. options,
  1032. columns: tableFullColumn
  1033. }, () => {
  1034. const reader = new FileReader();
  1035. reader.onerror = () => {
  1036. (0, _log.errLog)('vxe.error.notType', [type]);
  1037. _importReject({
  1038. status: false
  1039. });
  1040. };
  1041. reader.onload = e => {
  1042. handleImport($xeTable, e.target.result, options);
  1043. };
  1044. reader.readAsText(file, options.encoding || 'UTF-8');
  1045. });
  1046. }
  1047. } else {
  1048. // 不支持的浏览器
  1049. (0, _log.errLog)('vxe.error.notExp');
  1050. _importResolve({
  1051. status: true
  1052. });
  1053. }
  1054. });
  1055. return rest.then(() => {
  1056. if (afterImportMethod) {
  1057. afterImportMethod({
  1058. status: true,
  1059. options: opts,
  1060. $table: $xeTable
  1061. });
  1062. }
  1063. }).catch(e => {
  1064. if (afterImportMethod) {
  1065. afterImportMethod({
  1066. status: false,
  1067. options: opts,
  1068. $table: $xeTable
  1069. });
  1070. }
  1071. return Promise.reject(e);
  1072. });
  1073. }
  1074. function handleCloseExport() {
  1075. if (_ui.VxeUI.modal) {
  1076. return _ui.VxeUI.modal.close('VXE_EXPORT_MODAL');
  1077. }
  1078. return Promise.resolve();
  1079. }
  1080. function handleFilterColumns(exportOpts, column, columns) {
  1081. return columns.some(item => {
  1082. if ((0, _util.isColumnInfo)(item)) {
  1083. return column.id === item.id;
  1084. } else if (_xeUtils.default.isString(item)) {
  1085. return column.field === item;
  1086. } else {
  1087. const colid = item.id || item.colId;
  1088. const type = item.type;
  1089. const field = item.field;
  1090. if (colid) {
  1091. return column.id === colid;
  1092. } else if (field && type) {
  1093. return column.field === field && column.type === type;
  1094. } else if (field) {
  1095. return column.field === field;
  1096. } else if (type) {
  1097. return column.type === type;
  1098. }
  1099. }
  1100. return false;
  1101. });
  1102. }
  1103. function handleFilterFields(exportOpts, column, includeFields, excludeFields) {
  1104. if (excludeFields) {
  1105. if (_xeUtils.default.includes(excludeFields, column.field)) {
  1106. return false;
  1107. }
  1108. }
  1109. if (includeFields) {
  1110. if (_xeUtils.default.includes(includeFields, column.field)) {
  1111. return true;
  1112. }
  1113. return false;
  1114. }
  1115. return exportOpts.original ? !!column.field : defaultFilterExportColumn(column);
  1116. }
  1117. function handleExportAndPrint($xeTable, options, isPrint) {
  1118. const props = $xeTable;
  1119. const reactData = $xeTable;
  1120. const internalData = $xeTable;
  1121. const $xeGrid = $xeTable.$xeGrid;
  1122. const $xeGantt = $xeTable.$xeGantt;
  1123. const $xeGGWrapper = $xeGrid || $xeGantt;
  1124. const {
  1125. treeConfig,
  1126. showHeader,
  1127. showFooter
  1128. } = props;
  1129. const {
  1130. initStore,
  1131. isGroup,
  1132. footerTableData,
  1133. exportStore,
  1134. exportParams
  1135. } = reactData;
  1136. const {
  1137. collectColumn,
  1138. mergeBodyList,
  1139. mergeFooterList
  1140. } = internalData;
  1141. const exportOpts = $xeTable.computeExportOpts;
  1142. const hasTree = treeConfig;
  1143. const customOpts = $xeTable.computeCustomOpts;
  1144. const selectRecords = $xeTable.getCheckboxRecords();
  1145. const proxyOpts = $xeGGWrapper ? $xeGGWrapper.computeProxyOpts : {};
  1146. const hasFooter = !!footerTableData.length;
  1147. const hasMerge = !!(mergeBodyList.length || mergeFooterList.length);
  1148. const defOpts = Object.assign({
  1149. message: true,
  1150. isHeader: showHeader,
  1151. isTitle: showHeader,
  1152. isFooter: showFooter,
  1153. isColgroup: isGroup,
  1154. isMerge: hasMerge,
  1155. useStyle: true,
  1156. current: 'current',
  1157. modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty'])
  1158. }, options);
  1159. const types = defOpts.types || _xeUtils.default.keys(exportOpts._typeMaps);
  1160. const modes = defOpts.modes || [];
  1161. const checkMethod = customOpts.checkMethod;
  1162. const exportColumns = collectColumn.slice(0);
  1163. const {
  1164. columns,
  1165. excludeFields,
  1166. includeFields
  1167. } = defOpts;
  1168. // 处理类型
  1169. const typeList = types.map(value => {
  1170. return {
  1171. value,
  1172. label: getI18n(`vxe.export.types.${value}`)
  1173. };
  1174. });
  1175. const modeList = modes.map(item => {
  1176. if (item && item.value) {
  1177. return {
  1178. value: item.value,
  1179. label: item.label || item.value
  1180. };
  1181. }
  1182. return {
  1183. value: item,
  1184. label: getI18n(`vxe.export.modes.${item}`)
  1185. };
  1186. });
  1187. // 默认选中
  1188. _xeUtils.default.eachTree(exportColumns, (column, index, items, path, parent) => {
  1189. const isColGroup = column.children && column.children.length > 0;
  1190. let isChecked = false;
  1191. if (columns && columns.length) {
  1192. isChecked = handleFilterColumns(defOpts, column, columns);
  1193. } else if (excludeFields || includeFields) {
  1194. isChecked = handleFilterFields(defOpts, column, includeFields, excludeFields);
  1195. } else {
  1196. isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column));
  1197. }
  1198. column.checked = isChecked;
  1199. column.halfChecked = false;
  1200. column.disabled = parent && parent.disabled || (checkMethod ? !checkMethod({
  1201. $table: $xeTable,
  1202. column
  1203. }) : false);
  1204. });
  1205. // 更新条件
  1206. Object.assign(exportStore, {
  1207. columns: exportColumns,
  1208. typeList,
  1209. modeList,
  1210. hasFooter,
  1211. hasMerge,
  1212. hasTree,
  1213. isPrint,
  1214. hasColgroup: isGroup,
  1215. visible: true
  1216. });
  1217. // 默认参数
  1218. Object.assign(exportParams, {
  1219. mode: selectRecords.length ? 'selected' : 'current'
  1220. }, defOpts);
  1221. const {
  1222. filename,
  1223. sheetName,
  1224. mode,
  1225. type
  1226. } = exportParams;
  1227. if (filename) {
  1228. if (_xeUtils.default.isFunction(filename)) {
  1229. exportParams.filename = filename({
  1230. options: defOpts,
  1231. $table: $xeTable,
  1232. $grid: $xeGrid,
  1233. $gantt: $xeGantt
  1234. });
  1235. } else {
  1236. exportParams.filename = `${filename}`;
  1237. }
  1238. }
  1239. if (sheetName) {
  1240. if (_xeUtils.default.isFunction(sheetName)) {
  1241. exportParams.sheetName = sheetName({
  1242. options: defOpts,
  1243. $table: $xeTable,
  1244. $grid: $xeGrid,
  1245. $gantt: $xeGantt
  1246. });
  1247. } else {
  1248. exportParams.sheetName = `${sheetName}`;
  1249. }
  1250. }
  1251. if (!modeList.some(item => item.value === mode)) {
  1252. exportParams.mode = modeList[0].value;
  1253. }
  1254. if (!typeList.some(item => item.value === type)) {
  1255. exportParams.type = typeList[0].value;
  1256. }
  1257. initStore.export = true;
  1258. return $xeTable.$nextTick();
  1259. }
  1260. const getConvertColumns = columns => {
  1261. const result = [];
  1262. columns.forEach(column => {
  1263. if (column.childNodes && column.childNodes.length) {
  1264. result.push(column);
  1265. result.push(...getConvertColumns(column.childNodes));
  1266. } else {
  1267. result.push(column);
  1268. }
  1269. });
  1270. return result;
  1271. };
  1272. const convertToRows = originColumns => {
  1273. let maxLevel = 1;
  1274. const traverse = (column, parent) => {
  1275. if (parent) {
  1276. column._level = parent._level + 1;
  1277. if (maxLevel < column._level) {
  1278. maxLevel = column._level;
  1279. }
  1280. }
  1281. if (column.childNodes && column.childNodes.length) {
  1282. let colSpan = 0;
  1283. column.childNodes.forEach(subColumn => {
  1284. traverse(subColumn, column);
  1285. colSpan += subColumn._colSpan;
  1286. });
  1287. column._colSpan = colSpan;
  1288. } else {
  1289. column._colSpan = 1;
  1290. }
  1291. };
  1292. originColumns.forEach(column => {
  1293. column._level = 1;
  1294. traverse(column);
  1295. });
  1296. const rows = [];
  1297. for (let i = 0; i < maxLevel; i++) {
  1298. rows.push([]);
  1299. }
  1300. const allColumns = getConvertColumns(originColumns);
  1301. allColumns.forEach(column => {
  1302. if (column.childNodes && column.childNodes.length) {
  1303. column._rowSpan = 1;
  1304. } else {
  1305. column._rowSpan = maxLevel - column._level + 1;
  1306. }
  1307. rows[column._level - 1].push(column);
  1308. });
  1309. return rows;
  1310. };
  1311. var _default = exports.default = {
  1312. methods: {
  1313. /**
  1314. * 导出文件,支持 csv/html/xml/txt
  1315. * 如果是树表格,则默认是导出所有节点
  1316. * 如果是启用了虚拟滚动,则只能导出数据源,可以配合 dataFilterMethod 函数转换数据
  1317. * @param {Object} options 参数
  1318. */
  1319. _exportData(options) {
  1320. const $xeTable = this;
  1321. const props = $xeTable;
  1322. const reactData = $xeTable;
  1323. const internalData = $xeTable;
  1324. const $xeGrid = $xeTable.$xeGrid;
  1325. const $xeGantt = $xeTable.$xeGantt;
  1326. const $xeGGWrapper = $xeGrid || $xeGantt;
  1327. const {
  1328. treeConfig,
  1329. showHeader,
  1330. showFooter
  1331. } = props;
  1332. const {
  1333. isGroup
  1334. } = reactData;
  1335. const {
  1336. tableFullColumn,
  1337. afterFullData,
  1338. afterTreeFullData,
  1339. collectColumn,
  1340. mergeBodyList,
  1341. mergeFooterList
  1342. } = internalData;
  1343. const exportOpts = $xeTable.computeExportOpts;
  1344. const treeOpts = $xeTable.computeTreeOpts;
  1345. const proxyOpts = $xeGGWrapper ? $xeGGWrapper.computeProxyOpts : {};
  1346. const hasMerge = !!(mergeBodyList.length || mergeFooterList.length);
  1347. const opts = Object.assign({
  1348. message: true,
  1349. isHeader: showHeader,
  1350. isTitle: showHeader,
  1351. isFooter: showFooter,
  1352. isColgroup: isGroup,
  1353. isMerge: hasMerge,
  1354. useStyle: true,
  1355. current: 'current',
  1356. modes: (proxyOpts.ajax && proxyOpts.ajax.queryAll ? ['all'] : []).concat(['current', 'selected', 'empty']),
  1357. download: true,
  1358. type: 'csv'
  1359. // filename: '',
  1360. // sheetName: '',
  1361. // original: false,
  1362. // isAllExpand: false,
  1363. // data: null,
  1364. // remote: false,
  1365. // dataFilterMethod: null,
  1366. // footerFilterMethod: null,
  1367. // exportMethod: null,
  1368. // columnFilterMethod: null,
  1369. // beforeExportMethod: null,
  1370. // afterExportMethod: null
  1371. }, exportOpts, options);
  1372. let {
  1373. filename,
  1374. sheetName,
  1375. type,
  1376. mode,
  1377. columns,
  1378. original,
  1379. columnFilterMethod,
  1380. beforeExportMethod,
  1381. includeFields,
  1382. excludeFields
  1383. } = opts;
  1384. let groups = [];
  1385. const selectRecords = $xeTable.getCheckboxRecords();
  1386. if (!mode) {
  1387. mode = selectRecords.length ? 'selected' : 'current';
  1388. }
  1389. let isCustomCol = false;
  1390. let customCols = [];
  1391. if (columns && columns.length) {
  1392. isCustomCol = true;
  1393. customCols = columns;
  1394. } else {
  1395. customCols = _xeUtils.default.searchTree(collectColumn, column => {
  1396. const isColGroup = column.children && column.children.length > 0;
  1397. let isChecked = false;
  1398. if (columns && columns.length) {
  1399. isChecked = handleFilterColumns(opts, column, columns);
  1400. } else if (excludeFields || includeFields) {
  1401. isChecked = handleFilterFields(opts, column, includeFields, excludeFields);
  1402. } else {
  1403. isChecked = column.visible && (isColGroup || defaultFilterExportColumn(column));
  1404. }
  1405. return isChecked;
  1406. }, {
  1407. children: 'children',
  1408. mapChildren: 'childNodes',
  1409. original: true
  1410. });
  1411. }
  1412. const handleOptions = Object.assign({}, opts, {
  1413. filename: '',
  1414. sheetName: ''
  1415. });
  1416. // 如果设置源数据,则默认导出设置了字段的列
  1417. if (!isCustomCol && !columnFilterMethod) {
  1418. columnFilterMethod = ({
  1419. column
  1420. }) => {
  1421. if (excludeFields) {
  1422. if (_xeUtils.default.includes(excludeFields, column.field)) {
  1423. return false;
  1424. }
  1425. }
  1426. if (includeFields) {
  1427. if (_xeUtils.default.includes(includeFields, column.field)) {
  1428. return true;
  1429. }
  1430. return false;
  1431. }
  1432. return original ? !!column.field : defaultFilterExportColumn(column);
  1433. };
  1434. handleOptions.columnFilterMethod = columnFilterMethod;
  1435. }
  1436. if (customCols) {
  1437. handleOptions._isCustomColumn = true;
  1438. groups = _xeUtils.default.searchTree(_xeUtils.default.mapTree(customCols, item => {
  1439. let targetColumn;
  1440. if (item) {
  1441. if ((0, _util.isColumnInfo)(item)) {
  1442. targetColumn = item;
  1443. } else if (_xeUtils.default.isString(item)) {
  1444. targetColumn = $xeTable.getColumnByField(item);
  1445. } else {
  1446. const colid = item.id || item.colId;
  1447. const type = item.type;
  1448. const field = item.field;
  1449. if (colid) {
  1450. targetColumn = $xeTable.getColumnById(colid);
  1451. } else if (field && type) {
  1452. targetColumn = tableFullColumn.find(column => column.field === field && column.type === type);
  1453. } else if (field) {
  1454. targetColumn = $xeTable.getColumnByField(field);
  1455. } else if (type) {
  1456. targetColumn = tableFullColumn.find(column => column.type === type);
  1457. }
  1458. }
  1459. return targetColumn || {};
  1460. }
  1461. }, {
  1462. children: 'childNodes',
  1463. mapChildren: '_children'
  1464. }), (column, index) => (0, _util.isColumnInfo)(column) && (!columnFilterMethod || columnFilterMethod({
  1465. $table: $xeTable,
  1466. $grid: $xeGrid,
  1467. $gantt: $xeGantt,
  1468. column: column,
  1469. $columnIndex: index
  1470. })), {
  1471. children: '_children',
  1472. mapChildren: 'childNodes',
  1473. original: true
  1474. });
  1475. } else {
  1476. groups = _xeUtils.default.searchTree(isGroup ? collectColumn : tableFullColumn, (column, index) => column.visible && (!columnFilterMethod || columnFilterMethod({
  1477. $table: $xeTable,
  1478. $grid: $xeGrid,
  1479. $gantt: $xeGantt,
  1480. column,
  1481. $columnIndex: index
  1482. })), {
  1483. children: 'children',
  1484. mapChildren: 'childNodes',
  1485. original: true
  1486. });
  1487. }
  1488. // 获取所有列
  1489. const cols = [];
  1490. _xeUtils.default.eachTree(groups, column => {
  1491. const isColGroup = column.children && column.children.length;
  1492. if (!isColGroup) {
  1493. cols.push(column);
  1494. }
  1495. }, {
  1496. children: 'childNodes'
  1497. });
  1498. // 构建分组层级
  1499. handleOptions.columns = cols;
  1500. handleOptions.colgroups = convertToRows(groups);
  1501. if (filename) {
  1502. if (_xeUtils.default.isFunction(filename)) {
  1503. handleOptions.filename = filename({
  1504. options: opts,
  1505. $table: $xeTable,
  1506. $grid: $xeGrid,
  1507. $gantt: $xeGantt
  1508. });
  1509. } else {
  1510. handleOptions.filename = `${filename}`;
  1511. }
  1512. }
  1513. if (!handleOptions.filename) {
  1514. handleOptions.filename = getI18n(handleOptions.original ? 'vxe.table.expOriginFilename' : 'vxe.table.expFilename', [_xeUtils.default.toDateString(Date.now(), 'yyyyMMddHHmmss')]);
  1515. }
  1516. if (sheetName) {
  1517. if (_xeUtils.default.isFunction(sheetName)) {
  1518. handleOptions.sheetName = sheetName({
  1519. options: opts,
  1520. $table: $xeTable,
  1521. $grid: $xeGrid,
  1522. $gantt: $xeGantt
  1523. });
  1524. } else {
  1525. handleOptions.sheetName = `${sheetName}`;
  1526. }
  1527. }
  1528. if (!handleOptions.sheetName) {
  1529. handleOptions.sheetName = document.title || '';
  1530. }
  1531. // 检查类型,如果为自定义导出,则不需要校验类型
  1532. if (!handleOptions.exportMethod && !_xeUtils.default.includes(_xeUtils.default.keys(exportOpts._typeMaps), type)) {
  1533. (0, _log.errLog)('vxe.error.notType', [type]);
  1534. if (['xlsx', 'pdf'].includes(type)) {
  1535. (0, _log.warnLog)('vxe.error.reqPlugin', [4, 'plugin-export-xlsx']);
  1536. }
  1537. const params = {
  1538. status: false
  1539. };
  1540. return Promise.reject(params);
  1541. }
  1542. if (!handleOptions.print) {
  1543. if (beforeExportMethod) {
  1544. beforeExportMethod({
  1545. options: handleOptions,
  1546. $table: $xeTable,
  1547. $grid: $xeGrid,
  1548. $gantt: $xeGantt
  1549. });
  1550. }
  1551. }
  1552. if (!handleOptions.data) {
  1553. handleOptions.data = [];
  1554. if (mode === 'selected') {
  1555. if (['html', 'pdf'].indexOf(type) > -1 && treeConfig) {
  1556. handleOptions.data = _xeUtils.default.searchTree($xeTable.getTableData().fullData, item => $xeTable.findRowIndexOf(selectRecords, item) > -1, Object.assign({}, treeOpts, {
  1557. data: '_row'
  1558. }));
  1559. } else {
  1560. handleOptions.data = selectRecords;
  1561. }
  1562. } else if (mode === 'all') {
  1563. if (!$xeGGWrapper) {
  1564. (0, _log.errLog)('vxe.error.errProp', ['all', 'mode=current,selected']);
  1565. }
  1566. if ($xeGGWrapper && !handleOptions.remote) {
  1567. const gridReactData = $xeGGWrapper;
  1568. const proxyOpts = $xeGGWrapper.computeProxyOpts;
  1569. const {
  1570. sortData
  1571. } = gridReactData;
  1572. const {
  1573. beforeQueryAll,
  1574. afterQueryAll,
  1575. ajax = {}
  1576. } = proxyOpts;
  1577. const resConfigs = proxyOpts.response || proxyOpts.props || {};
  1578. const ajaxMethods = ajax.queryAll;
  1579. const queryAllSuccessMethods = ajax.queryAllSuccess;
  1580. const queryAllErrorMethods = ajax.queryAllError;
  1581. if (!ajaxMethods) {
  1582. (0, _log.errLog)('vxe.error.notFunc', ['proxy-config.ajax.queryAll']);
  1583. }
  1584. if (ajaxMethods) {
  1585. const params = {
  1586. $table: $xeTable,
  1587. $grid: $xeGrid,
  1588. $gantt: $xeGantt,
  1589. sort: sortData.length ? sortData[0] : {},
  1590. sorts: sortData,
  1591. filters: gridReactData.filterData,
  1592. form: gridReactData.formData,
  1593. options: handleOptions
  1594. };
  1595. return Promise.resolve((beforeQueryAll || ajaxMethods)(params)).then(rest => {
  1596. const listProp = resConfigs.list;
  1597. handleOptions.data = (listProp ? _xeUtils.default.isFunction(listProp) ? listProp({
  1598. data: rest,
  1599. $table: $xeTable,
  1600. $grid: $xeGrid,
  1601. $gantt: $xeGantt
  1602. }) : _xeUtils.default.get(rest, listProp) : rest) || [];
  1603. if (afterQueryAll) {
  1604. afterQueryAll(params);
  1605. }
  1606. if (queryAllSuccessMethods) {
  1607. queryAllSuccessMethods(Object.assign(Object.assign({}, params), {
  1608. response: rest
  1609. }));
  1610. }
  1611. return handleExport($xeTable, handleOptions);
  1612. }).catch(rest => {
  1613. if (queryAllErrorMethods) {
  1614. queryAllErrorMethods(Object.assign(Object.assign({}, params), {
  1615. response: rest
  1616. }));
  1617. }
  1618. });
  1619. }
  1620. }
  1621. } else if (mode === 'current') {
  1622. handleOptions.data = treeConfig ? afterTreeFullData : afterFullData;
  1623. }
  1624. } else {
  1625. handleOptions._isCustomData = true;
  1626. }
  1627. return handleExport($xeTable, handleOptions);
  1628. },
  1629. _importByFile(file, options) {
  1630. const $xeTable = this;
  1631. const opts = Object.assign({}, options);
  1632. const {
  1633. beforeImportMethod
  1634. } = opts;
  1635. if (beforeImportMethod) {
  1636. beforeImportMethod({
  1637. options: opts,
  1638. $table: $xeTable
  1639. });
  1640. }
  1641. return handleFileImport($xeTable, file, opts);
  1642. },
  1643. _importData(options) {
  1644. const $xeTable = this;
  1645. const {
  1646. importOpts
  1647. } = this;
  1648. const opts = Object.assign({
  1649. types: _xeUtils.default.keys(importOpts._typeMaps)
  1650. // beforeImportMethod: null,
  1651. // afterImportMethod: null
  1652. }, importOpts, options);
  1653. const {
  1654. beforeImportMethod,
  1655. afterImportMethod
  1656. } = opts;
  1657. if (beforeImportMethod) {
  1658. beforeImportMethod({
  1659. options: opts,
  1660. $table: this
  1661. });
  1662. }
  1663. return _ui.VxeUI.readFile(opts).catch(e => {
  1664. if (afterImportMethod) {
  1665. afterImportMethod({
  1666. status: false,
  1667. options: opts,
  1668. $table: $xeTable
  1669. });
  1670. }
  1671. return Promise.reject(e);
  1672. }).then(params => {
  1673. const {
  1674. file
  1675. } = params;
  1676. return handleFileImport($xeTable, file, opts);
  1677. });
  1678. },
  1679. _saveFile(options) {
  1680. return _ui.VxeUI.saveFile(options);
  1681. },
  1682. _readFile(options) {
  1683. return _ui.VxeUI.readFile(options);
  1684. },
  1685. _print(options) {
  1686. const $xeTable = this;
  1687. const $xeGrid = $xeTable.$xeGrid;
  1688. const $xeGantt = $xeTable.$xeGantt;
  1689. const printOpts = $xeTable.computePrintOpts;
  1690. const opts = Object.assign({
  1691. original: false
  1692. // beforePrintMethod
  1693. }, printOpts, options, {
  1694. type: 'html',
  1695. download: false,
  1696. remote: false,
  1697. print: true
  1698. });
  1699. const {
  1700. sheetName
  1701. } = opts;
  1702. let printTitle = '';
  1703. if (sheetName) {
  1704. if (_xeUtils.default.isFunction(sheetName)) {
  1705. printTitle = sheetName({
  1706. options: opts,
  1707. $table: $xeTable,
  1708. $grid: $xeGrid,
  1709. $gantt: $xeGantt
  1710. });
  1711. } else {
  1712. printTitle = `${sheetName}`;
  1713. }
  1714. }
  1715. if (!printTitle) {
  1716. printTitle = document.title || '';
  1717. }
  1718. const beforePrintMethod = opts.beforePrintMethod;
  1719. const tableHtml = opts.html || opts.content;
  1720. return new Promise((resolve, reject) => {
  1721. if (_ui.VxeUI.print) {
  1722. if (tableHtml) {
  1723. resolve(_ui.VxeUI.print({
  1724. title: printTitle,
  1725. html: tableHtml,
  1726. customStyle: opts.style,
  1727. beforeMethod: beforePrintMethod ? ({
  1728. html
  1729. }) => {
  1730. return beforePrintMethod({
  1731. html,
  1732. content: html,
  1733. options: opts,
  1734. $table: $xeTable,
  1735. $grid: $xeGrid,
  1736. $gantt: $xeGantt
  1737. });
  1738. } : undefined
  1739. }));
  1740. } else {
  1741. resolve($xeTable.exportData(opts).then(({
  1742. content
  1743. }) => {
  1744. return _ui.VxeUI.print({
  1745. title: printTitle,
  1746. html: content,
  1747. customStyle: opts.style,
  1748. beforeMethod: beforePrintMethod ? ({
  1749. html
  1750. }) => {
  1751. return beforePrintMethod({
  1752. html,
  1753. content: html,
  1754. options: opts,
  1755. $table: $xeTable,
  1756. $grid: $xeGrid,
  1757. $gantt: $xeGantt
  1758. });
  1759. } : undefined
  1760. });
  1761. }));
  1762. }
  1763. } else {
  1764. const e = {
  1765. status: false
  1766. };
  1767. reject(e);
  1768. }
  1769. });
  1770. },
  1771. _getPrintHtml(options) {
  1772. const $xeTable = this;
  1773. const printOpts = $xeTable.computePrintOpts;
  1774. const opts = Object.assign({
  1775. original: false
  1776. // beforePrintMethod
  1777. }, printOpts, options, {
  1778. type: 'html',
  1779. download: false,
  1780. remote: false,
  1781. print: true
  1782. });
  1783. return $xeTable.exportData(opts).then(({
  1784. content
  1785. }) => {
  1786. return {
  1787. html: content
  1788. };
  1789. });
  1790. },
  1791. _closeImport() {
  1792. if (_ui.VxeUI.modal) {
  1793. return _ui.VxeUI.modal.close('VXE_IMPORT_MODAL');
  1794. }
  1795. return Promise.resolve();
  1796. },
  1797. _openImport(options) {
  1798. const $xeTable = this;
  1799. const props = $xeTable;
  1800. const reactData = $xeTable;
  1801. const {
  1802. treeConfig,
  1803. importConfig
  1804. } = props;
  1805. const {
  1806. initStore,
  1807. importStore,
  1808. importParams
  1809. } = reactData;
  1810. const importOpts = $xeTable.computeImportOpts;
  1811. const defOpts = Object.assign({
  1812. mode: 'insertTop',
  1813. message: true,
  1814. types: _xeUtils.default.keys(importOpts._typeMaps),
  1815. modes: ['insertTop', 'covering']
  1816. }, importOpts, options);
  1817. const types = defOpts.types || [];
  1818. const modes = defOpts.modes || [];
  1819. const isTree = !!treeConfig;
  1820. if (isTree) {
  1821. if (defOpts.message) {
  1822. _ui.VxeUI.modal.message({
  1823. content: getI18n('vxe.error.treeNotImp'),
  1824. status: 'error'
  1825. });
  1826. }
  1827. return;
  1828. }
  1829. if (!importConfig) {
  1830. (0, _log.errLog)('vxe.error.reqProp', ['import-config']);
  1831. }
  1832. // 处理类型
  1833. const typeList = types.map(value => {
  1834. return {
  1835. value,
  1836. label: getI18n(`vxe.export.types.${value}`)
  1837. };
  1838. });
  1839. const modeList = modes.map(item => {
  1840. if (item && item.value) {
  1841. return {
  1842. value: item.value,
  1843. label: item.label || item.value
  1844. };
  1845. }
  1846. return {
  1847. value: item,
  1848. label: getI18n(`vxe.import.modes.${item}`)
  1849. };
  1850. });
  1851. Object.assign(importStore, {
  1852. file: null,
  1853. type: '',
  1854. filename: '',
  1855. modeList,
  1856. typeList,
  1857. visible: true
  1858. });
  1859. Object.assign(importParams, defOpts);
  1860. if (!modeList.some(item => item.value === importParams.mode)) {
  1861. importParams.mode = modeList[0].value;
  1862. }
  1863. initStore.import = true;
  1864. },
  1865. _closeExport: handleCloseExport,
  1866. _openExport(options) {
  1867. const $xeTable = this;
  1868. const props = $xeTable;
  1869. const exportOpts = $xeTable.computeExportOpts;
  1870. const defOpts = Object.assign({
  1871. message: true,
  1872. types: _xeUtils.default.keys(exportOpts._typeMaps)
  1873. }, exportOpts, options);
  1874. if (!props.exportConfig) {
  1875. (0, _log.errLog)('vxe.error.reqProp', ['export-config']);
  1876. }
  1877. return handleExportAndPrint($xeTable, defOpts);
  1878. },
  1879. _closePrint: handleCloseExport,
  1880. _openPrint(options) {
  1881. const $xeTable = this;
  1882. const props = $xeTable;
  1883. const printOpts = $xeTable.computePrintOpts;
  1884. const defOpts = Object.assign({
  1885. message: true
  1886. }, printOpts, options);
  1887. if (!props.printConfig) {
  1888. (0, _log.errLog)('vxe.error.reqProp', ['print-config']);
  1889. }
  1890. return handleExportAndPrint($xeTable, defOpts, true);
  1891. }
  1892. }
  1893. };