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/set.vue |  233 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 171 insertions(+), 62 deletions(-)

diff --git a/src/views/set.vue b/src/views/set.vue
index 5422dda..eea93c9 100644
--- a/src/views/set.vue
+++ b/src/views/set.vue
@@ -8,7 +8,7 @@
     </div>
     <div class="form-content-box">
       <div class="form-box-l">
-        <div class="form-box-l-item">
+        <!-- <div class="form-box-l-item">
           <el-button
             type="primary"
             @click="buttonClick(1)"
@@ -17,7 +17,7 @@
           >
             缃戠粶閰嶇疆</el-button
           >
-        </div>
+        </div> -->
         <!-- <div class="form-box-l-item">
           <el-button
             type="primary"
@@ -28,7 +28,7 @@
             鍔犲叆闆嗙兢</el-button
           >
         </div> -->
-        <div class="form-box-l-item">
+        <!-- <div class="form-box-l-item">
           <el-button
             type="primary"
             @click="buttonClick(3)"
@@ -37,7 +37,7 @@
           >
             PLC閰嶇疆</el-button
           >
-        </div>
+        </div> -->
       </div>
       <div class="form-box-r">
         <el-form
@@ -236,18 +236,20 @@
             </el-form-item>
           </div>
           <div style="height: 100%" v-if="active == 3">
+            <div class="form-box-r-title" >PLC鍦板潃閰嶇疆</div>
             <div
               style="
                 overflow: auto;
-                width: 100%;
-                min-height: 180px;
+                width: 80%;
+                min-height: 200px;
                 padding-right: 10px;
+                margin:60px auto 0;
               "
             >
               <el-form-item
                 label="PLC鍝佺墝"
                 prop="brand"
-                class="form-item2 float_left"
+                class="form-item float_left"
               >
                 <!-- style="width: calc(100% - 30px)" -->
                 <el-select
@@ -270,7 +272,7 @@
                 ></i> -->
               </el-form-item>
 
-              <el-form-item label="鎺ュ彛鏂瑰紡" prop="method" class="form-item2">
+              <el-form-item label="鎺ュ彛鏂瑰紡" prop="method" class="form-item">
                 <!-- <el-input v-model="form.method" placeholder="璇疯緭鍏�"></el-input> -->
                 <el-select
                   v-model="form.method"
@@ -280,42 +282,123 @@
                   style="width: 100%"
                 >
                   <el-option label="modbusTCP" value="modbusTCP"></el-option>
-                  <el-option label="serial" value="serial"></el-option>
+                  <el-option label="涓插彛" value="serial"></el-option>
+                  <el-option label="modbusRTU" value="modbusRTU"></el-option>
                 </el-select>
               </el-form-item>
-              <el-form-item
-                label="娉㈢壒鐜�"
-                prop="baudRate"
-                v-if="form.method == 'serial'"
-                class="form-item2 float_right margin_left_10px"
-              >
-                <el-input
-                  v-model="form.baudRate"
-                  placeholder="璇疯緭鍏�"
-                ></el-input>
-              </el-form-item>
-              <el-form-item
-                label="涓插彛鍚嶇О"
-                prop="serialName"
-                v-if="form.method == 'serial'"
-                class="form-item2 float_right margin_left_10px"
-              >
-                <el-input
-                  v-model="form.serialName"
-                  placeholder="璇疯緭鍏�"
-                ></el-input>
-              </el-form-item>
-              <el-form-item
-                label="PLC鍦板潃"
-                v-if="form.method == 'modbusTCP'"
-                prop="address"
-                class="form-item2 float_right margin_left_10px"
-              >
-                <el-input
-                  v-model="form.address"
-                  placeholder="璇疯緭鍏�"
-                ></el-input>
-              </el-form-item>
+              <template v-if="form.method === 'modbusTCP'">
+                <el-form-item
+                  label="PLC鍦板潃"
+                  prop="address"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    v-model="form.address"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+
+                <el-form-item
+                  label="绔彛鍙�"
+                  prop="port"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    v-model.number="form.port"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+              </template>
+
+              <template v-if="form.method === 'serial'">
+                <el-form-item
+                  label="娉㈢壒鐜�"
+                  prop="baudRate"
+
+                  class="form-item float_right"
+                >
+                  <el-input
+                    type="number"
+                    min="1"
+                    v-model="form.baudRate"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+                <el-form-item
+                  label="涓插彛鍚嶇О"
+                  prop="serialName"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    v-model="form.serialName"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+              </template>
+
+              <template v-if="form.method === 'modbusRTU'">
+                <el-form-item
+                  label="鏁版嵁浣�"
+                  prop="dataBit"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    type="number"
+                    min="1"
+                    v-model="form.dataBit"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+
+                <el-form-item
+                  label="鍋滄浣�"
+                  prop="stopBit"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    type="number"
+                    min="1"
+                    v-model="form.stopBit"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+
+                <el-form-item label="鏍¢獙鏂瑰紡" prop="parity" class="form-item">
+                  <el-select
+                    v-model="form.parity"
+                    placeholder="璇烽�夋嫨"
+                    style="width: 100%"
+                  >
+                    <el-option label="濂囨牎楠�" :value="1"></el-option>
+                    <el-option label="鍋舵牎楠�" :value="2"></el-option>
+                    <el-option label="鏃犳牎楠�" :value="3"></el-option>
+                  </el-select>
+                </el-form-item>
+
+                <el-form-item
+                  label="娉㈢壒鐜�"
+                  prop="baudRate"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    v-model="form.baudRate"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+
+                <el-form-item
+                  label="涓插彛鍚嶇О"
+                  prop="serialName"
+                  class="form-item float_right"
+                >
+                  <el-input
+                    v-model="form.serialName"
+                    placeholder="璇疯緭鍏�"
+                  ></el-input>
+                </el-form-item>
+              </template>
+
+
               <!-- <el-form-item label="绔彛鍚嶇О" prop="portName" class="form-item2">
                 <el-select
                   v-model="form.portName"
