diff --git a/src/utils/curd.js b/src/utils/curd.js index e0c97db..76cd689 100644 --- a/src/utils/curd.js +++ b/src/utils/curd.js @@ -6,7 +6,22 @@ export default { install(Vue) { Vue.prototype.exportExcel_NPOI = function(param) { console.log(param, 1) - download(`${ExcelDownLoad}?param=${param}`) + return download(`${ExcelDownLoad}?param=${param}`) + } + Vue.prototype.runExcelExport = function(param, loadingKey) { + if (loadingKey) { + this[loadingKey] = true + } + return this.exportExcel_NPOI(param).then(() => { + this.$message.success('导出成功') + }).catch(error => { + console.error('导出失败:', error) + this.$message.error(error.message || '导出失败') + }).finally(() => { + if (loadingKey) { + this[loadingKey] = false + } + }) } // 用于生成传通讯服务器参数。 // 传入参数 @@ -396,24 +411,41 @@ export default { } } function download(url) { - getBlob(url, function(blob, filename) { + return getBlob(url).then(({ blob, filename }) => { console.log(blob, filename, 2) saveAs(blob, filename) + return filename }) } -function getBlob(url, cb) { - var xhr = new XMLHttpRequest() - xhr.open('GET', url, true) - xhr.responseType = 'blob' - xhr.onload = function() { - if (xhr.status === 200) { - const name = xhr.getResponseHeader('content-disposition').split('=')[1] - var filename = decodeURIComponent(name) - cb(xhr.response, filename) +function getBlob(url) { + return new Promise((resolve, reject) => { + var xhr = new XMLHttpRequest() + xhr.open('GET', url, true) + xhr.responseType = 'blob' + xhr.timeout = 1500000 + xhr.onload = function() { + if (xhr.status === 200) { + try { + const disposition = xhr.getResponseHeader('content-disposition') || '' + const name = disposition.indexOf('=') > -1 ? disposition.split('=').pop() : '导出.xlsx' + var filename = decodeURIComponent(name) + resolve({ blob: xhr.response, filename }) + } catch (error) { + reject(error) + } + } else { + reject(new Error('导出失败,状态码:' + xhr.status)) + } } - } - xhr.send() + xhr.onerror = function() { + reject(new Error('导出请求失败')) + } + xhr.ontimeout = function() { + reject(new Error('导出超时')) + } + xhr.send() + }) } function saveAs(blob, filename) { @@ -432,4 +464,3 @@ function saveAs(blob, filename) { window.URL.revokeObjectURL(link.href) } } - diff --git a/src/views/AndonSystem/AndonStatisticsStation/index.vue b/src/views/AndonSystem/AndonStatisticsStation/index.vue index 9836f0a..02b1bae 100644 --- a/src/views/AndonSystem/AndonStatisticsStation/index.vue +++ b/src/views/AndonSystem/AndonStatisticsStation/index.vue @@ -3,7 +3,7 @@ 工位号: - + 呼叫日期: 查询 + Excel @@ -105,6 +106,7 @@ export default { pageCurrent: 1, totalNum: 0, downloadLoading: '', + exportLoading: false, tableData_excel: [], stationNumberValue: '', stationNumber: [], @@ -132,16 +134,20 @@ export default { if (response.data.length > 0) this.stationNumberValue = response.data[0].工位号 }) }, - fetchData() { - this.listLoading = true + getParam(pageCurrent, pageSize) { var param = [] param[0] = ['开始时间', this.startTime[0] + ' 00:00:00'] param[1] = ['结束时间', this.startTime[1] + ' 23:59:59'] param[2] = ['工位号', this.stationNumberValue] - param[3] = ['PageCurrent', this.pageCurrent] - param[4] = ['PageSize', this.pageSize] + param[3] = ['PageCurrent', pageCurrent] + param[4] = ['PageSize', pageSize] param[5] = ['PageCount', 1000, 'int', '1'] param[6] = ['ItemCount', 1000, 'int', '1'] + return param + }, + fetchData() { + this.listLoading = true + var param = this.getParam(this.pageCurrent, this.pageSize) var Data = this.CreateData('11', 'ANDON_工位呼叫_综合查询', param) this.ExecDatabase(Data).then(response => { this.tableData = response.data.result @@ -159,6 +165,16 @@ export default { this.pageCurrent = val this.fetchData() }, + exportExcel() { + if (this.tableData.length === 0) { + this.$message.warning('暂无数据') + return + } + var exportData = JSON.parse(this.CreateData('2005', 'ANDON_工位呼叫_综合查询', this.getParam(1, 99999999))) + exportData.exportFileName = '工位呼叫统计' + exportData.exportColumns = '工位号,呼叫类型,呼叫时间,员工姓名=呼叫人,编号描述=问题描述,复位时间=解除时间,复位人员=解除人员,持续时间=持续时间(s)' + this.runExcelExport(JSON.stringify(exportData), 'exportLoading') + }, // 导出excel handleDownload() { this.downloadLoading = true @@ -393,4 +409,3 @@ span{ /*margin: 10px 0px 10px 10px;*/ } - diff --git a/src/views/AndonSystem/AndonStatisticsType/index.vue b/src/views/AndonSystem/AndonStatisticsType/index.vue index d2ed517..09f41e0 100644 --- a/src/views/AndonSystem/AndonStatisticsType/index.vue +++ b/src/views/AndonSystem/AndonStatisticsType/index.vue @@ -5,6 +5,7 @@ 呼叫日期: 查询 + Excel @@ -96,6 +97,7 @@ export default { pageCurrent: 1, totalNum: 0, downloadLoading: '', + exportLoading: false, tableData_excel: [], stationNumberValue: '', stationNumber: [], @@ -123,15 +125,19 @@ export default { if (response.data.length > 0) this.stationNumberValue = response.data[0].工位号 }) }, - fetchData() { - this.listLoading = true + getParam(pageCurrent, pageSize) { var param = [] param[0] = ['开始时间', this.startTime[0] + ' 00:00:00'] param[1] = ['结束时间', this.startTime[1] + ' 23:59:59'] - param[2] = ['PageCurrent', this.pageCurrent] - param[3] = ['PageSize', this.pageSize] + param[2] = ['PageCurrent', pageCurrent] + param[3] = ['PageSize', pageSize] param[4] = ['PageCount', 1000, 'int', '1'] param[5] = ['ItemCount', 1000, 'int', '1'] + return param + }, + fetchData() { + this.listLoading = true + var param = this.getParam(this.pageCurrent, this.pageSize) var Data = this.CreateData('11', 'ANDON_类型呼叫_综合查询', param) this.ExecDatabase(Data).then(response => { this.tableData = response.data.result @@ -149,6 +155,16 @@ export default { this.pageCurrent = val this.fetchData() }, + exportExcel() { + if (this.tableData.length === 0) { + this.$message.warning('暂无数据') + return + } + var exportData = JSON.parse(this.CreateData('2005', 'ANDON_类型呼叫_综合查询', this.getParam(1, 99999999))) + exportData.exportFileName = '类型呼叫统计' + exportData.exportColumns = '工位号,呼叫类型,呼叫时间,员工姓名=呼叫人,编号描述=问题描述,复位时间=解除时间,复位人员=解除人员,持续时间=持续时间(s)' + this.runExcelExport(JSON.stringify(exportData), 'exportLoading') + }, // 导出excel handleDownload() { this.downloadLoading = true @@ -379,4 +395,3 @@ span{ /*margin: 10px 0px 10px 10px;*/ } - diff --git a/src/views/BasicData/SystemAlarmLog/index.vue b/src/views/BasicData/SystemAlarmLog/index.vue index 1ddb6af..48ef66d 100644 --- a/src/views/BasicData/SystemAlarmLog/index.vue +++ b/src/views/BasicData/SystemAlarmLog/index.vue @@ -4,7 +4,7 @@
工位号: + style="width:240px"> 是否结束: @@ -17,6 +17,8 @@ start-placeholder="开始日期" end-placeholder="结束日期" /> 查询 + Excel 删除
@@ -80,7 +82,8 @@ export default { pageSize: 100, pageCurrent: 1, selectedRows: [], - deleteLoading: false + deleteLoading: false, + exportLoading: false } }, created() { @@ -114,22 +117,29 @@ export default { const found = this.stationNumber.find(item => item.value === stationCode) return found ? found.label : stationCode }, - searchTable() { + getQueryParam(pageCurrent, pageSize) { if (!this.dateTime || this.dateTime.length !== 2) { this.$message.warning('请选择查询时间范围!') - return + return null } - this.loading = true - this.tableData = [] const param = [] param.push(['工位号', this.stationNumberValue || '']) param.push(['是否结束', this.isEndedValue || '']) param.push(['开始时间', this.dateTime[0] + ' 00:00:00']) param.push(['结束时间', this.dateTime[1] + ' 23:59:59']) - param.push(['PageCurrent', this.pageCurrent]) - param.push(['PageSize', this.pageSize]) + param.push(['PageCurrent', pageCurrent]) + param.push(['PageSize', pageSize]) param.push(['PageCount', '0', 'int', '1']) param.push(['ItemCount', '0', 'int', '1']) + return param + }, + searchTable() { + const param = this.getQueryParam(this.pageCurrent, this.pageSize) + if (!param) { + return + } + this.loading = true + this.tableData = [] const Data = this.CreateData('11', '报警工位记录表_分页_查询', param) this.ExecDatabase(Data).then(response => { if (response.data.result && response.data.result.length > 0) { @@ -149,6 +159,21 @@ export default { console.error('searchTable error:', err) }) }, + exportExcel() { + if (this.tableData.length === 0) { + this.$message.warning('暂无数据') + return + } + const param = this.getQueryParam(1, 99999999) + if (!param) { + return + } + const exportData = JSON.parse(this.CreateData('2005', '报警工位记录表_分页_查询', param)) + exportData.exportFileName = '工位报警记录' + exportData.exportColumns = '工位号,开始时间,结束时间,持续时间' + const Data = JSON.stringify(exportData) + this.runExcelExport(Data, 'exportLoading') + }, handleSelectionChange(rows) { this.selectedRows = rows || [] }, diff --git a/src/views/BasicData/WorkStationAlarmLog/index.vue b/src/views/BasicData/WorkStationAlarmLog/index.vue index 4faaa2d..3f598cf 100644 --- a/src/views/BasicData/WorkStationAlarmLog/index.vue +++ b/src/views/BasicData/WorkStationAlarmLog/index.vue @@ -3,7 +3,7 @@
工位号: - + 消息来源: @@ -22,10 +22,11 @@ start-placeholder="开始日期" end-placeholder="结束日期" /> 查询 + Excel
+ style="width: 90%">