Browse Source

2025.05.15 物料属性设置 导出优化 导出所有数据

master
jiayang yue 8 months ago
parent
commit
d07dc9a90b
  1. 13
      src/api/qc/qc.js
  2. 126
      src/views/modules/qc/qcPartAttribute.vue

13
src/api/qc/qc.js

@ -74,6 +74,19 @@ export const getPlanLists = data => createAPI(`/pms/qc/getPlanLists`,'post',data
// ===================================== 物料属性设置 =====================================
export const qcPartAttributeSearch = data => createAPI(`/pms/qc/qcPartAttributeSearch`,'post',data)
export const qcPartAttributeExport = data =>
createAPI(
`/pms/qc/exportPartAttribute`,
'post',
data,
'download' // 关键:告诉 axios 要拿二进制流
);
export const qcPartAttributeExportAsync = data =>
createAPI(`/pms/qce/exportPartAttributeAsync`, 'post', data);
export const getExportStatus = params =>
createAPI(`/pms/qce/exportStatus`, 'get', params);
export const downloadExportFile = params =>
createAPI(`/pms/qce/download`, 'get', params, 'download');
export const qcPartAttributeSave = data => createAPI(`/pms/qc/qcPartAttributeSave`,'post',data)
export const qcPartAttributeDelete = data => createAPI(`/pms/qc/qcPartAttributeDelete`,'post',data)
export const searchPartAttributeDetails = data => createAPI(`/pms/qc/searchPartAttributeDetails`,'post',data)

126
src/views/modules/qc/qcPartAttribute.vue

@ -35,20 +35,13 @@
</el-form-item>
<el-form-item :label="' '">
<el-button type="primary" icon="el-icon-upload" @click="qcUpload()">导入</el-button>
<download-excel
:fields="fields()"
:data="exportData"
type="xls"
:name="exportName"
:header="exportHeader"
:footer="exportFooter"
:fetch="createExportData"
:before-generate="startDownload"
:before-finish="finishDownload"
worksheet="导出信息"
class="el-button el-button--primary el-button--medium">
{{ "导出" }}
</download-excel>
<el-button
:loading="importLoading"
type="primary"
@click="handleAsyncExport"
>
导出全部
</el-button>
</el-form-item>
</el-form>
@ -833,6 +826,12 @@
import {deleteObjectFile} from '@/api/eam/eam.js'
import qcUpload from "./qc_upload"
import qcSOPUploadFile from "./qc_SOP_upload_file"
import {
downloadExportFile,
getExportStatus,
qcPartAttributeExport,
qcPartAttributeExportAsync
} from "../../../api/qc/qc";
export default {
components: {
qcSOPUploadFile,
@ -851,6 +850,8 @@
exportList: [],
// end
tagNo: '',
importLoading: false,
pollTimer: null,
searchData: {
site: '',
userName: this.$store.state.user.name,
@ -1681,6 +1682,10 @@
}
},
beforeDestroy() {
if (this.pollTimer) clearInterval(this.pollTimer);
},
methods: {
// bu
getSiteAndBuByUserName () {
@ -2183,34 +2188,73 @@
}
},
//excel
async createExportData() {
this.searchData.limit = -1
this.searchData.page = 1
this.searchData.importFlag = true
await qcPartAttributeSearch(this.searchData).then(({data}) => {
this.exportList= data.page.list
})
this.searchData.importFlag = false
return this.exportList
},
startDownload() {},
finishDownload() {},
async handleAsyncExport() {
// 1. loading
this.importLoading = true;
let jobId;
try {
// 2. jobId
const initRes = await qcPartAttributeExportAsync(this.searchData);
jobId = initRes.data; // initRes.data.jobId
// 3.
this.pollTimer = setInterval(async () => {
try {
const statusRes = await getExportStatus({ jobId });
const { status } = statusRes.data;
if (status === 'SUCCESS') {
clearInterval(this.pollTimer);
// 4.
const fileRes = await downloadExportFile({ jobId });
const blob = new Blob([fileRes.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
// 8
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
a.download = '物料属性设置导出' + year + month + day + hours + minutes + seconds + '.xlsx';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
// **** loading
this.importLoading = false;
} else if (status === 'FAILED') {
clearInterval(this.pollTimer);
this.$message.error('导出任务失败');
// **** loading
this.importLoading = false;
}
// PROCESSING
} catch (err) {
clearInterval(this.pollTimer);
console.error(err);
this.$message.error('轮询状态出错');
// loading
this.importLoading = false;
}
}, 2000);
fields () {
let json = "{"
this.columnList1.forEach((item, index) => {
if (index == this.columnList1.length - 1) {
json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
} else {
json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
}
})
json += "}"
let s = eval("(" + json + ")")
return s
} catch (e) {
console.error('启动异步导出失败:', e);
this.$message.error('启动导出失败,请稍后重试');
// loading
this.importLoading = false;
}
},
//

Loading…
Cancel
Save