内部优化
This commit is contained in:
34
dist/index.common.js
vendored
34
dist/index.common.js
vendored
File diff suppressed because one or more lines are too long
32
dist/index.js
vendored
32
dist/index.js
vendored
@@ -38,13 +38,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function exportXLSX(params) {
|
function exportXLSX(params) {
|
||||||
var options = params.options,
|
var $table = params.$table,
|
||||||
|
options = params.options,
|
||||||
columns = params.columns,
|
columns = params.columns,
|
||||||
datas = params.datas;
|
datas = params.datas;
|
||||||
var sheetName = options.sheetName,
|
var sheetName = options.sheetName,
|
||||||
type = options.type,
|
type = options.type,
|
||||||
isHeader = options.isHeader,
|
isHeader = options.isHeader,
|
||||||
original = options.original;
|
original = options.original,
|
||||||
|
message = options.message;
|
||||||
var colHead = {};
|
var colHead = {};
|
||||||
|
|
||||||
if (isHeader) {
|
if (isHeader) {
|
||||||
@@ -76,6 +78,13 @@
|
|||||||
}); // 保存导出
|
}); // 保存导出
|
||||||
|
|
||||||
download(blob, options);
|
download(blob, options);
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
$table.$XModal.message({
|
||||||
|
message: i18n('vxe.table.expSuccess'),
|
||||||
|
status: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function download(blob, options) {
|
function download(blob, options) {
|
||||||
@@ -174,6 +183,18 @@
|
|||||||
$table.reloadData(data);
|
$table.reloadData(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.message) {
|
||||||
|
$table.$XModal.message({
|
||||||
|
message: i18n('vxe.table.impSuccess'),
|
||||||
|
status: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (options.message) {
|
||||||
|
$table.$XModal.message({
|
||||||
|
message: i18n('vxe.error.impFields'),
|
||||||
|
status: 'error'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_importCallback) {
|
if (_importCallback) {
|
||||||
@@ -213,10 +234,17 @@
|
|||||||
'event.import': handleImportEvent,
|
'event.import': handleImportEvent,
|
||||||
'event.export': handleExportEvent
|
'event.export': handleExportEvent
|
||||||
});
|
});
|
||||||
|
VXETablePluginExport.t = xtable.t;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_exports.VXETablePluginExport = VXETablePluginExport;
|
_exports.VXETablePluginExport = VXETablePluginExport;
|
||||||
|
|
||||||
|
function i18n(key) {
|
||||||
|
if (VXETablePluginExport.t) {
|
||||||
|
return VXETablePluginExport.t(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof window !== 'undefined' && window.VXETable) {
|
if (typeof window !== 'undefined' && window.VXETable) {
|
||||||
window.VXETable.use(VXETablePluginExport);
|
window.VXETable.use(VXETablePluginExport);
|
||||||
}
|
}
|
||||||
|
|||||||
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 n={exports:{}};t(n.exports,e.XEUtils,e.XLSX),e.VXETablePluginExport=n.exports.default}}(this,function(e,d,v){"use strict";var t;function a(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return a=function(){return e},e}function n(e){var t=e.options,r=e.columns,n=e.datas,o=t.sheetName,i=t.type,a=t.isHeader,l=t.original,u={};a&&r.forEach(function(e){u[e.id]=l?e.property:e.getTitle()});var s=n.map(function(t){var n={};return r.forEach(function(e){n[e.id]=l?d.default.get(t,e.property):t[e.id]}),n}),c=v.utils.book_new(),p=v.utils.json_to_sheet((a?[u]:[]).concat(s),{skipHeader:!0});v.utils.book_append_sheet(c,p,o);var f=v.write(c,{bookType:i,bookSST:!1,type:"binary"});!function(e,t){if(window.Blob){var n=t.filename,r=t.type;if(navigator.msSaveBlob)navigator.msSaveBlob(e,n);else{var o=document.createElement("a");o.target="_blank",o.download="".concat(n,".").concat(r),o.href=URL.createObjectURL(e),document.body.appendChild(o),o.click(),document.body.removeChild(o)}}else console.error("[vxe-table-plugin-export] The current environment does not support exports.")}(new Blob([function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r!==e.length;++r)n[r]=255&e.charCodeAt(r);return t}(f)],{type:"application/octet-stream"}),t)}function c(e){return e.replace(/^"/,"").replace(/"$/,"")}function r(e){var a=e.$table,l=e.columns,u=e.options,t=e.file,s=a._importCallback,n=new FileReader;n.onload=function(e){var t=v.read(e.target.result,{type:"binary"}),n=function(e,t){var n=t.split("\n"),r=[],o=[];if(n.length){var i=n.slice(1);n[0].split(",").forEach(function(e){var t=c(e);t&&r.push(t)}),i.forEach(function(e){if(e){var n={};e.split(",").forEach(function(e,t){n[r[t]]=c(e)}),o.push(n)}})}return{fields:r,rows:o}}(0,v.utils.sheet_to_csv(t.Sheets.Sheet1)),r=n.fields,o=n.rows,i=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)})}(l,r);i&&a.createData(o).then(function(e){"append"===u.mode?a.insertAt(e,-1):a.reloadData(e)}),s&&s(i)},n.readAsBinaryString(t)}function o(e){switch(e.options.type){case"xlsx":return r(e),!1}}function i(e){switch(e.options.type){case"xlsx":return n(e),!1}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.VXETablePluginExport=void 0,d=(t=d)&&t.__esModule?t:{default:t},v=function(e){if(e&&e.__esModule)return e;var t=a();if(t&&t.has(e))return t.get(e);var n={};if(null!=e){var r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var i=r?Object.getOwnPropertyDescriptor(e,o):null;i&&(i.get||i.set)?Object.defineProperty(n,o,i):n[o]=e[o]}}n.default=e,t&&t.set(e,n);return n}(v);var l={install:function(e){Object.assign(e.types,{xlsx:1}),e.interceptor.mixin({"event.import":o,"event.export":i})}};e.VXETablePluginExport=l,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(l);var u=l;e.default=u});
|
!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,b,x){"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 t=e.$table,r=e.options,n=e.columns,o=e.datas,a=r.sheetName,i=r.type,s=r.isHeader,u=r.original,l=r.message,c={};s&&n.forEach(function(e){c[e.id]=u?e.property:e.getTitle()});var p=o.map(function(t){var r={};return n.forEach(function(e){r[e.id]=u?b.default.get(t,e.property):t[e.id]}),r}),f=x.utils.book_new(),d=x.utils.json_to_sheet((s?[c]:[]).concat(p),{skipHeader:!0});x.utils.book_append_sheet(f,d,a);var v=x.write(f,{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("[vxe-table-plugin-export] The current environment does not support exports.")}(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}(v)],{type:"application/octet-stream"}),r),l&&t.$XModal.message({message:y("vxe.table.expSuccess"),status:"success"})}function c(e){return e.replace(/^"/,"").replace(/"$/,"")}function n(e){var i=e.$table,s=e.columns,u=e.options,t=e.file,l=i._importCallback,r=new FileReader;r.onload=function(e){var t=x.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=c(e);t&&n.push(t)}),a.forEach(function(e){if(e){var r={};e.split(",").forEach(function(e,t){r[n[t]]=c(e)}),o.push(r)}})}return{fields:n,rows:o}}(0,x.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"===u.mode?i.insertAt(e,-1):i.reloadData(e)}),u.message&&i.$XModal.message({message:y("vxe.table.impSuccess"),status:"success"})):u.message&&i.$XModal.message({message:y("vxe.error.impFields"),status:"error"}),l&&l(a)},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,b=(t=b)&&t.__esModule?t:{default:t},x=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}(x);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 y(e){if(s.t)return s.t(e)}e.VXETablePluginExport=s,"undefined"!=typeof window&&window.VXETable&&window.VXETable.use(s);var u=s;e.default=u});
|
||||||
@@ -51,8 +51,7 @@ gulp.task('build_umd', function () {
|
|||||||
globals: {
|
globals: {
|
||||||
[pack.name]: exportModuleName,
|
[pack.name]: exportModuleName,
|
||||||
'xe-utils': 'XEUtils',
|
'xe-utils': 'XEUtils',
|
||||||
'xlsx': 'XLSX',
|
'xlsx': 'XLSX'
|
||||||
'file-saver': 'FileSaver'
|
|
||||||
},
|
},
|
||||||
exactGlobals: true
|
exactGlobals: true
|
||||||
}]
|
}]
|
||||||
|
|||||||
23
index.ts
23
index.ts
@@ -10,8 +10,8 @@ function toBuffer(wbout: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function exportXLSX(params: any) {
|
function exportXLSX(params: any) {
|
||||||
const { options, columns, datas } = params
|
const { $table, options, columns, datas } = params
|
||||||
const { sheetName, type, isHeader, original } = options
|
const { sheetName, type, isHeader, original, message } = options
|
||||||
const colHead: any = {}
|
const colHead: any = {}
|
||||||
if (isHeader) {
|
if (isHeader) {
|
||||||
columns.forEach((column: any) => {
|
columns.forEach((column: any) => {
|
||||||
@@ -33,6 +33,9 @@ function exportXLSX(params: any) {
|
|||||||
const blob = new Blob([toBuffer(wbout)], { type: 'application/octet-stream' })
|
const blob = new Blob([toBuffer(wbout)], { type: 'application/octet-stream' })
|
||||||
// 保存导出
|
// 保存导出
|
||||||
download(blob, options)
|
download(blob, options)
|
||||||
|
if (message) {
|
||||||
|
$table.$XModal.message({ message: i18n('vxe.table.expSuccess'), status: 'success' })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function download(blob: Blob, options: any) {
|
function download(blob: Blob, options: any) {
|
||||||
@@ -50,7 +53,7 @@ function download(blob: Blob, options: any) {
|
|||||||
document.body.removeChild(linkElem)
|
document.body.removeChild(linkElem)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('[vxe-table-plugin-export] The current environment does not support exports.')
|
console.error(i18n('vxe.error.notExp'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +116,11 @@ function importXLSX(params: any) {
|
|||||||
$table.reloadData(data)
|
$table.reloadData(data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (options.message) {
|
||||||
|
$table.$XModal.message({ message: i18n('vxe.table.impSuccess'), status: 'success' })
|
||||||
|
}
|
||||||
|
} else if (options.message) {
|
||||||
|
$table.$XModal.message({ message: i18n('vxe.error.impFields'), status: 'error' })
|
||||||
}
|
}
|
||||||
if (_importCallback) {
|
if (_importCallback) {
|
||||||
_importCallback(status)
|
_importCallback(status)
|
||||||
@@ -140,13 +148,20 @@ function handleExportEvent(params: any) {
|
|||||||
/**
|
/**
|
||||||
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式
|
* 基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式
|
||||||
*/
|
*/
|
||||||
export const VXETablePluginExport = {
|
export const VXETablePluginExport: any = {
|
||||||
install(xtable: typeof VXETable) {
|
install(xtable: typeof VXETable) {
|
||||||
Object.assign(xtable.types, { xlsx: 1 })
|
Object.assign(xtable.types, { xlsx: 1 })
|
||||||
xtable.interceptor.mixin({
|
xtable.interceptor.mixin({
|
||||||
'event.import': handleImportEvent,
|
'event.import': handleImportEvent,
|
||||||
'event.export': handleExportEvent
|
'event.export': handleExportEvent
|
||||||
})
|
})
|
||||||
|
VXETablePluginExport.t = xtable.t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function i18n(key: string) {
|
||||||
|
if (VXETablePluginExport.t) {
|
||||||
|
return VXETablePluginExport.t(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vxe-table-plugin-export",
|
"name": "vxe-table-plugin-export",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"description": "基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式",
|
"description": "基于 vxe-table 表格的增强插件,支持导出 xlsx 等格式",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lib": "gulp build"
|
"lib": "gulp build"
|
||||||
@@ -49,12 +49,12 @@
|
|||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
"typescript": "^3.6.3",
|
"typescript": "^3.6.3",
|
||||||
"vue": "^2.6.10",
|
"vue": "^2.6.10",
|
||||||
"vxe-table": "^2.6.12",
|
"vxe-table": "^2.6.14",
|
||||||
"xe-utils": "^2.2.11",
|
"xe-utils": "^2.2.11",
|
||||||
"xlsx": "^0.15.1"
|
"xlsx": "^0.15.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"vxe-table": ">=2.6.14",
|
"vxe-table": ">=2.6.15",
|
||||||
"xe-utils": ">=2.2.0"
|
"xe-utils": ">=2.2.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
Reference in New Issue
Block a user