From 644abc7a1484ce77cfcc6686861c89296e39bd0a Mon Sep 17 00:00:00 2001 From: jishenghua <752718920@qq.com> Date: Sun, 14 Jan 2024 15:25:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=BB=9F=E8=AE=A1=E5=AF=BC=E5=87=BA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jshERP-web/src/api/manage.js | 35 ++++++------------- jshERP-web/src/mixins/JeecgListMixin.js | 30 +++++++++++++++- jshERP-web/src/views/report/MaterialStock.vue | 15 ++++---- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/jshERP-web/src/api/manage.js b/jshERP-web/src/api/manage.js index 903107bb..8c5d0750 100644 --- a/jshERP-web/src/api/manage.js +++ b/jshERP-web/src/api/manage.js @@ -6,7 +6,8 @@ const api = { role: '/api/role', service: '/api/service', permission: '/api/permission', - permissionNoPager: '/api/permission/no-pager' + permissionNoPager: '/api/permission/no-pager', + exportExcelByParam: '/systemConfig/exportExcelByParam' } export default api @@ -108,37 +109,23 @@ export function downFile(url,parameter){ return axios({ url: url, params: parameter, - method:'get' , + method: 'get', responseType: 'blob' }) } /** - * 下载文件 - * @param url 文件路径 - * @param fileName 文件名 + * 下载文件 用于excel导出 + * @param url * @param parameter * @returns {*} */ -export function downloadFile(url, fileName, parameter) { - return downFile(url, parameter).then((data) => { - if (!data || data.size === 0) { - Vue.prototype['$message'].warning('文件下载失败') - return - } - if (typeof window.navigator.msSaveBlob !== 'undefined') { - window.navigator.msSaveBlob(new Blob([data]), fileName) - } else { - let url = window.URL.createObjectURL(new Blob([data])) - let link = document.createElement('a') - link.style.display = 'none' - link.href = url - link.setAttribute('download', fileName) - document.body.appendChild(link) - link.click() - document.body.removeChild(link) //下载完成移除元素 - window.URL.revokeObjectURL(url) //释放掉blob对象 - } +export function downFilePost(parameter){ + return axios({ + url: api.exportExcelByParam, + data: parameter, + method: 'post', + responseType: 'blob' }) } diff --git a/jshERP-web/src/mixins/JeecgListMixin.js b/jshERP-web/src/mixins/JeecgListMixin.js index 1e2ea62c..49c643b5 100644 --- a/jshERP-web/src/mixins/JeecgListMixin.js +++ b/jshERP-web/src/mixins/JeecgListMixin.js @@ -4,7 +4,7 @@ * data中url定义 list为查询列表 delete为删除单条记录 deleteBatch为批量删除 */ import { filterObj,getNowFormatStr } from '@/utils/util'; -import { deleteAction, getAction, postAction, downFile, getFileAccessHttpUrl } from '@/api/manage' +import { deleteAction, getAction, postAction, downFile, downFilePost, getFileAccessHttpUrl } from '@/api/manage' import Vue from 'vue' import VueDraggableResizable from 'vue-draggable-resizable' import { ACCESS_TOKEN } from "@/store/mutation-types" @@ -293,6 +293,7 @@ export const JeecgListMixin = { let url = `${window._CONFIG['domianURL']}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`; window.location.href = url; }, + //通过get方式导出Excel handleExportXls(fileName){ if(!fileName || typeof fileName != "string"){ fileName = "导出文件" @@ -322,6 +323,33 @@ export const JeecgListMixin = { } }) }, + //通过post方式导出Excel + handleExportXlsPost(fileName, title, head, tip, list) { + if(!fileName || typeof fileName != "string"){ + fileName = "导出文件" + } + 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对象 + } + }) + }, /* 导入 */ handleImportExcel(info){ this.confirmLoading = true diff --git a/jshERP-web/src/views/report/MaterialStock.vue b/jshERP-web/src/views/report/MaterialStock.vue index 06486278..283c132f 100644 --- a/jshERP-web/src/views/report/MaterialStock.vue +++ b/jshERP-web/src/views/report/MaterialStock.vue @@ -130,7 +130,7 @@ import { JeecgListMixin } from '@/mixins/JeecgListMixin' import { getAction, getFileAccessHttpUrl } from '@/api/manage' import {queryMaterialCategoryTreeList} from '@/api/api' - import { getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util" + import { getMpListShort } from "@/utils/util" import JEllipsis from '@/components/jeecg/JEllipsis' import moment from 'moment' import Vue from 'vue' @@ -287,14 +287,17 @@ this.$refs.materialInOutList.disableSubmit = false; }, exportExcel() { - let aoa = [['条码', '名称', '规格', '型号', '颜色', '类别', '单位', '单价', '初始库存', '库存', '库存金额', '重量']] + let list = [] + let head = '条码, 名称, 规格, 型号, 颜色, 类别, 单位, 单价, 初始库存, 库存, 库存金额, 重量' for (let i = 0; i < this.dataSource.length; i++) { + let item = [] let ds = this.dataSource[i] - let item = [ds.mBarCode, ds.name, ds.standard, ds.model, ds.color, ds.categoryName, ds.unitName, - ds.purchaseDecimal, ds.initialStock, ds.currentStock, ds.currentStockPrice, ds.currentWeight] - aoa.push(item) + item.push(ds.mBarCode, ds.name, ds.standard, ds.model, ds.color, ds.categoryName, ds.unitName, + ds.purchaseDecimal, ds.initialStock, ds.currentStock, ds.currentStockPrice, ds.currentWeight) + list.push(item) } - openDownloadDialog(sheet2blob(aoa), '商品库存') + let tip = '商品库存查询' + this.handleExportXlsPost('商品库存', '商品库存', head, tip, list) } } }