Authored by hongyong.zhao

修改webpack配置

... ... @@ -9,6 +9,17 @@
<body>
<div id="app"></div>
<% for (var i=0; i<htmlWebpackPlugin.options.externalscripts.length; i++) {
var script = htmlWebpackPlugin.options.externalscripts[i];
%>
<script type="text/javascript" src="<%= script %>"></script>
<% } %>
<% if (htmlWebpackPlugin.options.filename === 'coupon.html') { %>
<script type="text/javascript" src="<%= htmlWebpackPlugin.options.xlsScript%>"> </script>
<%} %>
</body>
</html>
\ No newline at end of file
</html>
... ...
... ... @@ -86,7 +86,7 @@
<script>
import Api from 'api/api';
import dayjs from 'dayjs';
import xlsx from 'xlsx';
import XLSX from 'xlsx';
const api = new Api();
const forbidenTypeMap = {
... ... @@ -316,7 +316,7 @@ export default {
},
onBeforeUpload(file) {
const fileExt = file.name.split('.').pop().toLocaleLowerCase();
if (fileExt !== 'xlsx') {
if (fileExt !== 'XLSX') {
this.$Message.warning('文件格式错误');
return false;
}
... ... @@ -340,28 +340,28 @@ export default {
this.uploadTxt = '';
try {
const data = e.target.result;
const workbook = xlsx.read(data, { type: 'array' });
const workbook = XLSX.read(data, { type: 'array' });
const firstSheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheetName];
const results = xlsx.utils.sheet_to_json(worksheet);
const results = XLSX.utils.sheet_to_json(worksheet);
this.formData.productLimitValue = results.map(r => r['商品编码']).filter(r => r).join(',');
} catch (error) {
this.uploadTxt = '文件解析失败,请按照格式上传';
}
};
return false;
},
onExample() {
const wb = xlsx.utils.book_new();
const ws = xlsx.utils.json_to_sheet([{
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet([{
'商品编码': '123456'
}]);
xlsx.utils.book_append_sheet(wb, ws, '优惠券适用范围示例');
xlsx.writeFile(wb, '优惠券适用范围示例.xlsx');
XLSX.utils.book_append_sheet(wb, ws, '优惠券适用范围示例');
XLSX.writeFile(wb, '优惠券适用范围示例.xlsx');
}
}
};
... ...
... ... @@ -13,7 +13,9 @@ fs
filename: `${file}.html`,
template: './src/template/index.ejs',
inject: true,
chunks: ['vendors', file]
chunks: ['vendors', file],
externalscripts: ["https://cdn.yoho.cn/20190712/vue.min.js", 'https://cdn.yoho.cn/20190712/iview.min.js'],
xlsScript:'https://cdn.yoho.cn/20190712/xlsx.full.min.js',
}));
});
... ... @@ -22,6 +24,11 @@ module.exports = {
output: {
path: path.join(__dirname, './dist')
},
externals: {
vue: 'Vue',
iview: 'iview',
xlsx: 'XLSX'
},
module: {
rules: [{
test: /.vue$/,
... ... @@ -102,11 +109,11 @@ module.exports = {
'node_modules'
],
alias: {
'vue': 'vue/dist/vue.esm.js',
'@': path.join(process.cwd(), 'src'),
'components': path.join(process.cwd(), 'src/components'),
'assets': path.join(process.cwd(), 'src/assets')
}
},
plugins: plugins
};
\ No newline at end of file
plugins: [...plugins]
};
... ...