diff --git a/jshERP-web/package-lock.json b/jshERP-web/package-lock.json index 405853b30..7b83bba1c 100644 --- a/jshERP-web/package-lock.json +++ b/jshERP-web/package-lock.json @@ -18129,25 +18129,6 @@ "async-limiter": "~1.0.0" } }, - "xlsx": { - "version": "0.14.5", - "requires": { - "adler-32": "~1.2.0", - "cfb": "^1.1.2", - "codepage": "~1.14.0", - "commander": "~2.17.1", - "crc-32": "~1.2.0", - "exit-on-epipe": "~1.0.1", - "ssf": "~0.10.2" - }, - "dependencies": { - "commander": { - "version": "2.17.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", - "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==" - } - } - }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/jshERP-web/package.json b/jshERP-web/package.json index d2c6c0538..1ce287203 100644 --- a/jshERP-web/package.json +++ b/jshERP-web/package.json @@ -36,8 +36,7 @@ "vue-router": "^3.0.1", "vue-splitpane": "^1.0.4", "vuedraggable": "^2.20.0", - "vuex": "^3.1.0", - "xlsx": "^0.14.3" + "vuex": "^3.1.0" }, "devDependencies": { "@babel/polyfill": "^7.2.5", diff --git a/jshERP-web/src/utils/util.js b/jshERP-web/src/utils/util.js index 9edacc977..4024016e2 100644 --- a/jshERP-web/src/utils/util.js +++ b/jshERP-web/src/utils/util.js @@ -1,5 +1,5 @@ import { isURL } from '@/utils/validate' -import XLSX from 'xlsx' +import { downFilePost} from '@/api/manage' import Vue from 'vue' import introJs from 'intro.js' @@ -585,58 +585,32 @@ export function changeListFmtMinus(str) { return newArr; } -/** - 通用的打开下载对话框方法,没有测试过具体兼容性 - @param url 下载地址,也可以是一个blob对象,必选 - @param saveName 保存文件名,可选 - */ -export function openDownloadDialog (url, saveName) { - if (typeof url === 'object' && url instanceof Blob) { - url = URL.createObjectURL(url) // 创建blob地址 +//通过post方式导出Excel +export function exportXlsPost(fileName, title, head, tip, list) { + if(!fileName || typeof fileName != "string"){ + fileName = "导出文件" } - let aLink = document.createElement('a') - aLink.href = url - saveName = saveName + '_' + getNowFormatStr() + '.xls' - aLink.download = saveName || '' // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效 - let event - if (window.MouseEvent) event = new MouseEvent('click') - else { - event = document.createEvent('MouseEvents') - event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) - } - aLink.dispatchEvent(event) -} - -/** - * 将一个sheet转成最终的excel文件的blob对象,然后利用URL.createObjectURL下载 - * @param sheet - * @param sheetName - * @returns {Blob} - */ -export function sheet2blob (aoa, sheetName) { - let sheet = XLSX.utils.aoa_to_sheet(aoa) - sheetName = sheetName || 'sheet1' - let workbook = { - SheetNames: [sheetName], - Sheets: {} - } - workbook.Sheets[sheetName] = sheet - // 生成excel的配置项 - let wopts = { - bookType: 'xls', // 要生成的文件类型 - bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性 - type: 'binary' - } - let wbout = XLSX.write(workbook, wopts) - let blob = new Blob([s2ab(wbout)], { type: 'application/octet-stream' }) - // 字符串转ArrayBuffer - function s2ab (s) { - let buf = new ArrayBuffer(s.length) - let view = new Uint8Array(buf) - for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF - return buf - } - return blob + let paramObj = {'title': title, 'head': head, 'tip': tip, 'list': list} + console.log("导出参数", paramObj) + downFilePost(paramObj).then((data)=>{ + if (!data) { + this.$message.warning("文件下载失败") + return + } + if (typeof window.navigator.msSaveBlob !== 'undefined') { + window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls') + }else{ + let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'})) + let link = document.createElement('a') + link.style.display = 'none' + link.href = url + link.setAttribute('download', fileName + '_' + getNowFormatStr()+'.xls') + document.body.appendChild(link) + link.click() + document.body.removeChild(link); //下载完成移除元素 + window.URL.revokeObjectURL(url); //释放掉blob对象 + } + }) } /** diff --git a/jshERP-web/src/views/bill/dialog/BillDetail.vue b/jshERP-web/src/views/bill/dialog/BillDetail.vue index 777b50aea..f6ddc0ce2 100644 --- a/jshERP-web/src/views/bill/dialog/BillDetail.vue +++ b/jshERP-web/src/views/bill/dialog/BillDetail.vue @@ -1127,7 +1127,7 @@ import pick from 'lodash.pick' import { getAction, postAction, getFileAccessHttpUrl } from '@/api/manage' import { findBillDetailByNumber, findFinancialDetailByNumber, getPlatformConfigByKey, getCurrentSystemConfig} from '@/api/api' - import { getMpListShort, getCheckFlag, openDownloadDialog, sheet2blob } from "@/utils/util" + import { getMpListShort, getCheckFlag, exportXlsPost } from "@/utils/util" import BillPrintIframe from './BillPrintIframe' import FinancialDetail from '../../financial/dialog/FinancialDetail' import JUpload from '@/components/jeecg/JUpload' @@ -1747,21 +1747,22 @@ }, //零售出库|零售退货入库 retailExportExcel() { - let aoa = [] - aoa = [['会员卡号:', this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]] - let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '备注'] - aoa.push(title) + let list = [] + let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, - ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark] - aoa.push(item) + item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, + ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let organName = this.model.organName? '会员卡号' + this.model.organName: '' + let tip = organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //采购订单|销售订单 orderExportExcel() { - let aoa = [] + let list = [] let finishType = '' let organType = '' if(this.billType === '采购订单') { @@ -1771,98 +1772,104 @@ finishType = '已出库' organType = '客户:' } - aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]] - let title = ['条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '多属性', '数量', finishType, '单价', '金额', '税率(%)', '税额', '价税合计', '备注'] - aoa.push(title) + let head = '条码,名称,规格,型号,颜色,扩展信息,库存,单位,多属性,数量,' + finishType + ',单价,金额,税率(%),税额,价税合计,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, ds.sku, - ds.operNumber, ds.finishNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.remark] - aoa.push(item) + item.push(ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, ds.sku, + ds.operNumber, ds.finishNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let organName = this.model.organName? this.model.organName: '' + let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //采购入库|采购退货出库|销售出库|销售退货入库 purchaseSaleExportExcel() { - let aoa = [] + let list = [] let organType = '' if(this.billType === '采购入库' || this.billType === '采购退货出库') { organType = '供应商:' } else if(this.billType === '销售出库' || this.billType === '销售退货入库') { organType = '客户:' } - aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number, '', '关联单号:', this.model.linkNumber],[]] - let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '税率(%)', '税额', '价税合计', '重量', '备注'] - aoa.push(title) + let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,税率(%),税额,价税合计,重量,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, - ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.weight, ds.remark] - aoa.push(item) + item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, + ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.weight, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let organName = this.model.organName? this.model.organName: '' + let linkNumber = this.model.linkNumber? this.model.linkNumber: '' + let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + + this.model.number + '' + '关联单号:' + linkNumber + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //其它入库|其它出库 otherExportExcel() { - let aoa = [] + let list = [] let organType = '' if(this.billType === '其它入库') { organType = '供应商:' } else if(this.billType === '其它出库') { organType = '客户:' } - aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]] - let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '备注'] - aoa.push(title) + let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, - ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark] - aoa.push(item) + item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, + ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let organName = this.model.organName? this.model.organName: '' + let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //调拨出库 allocationOutExportExcel() { - let aoa = [] - aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]] - let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '调入仓库', '单位', '多属性', '数量', '单价', '金额', '备注'] - aoa.push(title) + let list = [] + let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,调入仓库,单位,多属性,数量,单价,金额,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.anotherDepotName, ds.unit, - ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark] - aoa.push(item) + item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.anotherDepotName, ds.unit, + ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //组装单|拆卸单 assembleExportExcel() { - let aoa = [] - aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]] - let title = ['商品类型', '仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '多属性', '数量', '单价', '金额', '备注'] - aoa.push(title) + let list = [] + let head = ['商品类型,仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,多属性,数量,单价,金额,备注'] for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.mType, ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, - ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark] - aoa.push(item) + item.push(ds.mType, ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, + ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) }, //盘点复盘 stockCheckReplayExportExcel() { - let aoa = [] - aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number, '', '关联单据:', this.model.linkNumber],[]] - let title = ['仓库名称', '条码', '名称', '规格', '型号', '扩展信息', '库存', '单位', '多属性', '数量', '单价', '金额', '备注'] - aoa.push(title) + let list = [] + let head = '仓库名称,条码,名称,规格,型号,扩展信息,库存,单位,多属性,数量,单价,金额,备注' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.materialOther, ds.stock, ds.unit, - ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark] - aoa.push(item) + item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.materialOther, ds.stock, ds.unit, + ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number) + let linkNumber = this.model.linkNumber? this.model.linkNumber: '' + let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + '' + '关联单号:' + linkNumber + exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list) } } } diff --git a/jshERP-web/src/views/report/AllocationDetail.vue b/jshERP-web/src/views/report/AllocationDetail.vue index c9944fdd9..170a7130f 100644 --- a/jshERP-web/src/views/report/AllocationDetail.vue +++ b/jshERP-web/src/views/report/AllocationDetail.vue @@ -135,7 +135,7 @@