Browse Source

2026-09-21

IQC基础数据导入
master
fengyuan_yang 5 days ago
parent
commit
caf0d7cd24
  1. 2
      src/api/qc/qc.js
  2. 2
      src/views/modules/qc/qcItem.vue
  3. 17
      src/views/modules/qc/qcMethod.vue
  4. 2
      src/views/modules/qc/qcTemplate.vue
  5. 293
      src/views/modules/qc/qc_upload.vue

2
src/api/qc/qc.js

@ -5,6 +5,8 @@ export const qcMethodSearch = data => createAPI(`/pms/qc/qcMethodSearch`,'post',
export const qcMethodSave = data => createAPI(`/pms/qc/qcMethodSave`,'post',data) export const qcMethodSave = data => createAPI(`/pms/qc/qcMethodSave`,'post',data)
export const qcMethodUpdate = data => createAPI(`/pms/qc/qcMethodUpdate`,'post',data) export const qcMethodUpdate = data => createAPI(`/pms/qc/qcMethodUpdate`,'post',data)
export const qcMethodDelete = data => createAPI(`/pms/qc/qcMethodDelete`,'post',data) export const qcMethodDelete = data => createAPI(`/pms/qc/qcMethodDelete`,'post',data)
export const uploadMethodExcel = data => createAPI(`/pms/qc/uploadMethodExcel`,'post',data)
export const downloadQcImportTemplate = (flag, site) => createAPI(`/pms/qc/downloadQcImportTemplate?flag=${flag}&site=${encodeURIComponent(site || '')}`,'post','download')
// ===================================== 检验项目 ===================================== // ===================================== 检验项目 =====================================
export const qcItemSearch = data => createAPI(`/pms/qc/qcItemSearch`,'post',data) export const qcItemSearch = data => createAPI(`/pms/qc/qcItemSearch`,'post',data)

2
src/views/modules/qc/qcItem.vue

@ -37,7 +37,7 @@
<el-button v-if="authSave" type="primary" @click="addModal()">新增</el-button> <el-button v-if="authSave" type="primary" @click="addModal()">新增</el-button>
</el-form-item> </el-form-item>
<el-form-item label=" "> <el-form-item label=" ">
<!-- <el-button type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>-->
<el-button v-if="authSave" type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>
<download-excel <download-excel
:fields="fields()" :fields="fields()"
:data="exportData" :data="exportData"

17
src/views/modules/qc/qcMethod.vue

@ -35,6 +35,7 @@
<el-form-item label=" "> <el-form-item label=" ">
<el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button> <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
<el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button> <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
<el-button v-if="!authSave" type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>
<download-excel <download-excel
:fields="fields()" :fields="fields()"
:data="exportData" :data="exportData"
@ -149,6 +150,7 @@
<el-button type="primary" @click="modalFlag = false">关闭</el-button> <el-button type="primary" @click="modalFlag = false">关闭</el-button>
</el-footer> </el-footer>
</el-dialog> </el-dialog>
<qcUpload ref="qcUpload" @refreshPageTables="getDataList()" v-drag></qcUpload>
</div> </div>
</template> </template>
@ -163,7 +165,11 @@
} from "@/api/qc/qc.js" } from "@/api/qc/qc.js"
import {getTableDefaultListLanguage, getTableUserListLanguage,updateColumnSize} from "@/api/table.js" import {getTableDefaultListLanguage, getTableUserListLanguage,updateColumnSize} from "@/api/table.js"
import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js' import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
import qcUpload from "./qc_upload"
export default { export default {
components: {
qcUpload
},
data () { data () {
return { return {
columnsProp:['createBy', 'updateBy'], columnsProp:['createBy', 'updateBy'],
@ -670,6 +676,17 @@
return s return s
}, },
qcUpload () {
let currentData = {
flag: 'method',
createBy: this.$store.state.user.name,
site: this.$store.state.user.site,
}
this.$nextTick(() => {
this.$refs.qcUpload.init(currentData)
})
},
// 动态列开始 获取 用户保存的 格式列 // 动态列开始 获取 用户保存的 格式列
async getTableUserColumn (tableId, columnId) { async getTableUserColumn (tableId, columnId) {
let queryTableUser = { let queryTableUser = {

2
src/views/modules/qc/qcTemplate.vue

@ -38,7 +38,7 @@
<el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button> <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
</el-form-item> </el-form-item>
<el-form-item :label="' '"> <el-form-item :label="' '">
<!-- <el-button type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>-->
<el-button v-if="!authSave" type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>
<download-excel <download-excel
:fields="fields()" :fields="fields()"
:data="exportData" :data="exportData"

293
src/views/modules/qc/qc_upload.vue

@ -1,15 +1,15 @@
<template> <template>
<div class="customer-css"> <div class="customer-css">
<el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog">
<el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" class="customer-dialog">
<el-form :inline="true" label-position="top" label-width="80px"> <el-form :inline="true" label-position="top" label-width="80px">
<el-button type="primary" @click="downloadFile()">下载文件模板</el-button> <el-button type="primary" @click="downloadFile()">下载文件模板</el-button>
<el-form-item label="BU">
<el-select v-model="bu" placeholder="请选择" style="width: 295px">
<el-form-item v-if="needSelectBu" label="BU">
<el-select v-model="bu" placeholder="请选择" style="width: 295px">
<el-option <el-option
v-for = "i in userBuList"
:key = "i.buNo"
:label = "i.sitename"
:value = "i.buNo">
v-for="i in userBuList"
:key="i.buNo"
:label="i.sitename"
:value="i.buNo">
<span style="float: left;width: 100px">{{ i.sitename }}</span> <span style="float: left;width: 100px">{{ i.sitename }}</span>
<span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;"> <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;">
{{ i.buDesc }} {{ i.buDesc }}
@ -20,7 +20,7 @@
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls" <el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls"
:before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;">
:before-upload="beforeUploadHandle" :on-change="onChange" :on-remove="onRemove" :auto-upload="false" style="text-align: left;">
<i class="el-icon-upload"></i> <i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
</el-upload> </el-upload>
@ -28,7 +28,7 @@
</el-row> </el-row>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="saveUploadFile()">保存</el-button>
<el-button type="primary" :loading="saveLoading" @click="saveUploadFile()">保存</el-button>
<el-button type="primary" @click="closeDialog">关闭</el-button> <el-button type="primary" @click="closeDialog">关闭</el-button>
</span> </span>
</el-dialog> </el-dialog>
@ -39,14 +39,14 @@
import { import {
uploadExcel, // 导入项目文件 uploadExcel, // 导入项目文件
uploadTemplateExcel, // 导入模板文件 uploadTemplateExcel, // 导入模板文件
uploadMethodExcel, // 导入方法文件
uploadPartAttributeExcel, // 导入物料属性文件 uploadPartAttributeExcel, // 导入物料属性文件
uploadFamilyAttributeExcel, // 导入类别属性文件 uploadFamilyAttributeExcel, // 导入类别属性文件
downloadQcImportTemplate,
queryFileId, // 查询文件ID queryFileId, // 查询文件ID
getSiteAndBuByUserName getSiteAndBuByUserName
} from "@/api/qc/qc.js" } from "@/api/qc/qc.js"
import { downLoadObjectFile } from '@/api/eam/eam_object_list.js' import { downLoadObjectFile } from '@/api/eam/eam_object_list.js'
import axios from 'axios'
import Vue from 'vue'
export default { export default {
data() { data() {
return { return {
@ -54,7 +54,8 @@ export default {
visible: false, visible: false,
fileList: [], fileList: [],
bu: '', bu: '',
userBuList:[],
userBuList: [],
saveLoading: false,
pageData: { pageData: {
flag: '', flag: '',
createBy: '', createBy: '',
@ -62,11 +63,21 @@ export default {
}, },
} }
}, },
computed: {
isMasterImport() {
return ['item', 'method', 'template'].indexOf(this.pageData.flag) !== -1
},
needSelectBu() {
return !this.isMasterImport
},
importSite() {
return this.pageData.site || (this.$store.state.user && this.$store.state.user.site) || ''
}
},
created(){ created(){
this.getSiteAndBu(); this.getSiteAndBu();
}, },
methods: { methods: {
// 获取用户的bu
getSiteAndBu () { getSiteAndBu () {
let tempData = { let tempData = {
username: this.$store.state.user.name, username: this.$store.state.user.name,
@ -77,103 +88,136 @@ export default {
} }
}) })
}, },
//初始化组件的参数
init(currentRow) { init(currentRow) {
// 获得类别
this.pageData = JSON.parse(JSON.stringify(currentRow)) this.pageData = JSON.parse(JSON.stringify(currentRow))
//打开页面
this.visible = true;
this.fileList = []
this.bu = ''
this.saveLoading = false
this.visible = true
this.$nextTick(() => {
if (this.$refs.uploadFile) {
this.$refs.uploadFile.clearFiles()
}
})
}, },
// 上传之前
beforeUploadHandle(file) { beforeUploadHandle(file) {
let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
const name = file && file.name ? file.name : ''
let extName = name.substring(name.lastIndexOf('.')).toLowerCase()
if (!(extName === '.xlsx' || extName === '.xls')) { if (!(extName === '.xlsx' || extName === '.xls')) {
this.$message.error('数据导入失败,请选择正确的xlsx模板文件') this.$message.error('数据导入失败,请选择正确的xlsx模板文件')
return false return false
} }
}, },
/*选择上传文件时*/
onChange(file){
this.fileList.push(file);
onChange(file, fileList) {
this.fileList = fileList.slice(-1)
},
onRemove() {
this.fileList = []
}, },
/*关闭modal*/
closeDialog(){ closeDialog(){
this.fileList = [];
// 刷新报工的页面
this.fileList = []
this.bu = ''
this.saveLoading = false
this.$emit('refreshPageTables'); this.$emit('refreshPageTables');
// 关闭当前的页面
this.visible = false; this.visible = false;
}, },
/*保修当前的数据*/
showImportError(msg) {
const text = msg || '导入失败'
if (text.indexOf('<br/>') !== -1 || text.indexOf('<br>') !== -1) {
this.$alert(text, '导入失败', {
confirmButtonText: '确定',
dangerouslyUseHTMLString: true
})
} else {
this.$message.warning(text)
}
},
handleImportResult(data) {
if (data && data.code === 0) {
this.$message.success(data.msg || '导入成功')
if (this.$refs.uploadFile) {
this.$refs.uploadFile.clearFiles()
}
this.closeDialog()
} else {
this.showImportError(data && data.msg)
}
},
saveUploadFile(){ saveUploadFile(){
if (this.bu==''||this.bu == null){
if (this.needSelectBu && (this.bu === '' || this.bu == null)){
this.$message.warning("请选择BU!"); this.$message.warning("请选择BU!");
return false; return false;
} }
/*判断文件是否上传*/
if(null == this.fileList || 0 == this.fileList.length){
if (this.isMasterImport && !this.importSite) {
this.$message.warning("未获取到当前用户工厂");
return false;
}
if (this.fileList == null || this.fileList.length === 0){
this.$message.error("请先上传文件!"); this.$message.error("请先上传文件!");
return false; return false;
} }
const formData = new FormData(); const formData = new FormData();
formData.append("file", this.fileList[0].raw); formData.append("file", this.fileList[0].raw);
formData.append("createBy", this.pageData.createBy); formData.append("createBy", this.pageData.createBy);
formData.append("site", this.bu.split('_')[0]);
if (this.isMasterImport) {
formData.append("site", this.importSite);
} else if (this.pageData.flag === 'partAttribute') {
formData.append("site", this.bu);
} else {
formData.append("site", this.bu.split('_')[0]);
}
let request
if (this.pageData.flag === 'item'){ if (this.pageData.flag === 'item'){
uploadExcel(formData).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg);
// 清空文件上传记录
this.$refs.uploadFile.clearFiles();
// 关闭窗口并刷新页面
this.closeDialog();
}else {
this.$message.warning(data.msg);
}
})
request = uploadExcel(formData)
} else if (this.pageData.flag === 'method'){
request = uploadMethodExcel(formData)
} else if (this.pageData.flag === 'template'){ } else if (this.pageData.flag === 'template'){
formData.set('site',this.bu)
uploadTemplateExcel(formData).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg);
// 清空文件上传记录
this.$refs.uploadFile.clearFiles();
// 关闭窗口并刷新页面
this.closeDialog();
}else {
this.$message.warning(data.msg);
}
})
}else if (this.pageData.flag === 'partAttribute'){
formData.set('site',this.bu)
uploadPartAttributeExcel(formData).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg);
// 清空文件上传记录
this.$refs.uploadFile.clearFiles();
// 关闭窗口并刷新页面
this.closeDialog();
}else {
this.$message.warning(data.msg);
}
})
}else if (this.pageData.flag === 'familyAttribute'){
uploadFamilyAttributeExcel(formData).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg);
// 清空文件上传记录
this.$refs.uploadFile.clearFiles();
// 关闭窗口并刷新页面
this.closeDialog();
}else {
this.$message.warning(data.msg);
}
})
request = uploadTemplateExcel(formData)
} else if (this.pageData.flag === 'partAttribute'){
request = uploadPartAttributeExcel(formData)
} else if (this.pageData.flag === 'familyAttribute'){
request = uploadFamilyAttributeExcel(formData)
} else {
this.$message.warning('不支持的导入类型')
return false
} }
this.bu = '';
this.saveLoading = true
request.then(({data}) => {
this.saveLoading = false
this.handleImportResult(data)
}).catch(() => {
this.saveLoading = false
this.$message.error('导入失败,请检查文件格式和内容')
})
},
bindDownloadBlob(data, fileName) {
const blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})
const linkNode = document.createElement('a')
linkNode.download = fileName
linkNode.style.display = 'none'
linkNode.href = URL.createObjectURL(blob)
document.body.appendChild(linkNode)
linkNode.click()
URL.revokeObjectURL(linkNode.href)
document.body.removeChild(linkNode)
}, },
// 下载
async downloadFile(){ async downloadFile(){
const dynamicFlags = ['item', 'template', 'method']
if (dynamicFlags.indexOf(this.pageData.flag) !== -1) {
const fileNameMap = {
item: '检验项目导入模板.xlsx',
template: '检验模板导入模板.xlsx',
method: '检验方法导入模板.xlsx'
}
if (!this.importSite) {
this.$message.warning("未获取到当前用户工厂")
return
}
await downloadQcImportTemplate(this.pageData.flag, this.importSite).then(({data}) => {
this.bindDownloadBlob(data, fileNameMap[this.pageData.flag])
})
return
}
let file = { let file = {
id: 0, id: 0,
fileName: '' fileName: ''
@ -182,80 +226,33 @@ export default {
orderRef1: '', orderRef1: '',
orderRef2: '' orderRef2: ''
} }
if(this.pageData.flag === 'item'){ // 检验项目
tempData.orderRef1 = 'qc';
tempData.orderRef2 = 'itemFormat';
await queryFileId(tempData).then(({data}) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
this.$alert(data.msg, '错误', {
confirmButtonText: '确定'
})
}
})
}else if (this.pageData.flag === 'template'){ // 检验模板
tempData.orderRef1 = 'qc';
tempData.orderRef2 = 'templateFormat';
await queryFileId(tempData).then(({data}) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
this.$alert(data.msg, '错误', {
confirmButtonText: '确定'
})
}
})
}else if (this.pageData.flag === 'partAttribute'){ // 物料属性设置
if (this.pageData.flag === 'partAttribute'){
tempData.orderRef1 = 'qc'; tempData.orderRef1 = 'qc';
tempData.orderRef2 = 'partAttributeFormat'; tempData.orderRef2 = 'partAttributeFormat';
await queryFileId(tempData).then(({data}) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
this.$alert(data.msg, '错误', {
confirmButtonText: '确定'
})
}
})
}else if (this.pageData.flag === 'familyAttribute'){ // 类别属性设置
} else if (this.pageData.flag === 'familyAttribute'){
tempData.orderRef1 = 'qc'; tempData.orderRef1 = 'qc';
tempData.orderRef2 = 'familyAttributeFormat'; tempData.orderRef2 = 'familyAttributeFormat';
await queryFileId(tempData).then(({data}) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
this.$alert(data.msg, '错误', {
confirmButtonText: '确定'
})
}
})
} else {
this.$message.warning('未找到对应的导入模板')
return
}
await queryFileId(tempData).then(({data}) => {
if (data && data.code === 0) {
file.id = data.data.id
file.fileName = data.data.fileName
} else {
this.$alert(data.msg, '错误', {
confirmButtonText: '确定'
})
}
})
if (!file.id) {
return
} }
await downLoadObjectFile(file).then(({data}) => { await downLoadObjectFile(file).then(({data}) => {
// 不限制文件下载类型
const blob = new Blob([data], {type: "application/octet-stream"})
// 下载文件名称
const fileName = file.fileName
// a标签下载
const linkNode = document.createElement('a')
// a标签的download属性规定下载文件的名称
linkNode.download = fileName
linkNode.style.display = 'none'
// 生成一个Blob URL
linkNode.href = URL.createObjectURL(blob)
document.body.appendChild(linkNode)
// 模拟在按钮上的一次鼠标单击
linkNode.click()
// 释放URL 对象
URL.revokeObjectURL(linkNode.href)
document.body.removeChild(linkNode)
})
this.bindDownloadBlob(data, file.fileName)
})
}, },
} }
} }
</script> </script>

Loading…
Cancel
Save