|
@@ -29,7 +29,7 @@
|
|
|
<!-- 操作按钮区域 -->
|
|
|
<div class="table-operator">
|
|
|
<!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
|
|
|
- <a-button type="primary" icon="download" @click="daochu('1立方温箱历史数据')">导出</a-button>
|
|
|
+ <a-button type="primary" icon="download" @click="dc('1立方温箱历史数据')">导出</a-button>
|
|
|
<!-- <a-button type="primary" icon="download" @click="handleExportXls('1立方温箱历史数据')">导出</a-button>-->
|
|
|
<!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
|
|
|
<!-- <a-button type="primary" icon="import">导入</a-button>-->
|
|
@@ -312,91 +312,83 @@
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- // 导出
|
|
|
- daochu(fileName){
|
|
|
+
|
|
|
+ // 判断时间段是否在3个月内,在的话导出,超出的话提示
|
|
|
+ dc(fileName){
|
|
|
console.log(11111,this.queryParam)
|
|
|
+ //判断时间段是否在3个月内
|
|
|
+ let flag = this.completeDate(queryParam.createTime_begin,queryParam.createTime_end,3)
|
|
|
|
|
|
- var time1 = new Date(this.queryParam.createTime_begin).getTime();
|
|
|
- var time2 = new Date(this.queryParam.createTime_end).getTime();
|
|
|
- var flag = true;
|
|
|
- if(this.queryParam.createTime_begin==''){
|
|
|
- alert("开始时间不能为空");
|
|
|
- flag = false;
|
|
|
+ if(flag){
|
|
|
+ this.handleExportXls(fileName)
|
|
|
+ }else {
|
|
|
+ this.$message.error("时间跨度不得超过3个月!")
|
|
|
}
|
|
|
- if(this.queryParam.createTime_end==''){
|
|
|
- alert("结束时间不能为空");
|
|
|
- flag = false;
|
|
|
+ },
|
|
|
+
|
|
|
+ //导出xls
|
|
|
+ handleExportXls(fileName){
|
|
|
+ if(!fileName || typeof fileName != "string"){
|
|
|
+ fileName = "导出文件"
|
|
|
}
|
|
|
- if(time1 > time2){
|
|
|
- alert("开始时间不能大于结束时间");
|
|
|
- flag = false;
|
|
|
+ let param = this.getQueryParams();
|
|
|
+ if(this.selectedRowKeys && this.selectedRowKeys.length>0){
|
|
|
+ param['selections'] = this.selectedRowKeys.join(",")
|
|
|
}
|
|
|
-
|
|
|
- //判断时间跨度是否大于3个月
|
|
|
- var arr1 = this.queryParam.createTime_begin.split('-');
|
|
|
- var arr2 = this.queryParam.createTime_end.split('-');
|
|
|
- arr1[1] = parseInt(arr1[1]);
|
|
|
- arr1[2] = parseInt(arr1[2]);
|
|
|
- arr2[1] = parseInt(arr2[1]);
|
|
|
- arr2[2] = parseInt(arr2[2]);
|
|
|
- if(arr1[0] == arr2[0]){//同年
|
|
|
- if(arr2[1]-arr1[1] > 3){ //月间隔超过3个月
|
|
|
- flag = false;
|
|
|
- }else if(arr2[1]-arr1[1] == 3){ //月相隔3个月,比较日
|
|
|
- if(arr2[2] > arr1[2]){ //结束日期的日大于开始日期的日
|
|
|
- flag = false;
|
|
|
- }
|
|
|
+ console.log("导出参数",param)
|
|
|
+ downFile(this.url.exportXlsUrl,param).then((data)=>{
|
|
|
+ if (!data) {
|
|
|
+ this.$message.warning("文件下载失败")
|
|
|
+ return
|
|
|
}
|
|
|
- }else{ //不同年
|
|
|
- if(arr2[0] - arr1[0] > 1){
|
|
|
- flag = false;
|
|
|
- }else if(arr2[0] - arr1[0] == 1){
|
|
|
- if(arr1[1] < 10){ //开始年的月份小于10时,不需要跨年
|
|
|
- flag = false;
|
|
|
- }else if(arr1[1]+3-arr2[1] < 12){ //月相隔大于3个月
|
|
|
- flag = false;
|
|
|
- }else if(arr1[1]+3-arr2[1] == 12){ //月相隔3个月,比较日
|
|
|
- if(arr2[2] > arr1[2]){ //结束日期的日大于开始日期的日
|
|
|
- flag = false;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
|
+ window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
|
|
|
+ }else{
|
|
|
+ let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
|
|
|
+ let link = document.createElement('a')
|
|
|
+ link.style.display = 'none'
|
|
|
+ link.href = url
|
|
|
+ link.setAttribute('download', fileName+'.xls')
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link); //下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(url); //释放掉blob对象
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ })
|
|
|
+ },
|
|
|
|
|
|
- if(flag){
|
|
|
- console.log("flag:",flag)
|
|
|
- if(!fileName || typeof fileName != "string"){
|
|
|
- fileName = "导出文件"
|
|
|
+ //判断时间段是否在3个月内,是的话返回true,否则返回false
|
|
|
+ completeDate (time1, time2, m) {
|
|
|
+ const year1 = time1.getFullYear()
|
|
|
+ const year2 = time2.getFullYear()
|
|
|
+ const month1 = time1.getMonth() + 1
|
|
|
+ const month2 = time2.getMonth() + 1
|
|
|
+ const day1 = time1.getDate()
|
|
|
+ const day2 = time2.getDate()
|
|
|
+ if (year2 === year1) { // 判断两个日期 是否是同年
|
|
|
+ if (month2 - month1 > m) { // 相差是否 在m个月中
|
|
|
+ return false
|
|
|
+ } else if (month2 - month1 === m) { // 如果正好为 m月 判断天数
|
|
|
+ if (day2 > day1) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
- let param = this.getQueryParams();
|
|
|
- if(this.selectedRowKeys && this.selectedRowKeys.length>0){
|
|
|
- param['selections'] = this.selectedRowKeys.join(",")
|
|
|
+ } else { // 不同年
|
|
|
+ if (year2 - year1 > 1) {
|
|
|
+ return false
|
|
|
}
|
|
|
- console.log("导出参数",param)
|
|
|
- downFile(this.url.exportXlsUrl,param).then((data)=>{
|
|
|
- if (!data) {
|
|
|
- this.$message.warning("文件下载失败")
|
|
|
- return
|
|
|
+ else if (year2 - year1 === 1) {
|
|
|
+ if (month2 > m || month1 + m - month2 < 12) {
|
|
|
+ return false
|
|
|
}
|
|
|
- if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
|
- window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
|
|
|
- }else{
|
|
|
- let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
|
|
|
- let link = document.createElement('a')
|
|
|
- link.style.display = 'none'
|
|
|
- link.href = url
|
|
|
- link.setAttribute('download', fileName+'.xls')
|
|
|
- document.body.appendChild(link)
|
|
|
- link.click()
|
|
|
- document.body.removeChild(link); //下载完成移除元素
|
|
|
- window.URL.revokeObjectURL(url); //释放掉blob对象
|
|
|
+ else if (month1 + m - month2 === 12) { // 正好为m月 判断天数
|
|
|
+ if (day2 > day1) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- }else {
|
|
|
- console.log("!flag:",!flag)
|
|
|
- this.$message.error("时间跨度不得超过3个月!")
|
|
|
+ }
|
|
|
}
|
|
|
+ return true
|
|
|
},
|
|
|
|
|
|
initDictConfig(){
|