添加core-js依赖

excel导出问题修复
master
toesbieya 6 years ago
parent d818e11cda
commit b0f5c34d99
  1. 1
      vue/package.json
  2. 39
      vue/src/utils/excel.js
  3. 6
      vue/src/views/example/developingTest/components/ExportExcelTest.vue
  4. 16
      vue/src/views/purchase/inbound/index.vue
  5. 20
      vue/src/views/purchase/order/index.vue
  6. 20
      vue/src/views/sell/order/index.vue
  7. 16
      vue/src/views/sell/outbound/index.vue
  8. 20
      vue/src/views/stock/current/index.vue

@ -9,6 +9,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",
"core-js": "^3.6.4",
"decimal.js": "^10.2.0", "decimal.js": "^10.2.0",
"element-ui": "^2.13.0", "element-ui": "^2.13.0",
"fuse.js": "^3.6.1", "fuse.js": "^3.6.1",

@ -3,7 +3,13 @@ import {download} from "@/utils/file"
import request from "@/config/request" import request from "@/config/request"
import {elError} from "@/utils/message" import {elError} from "@/utils/message"
//导出excel /**
* 搜索表格页导出excel
* 响应头为json时进行前端导出否则直接下载文件
* @param url 搜索的请求地址
* @param searchForm 搜索参数
* @param options 合并选项{column, merge}只有前端导出时才需要
*/
export function exportExcel(url, searchForm, options) { export function exportExcel(url, searchForm, options) {
request({url, method: 'post', responseType: 'blob', data: searchForm}) request({url, method: 'post', responseType: 'blob', data: searchForm})
.then(({headers, data}) => { .then(({headers, data}) => {
@ -21,9 +27,8 @@ export function exportExcel(url, searchForm, options) {
exportExcelByJs(sheet, filename) exportExcelByJs(sheet, filename)
} }
reader.readAsText(data) reader.readAsText(data)
return
} }
download(data, filename) else download(data, filename)
}) })
.catch(e => elError(e)) .catch(e => elError(e))
} }
@ -52,13 +57,13 @@ export function exportExcelByJs(sheet, filename) {
*/ */
export function json2sheet(column, data, mergeOption, headerRows = 1) { export function json2sheet(column, data, mergeOption, headerRows = 1) {
const header = [] const header = []
const aliasMap = {} const propMap = {}
const colWidth = [] const colWidth = []
const needMerge = [] const needMerge = []
column.forEach((item, i) => { column.forEach((item, i) => {
if (!isEmpty(item.header)) header[i] = item.header if (!isEmpty(item.header)) header[i] = item.header
if (!isEmpty(item.alias)) aliasMap[item.alias] = i if (!isEmpty(item.prop)) propMap[item.prop] = i
if (item.merge) needMerge[i] = item.alias if (item.merge) needMerge[i] = item.prop
colWidth[i] = {wch: item.width || 20} colWidth[i] = {wch: item.width || 20}
}) })
@ -69,7 +74,7 @@ export function json2sheet(column, data, mergeOption, headerRows = 1) {
} }
let result = data.map(i => Object.keys(i).reduce((arr, key) => { let result = data.map(i => Object.keys(i).reduce((arr, key) => {
arr[aliasMap[key]] = i[key] arr[propMap[key]] = i[key]
return arr return arr
}, [])) }, []))
@ -85,23 +90,23 @@ export function json2sheet(column, data, mergeOption, headerRows = 1) {
* 合并excel * 合并excel
* @param primaryKey 该行json的唯一标识字段名 * @param primaryKey 该行json的唯一标识字段名
* @param indexKey 该行json的序号字段名 * @param indexKey 该行json的序号字段名
* @param alias 表头别名用于映射json * @param prop 表头的属性名称用于映射json
* @param data json数组 * @param data json数组
* @param ignoreRows 忽略的行数默认为1忽略表头 * @param ignoreRows 忽略的行数默认为1忽略表头
*/ */
function mergeExcel(alias, data, primaryKey, indexKey, ignoreRows = 1) { function mergeExcel(prop, data, primaryKey, indexKey, ignoreRows = 1) {
const result = [] const result = []
const startRows = ignoreRows + 1 const startRows = ignoreRows + 1
const merge = alias.map(_ => isEmpty(_) ? undefined : [1]) const merge = prop.map(_ => isEmpty(_) ? undefined : [1])
const temp = alias.map(_ => isEmpty(_) ? undefined : 1) const temp = prop.map(_ => isEmpty(_) ? undefined : 1)
//序号从1开始 //序号从1开始
let indexAfterMerge = 1 let indexAfterMerge = 1
data[0][indexKey] = indexAfterMerge data[0][indexKey] = indexAfterMerge
function compare(currentRow, lastRow, nextRow, colIndex) { function compare(currentRow, lastRow, nextRow, colIndex) {
const attr = alias[colIndex] const attr = prop[colIndex]
//若与上一行的primaryKey相同且属性相同,则temp对应项+1 //若与上一行的primaryKey相同且属性相同,则temp对应项+1
if (currentRow[primaryKey] === lastRow[primaryKey] if (currentRow[primaryKey] === lastRow[primaryKey]
@ -142,7 +147,7 @@ function mergeExcel(alias, data, primaryKey, indexKey, ignoreRows = 1) {
nextRow[indexKey] = currentRow[indexKey] nextRow[indexKey] = currentRow[indexKey]
} }
alias.forEach((_, colIndex) => !isEmpty(_) && compare(currentRow, lastRow, nextRow, colIndex)) prop.forEach((_, colIndex) => !isEmpty(_) && compare(currentRow, lastRow, nextRow, colIndex))
} }
function number2excelColumnHeader(n) { function number2excelColumnHeader(n) {
@ -166,9 +171,7 @@ function mergeExcel(alias, data, primaryKey, indexKey, ignoreRows = 1) {
}) })
} }
merge.forEach((arr, index) => { merge.forEach((arr, index) => arr && mergeResultConstructor(arr, index))
arr && mergeResultConstructor(arr, index)
})
return result return result
} }
@ -177,9 +180,7 @@ function mergeExcel(alias, data, primaryKey, indexKey, ignoreRows = 1) {
const defaultCellStyle = { const defaultCellStyle = {
font: {name: '宋体'}, font: {name: '宋体'},
alignment: { alignment: {
// 自动换行 wrapText: 1,// 自动换行
wrapText: 1,
// 居中
horizontal: "center", horizontal: "center",
vertical: "center", vertical: "center",
indent: 0 indent: 0

@ -20,9 +20,9 @@
return { return {
loading: false, loading: false,
column: [ column: [
{header: '序号', alias: 'no', merge: true}, {header: '序号', prop: 'no', merge: true},
{header: '名称', alias: 'name', merge: true}, {header: '名称', prop: 'name', merge: true},
{header: '日期', alias: 'date'}, {header: '日期', prop: 'date'},
], ],
row: { row: {
no: 1, no: 1,

@ -126,14 +126,14 @@
}, },
excel: { excel: {
column: [ column: [
{header: '序号', alias: 'id'}, {header: '序号', prop: 'id'},
{header: '采购订单单号', alias: 'pid', width: 30}, {header: '采购订单单号', prop: 'pid', width: 30},
{header: '创建人', alias: 'cname'}, {header: '创建人', prop: 'cname'},
{header: '创建时间', alias: 'ctime'}, {header: '创建时间', prop: 'ctime'},
{header: '审核人', alias: 'vname'}, {header: '审核人', prop: 'vname'},
{header: '审核时间', alias: 'vtime'}, {header: '审核时间', prop: 'vtime'},
{header: '状态', alias: 'status'}, {header: '状态', prop: 'status'},
{header: '备注', alias: 'remark', width: 50} {header: '备注', prop: 'remark', width: 50}
] ]
}, },
} }

@ -158,16 +158,16 @@
api: {search, del, getSubById}, api: {search, del, getSubById},
excel: { excel: {
column: [ column: [
{header: '序号', alias: 'id'}, {header: '序号', prop: 'id'},
{header: '供应商', alias: 'sname', width: 30}, {header: '供应商', prop: 'sname', width: 30},
{header: '创建人', alias: 'cname'}, {header: '创建人', prop: 'cname'},
{header: '创建时间', alias: 'ctime'}, {header: '创建时间', prop: 'ctime'},
{header: '审核人', alias: 'vname'}, {header: '审核人', prop: 'vname'},
{header: '审核时间', alias: 'vtime'}, {header: '审核时间', prop: 'vtime'},
{header: '状态', alias: 'status'}, {header: '状态', prop: 'status'},
{header: '完成情况', alias: 'finish'}, {header: '完成情况', prop: 'finish'},
{header: '完成时间', alias: 'ftime'}, {header: '完成时间', prop: 'ftime'},
{header: '备注', alias: 'remark', width: 50} {header: '备注', prop: 'remark', width: 50}
] ]
} }
} }

@ -158,16 +158,16 @@
api: {search, del, getSubById}, api: {search, del, getSubById},
excel: { excel: {
column: [ column: [
{header: '序号', alias: 'id'}, {header: '序号', prop: 'id'},
{header: '客户', alias: 'custoemr_name', width: 30}, {header: '客户', prop: 'customer_name', width: 30},
{header: '创建人', alias: 'cname'}, {header: '创建人', prop: 'cname'},
{header: '创建时间', alias: 'ctime'}, {header: '创建时间', prop: 'ctime'},
{header: '审核人', alias: 'vname'}, {header: '审核人', prop: 'vname'},
{header: '审核时间', alias: 'vtime'}, {header: '审核时间', prop: 'vtime'},
{header: '状态', alias: 'status'}, {header: '状态', prop: 'status'},
{header: '完成情况', alias: 'finish'}, {header: '完成情况', prop: 'finish'},
{header: '完成时间', alias: 'ftime'}, {header: '完成时间', prop: 'ftime'},
{header: '备注', alias: 'remark', width: 50} {header: '备注', prop: 'remark', width: 50}
] ]
} }
} }

@ -126,14 +126,14 @@
}, },
excel: { excel: {
column: [ column: [
{header: '序号', alias: 'id'}, {header: '序号', prop: 'id'},
{header: '销售订单单号', alias: 'pid', width: 30}, {header: '销售订单单号', prop: 'pid', width: 30},
{header: '创建人', alias: 'cname'}, {header: '创建人', prop: 'cname'},
{header: '创建时间', alias: 'ctime'}, {header: '创建时间', prop: 'ctime'},
{header: '审核人', alias: 'vname'}, {header: '审核人', prop: 'vname'},
{header: '审核时间', alias: 'vtime'}, {header: '审核时间', prop: 'vtime'},
{header: '状态', alias: 'status'}, {header: '状态', prop: 'status'},
{header: '备注', alias: 'remark', width: 50} {header: '备注', prop: 'remark', width: 50}
] ]
} }
} }

