From 17ee16ee3bd2adcbd4998952db3977c887d4e488 Mon Sep 17 00:00:00 2001 From: yangzz <9704.yyds@163.com> Date: Tue, 2 Jun 2026 10:48:14 +0800 Subject: [PATCH] =?UTF-8?q?QC=E5=AD=90=E4=BB=B6=E4=BF=A1=E6=81=AF=E5=BD=95?= =?UTF-8?q?=E5=85=A5-=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/report/qcSubPart.js | 1 + src/views/modules/report/qcSubpart.vue | 58 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/api/report/qcSubPart.js b/src/api/report/qcSubPart.js index a0e1f53..9b1afa3 100644 --- a/src/api/report/qcSubPart.js +++ b/src/api/report/qcSubPart.js @@ -2,6 +2,7 @@ import { createAPI } from '@/utils/httpRequest.js' export const getHeaderList = data => createAPI('/report/qcSubPartQuery/getHeaderList', 'POST', data) export const getDetailList = data => createAPI('/report/qcSubPartQuery/getDetailList', 'POST', data) +export const exportQcSubPart = data => createAPI('/report/qcSubPartQuery/exportQcSubPart', 'POST', data, 'download') export const queryAddMainList = data => createAPI('/report/qcSubPartAdd/queryAddMainList', 'POST', data) export const queryAddDetailList = data => createAPI('/report/qcSubPartAdd/queryAddDetailList', 'POST', data) diff --git a/src/views/modules/report/qcSubpart.vue b/src/views/modules/report/qcSubpart.vue index 8ea2d36..f35415f 100644 --- a/src/views/modules/report/qcSubpart.vue +++ b/src/views/modules/report/qcSubpart.vue @@ -43,6 +43,7 @@ 查询 重置 新增 + {{ exportLoading ? '导出中...' : '导出' }} @@ -257,6 +258,7 @@ import { getSiteAndBuByUserName } from '@/api/qc/qc.js' import { getHeaderList, getDetailList, + exportQcSubPart, queryAddMainList, queryAddDetailList, saveAddRecord, @@ -276,6 +278,7 @@ export default { headerLoading: false, detailLoading: false, addMainLoading: false, + exportLoading: false, headerList: [], detailList: [], currentHeader: null, @@ -401,6 +404,52 @@ export default { this.headerLoading = false }) }, + exportFile () { + const payload = { + ...this.queryForm, + site: this.extractSiteFromBuKey(this.queryForm.citemCode), + searchFlag: 'Y' + } + this.exportLoading = true + exportQcSubPart(payload).then((response) => { + const blobData = response.data + const contentType = String((response.headers && response.headers['content-type']) || blobData.type || '').toLowerCase() + if (!blobData || blobData.size === 0) { + this.$message.warning('无可导出数据') + return + } + if (contentType.includes('application/json')) { + const reader = new FileReader() + reader.onload = () => { + let msg = '无可导出数据' + try { + const json = JSON.parse(reader.result) + if (json && json.msg) { + msg = json.msg + } + } catch (e) {} + this.$message.warning(msg) + } + reader.readAsText(blobData, 'utf-8') + return + } + const blob = new Blob([blobData], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) + const fileName = `QC子件报表_${this.formatExportTimestamp(new Date())}.xlsx` + 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) + this.$message.success('导出完成') + }).catch(() => { + this.$message.error('导出失败') + }).finally(() => { + this.exportLoading = false + }) + }, onHeaderCurrentChange (row) { this.currentHeader = row if (!row) { @@ -667,6 +716,15 @@ export default { const mm = '00' return `${y}-${m}-${d} ${hh}:${mm}` }, + formatExportTimestamp (date) { + const y = date.getFullYear() + const m = (`0${date.getMonth() + 1}`).slice(-2) + const d = (`0${date.getDate()}`).slice(-2) + const hh = (`0${date.getHours()}`).slice(-2) + const mm = (`0${date.getMinutes()}`).slice(-2) + const ss = (`0${date.getSeconds()}`).slice(-2) + return `${y}${m}${d}${hh}${mm}${ss}` + }, extractSiteFromBuKey (buKey) { if (!buKey || buKey.indexOf('_') < 0) { return this.$store.state.user.site