优化导出
This commit is contained in:
20
README.md
20
README.md
@@ -1,26 +1,26 @@
|
||||
# vxe-table-plugin-export
|
||||
# vxe-table-plugin-export-xlsx
|
||||
|
||||
[](https://gitee.com/xuliangzhan_admin/vxe-table-plugin-export/stargazers)
|
||||
[](https://www.npmjs.org/package/vxe-table-plugin-export)
|
||||
[](http://npm-stat.com/charts.html?package=vxe-table-plugin-export)
|
||||
[](https://unpkg.com/vxe-table-plugin-export/dist/index.min.js)
|
||||
[](https://github.com/xuliangzhan/vxe-table-plugin-export/blob/master/LICENSE)
|
||||
[](https://gitee.com/xuliangzhan_admin/vxe-table-plugin-export-xlsx/stargazers)
|
||||
[](https://www.npmjs.org/package/vxe-table-plugin-export-xlsx)
|
||||
[](http://npm-stat.com/charts.html?package=vxe-table-plugin-export-xlsx)
|
||||
[](https://unpkg.com/vxe-table-plugin-export-xlsx/dist/index.min.js)
|
||||
[](https://github.com/xuliangzhan/vxe-table-plugin-export-xlsx/blob/master/LICENSE)
|
||||
|
||||
基于 [vxe-table](https://github.com/xuliangzhan/vxe-table) 表格的增强插件,支持导出 xlsx 等格式
|
||||
基于 [vxe-table](https://github.com/xuliangzhan/vxe-table) 表格的增强插件,支持导出 xlsx 格式
|
||||
|
||||
## Installing
|
||||
|
||||
```shell
|
||||
npm install xe-utils vxe-table vxe-table-plugin-export xlsx
|
||||
npm install xe-utils vxe-table vxe-table-plugin-export-xlsx xlsx
|
||||
```
|
||||
|
||||
```javascript
|
||||
import Vue from 'vue'
|
||||
import VXETable from 'vxe-table'
|
||||
import VXETablePluginExport from 'vxe-table-plugin-export'
|
||||
import VXETablePluginExportXLSX from 'vxe-table-plugin-export-xlsx'
|
||||
|
||||
Vue.use(VXETable)
|
||||
VXETable.use(VXETablePluginExport)
|
||||
VXETable.use(VXETablePluginExportXLSX)
|
||||
```
|
||||
|
||||
## Demo
|
||||
|
||||
83
dist/index.common.js
vendored
83
dist/index.common.js
vendored
File diff suppressed because one or more lines are too long
87
dist/index.js
vendored
87
dist/index.js
vendored
@@ -1,6 +1,6 @@
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define("vxe-table-plugin-export", ["exports", "xe-utils", "xlsx"], factory);
|
||||
define("vxe-table-plugin-export-xlsx", ["exports", "xe-utils", "xlsx"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("xe-utils"), require("xlsx"));
|
||||
} else {
|
||||
@@ -8,21 +8,17 @@
|
||||
exports: {}
|
||||
};
|
||||
factory(mod.exports, global.XEUtils, global.XLSX);
|
||||
global.VXETablePluginExport = mod.exports.default;
|
||||
global.VXETablePluginExportXLSX = mod.exports.default;
|
||||
}
|
||||
})(this, function (_exports, _xeUtils, XLSX) {
|
||||
})(this, function (_exports, _xeUtils, _xlsx) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(_exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
_exports["default"] = _exports.VXETablePluginExport = void 0;
|
||||
_exports["default"] = _exports.VXETablePluginExportXLSX = void 0;
|
||||
_xeUtils = _interopRequireDefault(_xeUtils);
|
||||
XLSX = _interopRequireWildcard(XLSX);
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
_xlsx = _interopRequireDefault(_xlsx);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
@@ -54,14 +50,29 @@
|
||||
|
||||
if (isHeader) {
|
||||
columns.forEach(function (column) {
|
||||
colHead[column.id] = (original ? column.property : column.getTitle()) || '';
|
||||
colHead[column.id] = _xeUtils["default"].toString(original ? column.property : column.getTitle());
|
||||
});
|
||||
}
|
||||
|
||||
var rowList = datas.map(function (row) {
|
||||
var rowList = datas.map(function (row, rowIndex) {
|
||||
var item = {};
|
||||
columns.forEach(function (column) {
|
||||
item[column.id] = original ? _xeUtils["default"].get(row, column.property) : row[column.id];
|
||||
columns.forEach(function (column, columnIndex) {
|
||||
var cellValue;
|
||||
var property = column.property;
|
||||
var isIndex = column.type === 'index';
|
||||
|
||||
if (!original || isIndex) {
|
||||
cellValue = isIndex ? column.indexMethod ? column.indexMethod({
|
||||
row: row,
|
||||
rowIndex: rowIndex,
|
||||
column: column,
|
||||
columnIndex: columnIndex
|
||||
}) : rowIndex + 1 : row[column.id];
|
||||
} else {
|
||||
cellValue = _xeUtils["default"].get(row, property);
|
||||
}
|
||||
|
||||
item[column.id] = cellValue;
|
||||
});
|
||||
return item;
|
||||
});
|
||||
@@ -78,17 +89,21 @@
|
||||
});
|
||||
}
|
||||
|
||||
var book = XLSX.utils.book_new();
|
||||
var sheet = XLSX.utils.json_to_sheet((isHeader ? [colHead] : []).concat(rowList).concat(footList), {
|
||||
var book = _xlsx["default"].utils.book_new();
|
||||
|
||||
var sheet = _xlsx["default"].utils.json_to_sheet((isHeader ? [colHead] : []).concat(rowList).concat(footList), {
|
||||
skipHeader: true
|
||||
}); // 转换数据
|
||||
|
||||
XLSX.utils.book_append_sheet(book, sheet, sheetName);
|
||||
var wbout = XLSX.write(book, {
|
||||
|
||||
_xlsx["default"].utils.book_append_sheet(book, sheet, sheetName);
|
||||
|
||||
var wbout = _xlsx["default"].write(book, {
|
||||
bookType: type,
|
||||
bookSST: false,
|
||||
type: 'binary'
|
||||
});
|
||||
|
||||
var blob = new Blob([toBuffer(wbout)], {
|
||||
type: 'application/octet-stream'
|
||||
}); // 保存导出
|
||||
@@ -109,7 +124,7 @@
|
||||
type = options.type;
|
||||
|
||||
if (navigator.msSaveBlob) {
|
||||
navigator.msSaveBlob(blob, filename);
|
||||
navigator.msSaveBlob(blob, "".concat(filename, ".").concat(type));
|
||||
} else {
|
||||
var linkElem = document.createElement('a');
|
||||
linkElem.target = '_blank';
|
||||
@@ -183,10 +198,12 @@
|
||||
var fileReader = new FileReader();
|
||||
|
||||
fileReader.onload = function (e) {
|
||||
var workbook = XLSX.read(e.target.result, {
|
||||
var workbook = _xlsx["default"].read(e.target.result, {
|
||||
type: 'binary'
|
||||
});
|
||||
var csvData = XLSX.utils.sheet_to_csv(workbook.Sheets.Sheet1);
|
||||
|
||||
var csvData = _xlsx["default"].utils.sheet_to_csv(workbook.Sheets.Sheet1);
|
||||
|
||||
var rest = parseCsv(columns, csvData);
|
||||
var fields = rest.fields,
|
||||
rows = rest.rows;
|
||||
@@ -230,26 +247,24 @@
|
||||
}
|
||||
|
||||
function handleImportEvent(params) {
|
||||
switch (params.options.type) {
|
||||
case 'xlsx':
|
||||
importXLSX(params);
|
||||
return false;
|
||||
if (params.options.type === 'xlsx') {
|
||||
importXLSX(params);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleExportEvent(params) {
|
||||
switch (params.options.type) {
|
||||
case 'xlsx':
|
||||
exportXLSX(params);
|
||||
return false;
|
||||
if (params.options.type === 'xlsx') {
|
||||
exportXLSX(params);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式
|
||||
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 格式
|
||||
*/
|
||||
|
||||
|
||||
var VXETablePluginExport = {
|
||||
var VXETablePluginExportXLSX = {
|
||||
install: function install(xtable) {
|
||||
Object.assign(xtable.types, {
|
||||
xlsx: 1
|
||||
@@ -258,21 +273,21 @@
|
||||
'event.import': handleImportEvent,
|
||||
'event.export': handleExportEvent
|
||||
});
|
||||
VXETablePluginExport.t = xtable.t;
|
||||
VXETablePluginExportXLSX.t = xtable.t;
|
||||
}
|
||||
};
|
||||
_exports.VXETablePluginExport = VXETablePluginExport;
|
||||
_exports.VXETablePluginExportXLSX = VXETablePluginExportXLSX;
|
||||
|
||||
function i18n(key) {
|
||||
if (VXETablePluginExport.t) {
|
||||
return VXETablePluginExport.t(key);
|
||||
if (VXETablePluginExportXLSX.t) {
|
||||
return VXETablePluginExportXLSX.t(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && window.VXETable) {
|
||||
window.VXETable.use(VXETablePluginExport);
|
||||
window.VXETable.use(VXETablePluginExportXLSX);
|
||||
}
|
||||
|
||||
var _default = VXETablePluginExport;
|
||||
var _default = VXETablePluginExportXLSX;
|
||||
_exports["default"] = _default;
|
||||
});
|
||||
2
dist/index.min.js
vendored
2
dist/index.min.js
vendored
@@ -1 +1 @@
|
||||
!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-export",["exports","xe-utils","xlsx"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"),require("xlsx"));else{var r={exports:{}};t(r.exports,e.XEUtils,e.XLSX),e.VXETablePluginExport=r.exports.default}}(this,function(e,y,g){"use strict";var t;function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function r(e){var n=e.$table,t=e.options,o=e.columns,r=e.datas,a=t.sheetName,i=t.type,s=t.isHeader,l=t.isFooter,u=t.original,c=t.message,f=t.footerFilterMethod,p={},d=[];s&&o.forEach(function(e){p[e.id]=(u?e.property:e.getTitle())||""});var v=r.map(function(t){var r={};return o.forEach(function(e){r[e.id]=u?y.default.get(t,e.property):t[e.id]}),r});if(l){var b=n.footerData;(f?b.filter(f):b).forEach(function(t){var r={};o.forEach(function(e){r[e.id]=t[n.getColumnIndex(e)]||""}),d.push(r)})}var m=g.utils.book_new(),h=g.utils.json_to_sheet((s?[p]:[]).concat(v).concat(d),{skipHeader:!0});g.utils.book_append_sheet(m,h,a);var x=g.write(m,{bookType:i,bookSST:!1,type:"binary"});!function(e,t){if(window.Blob){var r=t.filename,n=t.type;if(navigator.msSaveBlob)navigator.msSaveBlob(e,r);else{var o=document.createElement("a");o.target="_blank",o.download="".concat(r,".").concat(n),o.href=URL.createObjectURL(e),document.body.appendChild(o),o.click(),document.body.removeChild(o)}}else console.error(w("vxe.error.notExp"))}(new Blob([function(e){for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),n=0;n!==e.length;++n)r[n]=255&e.charCodeAt(n);return t}(x)],{type:"application/octet-stream"}),t),!1!==c&&n.$XModal.message({message:w("vxe.table.expSuccess"),status:"success"})}function f(e){return e.replace(/^"/,"").replace(/"$/,"")}function n(e){var i=e.$table,s=e.columns,l=e.options,t=e.file,u=i._importCallback,c=i._importResolve,r=new FileReader;r.onload=function(e){var t=g.read(e.target.result,{type:"binary"}),r=function(e,t){var r=t.split("\n"),n=[],o=[];if(r.length){var a=r.slice(1);r[0].split(",").forEach(function(e){var t=f(e);t&&n.push(t)}),a.forEach(function(e){if(e){var r={};e.split(",").forEach(function(e,t){r[n[t]]=f(e)}),o.push(r)}})}return{fields:n,rows:o}}(0,g.utils.sheet_to_csv(t.Sheets.Sheet1)),n=r.fields,o=r.rows,a=function(e,t){var r=[];return e.forEach(function(e){var t=e.property;t&&r.push(t)}),r.every(function(e){return t.includes(e)})}(s,n);a?(i.createData(o).then(function(e){"append"===l.mode?i.insertAt(e,-1):i.reloadData(e)}),!1!==l.message&&i.$XModal.message({message:w("vxe.table.impSuccess"),status:"success"})):!1!==l.message&&i.$XModal.message({message:w("vxe.error.impFields"),status:"error"}),c?(c(a),i._importResolve=null):u&&(u(a),i._importCallback=null)},r.readAsBinaryString(t)}function o(e){switch(e.options.type){case"xlsx":return n(e),!1}}function a(e){switch(e.options.type){case"xlsx":return r(e),!1}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExport=void 0,y=(t=y)&&t.__esModule?t:{default:t},g=function(e){if(e&&e.__esModule)return e;var t=i();if(t&&t.has(e))return t.get(e);var r={};if(null!=e){var n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var a=n?Object.getOwnPropertyDescriptor(e,o):null;a&&(a.get||a.set)?Object.defineProperty(r,o,a):r[o]=e[o]}}r.default=e,t&&t.set(e,r);return r}(g);var s={install:function(e){Object.assign(e.types,{xlsx:1}),e.interceptor.mixin({"event.import":o,"event.export":a}),s.t=e.t}};function w(e){if(s.t)return s.t(e)}e.VXETablePluginExport=s,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(s);var l=s;e.default=l});
|
||||
!function(e,t){if("function"==typeof define&&define.amd)define("vxe-table-plugin-export-xlsx",["exports","xe-utils","xlsx"],t);else if("undefined"!=typeof exports)t(exports,require("xe-utils"),require("xlsx"));else{var n={exports:{}};t(n.exports,e.XEUtils,e.XLSX),e.VXETablePluginExportXLSX=n.exports.default}}(this,function(e,g,y){"use strict";function t(e){return e&&e.__esModule?e:{default:e}}function n(e){var o=e.$table,t=e.options,r=e.columns,n=e.datas,a=t.sheetName,i=t.type,s=t.isHeader,l=t.isFooter,u=t.original,c=t.message,f=t.footerFilterMethod,d={},p=[];s&&r.forEach(function(e){d[e.id]=g.default.toString(u?e.property:e.getTitle())});var v=n.map(function(a,i){var s={};return r.forEach(function(e,t){var n,o=e.property,r="index"===e.type;n=!u||r?r?e.indexMethod?e.indexMethod({row:a,rowIndex:i,column:e,columnIndex:t}):i+1:a[e.id]:g.default.get(a,o),s[e.id]=n}),s});if(l){var x=o.footerData;(f?x.filter(f):x).forEach(function(t){var n={};r.forEach(function(e){n[e.id]=t[o.getColumnIndex(e)]||""}),p.push(n)})}var m=y.default.utils.book_new(),h=y.default.utils.json_to_sheet((s?[d]:[]).concat(v).concat(p),{skipHeader:!0});y.default.utils.book_append_sheet(m,h,a);var b=y.default.write(m,{bookType:i,bookSST:!1,type:"binary"});!function(e,t){if(window.Blob){var n=t.filename,o=t.type;if(navigator.msSaveBlob)navigator.msSaveBlob(e,"".concat(n,".").concat(o));else{var r=document.createElement("a");r.target="_blank",r.download="".concat(n,".").concat(o),r.href=URL.createObjectURL(e),document.body.appendChild(r),r.click(),document.body.removeChild(r)}}else console.error(w("vxe.error.notExp"))}(new Blob([function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),o=0;o!==e.length;++o)n[o]=255&e.charCodeAt(o);return t}(b)],{type:"application/octet-stream"}),t),!1!==c&&o.$XModal.message({message:w("vxe.table.expSuccess"),status:"success"})}function f(e){return e.replace(/^"/,"").replace(/"$/,"")}function o(e){var i=e.$table,s=e.columns,l=e.options,t=e.file,u=i._importCallback,c=i._importResolve,n=new FileReader;n.onload=function(e){var t=y.default.read(e.target.result,{type:"binary"}),n=function(e,t){var n=t.split("\n"),o=[],r=[];if(n.length){var a=n.slice(1);n[0].split(",").forEach(function(e){var t=f(e);t&&o.push(t)}),a.forEach(function(e){if(e){var n={};e.split(",").forEach(function(e,t){n[o[t]]=f(e)}),r.push(n)}})}return{fields:o,rows:r}}(0,y.default.utils.sheet_to_csv(t.Sheets.Sheet1)),o=n.fields,r=n.rows,a=function(e,t){var n=[];return e.forEach(function(e){var t=e.property;t&&n.push(t)}),n.every(function(e){return t.includes(e)})}(s,o);a?(i.createData(r).then(function(e){"append"===l.mode?i.insertAt(e,-1):i.reloadData(e)}),!1!==l.message&&i.$XModal.message({message:w("vxe.table.impSuccess"),status:"success"})):!1!==l.message&&i.$XModal.message({message:w("vxe.error.impFields"),status:"error"}),c?(c(a),i._importResolve=null):u&&(u(a),i._importCallback=null)},n.readAsBinaryString(t)}function r(e){if("xlsx"===e.options.type)return o(e),!1}function a(e){if("xlsx"===e.options.type)return n(e),!1}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExportXLSX=void 0,g=t(g),y=t(y);var i={install:function(e){Object.assign(e.types,{xlsx:1}),e.interceptor.mixin({"event.import":r,"event.export":a}),i.t=e.t}};function w(e){if(i.t)return i.t(e)}e.VXETablePluginExportXLSX=i,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(i);var s=i;e.default=s});
|
||||
@@ -8,10 +8,10 @@ const sourcemaps = require('gulp-sourcemaps')
|
||||
const ts = require('gulp-typescript')
|
||||
const pack = require('./package.json')
|
||||
|
||||
const exportModuleName = 'VXETablePluginExport'
|
||||
const exportModuleName = 'VXETablePluginExportXLSX'
|
||||
|
||||
gulp.task('build_commonjs', function () {
|
||||
return gulp.src(['depend.ts', 'index.ts'])
|
||||
return gulp.src(['index.d.ts', 'depend.ts', 'index.ts'])
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(ts({
|
||||
strict: true,
|
||||
@@ -32,7 +32,7 @@ gulp.task('build_commonjs', function () {
|
||||
})
|
||||
|
||||
gulp.task('build_umd', function () {
|
||||
return gulp.src(['depend.ts', 'index.ts'])
|
||||
return gulp.src(['index.d.ts', 'depend.ts', 'index.ts'])
|
||||
.pipe(ts({
|
||||
strict: true,
|
||||
moduleResolution: 'node',
|
||||
|
||||
15
index.d.ts
vendored
Normal file
15
index.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
declare module 'xlsx' {
|
||||
interface utils {
|
||||
book_new(): any;
|
||||
json_to_sheet(list: any[], options: any): any;
|
||||
sheet_to_csv(Sheet: any): any;
|
||||
book_append_sheet(book: any, sheet: any, sheetName: string): any;
|
||||
}
|
||||
interface XLSXMethods {
|
||||
utils: utils;
|
||||
read(result: any, options: any): any;
|
||||
write(book: any, options: any): any;
|
||||
}
|
||||
const XLSX: XLSXMethods;
|
||||
export default XLSX
|
||||
}
|
||||
52
index.ts
52
index.ts
@@ -1,6 +1,6 @@
|
||||
import XEUtils from 'xe-utils/methods/xe-utils'
|
||||
import VXETable from 'vxe-table/lib/vxe-table'
|
||||
import * as XLSX from 'xlsx'
|
||||
import XLSX from 'xlsx'
|
||||
|
||||
function toBuffer(wbout: any) {
|
||||
let buf = new ArrayBuffer(wbout.length)
|
||||
@@ -16,19 +16,27 @@ function exportXLSX(params: any) {
|
||||
const footList: any[] = []
|
||||
if (isHeader) {
|
||||
columns.forEach((column: any) => {
|
||||
colHead[column.id] = (original ? column.property : column.getTitle()) || ''
|
||||
colHead[column.id] = XEUtils.toString(original ? column.property : column.getTitle())
|
||||
})
|
||||
}
|
||||
const rowList = datas.map((row: any) => {
|
||||
const rowList: any[] = datas.map((row: any, rowIndex: number) => {
|
||||
const item: any = {}
|
||||
columns.forEach((column: any) => {
|
||||
item[column.id] = original ? XEUtils.get(row, column.property) : row[column.id]
|
||||
columns.forEach((column: any, columnIndex: number) => {
|
||||
let cellValue
|
||||
const property = column.property
|
||||
const isIndex = column.type === 'index'
|
||||
if (!original || isIndex) {
|
||||
cellValue = isIndex ? (column.indexMethod ? column.indexMethod({ row, rowIndex, column, columnIndex }) : rowIndex + 1) : row[column.id]
|
||||
} else {
|
||||
cellValue = XEUtils.get(row, property)
|
||||
}
|
||||
item[column.id] = cellValue
|
||||
})
|
||||
return item
|
||||
})
|
||||
if (isFooter) {
|
||||
const footerData = $table.footerData
|
||||
const footers = footerFilterMethod ? footerData.filter(footerFilterMethod) : footerData
|
||||
const footerData: any[] = $table.footerData
|
||||
const footers: any[] = footerFilterMethod ? footerData.filter(footerFilterMethod) : footerData
|
||||
footers.forEach((rows: any[]) => {
|
||||
const item: any = {}
|
||||
columns.forEach((column: any) => {
|
||||
@@ -54,7 +62,7 @@ function downloadFile(blob: Blob, options: any) {
|
||||
if (window.Blob) {
|
||||
const { filename, type } = options
|
||||
if (navigator.msSaveBlob) {
|
||||
navigator.msSaveBlob(blob, filename)
|
||||
navigator.msSaveBlob(blob, `${filename}.${type}`)
|
||||
} else {
|
||||
var linkElem = document.createElement('a')
|
||||
linkElem.target = '_blank'
|
||||
@@ -147,43 +155,41 @@ function importXLSX(params: any) {
|
||||
}
|
||||
|
||||
function handleImportEvent(params: any) {
|
||||
switch (params.options.type) {
|
||||
case 'xlsx':
|
||||
importXLSX(params)
|
||||
return false
|
||||
if (params.options.type === 'xlsx') {
|
||||
importXLSX(params)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function handleExportEvent(params: any) {
|
||||
switch (params.options.type) {
|
||||
case 'xlsx':
|
||||
exportXLSX(params)
|
||||
return false
|
||||
if (params.options.type === 'xlsx') {
|
||||
exportXLSX(params)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式
|
||||
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 格式
|
||||
*/
|
||||
export const VXETablePluginExport: any = {
|
||||
export const VXETablePluginExportXLSX: any = {
|
||||
install(xtable: typeof VXETable) {
|
||||
Object.assign(xtable.types, { xlsx: 1 })
|
||||
xtable.interceptor.mixin({
|
||||
'event.import': handleImportEvent,
|
||||
'event.export': handleExportEvent
|
||||
})
|
||||
VXETablePluginExport.t = xtable.t
|
||||
VXETablePluginExportXLSX.t = xtable.t
|
||||
}
|
||||
}
|
||||
|
||||
function i18n(key: string) {
|
||||
if (VXETablePluginExport.t) {
|
||||
return VXETablePluginExport.t(key)
|
||||
if (VXETablePluginExportXLSX.t) {
|
||||
return VXETablePluginExportXLSX.t(key)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined' && window.VXETable) {
|
||||
window.VXETable.use(VXETablePluginExport)
|
||||
window.VXETable.use(VXETablePluginExportXLSX)
|
||||
}
|
||||
|
||||
export default VXETablePluginExport
|
||||
export default VXETablePluginExportXLSX
|
||||
|
||||
24
package.json
24
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vxe-table-plugin-export",
|
||||
"version": "1.0.10",
|
||||
"description": "基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式",
|
||||
"name": "vxe-table-plugin-export-xlsx",
|
||||
"version": "1.0.0-alpha.4",
|
||||
"description": "基于 vxe-table 表格的增强插件,支持导出 xlsx 格式",
|
||||
"scripts": {
|
||||
"lib": "gulp build"
|
||||
},
|
||||
@@ -20,7 +20,6 @@
|
||||
"@babel/plugin-transform-runtime": "^7.4.4",
|
||||
"@babel/preset-env": "^7.4.4",
|
||||
"@babel/runtime": "^7.4.4",
|
||||
"@types/file-saver": "^2.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^2.3.1",
|
||||
"@typescript-eslint/parser": "^2.3.1",
|
||||
"del": "^5.1.0",
|
||||
@@ -47,22 +46,23 @@
|
||||
"gulp-uglify": "^3.0.2",
|
||||
"markdown-doctest": "^0.9.1",
|
||||
"prettier": "^1.18.2",
|
||||
"typescript": "^3.6.3",
|
||||
"typescript": "^3.7.2",
|
||||
"vue": "^2.6.10",
|
||||
"vxe-table": "^2.6.15",
|
||||
"vxe-table": "^2.6.18",
|
||||
"xe-utils": "^2.2.11",
|
||||
"xlsx": "^0.15.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vxe-table": ">=2.6.15",
|
||||
"xe-utils": ">=2.2.0"
|
||||
"vxe-table": ">=2.6.19",
|
||||
"xe-utils": ">=2.2.0",
|
||||
"xlsx": ">=0.15.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/xuliangzhan/vxe-table-plugin-export.git"
|
||||
"url": "git+https://github.com/xuliangzhan/vxe-table-plugin-export-xlsx.git"
|
||||
},
|
||||
"keywords": [
|
||||
"vxe-table-plugin-export"
|
||||
"vxe-table-plugin-export-xlsx"
|
||||
],
|
||||
"author": {
|
||||
"name": "Xu Liangzhan",
|
||||
@@ -70,7 +70,7 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/xuliangzhan/vxe-table-plugin-export/issues"
|
||||
"url": "https://github.com/xuliangzhan/vxe-table-plugin-export-xlsx/issues"
|
||||
},
|
||||
"homepage": "https://github.com/xuliangzhan/vxe-table-plugin-export#readme"
|
||||
"homepage": "https://github.com/xuliangzhan/vxe-table-plugin-export-xlsx#readme"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"index.ts",
|
||||
"depend.ts"
|
||||
],
|
||||
@@ -8,6 +9,9 @@
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": true,
|
||||
"target": "es6",
|
||||
"lib": ["dom", "es6"]
|
||||
"lib": [
|
||||
"dom",
|
||||
"es6"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user