Przeglądaj źródła

修复bug 地址携带参数只可用一次 改用缓存+计数器实现

李士越 10 miesięcy temu
rodzic
commit
5be7ffaded

+ 19 - 6
wwwroot/mes/rpt/rpt041/rpt_index.html

@@ -82,13 +82,12 @@
             var ctime = new Date();
             var beginDate = ctime.getFullYear() + "-" + (ctime.getMonth() + 1) + "-" + ctime.getDate() + " 00:00:00";
             var endDate = ctime.getFullYear() + "-" + (ctime.getMonth() + 1) + "-" + ctime.getDate() + " 23:59:59";
-            $("#firstdatebeginMaster").datetimebox("setValue", beginDate);
-            $("#firstdateendMaster").datetimebox("setValue", endDate);
+            //$("#firstdatebeginMaster").datetimebox("setValue", beginDate);
+            //$("#firstdateendMaster").datetimebox("setValue", endDate);
             $("#twodatebeginMaster").datetimebox("setValue", beginDate);
 			$("#twodateendMaster").datetimebox("setValue", endDate);
 			click();
-		});
-
+		}); 
 		//搜索提交
 		function tbSearchSubmit() { 
 			if ($('#ffMaster').form("validate")) {
@@ -148,10 +147,24 @@
 							// 穿透parent.$('#tabs')
 							//***
 							parent.$('#tabs').tabsOpen({
-								title: "产品跟踪表",       // 标签页标题(可自定义)
-								url: 'rpt/rpt042/rpt_index.html?barcode=' + barcode,
+								title: "产品跟踪表",
+                                url: 'rpt/rpt042/rpt_index.html?startBarcodeTimer=true',
 								closable: true
 							});
+							const now = new Date();
+                            const formatter = new Intl.DateTimeFormat('zh-CN', {
+                                year: 'numeric',
+                                month: '2-digit',
+                                day: '2-digit',
+                                hour: '2-digit',
+								minute: '2-digit',
+                                second: '2-digit',
+                                hour12: false
+							});
+							//创建储存条码对象
+							const bar = { barcode: barcode, createtime: formatter.format(now).replace(/\//g, '-') };
+							//放入浏览器缓存中
+                            sessionStorage.setItem('bar', JSON.stringify(bar));
 						}
 					}
 				}

+ 46 - 11
wwwroot/mes/rpt/rpt042/rpt_index.html

@@ -88,20 +88,22 @@
 		</div>
 	</div>
 	<script type="text/javascript"> 
-		$(document).ready(function () { 
-            let params = getQueryParams(); 
+		$(document).ready(function () {
+			let params = getQueryParams();
 			console.log("更总表--", request('barcode'), params);
 			// 从新每窑报表的改判调过来的条码
 			if (request('barcode') != null && request('barcode') != "") {
 				$('#BARCODE').textbox('setValue', request('barcode'));
-				tbSearchSubmit(); 
-                // 显示
-                $('#btnBack').show();
-			} else { 
-                // 显示
-                $('#btnBack').hide();
-            }           
-        });
+				tbSearchSubmit();
+				// 显示
+				$('#btnBack').show();
+			} else {
+				// 显示
+				$('#btnBack').hide();
+			}
+			//启动定时器
+			startBarcodeTimer(); 
+		});
 
 		 
 		//搜索提交
@@ -171,7 +173,40 @@
             }
             return params;
         }
-
+		/**获取产品条码 */
+		const getbarcode = () => {
+			//从浏览器缓存中读取条码信息
+			const data = JSON.parse(sessionStorage.getItem('bar'));
+			//数据存在 为清除数据做准备
+            if (data) {
+				//当前时间
+				const currentTime = new Date();
+				//缓存记录时间
+				const cachedTime = new Date(data.createtime);
+				// 计算秒差
+				const timeDiff = Math.abs(currentTime - cachedTime) / 1000;
+				// 允许2秒误差
+				if (timeDiff <= 2) {
+					//更新数据
+					$('#BARCODE').textbox('setValue', data.barcode);
+					tbSearchSubmit();
+				}
+				//清除缓存
+				sessionStorage.removeItem('bar');
+			}
+		}
+		/**记录定时器 */
+        let barcodeTimer = null;
+        /**启动计时器的函数*/
+        const  startBarcodeTimer=() =>{
+            // 先清除可能存在的旧计时器(防止重复启动)
+            if (barcodeTimer) {
+                clearInterval(barcodeTimer);
+            } 
+            // 设置每秒执行一次getbarcode函数
+            barcodeTimer = setInterval(getbarcode, 1000); 
+		}
+        
 	</script>
 </body>
 </html>