feat(production-master-data): add 异常不良管理功能
1. 新增设备类别API接口封装 2. 新增异常不良管理的CRUD、导入导出API 3. 添加异常不良管理页面路由与多语言配置 4. 新增文件工具类支持Excel读写下载 5. 实现完整的异常不良管理页面与导入弹窗 6. 新增功能测试流程文档 7. 安装xlsx依赖支持Excel操作
This commit is contained in:
41
src/utils/file.js
Normal file
41
src/utils/file.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import * as XLSX from 'xlsx'
|
||||
|
||||
export function downloadRename (blob, fileType, filename) {
|
||||
const typesMap = {
|
||||
xlsx: 'application/vnd.ms-excel',
|
||||
xls: 'application/vnd.ms-excel',
|
||||
pdf: 'application/pdf',
|
||||
doc: 'application/msword',
|
||||
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
csv: 'text/csv'
|
||||
}
|
||||
const type = typesMap[fileType] || ''
|
||||
const newBlob = new Blob([blob], { type })
|
||||
const href = URL.createObjectURL(newBlob)
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = filename + '.' + fileType
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(href)
|
||||
}
|
||||
|
||||
export function readExcel (file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.readAsBinaryString(file)
|
||||
reader.onload = ev => {
|
||||
try {
|
||||
const data = ev.target.result
|
||||
const workbook = XLSX.read(data, { type: 'binary' })
|
||||
const firstSheet = workbook.Sheets[workbook.SheetNames[0]]
|
||||
const list = XLSX.utils.sheet_to_json(firstSheet)
|
||||
resolve(list)
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
}
|
||||
reader.onerror = () => reject(new Error('文件读取失败'))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user