LLL преди 1 година
родител
ревизия
a609414bb4
променени са 1 файла, в които са добавени 81 реда и са изтрити 1 реда
  1. 81 1
      itdmWeb/src/views/module-iTDM/itdmWenxiangVoltage/ItdmWenxiangVoltageList.vue

+ 81 - 1
itdmWeb/src/views/module-iTDM/itdmWenxiangVoltage/ItdmWenxiangVoltageList.vue

@@ -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="handleExportXls('温箱集体电压历史数据')">导出</a-button>
+      <a-button type="primary" icon="download" @click="dc('温箱集体电压历史数据')">导出</a-button>
       <!--  <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
         <a-button type="primary" icon="import">导入</a-button>
       </a-upload> -->
@@ -125,6 +125,7 @@
   import { mixinDevice } from '@/utils/mixin'
   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
   import ItdmWenxiangVoltageModal from './modules/ItdmWenxiangVoltageModal'
+  import { downFile } from '@/api/manage'
 
   export default {
     name: 'ItdmWenxiangVoltageList',
@@ -245,6 +246,85 @@
       },
     },
     methods: {
+
+      // 判断时间段是否在3个月内,在的话导出,超出的话提示
+      dc(fileName){
+        console.log(11111,this.queryParam)
+        //判断时间段是否在3个月内
+        let flag = this.completeDate(queryParam.createTime_begin,queryParam.createTime_end,3)
+
+        if(flag){
+          this.handleExportXls(fileName)
+        }else {
+          this.$message.error("时间跨度不得超过3个月!")
+        }
+      },
+
+      //导出xls
+      handleExportXls(fileName){
+        if(!fileName || typeof fileName != "string"){
+          fileName = "导出文件"
+        }
+        let param = this.getQueryParams();
+        if(this.selectedRowKeys && this.selectedRowKeys.length>0){
+          param['selections'] = this.selectedRowKeys.join(",")
+        }
+        console.log("导出参数",param)
+        downFile(this.url.exportXlsUrl,param).then((data)=>{
+          if (!data) {
+            this.$message.warning("文件下载失败")
+            return
+          }
+          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对象
+          }
+        })
+      },
+
+      //判断时间段是否在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
+            }
+          }
+        } else { // 不同年
+          if (year2 - year1 > 1) {
+            return false
+          }
+          else if (year2 - year1 === 1) {
+            if (month2 > m || month1 + m - month2 < 12) {
+              return false
+            }
+            else if (month1 + m - month2 === 12) { // 正好为m月 判断天数
+              if (day2 > day1) {
+                return false
+              }
+            }
+          }
+        }
+        return true
+      },
+
       initDictConfig(){
       },
       getSuperFieldList(){