From 86d4b4787748a83e76d048cd6a0b5583a2cd0651 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 21 四月 2025 10:00:24 +0800
Subject: [PATCH] 修改多线程导致数采不成功的问题

---
 vue.config.js                                    |   59 ++++++--------
 src/workers/DataWorker.worker.js                 |  131 ++++++++++++++++----------------
 src/views/business/inspectionTask/inspection.vue |    3 
 3 files changed, 94 insertions(+), 99 deletions(-)

diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue
index d029a56..5a1ce4c 100644
--- a/src/views/business/inspectionTask/inspection.vue
+++ b/src/views/business/inspectionTask/inspection.vue
@@ -289,7 +289,7 @@
                       state == 1
                     "><span :style="`font-family:${n.v.ff} !important;`">{{
                       toFixed(n.v.v, n.v.ct)
-                        }}</span></template>
+                    }}</span></template>
                     <template v-else-if="
                       n.v.ps != undefined &&
                       n.v.ps.value === '鏈�缁堝��' &&
@@ -1471,6 +1471,7 @@
     },
     // 澶氱嚎绋�
     startWorker() {
+      console.log(`Worker 绾跨▼寮�濮嬭繍琛�...`, this.worker, this.worker0)
       if (this.worker) {
         this.stopWorker(); // 纭繚涔嬪墠鐨� Worker 宸插仠姝�
       }
diff --git a/src/workers/DataWorker.worker.js b/src/workers/DataWorker.worker.js
index 1b24712..aaf032e 100644
--- a/src/workers/DataWorker.worker.js
+++ b/src/workers/DataWorker.worker.js
@@ -45,7 +45,7 @@
           if (num == 1) {
             str = str + m.v.v + ",";
             num++;
-          } else {
+          } else if (num == 0) {
             str = m.v.v + ",";
             num++;
           }
@@ -74,6 +74,11 @@
               n.v.ps.value.includes("妫�楠屽��")
             ) {
               let arr = n.v.ps.value.split("鍊�");
+              // console.log(
+              //   `dataAcquisitionInfo[str].value`,
+              //   dataAcquisitionInfo[str].value,
+              //   str
+              // );
               if (Array.isArray(dataAcquisitionInfo[str].value)) {
                 // 濡傛灉鏁版嵁婧愪负鏁扮粍锛屽垯鎵ц
                 for (
@@ -84,37 +89,34 @@
                   if (i + 1 == arr[1]) {
                     // 璧嬪�兼暟閲囦紭鍖栨楠岄」鍒楄〃
                     arrSpecial.push(n.i);
-                    setTimeout(() => {
-                      let num0 = 0;
-                      if (
-                        n.v.ct &&
-                        n.v.ct.fa &&
-                        typeof n.v.ct.fa == "string" &&
-                        n.v.ct.fa.includes(".")
-                      ) {
-                        // 淇濈暀妯℃澘閰嶇疆鐨勫皬鏁扮偣浣嶆暟
-                        let str0 = n.v.ct.fa.split(".")[1];
-                        num0 = str0.length;
-                        n.v.v = dataAcquisitionInfo[str].value[i]
-                          ? Number(dataAcquisitionInfo[str].value[i]).toFixed(
-                              num0
-                            )
-                          : dataAcquisitionInfo[str].value[i];
-                      } else {
-                        // 鐩存帴璧嬪��
-                        console.log(44444, dataAcquisitionInfo, str);
-                        n.v.v = dataAcquisitionInfo[str].value[i];
-                      }
-                      // 浼犻�掔粰涓荤嚎绋�
-                      result = {
-                        method: "changeInput",
-                        value: {
-                          list: list,
-                          n: n,
-                        },
-                      };
-                      self.postMessage(JSON.stringify(result));
-                    }, 2000);
+                    let num0 = 0;
+                    if (
+                      n.v.ct &&
+                      n.v.ct.fa &&
+                      typeof n.v.ct.fa == "string" &&
+                      n.v.ct.fa.includes(".")
+                    ) {
+                      // 淇濈暀妯℃澘閰嶇疆鐨勫皬鏁扮偣浣嶆暟
+                      let str0 = n.v.ct.fa.split(".")[1];
+                      num0 = str0.length;
+                      n.v.v = dataAcquisitionInfo[str].value[i]
+                        ? Number(dataAcquisitionInfo[str].value[i]).toFixed(
+                            num0
+                          )
+                        : dataAcquisitionInfo[str].value[i];
+                    } else {
+                      // 鐩存帴璧嬪��
+                      n.v.v = dataAcquisitionInfo[str].value[i];
+                    }
+                    // 浼犻�掔粰涓荤嚎绋�
+                    result = {
+                      method: "changeInput",
+                      value: {
+                        list: list,
+                        n: n,
+                      },
+                    };
+                    self.postMessage(JSON.stringify(result));
                   }
                 }
               } else {
@@ -122,7 +124,36 @@
                 if (arr[1] == dataAcquisitionInfo[str].frequency) {
                   // 濡傛灉鏁伴噰娆℃暟绛変簬妫�楠屽�煎簭鍙凤紝鍒欒祴鍊肩粰褰撳墠妫�楠屽��
                   arrSpecial.push(n.i);
-                  setTimeout(() => {
+                  let num0 = 0;
+                  if (
+                    n.v.ct &&
+                    n.v.ct.fa &&
+                    typeof n.v.ct.fa == "string" &&
+                    n.v.ct.fa.includes(".")
+                  ) {
+                    // 淇濈暀妯℃澘閰嶇疆鐨勫皬鏁扮偣浣嶆暟
+                    let str0 = n.v.ct.fa.split(".")[1];
+                    num0 = str0.length;
+                    n.v.v = dataAcquisitionInfo[str].value
+                      ? Number(dataAcquisitionInfo[str].value).toFixed(num0)
+                      : dataAcquisitionInfo[str].value;
+                  } else {
+                    // 鐩存帴璧嬪��
+                    n.v.v = dataAcquisitionInfo[str].value;
+                  }
+                  // 浼犻�掔粰涓荤嚎绋�
+                  result = {
+                    method: "changeInput",
+                    value: {
+                      list: list,
+                      n: n,
+                    },
+                  };
+                  self.postMessage(JSON.stringify(result));
+                } else if (Number(dataAcquisitionInfo[str].frequency) > num) {
+                  // 濡傛灉鏁伴噰娆℃暟澶т簬妫�楠屽�煎簭鍙凤紝鍒欒祴鍊肩粰鏈�鍚庝竴涓楠屽��
+                  if (n.v.ps.value.includes(num)) {
+                    arrSpecial.push(n.i);
                     let num0 = 0;
                     if (
                       n.v.ct &&
@@ -138,6 +169,7 @@
                         : dataAcquisitionInfo[str].value;
                     } else {
                       // 鐩存帴璧嬪��
+                      console.log(555, dataAcquisitionInfo, str);
                       n.v.v = dataAcquisitionInfo[str].value;
                     }
                     // 浼犻�掔粰涓荤嚎绋�
@@ -149,39 +181,6 @@
                       },
                     };
                     self.postMessage(JSON.stringify(result));
-                  }, 2000);
-                } else if (Number(dataAcquisitionInfo[str].frequency) > num) {
-                  // 濡傛灉鏁伴噰娆℃暟澶т簬妫�楠屽�煎簭鍙凤紝鍒欒祴鍊肩粰鏈�鍚庝竴涓楠屽��
-                  if (n.v.ps.value.includes(num)) {
-                    arrSpecial.push(n.i);
-                    setTimeout(() => {
-                      let num0 = 0;
-                      if (
-                        n.v.ct &&
-                        n.v.ct.fa &&
-                        typeof n.v.ct.fa == "string" &&
-                        n.v.ct.fa.includes(".")
-                      ) {
-                        // 淇濈暀妯℃澘閰嶇疆鐨勫皬鏁扮偣浣嶆暟
-                        let str0 = n.v.ct.fa.split(".")[1];
-                        num0 = str0.length;
-                        n.v.v = dataAcquisitionInfo[str].value
-                          ? Number(dataAcquisitionInfo[str].value).toFixed(num0)
-                          : dataAcquisitionInfo[str].value;
-                      } else {
-                        // 鐩存帴璧嬪��
-                        n.v.v = dataAcquisitionInfo[str].value;
-                      }
-                      // 浼犻�掔粰涓荤嚎绋�
-                      result = {
-                        method: "changeInput",
-                        value: {
-                          list: list,
-                          n: n,
-                        },
-                      };
-                      self.postMessage(JSON.stringify(result));
-                    }, 2000);
                   }
                 }
               }