@ -104,16 +104,16 @@
detailDialog: false, detailDialog: false,
excel: { excel: {
column: [ column: [
{header: '序号', alias: 'id', width: 20, merge: true}, {header: '序号', prop: 'id', width: 20, merge: true},
{header: '分类名称', alias: 'cname', width: 20, merge: true}, {header: '分类名称', prop: 'cname', width: 20, merge: true},
{header: '库存总数', alias: 'total_num', width: 20, merge: true}, {header: '库存总数', prop: 'total_num', width: 20, merge: true},
{header: '库存总值', alias: 'total_price', width: 20, merge: true}, {header: '库存总值', prop: 'total_price', width: 20, merge: true},
{header: '采购订单号', alias: 'cgddid', width: 20, merge: true}, {header: '采购订单号', prop: 'cgddid', width: 20, merge: true},
{header: '采购单价', alias: 'cg_price', width: 20, merge: true}, {header: '采购单价', prop: 'cg_price', width: 20, merge: true},
{header: '采购数量', alias: 'cg_num', width: 20, merge: true}, {header: '采购数量', prop: 'cg_num', width: 20, merge: true},
{header: '采购入库单号', alias: 'cgrkid', width: 20}, {header: '采购入库单号', prop: 'cgrkid', width: 20},
{header: '入库时间', alias: 'ctime', width: 20}, {header: '入库时间', prop: 'ctime', width: 20},
{header: '入库数量', alias: 'rk_num', width: 20}, {header: '入库数量', prop: 'rk_num', width: 20},
], ],
merge: {primaryKey: 'cid', orderKey: 'id'} merge: {primaryKey: 'cid', orderKey: 'id'}
} }

Loading…
Cancel
Save