From f6739d7542be48f7f8139c3d5fc7b2326e5cfc8d Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期三, 22 十一月 2023 11:06:35 +0800
Subject: [PATCH] feat: 轮询plc时间调整; 接口报错时也轮询plc

---
 src/views/visualization.vue |  193 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 147 insertions(+), 46 deletions(-)

diff --git a/src/views/visualization.vue b/src/views/visualization.vue
index 24b7b59..8811c49 100644
--- a/src/views/visualization.vue
+++ b/src/views/visualization.vue
@@ -4,8 +4,9 @@
     <!-- v-if="Tasks&&Tasks.length>0" -->
     <template >
       <div class="left">
-        <p class="title">
-          <template v-if="Number(ChannelAmount)>1">
+        <div class="title">
+          <div class="dashboard-channels">
+            <template v-if="Number(ChannelAmount)>1">
             <span
               class="font set-title"
               style="float: left; margin-right: 15px;"
@@ -16,36 +17,48 @@
                 <img style="width:32px;" src="../../public/one.png" />
               </span>
             </span>
-            <span class="font set-title" style="float: left;margin-right: 15px;" @click="cutClick(2)">
+              <span class="font set-title" style="float: left;margin-right: 15px;" @click="cutClick(2)">
               <img style="width:32px;" v-if="activeName == 2" src="../../public/two-blue.png" />
               <img style="width:32px;" v-else src="../../public/two.png" />
             </span>
-            <span
-              class="font set-title"
-              style="float: left;"
-              @click="cutClick(3)"
-            >
+              <span
+                class="font set-title"
+                style="float: left;"
+                @click="cutClick(3)"
+              >
               <img style="width:32px;" v-if="activeName == 3" src="../../public/right-blue.png" />
               <span  v-else>
                 <img style="width:32px;" src="../../public/right.png" />
               </span>
             </span>
-         </template>
-          鏅鸿兘宸ヤ綔鍙�
-          <span
-            class="font el-icon-setting set-title"
-            style="float: right"
-            @click="setUrl"
-          ></span>
-          <span
-            style="float: right;margin-right:20px;font-size:28px;line-height:25px;"
-            @click="taskClick"
-          >
+            </template>
+          </div>
+         <div class="dashboard-title">
+           鏅鸿兘宸ヤ綔鍙� 鈥� {{currentDeviceName}}
+
+           <i  @click="showDeviceModal=true" class="el-icon" style="font-size: 26px; height: 32px; color: #0db7f5; margin-left: 20px; cursor: pointer;"><svg data-v-c3da359e="" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path fill="currentColor" d="M13 5h9v2h-9zM2 7h7v2h2V3H9v2H2zm7 10h13v2H9zm10-6h3v2h-3zm-2 4V9.012h-2V11H2v2h13v2zM7 21v-6H5v2H2v2h3v2z"></path></svg></i>
+         </div>
+          <div class="dashboard-btn">
+            <span
+              class="font el-icon-setting set-title"
+              style="float: right"
+              @click="setUrl"
+            ></span>
+            <span
+              class="font el-icon-s-tools set-title"
+              style="float: right;margin-right: 6px"
+              @click="openParamsConfigModal"
+            ></span>
+            <span
+              style="float: right;margin-right:20px;font-size:28px;line-height:25px;"
+              @click="taskClick"
+            >
           <el-badge :value="TaskCount"  :class="(TaskCount==0||isTipShow)?'item color_666':'item color_fff'">
             <i   class="el-icon-chat-dot-round" />
           </el-badge>
         </span>
-        </p>
+          </div>
+        </div>
         <div
           :class="(activeName == 1||activeName == 3) ? 'active-one' : 'active-two'"
           v-for="(taskData, index) in Tasks"
@@ -53,7 +66,7 @@
         >
         <template v-if="taskData">
           <div class="gong-date">
-            宸ュ簭杩愯鏃堕棿锛歿{ getFormatTime(taskData.Procedure.startTime) }}
+            宸ュ簭杩愯鏃堕棿锛歿{ getTaskRunningTime(taskData.Procedure.realStartTime,taskData.Procedure.realEndTime) }}
           </div>
           <div class="statelist">
             <span class="title-item"
@@ -593,6 +606,8 @@
       :listData="listData"
       @updateGet="updateGet"
     />
+    <ParamsConfigModal :visible="paramsConfigIsShow" @close="closeParamsConfigModal"></ParamsConfigModal>
+    <DeviceSelectModal :visible.sync="showDeviceModal" @should-reload="reloadAllData"></DeviceSelectModal>
   </div>
 </template>
 
@@ -616,8 +631,13 @@
 import TaskControlModal from "@/components/TaskControlModal.vue";
 import {channelNameConfig} from "@/common/constants";
 import _ from 'lodash'