diff --git a/vue.config.js b/vue.config.js
index 467e75f..87533b2 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -1,5 +1,6 @@
 "use strict";
 const path = require("path");
+const { version } = Math.floor(1); // 寮曞叆椤圭洰鐗堟湰鍙�
 
 function resolve(dir) {
   return path.join(__dirname, dir);
@@ -11,33 +12,21 @@
 
 const port = process.env.port || process.env.npm_config_port || 80; // 绔彛
 
-// vue.config.js 閰嶇疆璇存槑
-//瀹樻柟vue.config.js 鍙傝�冩枃妗� https://cli.vuejs.org/zh/config/#css-loaderoptions
-// 杩欓噷鍙垪涓�閮ㄥ垎锛屽叿浣撻厤缃弬鑰冩枃妗�
 module.exports = {
-  // 閮ㄧ讲鐢熶骇鐜鍜屽紑鍙戠幆澧冧笅鐨刄RL銆�
-  // 榛樿鎯呭喌涓嬶紝Vue CLI 浼氬亣璁句綘鐨勫簲鐢ㄦ槸琚儴缃插湪涓�涓煙鍚嶇殑鏍硅矾寰勪笂
-  // 渚嬪 https://www.ruoyi.vip/銆傚鏋滃簲鐢ㄨ閮ㄧ讲鍦ㄤ竴涓瓙璺緞涓婏紝浣犲氨闇�瑕佺敤杩欎釜閫夐」鎸囧畾杩欎釜瀛愯矾寰勩�備緥濡傦紝濡傛灉浣犵殑搴旂敤琚儴缃插湪 https://www.ruoyi.vip/admin/锛屽垯璁剧疆 baseUrl 涓� /admin/銆�
   publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
-  // 鍦╪pm run build 鎴� yarn build 鏃� 锛岀敓鎴愭枃浠剁殑鐩綍鍚嶇О锛堣鍜宐aseUrl鐨勭敓浜х幆澧冭矾寰勪竴鑷达級锛堥粯璁ist锛�
   outputDir: "dist",
-  // 鐢ㄤ簬鏀剧疆鐢熸垚鐨勯潤鎬佽祫婧� (js銆乧ss銆乮mg銆乫onts) 鐨勶紱锛堥」鐩墦鍖呬箣鍚庯紝闈欐�佽祫婧愪細鏀惧湪杩欎釜鏂囦欢澶逛笅锛�
   assetsDir: "static",
-  // 鏄惁寮�鍚痚slint淇濆瓨妫�娴嬶紝鏈夋晥鍊硷細ture | false | 'error'
   lintOnSave: process.env.NODE_ENV === "development",
-  // 濡傛灉浣犱笉闇�瑕佺敓浜х幆澧冪殑 source map锛屽彲浠ュ皢鍏惰缃负 false 浠ュ姞閫熺敓浜х幆澧冩瀯寤恒��
   productionSourceMap: false,
   transpileDependencies: ["quill"],
-  // webpack-dev-server 鐩稿叧閰嶇疆
   devServer: {
     host: "0.0.0.0",
     port: port,
     open: true,
     proxy: {
-      // detail: https://cli.vuejs.org/config/#devserver-proxy
       [process.env.VUE_APP_BASE_API]: {
-        // target: `http://10.21.10.124:8001`, //鏈湴
-        target: `http://192.168.18.50:7002`, //娴嬭瘯搴�
+        target: `http://10.21.10.67:8088`, //鏈湴
+        // target: `http://192.168.18.50:7002`, //娴嬭瘯搴�
         changeOrigin: true,
         pathRewrite: {
           ["^" + process.env.VUE_APP_BASE_API]: "",
@@ -45,6 +34,11 @@
       },
     },
     disableHostCheck: true,
+    headers: {
+      "Cache-Control": "no-cache, no-store, must-revalidate",
+      Pragma: "no-cache",
+      Expires: 0,
+    },
   },
   css: {
     loaderOptions: {
@@ -55,6 +49,10 @@
   },
   configureWebpack: {
     name: name,
+    cache: false,
+    output: {
+      hashDigestLength: 8, // 璋冩暣鍝堝笇闀垮害
+    },
     resolve: {
       alias: {
         "@": resolve("src"),
@@ -68,29 +66,27 @@
             loader: "worker-loader",
             options: {
               inline: "fallback",
-              filename: "[name].[contenthash].worker.js", // 娣诲姞鍐呭鍝堝笇鍒版枃浠跺悕
+              filename: `[name].[contenthash:8].worker.js?v=${version}`, // 娣诲姞鐗堟湰鍙蜂綔涓烘煡璇㈠弬鏁�
             },
           },
         },
       ],
     },
     plugins: [
-      // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#浣跨敤gzip瑙e帇缂╅潤鎬佹枃浠�
       new CompressionPlugin({
-        cache: false, // 涓嶅惎鐢ㄦ枃浠剁紦瀛�
-        test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 鍘嬬缉鏂囦欢鏍煎紡
-        filename: "[path][base].gz[query]", // 鍘嬬缉鍚庣殑鏂囦欢鍚�
-        algorithm: "gzip", // 浣跨敤gzip鍘嬬缉
-        minRatio: 0.8, // 鍘嬬缉姣斾緥锛屽皬浜� 80% 鐨勬枃浠朵笉浼氳鍘嬬缉
-        deleteOriginalAssets: false, // 鍘嬬缉鍚庡垹闄ゅ師鏂囦欢
+        cache: false,
+        test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i,
+        filename: "[path][base].gz[query]",
+        algorithm: "gzip",
+        minRatio: 0.8,
+        deleteOriginalAssets: false,
       }),
     ],
   },
   chainWebpack(config) {
-    config.plugins.delete("preload"); // TODO: need test
-    config.plugins.delete("prefetch"); // TODO: need test
+    config.plugins.delete("preload");
+    config.plugins.delete("prefetch");
 
-    // set svg-sprite-loader
     config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
     config.module
       .rule("icons")
@@ -110,7 +106,6 @@
         .after("html")
         .use("script-ext-html-webpack-plugin", [
           {
-            // `runtime` must same as runtimeChunk name. default is `runtime`
             inline: /runtime\..*\.js$/,
           },
         ])
@@ -123,17 +118,17 @@
             name: "chunk-libs",
             test: /[\\/]node_modules[\\/]/,
             priority: 10,
-            chunks: "initial", // only package third parties that are initially dependent
+            chunks: "initial",
           },
           elementUI: {
-            name: "chunk-elementUI", // split elementUI into a single package
-            test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
-            priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
+            name: "chunk-elementUI",
+            test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
+            priority: 20,
           },
           commons: {
             name: "chunk-commons",
-            test: resolve("src/components"), // can customize your rules
-            minChunks: 3, //  minimum common number
+            test: resolve("src/components"),
+            minChunks: 3,
             priority: 5,
             reuseExistingChunk: true,
           },

--
Gitblit v1.9.3