From 0b3d2deb37745ea5dce42fa4a18f22a29d2f4a12 Mon Sep 17 00:00:00 2001
From: fei.wang <wf18701153496@163.com>
Date: 星期三, 16 四月 2025 09:13:24 +0800
Subject: [PATCH] v2.0.2更新时间4.16

---
 src/views/analysis/index.vue |  410 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 266 insertions(+), 144 deletions(-)

diff --git a/src/views/analysis/index.vue b/src/views/analysis/index.vue
index c59c8c7..92c50aa 100644
--- a/src/views/analysis/index.vue
+++ b/src/views/analysis/index.vue
@@ -19,11 +19,26 @@
           鏂板
         </el-button> -->
       </el-button-group>
+
+      <span style="margin-left: 100px;">
+        <el-date-picker v-model="timeExport" type="daterange" unlink-panels :picker-options="pickerOptions"
+          range-separator="鑷�" start-placeholder="寮�濮嬫椂闂�" end-placeholder="缁撴潫鏃堕棿" value-format="yyyy-MM-dd" />
+
+        <el-button style="margin-left: 10px;" type="primary" @click="exportExcel">瀵煎嚭EXCEL</el-button>
+
+        <el-button style="margin-left: 10px;" type="primary" @click="resetinitv">閲嶇疆鍒濆鍊�</el-button>
+
+      </span>
+
+
     </div>
 
     <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit height="100%"
-      class="table-container" highlight-current-row>
+      class="table-container" highlight-current-row @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55">
+      </el-table-column>
       <el-table-column fixed label="搴忓彿" width="80">
+
         <template slot-scope="scope">
           {{ scope.row.id }}
         </template>
@@ -70,7 +85,12 @@
 
 
       </el-table-column>
-      <el-table-column label="娣诲姞鏃堕棿" >
+      <el-table-column label="鍒濆鍊间笢鍖楀ぉ" width="250">
+        <template slot-scope="scope">
+          {{ scope.row.ed + ';' + scope.row.nd + ';' + scope.row.td }}
+        </template>
+      </el-table-column>
+      <el-table-column label="娣诲姞鏃堕棿">
         <template slot-scope="scope">
           {{ scope.row.addtime }}
         </template>
@@ -84,8 +104,8 @@
   </div>
   <div v-else class="app-container">
     <div style="margin-bottom: 30px;">
-      <el-date-picker v-model="queryForm.time" type="monthrange"  unlink-panels  :picker-options="pickerOptions" range-separator="鑷�" start-placeholder="寮�濮嬫椂闂�"
-        end-placeholder="缁撴潫鏃堕棿" value-format="yyyy-MM-dd" />
+      <el-date-picker v-model="queryForm.time" type="daterange" unlink-panels :picker-options="pickerOptions"
+        range-separator="鑷�" start-placeholder="寮�濮嬫椂闂�" end-placeholder="缁撴潫鏃堕棿" value-format="yyyy-MM-dd" />
       <el-button style="margin-left: 10px;" type="primary" @click="handlechart">鎼滅储</el-button>
       <el-button style="position: absolute; right: 50px;" type="primary" @click="fanhui">杩斿洖</el-button>
 
@@ -100,7 +120,8 @@
       <el-button v-if="last" style="margin-left: 10px;" :type="lastyearprimary" @click="lastyear">涓婁竴骞�</el-button>
       <el-button v-if="next" style="margin-left: 10px;" :type="nextyearprimary" @click="nextyear">涓嬩竴骞�</el-button>
     </div>
-    <span style=" display: flex;justify-content: center;align-items: center;font-size: 25px;"> {{ this.anchorname+"-" +this.tagid+"鍙樺寲瓒嬪娍鍥�"}}</span>
+    <span style=" display: flex;justify-content: center;align-items: center;font-size: 25px;"> {{ this.anchorname + "-"
+      + this.tagid + "鍙樺寲瓒嬪娍鍥�" }}</span>
     <line-chart :chart-data="lineChartData" />
 
 
@@ -108,10 +129,12 @@
 </template>
 
 <script>
+import * as XLSX from 'xlsx';
+import { saveAs } from 'file-saver';
 import { formatTime1 } from "@/utils/index.js"; //鏃ユ湡鏍煎紡杞崲
 import LineChart from "./components/LineChart";
 import Pagination from '@/components/Pagination'
-import { getList, searcheveryday, handlechart2, handlechartupdate3 } from '@/api/analysis'
+import { getList, searcheveryday, handlechart2, handlechartupdate3, handlechartupdate2,resetinitv } from '@/api/analysis'
 import { deepClone } from '@/utils'
 
 const lineChartData = {
@@ -120,7 +143,7 @@
     nd: [],
     hd: [],
     x: [],
-   
+
   },
 
 };