+import ParamsConfigModal from "@/components/ParamsConfigModal.vue";
+import DeviceSelectModal from "@/components/DeviceSelectModal.vue";
+import {mapActions, mapGetters, mapState} from "vuex";
 export default {
   components: {
+    DeviceSelectModal,
+    ParamsConfigModal,
     TaskControlModal,
     Card,
     Knowledge,
@@ -627,6 +647,7 @@
   },
   data() {
     return {
+      showDeviceModal:false,
       pollingTaskCountTimer: null,
       activeName: 1,
       progress: 70, //杩涘害
@@ -753,6 +774,7 @@
       resprocInfoTimer:null,
       channelNameConfig: channelNameConfig,
       index:null,
+      paramsConfigIsShow:false
     };
   },
   mounted() {
@@ -773,6 +795,7 @@
     this.activeName = channelType
     this.getTaskInfo(channelType);
     this.getTaskCountStatistics()
+    this.getDeviceInfo()
   },
   beforeDestroy() {
     clearTimeout(this.pollingTaskCountTimer)
@@ -787,6 +810,8 @@
     // }
   },
   computed:{
+    ...mapState(['deviceInfo']),
+    ...mapGetters(['currentDeviceName']),
     displayPLCStatus(){
       let PLCStatus = []
       if (this.activeName===1){
@@ -803,6 +828,13 @@
     }
   },
   methods: {
+    ...mapActions(["getDeviceInfo"]),
+    reloadAllData(){
+      console.log(1)
+      this.getTaskInfo(this.activeName);
+      this.getTaskCountStatistics()
+      this.getDeviceInfo()
+    },
     newTaskPlaceholder(channel){
       return {
         Order: {},
@@ -882,12 +914,12 @@
     getModelList(){
       for (let i in this.TasksCopy){
         this.TasksCopy[i].isUpdateIcon=false;
-        if(this.TasksCopy[i].Procedure.ID&&this.TasksCopy[i].number){
+        // number:this.TasksCopy[i].number
+        if(this.TasksCopy[i].Procedure.ID){
           processModelList({
             procedureId: this.TasksCopy[i].Procedure.ID,
             page: 1,
             pageSize:6,
-            number:this.TasksCopy[i].number
           }).then(res=>{
             if(res.code==200){
               this.processList=res.data?res.data:[];
@@ -902,7 +934,7 @@
               }
             }
             this.resResult[i]=res;
-            console.log( this.resResult[i],'===res111')
+            // console.log( this.resResult[i],'===res111')
           })
         }
       }
@@ -911,12 +943,11 @@
       this.listData=list;
       this.index=index
       if( Object.keys(this.listData).length > 0){
-        if(this.listData.Procedure.ID&&this.listData.number){
+        if(this.listData.Procedure.ID){
           this.$refs.processModel.islook=true
           return true;
         }
       }
-      this.$message.error('褰撳墠宸ュ簭鏃犵紪鍙凤紝鏃犳硶鏌ョ湅宸ュ簭!')
     },
     getProcessModelList(){
       this.getModelList()
@@ -1058,23 +1089,55 @@
       let now = new Date();
       this.formatTime2 = this.getDateObj(now, "yyyy骞碝M鏈坉d鏃�");
     },
-    getFormatTime(date){
-      const getCha=()=>{
-        let now=new Date().getTime()
-        let String=now-date*1000;
-        let seconds=Math.floor(String/1000)
-        let minutes=Math.floor(seconds/60)
-
-        let days=Math.floor(String/1000/60/60/24)
-        let hours=Math.floor(minutes/60)-days*24
-        let m=minutes-days*24*60-hours*60
-        return days+'澶�'+hours+'鏃�'+m+'鍒�'
+    /**
+     * 璁$畻鏃堕棿娈�, 娉ㄦ剰鍙傛暟瑕佹眰鏃堕棿鎴充负 JS Date 鐨�13浣嶆椂闂存埑
+     * @param {number} startTime
+     * @param {number} endTime
+     * @return {string}
+     */
+    calcRunningDuration(startTime,endTime){
+      let timeDuration=endTime-startTime;
+      if (timeDuration<0){
+        return '0澶�0鏃�0鍒�'
       }
-      let d= getCha()
+
+      let seconds=Math.floor(timeDuration/1000)
+      let minutes=Math.floor(seconds/60)
+
+      let days=Math.floor(timeDuration/1000/60/60/24)
+      let hours=Math.floor(minutes/60)-days*24
+      let m=minutes-days*24*60-hours*60
+      return `${days}澶�${hours}鏃�${m}鍒哷
+    },
+
+    /**
+     * 宸ュ簭杩愯鏃堕棿
+     * 鏍规嵁鎺ュ彛杩斿洖 realStartTime realEndTime 鍒ゆ柇濡備綍灞曠ず
+     * 濡傛灉 realEndTime 涓� 0 鍒� 鐢ㄥ綋鍓嶆椂闂� - realStartTime
+     * 濡傛灉 瀛樺湪 realEndTime, 鍒� realEndTime - realStartTime
+     * 娉ㄦ剰 realStartTime realEndTime 鏄帴鍙h繑鍥炵殑10浣嶆椂闂存埑
+     * @param realStartTime
+     * @param realEndTime
+     * @return {string}
+     */
+    getTaskRunningTime(realStartTime,realEndTime){
+      const getInfo = ()=>{
+        if (!realStartTime && !realEndTime){
+          return '--'
+        }
+        if(!realEndTime){
+          const now = Math.floor(new Date().getTime()/1000) * 1000
+          return this.calcRunningDuration(realStartTime*1000,now)
+        }
+
+        return this.calcRunningDuration(realStartTime*1000,realEndTime*1000)
+      }
+
+      let result = getInfo()
       setInterval(() => {
-       d= getCha();
+        result = getInfo();
       }, 6000);
-      return date?d:'--';
+      return result;
     },
     setInterCard(value, name, i) {
       if (this.TasksCopy[i].Procedure.procedure[value]!=null) {
@@ -1122,6 +1185,8 @@
       getTaskInfo({taskMode:1}).then((res) => {
         if (res.code === 200&&res.data) {
           this.TaskCount=res.data?.TaskCount ?? 0
+        }else {
+          this.TaskCount = 0
         }
       },err=>{
         this.TaskCount = 0
@@ -1129,8 +1194,8 @@
       }).finally(()=>{
         this.pollingTaskCountTimer = setTimeout(()=>{
           this.getTaskCountStatistics()
-        //   20绉掍竴娆¤疆璇�
-        },20000)
+        //   20绉掍竴娆¤疆璇� // 鏀逛竴鍒嗛挓
+        },60000)
       });
     },
 
@@ -1226,7 +1291,12 @@
           }
           this.getProcessModelList();
           this.getStartArr()
-          this.cutClick(val?val:1)
+          if(this.ChannelAmount===1){
+            this.cutClick(1)
+          }else{
+            this.cutClick(val?val:1)
+          }
+
           if(info=='new'){
             return true;
           }
@@ -1237,6 +1307,19 @@
                   this.getProgressInfo();
                 }, 3000);
               }
+        }else{
+          this.TaskCount = 0
+          const allChannels = [0,1];
+          this.workers = []
+          allChannels.forEach(channel => this.TasksCopy.push(this.newTaskPlaceholder(channel)))
+          this.TasksCopy.sort((a,b)=>a.Channel - b.Channel)
+          this.cutClick(1)
+          this.getProgressInfo();
+          if (!this.procInfoTimer&&!this.resprocInfoTimer) {
+            this.procInfoTimer = setInterval(() => {
+              this.getProgressInfo();
+            }, 3000);
+          }
         }
         // if (res.code != 200 || this.TasksCopy.length == 0) {
         //   this.getcountdown();
@@ -1248,6 +1331,14 @@
         //   }
         // }
 
+      },err=>{
+        console.error(err)
+        this.TaskCount = 0
+        const allChannels = [0,1];
+        this.workers = []
+        allChannels.forEach(channel => this.TasksCopy.push(this.newTaskPlaceholder(channel)))
+        this.TasksCopy.sort((a,b)=>a.Channel - b.Channel)
+        this.cutClick(1)
       });
       // this.TasksCopy.push(this.object)
       // this.TasksCopy.push(this.object)
@@ -1300,10 +1391,8 @@
     getProgressInfo() {
       this.resprocInfoTimer=null
       for (let i in this.TasksCopy){
-        if(this.TasksCopy[i].Procedure.ID){
           getProgress({
             channel: Number(i),
-            procedureId: this.TasksCopy[i].Procedure.ID,
           }).then((res) => {
             if (res.code == 200) {
               this.TasksCopy[i].finishNumber = res.data?.finishNumber ?? 0;
@@ -1313,7 +1402,6 @@
             }
             this.resprocInfoTimer=res;
           });
-        }
       }
     },
     // 璁剧疆
@@ -1325,6 +1413,12 @@
       this.$router.push({
         path: "/set",
       });
+    },
+    openParamsConfigModal(){
+      this.paramsConfigIsShow=true
+    },
+    closeParamsConfigModal(){
+      this.paramsConfigIsShow=false
     },
     // 鍙充晶鎺у埗
     controlClick() {
@@ -1803,6 +1897,9 @@
     padding: 30px;
     padding-top: 20px;
     .title {
+      display: flex;
+      align-items: center;
+      justify-content: space-between;
       font-size: 30px;
       font-weight: 600;
       height:40px;
@@ -2285,4 +2382,8 @@
     display: none;
   }
 }
+.dashboard-title{
+  display: flex;
+  align-items: center;
+}
 </style>

--
Gitblit v1.8.0