@@ -331,19 +414,8 @@
                   ></el-option>
                 </el-select>
               </el-form-item> -->
-              <el-form-item
-                label="绔彛鍙�"
-                prop="port"
-                v-if="form.method == 'modbusTCP'"
-                class="form-item2 float_right"
-              >
-                <el-input
-                  v-model.number="form.port"
-                  placeholder="璇疯緭鍏�"
-                ></el-input>
-              </el-form-item>
             </div>
-            <el-button
+            <!-- <el-button
               style="margin-bottom: 10px; float: right"
               @click="addPreProduction"
               type="primary"
@@ -392,7 +464,6 @@
               </el-table-column>
               <el-table-column prop="type" label="鏁版嵁绫诲瀷" width="120">
                 <template slot-scope="scope">
-                  <!--  :popper-append-to-body="false" -->
                   <el-select
                     v-if="scope.row.edit"
                     v-model="scope.row.type"
@@ -444,7 +515,7 @@
                   </span>
                 </template>
               </el-table-column>
-            </el-table>
+            </el-table> -->
           </div>
         </el-form>
 
@@ -494,7 +565,7 @@
   props: {},
   data() {
     return {
-      active: 1,
+      active: 3,
       form: {
         isRequired: false,
         dns: "",
@@ -510,8 +581,13 @@
         portName: "",
         port: "",
         address: "",
-        baudRate:'',
+        // 娉㈢壒鐜囬粯璁�9600
+        baudRate: 0,
         serialName:'',
+        dataBit: 0,
+        stopBit: 0,
+        // 鏍¢獙鏂瑰紡 1濂囨牎楠�2鍋舵牎楠�3鏃犳牎楠�
+        parity: 3,
       },
 
       rules: {
@@ -570,7 +646,7 @@
     };
   },
   mounted() {
-    this.getnetworkCardList();
+    this.buttonClick(this.active)
   },
   watch: {},
   methods: {
@@ -656,6 +732,14 @@
       getPlc().then((res) => {
         if (res.code == 200) {
           this.form = JSON.parse(JSON.stringify(res.data));
+          this.form = {
+            ...this.form,
+            dataBit: this.form?.dataBit || 0,
+            stopBit: this.form?.stopBit || 0,
+            parity: this.form?.parity || 3,
+            baudRate: this.form?.baudRate || 0,
+          }
+          console.log('f',this.form)
           this.pclList = res.data.details
             ? JSON.parse(JSON.stringify(res.data.details))
             : [];
@@ -906,7 +990,32 @@
 
     saveThree() {
       let params = JSON.parse(JSON.stringify(this.form));
-      params.details = this.pclList;
+      params = {
+        ...params,
+        details : this.pclList,
+        dataBit: +params.dataBit,
+        stopBit: +params.stopBit,
+        parity: +params.parity,
+        baudRate: +params.baudRate
+      }
+
+      if (params.method === 'modbusRTU'){
+        if (!params.dataBit){
+          this.$message.error("鏁版嵁浣嶄笉鑳戒负 0")
+          return
+        }
+
+        if (!params.stopBit){
+          this.$message.error("鍋滄浣嶄笉鑳戒负 0")
+          return
+        }
+
+        if (!params.baudRate){
+          this.$message.error("娉㈢壒鐜囦笉鑳戒负 0")
+          return
+        }
+      }
+
       setPlc(params).then((res) => {
         if (res.code == 200) {
           this.$message.success("PLC閰嶇疆鎴愬姛锛�");
@@ -954,7 +1063,7 @@
     margin: 30px 0 0 40px;
   }
   .height_100 {
-    height: calc(100% - 90px);
+    height: calc(100% - 120px);
   }
   .el-form {
     width: 100%;
@@ -1013,7 +1122,7 @@
   // position:absolute;
   // left:10px;
   // bottom:20px;
-  margin-top: 40px;
+  margin-top: 0px;
   float: right;
 }
 

--
Gitblit v1.8.0