@@ -132,43 +155,44 @@
   data() {
     return {
       pickerOptions: {
-          shortcuts: [{
-            text: '鏈湀',
-            onClick(picker) {
-              picker.$emit('pick', [new Date(), new Date()]);
-            }
-          }, {
-            text: '浠婂勾鑷充粖',
-            onClick(picker) {
-              const end = new Date();
-              const start = new Date(new Date().getFullYear(), 0);
-              picker.$emit('pick', [start, end]);
-            }
-          }, {
-            text: '鏈�杩戝叚涓湀',
-            onClick(picker) {
-              const end = new Date();
-              const start = new Date();
-              start.setMonth(start.getMonth() - 6);
-              picker.$emit('pick', [start, end]);
-            }
-          }]
-        },
-        yearprimary:'success',
-        oneprimary:'primary',
-        twoprimary:'primary',
-        threeprimary:'primary',
-        lastyearprimary:'primary',
-        nextyearprimary:'primary',
-      last:true,
-      next:false,
-      yeardata:0,
-      anchorname:'',
-      tagid:'',
+        shortcuts: [{
+          text: '鏈湀',
+          onClick(picker) {
+            picker.$emit('pick', [new Date(), new Date()]);
+          }
+        }, {
+          text: '浠婂勾鑷充粖',
+          onClick(picker) {
+            const end = new Date();
+            const start = new Date(new Date().getFullYear(), 0);
+            picker.$emit('pick', [start, end]);
+          }
+        }, {
+          text: '鏈�杩戝叚涓湀',
+          onClick(picker) {
+            const end = new Date();
+            const start = new Date();
+            start.setMonth(start.getMonth() - 6);
+            picker.$emit('pick', [start, end]);
+          }
+        }]
+      },
+      yearprimary: 'success',
+      oneprimary: 'primary',
+      twoprimary: 'primary',
+      threeprimary: 'primary',
+      lastyearprimary: 'primary',
+      nextyearprimary: 'primary',
+      last: true,
+      next: false,
+      yeardata: 0,
+      anchorname: '',
+      tagid: '',
       queryForm: {
         time: '',
         tagid: ''
       },
+      timeExport: '',
       lineChartData: lineChartData.newVisitis,
       analy: true,
       total: 0,
@@ -183,7 +207,7 @@
         time: undefined,
       },
       uploadUrl: '',
-
+      multipleSelection: [],
       dialogVisible: false,
       dialogType: 'create',
       loading: false
@@ -193,25 +217,111 @@
     this.fetchData()
   },
   methods: {
+    handleSelectionChange(val) {
+      this.multipleSelection = val;
+    },
+    resetinitv() {
+      console.log("閲嶇疆鍒濆鍊�");
+      console.log(this.multipleSelection);
+      if (this.multipleSelection.length == 0) {
+        this.$message({
+          message: '璇峰厛閫夋嫨涓�鏉℃暟鎹�',
+          type: 'error'
+        })
+      } else if (this.multipleSelection.length > 1) {
+        this.$message({
+          message: '璇烽�夋嫨涓�鏉℃暟鎹�',
+          type: 'error'
+        })
+
+
+      }else{
+
+      this.$confirm('浣犲皢纭畾灏�' + this.multipleSelection[0].tagid + ' 缂栧彿璁惧閲嶇疆鍒濆鍊间负' + this.multipleSelection[0].ed + ';' + this.multipleSelection[0].nd + ';' + this.multipleSelection[0].td + ' 鍚�?', '鎻愮ず', {
+        confirmButtonText: '纭畾',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning',
+        center: true
+      }).then(() => {
+        
+        const params = { tagid: this.multipleSelection[0].tagid , initv: this.multipleSelection[0].ed + ';' + this.multipleSelection[0].nd + ';' + this.multipleSelection[0].td };
+        resetinitv(params).then(response => {
+console.log(response);
+
+
+        })
+        this.$message({
+          type: 'success',
+          message: '閲嶇疆鎴愬姛!'
+        });
+      }).catch(() => {
+        this.$message({
+          type: 'info',
+          message: '宸插彇娑堥噸缃�'
+        });
+      });
+
+    }
+
+    },
+    exportExcel() {
+      console.log(this.timeExport);
+      // const data = []
+      const params = { date1: this.timeExport[1], date2: this.timeExport[0], username: localStorage.getItem('username') || '' };
+      handlechartupdate2(params).then(response => {
+        console.log(response);
+        const data = response.data
+        // 鑾峰彇瑕佸鍑虹殑鏁版嵁
+        // const data = this.list; // 鍋囪list鏄〃鏍肩殑鏁版嵁
+        // 鍒涘缓涓�涓┖鐨勫伐浣滅翱
+        const workbook = XLSX.utils.book_new();
+        // 鍒涘缓涓�涓伐浣滆〃
+        const worksheet = XLSX.utils.json_to_sheet(data);
+        // 灏嗗伐浣滆〃娣诲姞鍒板伐浣滅翱涓�
+        XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
+        // 灏嗗伐浣滅翱杞崲涓轰簩杩涘埗瀛楃涓�
+        const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
+        // 灏嗕簩杩涘埗瀛楃涓茶浆鎹负Blob瀵硅薄
+        const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' });
+        // 鍒涘缓涓�涓笅杞介摼鎺�
+        const url = URL.createObjectURL(blob);
+        // 鍒涘缓涓�涓殣钘忕殑閾炬帴鍏冪礌
+        const link = document.createElement('a');
+        link.href = url;
+        link.download = 'export.xlsx'; // 璁剧疆涓嬭浇鐨勬枃浠跺悕
+        // 妯℃嫙鐐瑰嚮涓嬭浇閾炬帴
+        link.click();
+        // 閲婃斁URL瀵硅薄
+        URL.revokeObjectURL(url);
+      })
+      // console.log(data);
+
+
+    },
+    Export() {
+
+    },
     fanhui() {
       this.analy = true
     },
     analyze(scope) {
-      this.anchorname=scope.row.anchorname
-      this.tagid=scope.row.tagid
-      const params = { date1: this.queryForm.time[1], date2: this.queryForm.time[0], username: localStorage.getItem('username') || '' ,tagid:scope.row.tagid};
+      this.anchorname = scope.row.anchorname
+      this.tagid = scope.row.tagid
+      const params = { date1: this.queryForm.time[1], date2: this.queryForm.time[0], username: localStorage.getItem('username') || '', tagid: scope.row.tagid };
       handlechart2(params).then(response => {
+        console.log(response);
+
         this.lineChartData = response.data
         this.analy = false
       })
     },
     one() {
-      this.oneprimary='success'
-      this.twoprimary='primary'
-      this.threeprimary='primary'
-      this.yearprimary='primary'
-      this.lastyearprimary='primary'
-      this.nextyearprimary='primary'
+      this.oneprimary = 'success'
+      this.twoprimary = 'primary'
+      this.threeprimary = 'primary'
+      this.yearprimary = 'primary'
+      this.lastyearprimary = 'primary'
+      this.nextyearprimary = 'primary'
       // 鑾峰彇褰撳墠鏃ユ湡
       const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
@@ -224,22 +334,22 @@
       var time = []
       time.push(newDate)
       time.push(dateYear)
-      this.queryForm.time=time
-      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '' ,tagid:this.tagid};
+      this.queryForm.time = time
+      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
         this.lineChartData = response.data
       })
 
     },
     two() {
-      this.oneprimary='primary'
-      this.twoprimary='success'
-      this.threeprimary='primary'
-      this.yearprimary='primary'
-      this.lastyearprimary='primary'
-      this.nextyearprimary='primary'
-        // 鑾峰彇褰撳墠鏃ユ湡
-        const currentDate = new Date();
+      this.oneprimary = 'primary'
+      this.twoprimary = 'success'
+      this.threeprimary = 'primary'
+      this.yearprimary = 'primary'
+      this.lastyearprimary = 'primary'
+      this.nextyearprimary = 'primary'
+      // 鑾峰彇褰撳墠鏃ユ湡
+      const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
       const currentMonth = currentDate.getMonth();
       // 璁剧疆鏃ユ湡鐨勬湀浠戒负褰撳墠鏈堜唤鍑忎竴
@@ -250,20 +360,20 @@
       var time = []
       time.push(newDate)
       time.push(dateYear)
-      this.queryForm.time=time
-      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '' ,tagid:this.tagid};
+      this.queryForm.time = time
+      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
         this.lineChartData = response.data
       })
 
     },
     three() {
-      this.oneprimary='primary'
-      this.twoprimary='primary'
-      this.threeprimary='success'
-      this.yearprimary='primary'
-      this.lastyearprimary='primary'
-      this.nextyearprimary='primary'
+      this.oneprimary = 'primary'
+      this.twoprimary = 'primary'
+      this.threeprimary = 'success'
+      this.yearprimary = 'primary'
+      this.lastyearprimary = 'primary'
+      this.nextyearprimary = 'primary'
       // 鑾峰彇褰撳墠鏃ユ湡
       const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
@@ -277,23 +387,23 @@
       var time = []
       time.push(newDate)
       time.push(dateYear)
-      this.queryForm.time=time
-      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '',tagid:this.tagid };
+      this.queryForm.time = time
+      const params = { date1: dateYear, date2: newDate, username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
-        
+
         this.lineChartData = response.data
       })
     },
 
     year() {
-      this.oneprimary='primary'
-      this.twoprimary='primary'
-      this.threeprimary='primary'
-      this.yearprimary='success'
-      this.lastyearprimary='primary'
-      this.nextyearprimary='primary'
-      this.next=false
-      this.last=true
+      this.oneprimary = 'primary'
+      this.twoprimary = 'primary'
+      this.threeprimary = 'primary'
+      this.yearprimary = 'success'
+      this.lastyearprimary = 'primary'
+      this.nextyearprimary = 'primary'
+      this.next = false
+      this.last = true
       // 鑾峰彇褰撳墠鏃ユ湡
       // const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
@@ -303,119 +413,119 @@
       const newDate = formatTime1(new Date(), "yyyy-MM-dd");
       //鑾峰彇褰撳墠骞存湀鏃�
       const dateYear = formatTime1(new Date(), "yyyy");
-      console.log(dateYear+'-01-01');
+      console.log(dateYear + '-01-01');
       this.yeardata = dateYear
       var time = []
-      time.push(newDate+'-01-01')
+      time.push(newDate + '-01-01')
       time.push(newDate)
-      this.queryForm.time=time
-      const params = { date1: newDate, date2: dateYear+'-01-01', username: localStorage.getItem('username') || '',tagid:this.tagid };
+      this.queryForm.time = time
+      const params = { date1: newDate, date2: dateYear + '-01-01', username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
         console.log(response);
-        
+
         this.lineChartData = response.data
       })
     },
 
-    lastornext(){
+    lastornext() {
       const currentDate = new Date();
       const currentMonth = currentDate.getFullYear();
       console.log(currentMonth);
       console.log(this.yeardata);
-      
-      
-      if (this.yeardata<currentMonth) {
-        this.next=true
-        if (this.yeardata<=2022) {
-        this.last=false
-      }else{
-        this.last=true
+
+
+      if (this.yeardata < currentMonth) {
+        this.next = true
+        if (this.yeardata <= 2022) {
+          this.last = false
+        } else {
+          this.last = true
+        }
+      } else {
+        this.next = false
       }
-      }else {
-        this.next=false
-      }
-      
+
     },
 
     lastyear() {
-      this.oneprimary='primary'
-      this.twoprimary='primary'
-      this.threeprimary='primary'
-      this.yearprimary='primary'
-      this.lastyearprimary='success'
-      this.nextyearprimary='primary'
+      this.oneprimary = 'primary'
+      this.twoprimary = 'primary'
+      this.threeprimary = 'primary'
+      this.yearprimary = 'primary'
+      this.lastyearprimary = 'success'
+      this.nextyearprimary = 'primary'
       // 鑾峰彇褰撳墠鏃ユ湡
       const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
       const currentMonth = currentDate.getFullYear();
 
       // 璁剧疆鏃ユ湡鐨勬湀浠戒负褰撳墠鏈堜唤鍑忎竴
-      
-      if (this.yeardata=="") {
+
+      if (this.yeardata == "") {
         currentDate.setFullYear(currentMonth - 1);
         // this.yeardata=currentMonth - 1;
 
-      }else{
+      } else {
         currentDate.setFullYear(this.yeardata - 1);
         // this.yeardata = this.yeardata - 1
 
       }
       const newDate = formatTime1(currentDate, "yyyy");
-      
+
       this.yeardata = parseInt(newDate)
-this.lastornext()
+      this.lastornext()
       //鑾峰彇褰撳墠骞存湀鏃�
       const dateYear = formatTime1(new Date(), "yyyy-MM-dd");
       // this.queryForm.time.push(newDate+'-01-01')
       // this.queryForm.time.push(newDate+'-12-31')
       var time = []
-      time.push(newDate+'-01-01')
-      time.push(newDate+'-12-31')
-      this.queryForm.time=time
-      const params = { date1: newDate+'-12-31', date2: newDate+'-01-01', username: localStorage.getItem('username') || '',tagid:this.tagid };
+      time.push(newDate + '-01-01')
+      time.push(newDate + '-12-31')
+      this.queryForm.time = time
+      const params = { date1: newDate + '-12-31', date2: newDate + '-01-01', username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
-        
+
         this.lineChartData = response.data
       })
     },
 
     nextyear() {
-      this.oneprimary='primary'
-      this.twoprimary='primary'
-      this.threeprimary='primary'
-      this.yearprimary='primary'
-      this.lastyearprimary='primary'
-      this.nextyearprimary='success'
+      this.oneprimary = 'primary'
+      this.twoprimary = 'primary'
+      this.threeprimary = 'primary'
+      this.yearprimary = 'primary'
+      this.lastyearprimary = 'primary'
+      this.nextyearprimary = 'success'
       // 鑾峰彇褰撳墠鏃ユ湡
       const currentDate = new Date();
       // 鑾峰彇褰撳墠鏈堜唤
       // const currentMonth = currentDate.getFullYear();
       // 璁剧疆鏃ユ湡鐨勬湀浠戒负褰撳墠鏈堜唤鍑忎竴
       console.log(this.yeardata);
-      
-      currentDate.setFullYear( this.yeardata + 1);
+
+      currentDate.setFullYear(this.yeardata + 1);
       const newDate = formatTime1(currentDate, "yyyy");
       console.log(newDate);
-      
+
       this.yeardata = parseInt(newDate)
       //鑾峰彇褰撳墠骞存湀鏃�
       this.lastornext()
       const dateYear = formatTime1(new Date(), "yyyy-MM-dd");
       var time = []
-      time.push(newDate+'-01-01')
-      time.push(newDate+'-12-31')
-      this.queryForm.time=time
-      const params = { date1: newDate+'-12-31', date2: newDate+'-01-01', username: localStorage.getItem('username') || '',tagid:this.tagid };
+      time.push(newDate + '-01-01')
+      time.push(newDate + '-12-31')
+      this.queryForm.time = time
+      const params = { date1: newDate + '-12-31', date2: newDate + '-01-01', username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
-        
+
         this.lineChartData = response.data
       })
     },
-    
+
     handlechart() {
       console.log(this.queryForm.time);
-      
-      const params = { date1: this.queryForm.time[1], date2: this.queryForm.time[0], username: localStorage.getItem('username') || '',tagid:this.tagid };
+
+      const params = { date1: this.queryForm.time[1], date2: this.queryForm.time[0], username: localStorage.getItem('username') || '', tagid: this.tagid };
       handlechartupdate3(params).then(response => {
         this.lineChartData = response.data
       })
@@ -425,8 +535,16 @@
     search() {
       this.listLoading = true
       searcheveryday(this.listQuery).then(response => {
-        this.list = response.data.records
-        this.total = response.data.total
+        if (response.data != null) {
+          this.list = response.data.records
+          this.total = response.data.total
+        } else {
+          this.$message({
+            message: '鏈悳绱㈠埌鏁版嵁',
+            type: 'error'
+          })
+        }
+
         this.listLoading = false
       })
     },
@@ -445,7 +563,7 @@
       this.listLoading = true
       getList(this.listQuery).then(response => {
         console.log(response);
-        
+
         this.list = response.data.records
         this.total = response.data.total
         this.listLoading = false
@@ -455,21 +573,21 @@
 
 
     searchorfetchData() {
-console.log(this.listQuery.keyword);
+      console.log(this.listQuery.keyword);
 
-      if (this.listQuery.keyword!=undefined) {
+      if (this.listQuery.keyword != undefined) {
         console.log(111111);
-        
+
         this.search()
-      }else{
+      } else {
         console.log(2222);
-        
+
         this.fetchData()
       }
       // this.listLoading = true
       // getList(this.listQuery).then(response => {
       //   console.log(response);
-        
+
       //   this.list = response.data.records
       //   this.total = response.data.total
       //   this.listLoading = false
@@ -499,14 +617,18 @@
     text-align: center;
   }
 }
+
 .el-table .el-table__body tr:hover {
-  background-color: transparent!important; /* 浣犳兂瑕佺殑鑳屾櫙鑹� */
-  color: #000!important;
+  background-color: transparent !important;
+  /* 浣犳兂瑕佺殑鑳屾櫙鑹� */
+  color: #000 !important;
 }
+
 .el-table__body {
-  tr:hover > td {
-    background-color: transparent!important; /* 浣犳兂瑕佺殑鑳屾櫙鑹� */
-    color: #000!important;
+  tr:hover>td {
+    background-color: transparent !important;
+    /* 浣犳兂瑕佺殑鑳屾櫙鑹� */
+    color: #000 !important;
   }
 }
 

--
Gitblit v1.9.3