Commit 1b46f69c authored by YuY's avatar YuY

Merge remote-tracking branch 'origin/project2024-3-5' into project2024-3-5

# Conflicts:
#	src/views/equipment/inventoryManagement/index.vue
parents 7422b763 b0c5b511
import request from '@/utils/request'
import Qs from 'qs'
/* 分页查询 */
export function listdevice_t(query) {
......@@ -36,6 +37,32 @@ export function exportWarehouse(query) {
responseType: 'blob'
})
}
// 导入库存信息
export function importExcel(data) {
return request({
url: '/wbwarehouse-test/importExcel',
method: 'post',
headers: {
'Content-Type': 'multipart/form-data'
},
transformRequest: [(data) => {
return data
}],
data
})
}
// 下载错误文件
export function uploadFalseFile(params) {
params = Qs.stringify(params)
return request({
url: '/wbwarehouse-test/downFalseFile',
method: 'post',
data: params,
responseType: 'blob'
})
}
// 查询设备列表
export function listdevice(query) {
return request({
......
......@@ -202,7 +202,7 @@
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
:on-change="employeeUpload"
:on-change="wareHorseUpload"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:on-preview="handlePreview"
......@@ -229,7 +229,14 @@
</template>
<script>
import {listdevice_t, getDetailById_t, updatadevice_t, exportWarehouse} from '@/api/magnagement'
import {
listdevice_t,
getDetailById_t,
updatadevice_t,
exportWarehouse,
importExcel,
uploadFalseFile
} from '@/api/magnagement'
import { resetForm } from '@/utils/common'
import { getToken } from '@/utils/auth'
......@@ -295,8 +302,12 @@ export default {
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + '导入接口'
url: process.env.VUE_APP_BASE_API + '/wbwarehouse-test/importExcel'
},
// 导入列表
fileList: [],
importLoading: false,
// 表单校验
rules: {
pn: [
......@@ -449,9 +460,69 @@ export default {
handleFileSuccess(response, file, fileList) {
this.upload.open = false
this.upload.isUploading = false
this.$refs.upload.clearFiles()
this.$refs.upload.cclearFiles()
this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
this.getList()
},
// 提交上传文件
submitFileForm() {
this.importLoading = true
if (this.fileList.length === 0) {
this.$message.warning('请上传文件')
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = true
} else { // 根据后台需求数据格式
var formData = new FormData() // 当前为空
formData.append('file', this.fileList)
importExcel(formData).then(res => {
if (res.code === 200) {
if (res.data.filename === null) {
this.$message.success('导入成功')
this.fileList = []
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = false
// 导入成功后刷新页面
this.getList()
} else {
uploadFalseFile({ fileName: res.data.filename }).then(res => {
const blob = new Blob([res])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = '模板错误提示' + '.txt' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click() // 点击下载
document.body.removeChild(downloadElement) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放掉blob对象
})
}
this.importLoading = false
} else if (res.code === 41020) {
this.$message.info('上传超时,请重新上传')
this.importLoading = false
}
}).catch(err => {
this.importLoading = false
this.$message.success(err.message)
})
}
},
wareHorseUpload(file, fileList) {
if (fileList.length > 1) {
fileList.splice(0, 1)
}
this.fileList = fileList[0].raw
},
handleRemove(file, fileList) {
this.fileList = []
},
beforeRemove(file, fileList) {
this.fileList = []
},
/* 上传文件所需求 */
handlePreview(file) {
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment