Kaynağa Gözat

配置缓存清除

yangzj 2 yıl önce
ebeveyn
işleme
6ee0e2fbb7
2 değiştirilmiş dosya ile 45 ekleme ve 2 silme
  1. 25 1
      package-lock.json
  2. 20 1
      template.h5.html

+ 25 - 1
package-lock.json

@@ -1,11 +1,35 @@
 {
+  "name": "parking_h5",
+  "lockfileVersion": 2,
   "requires": true,
-  "lockfileVersion": 1,
+  "packages": {
+    "": {
+      "dependencies": {
+        "vue-jsonp": "^2.0.0",
+        "weixin-js-sdk": "^1.6.0"
+      }
+    },
+    "node_modules/vue-jsonp": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/vue-jsonp/-/vue-jsonp-2.0.0.tgz",
+      "integrity": "sha512-Mzd9GNeuKP5hHFDWZNMWOsCuMILSkA6jo2l4A02wheFz3qqBzH7aSEFTey1BRCZCLizlaf1EqJ5YUtF392KspA=="
+    },
+    "node_modules/weixin-js-sdk": {
+      "version": "1.6.0",
+      "resolved": "https://registry.npmmirror.com/weixin-js-sdk/-/weixin-js-sdk-1.6.0.tgz",
+      "integrity": "sha512-3IYQH7aalJGFJrwdT3epvTdR1MboMiH7vIZ5BRL2eYOJ12BNah7csoMkmSZzkq1+l92sSq29XdTCVjCJoK2sBQ=="
+    }
+  },
   "dependencies": {
     "vue-jsonp": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/vue-jsonp/-/vue-jsonp-2.0.0.tgz",
       "integrity": "sha512-Mzd9GNeuKP5hHFDWZNMWOsCuMILSkA6jo2l4A02wheFz3qqBzH7aSEFTey1BRCZCLizlaf1EqJ5YUtF392KspA=="
+    },
+    "weixin-js-sdk": {
+      "version": "1.6.0",
+      "resolved": "https://registry.npmmirror.com/weixin-js-sdk/-/weixin-js-sdk-1.6.0.tgz",
+      "integrity": "sha512-3IYQH7aalJGFJrwdT3epvTdR1MboMiH7vIZ5BRL2eYOJ12BNah7csoMkmSZzkq1+l92sSq29XdTCVjCJoK2sBQ=="
     }
   }
 }

+ 20 - 1
template.h5.html

@@ -4,7 +4,8 @@
 		<meta charset="utf-8">
 		<meta http-equiv="X-UA-Compatible" content="IE=edge">
 		<link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico">
-		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+		<meta name="viewport"
+			content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 		<title>
 			<%= htmlWebpackPlugin.options.title %>
 		</title>
@@ -12,6 +13,24 @@
 			document.addEventListener('DOMContentLoaded', function() {
 				document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
 			})
+			window.addEventListener(
+				"error",
+				function(e) {
+					var jsLoadedErrorReload = window.sessionStorage.getItem(
+						"jsLoadedErrorReload" // 跳转的标识,存入sessionStorage。用于不可控情况下,防止一直满足条件,触发死循环性的跳转页面
+					);
+					const fileReg = /\/js\/((chunk-vendors)|(app))\.[a-zA-Z0-9]+/;
+					const filename = e.filename || e.target.src || "";
+					if (jsLoadedErrorReload !== "true" && filename.match(fileReg)) {
+						window.sessionStorage.setItem("jsLoadedErrorReload", true); // 满足条件则,存入标识
+						let url = window.location.href;
+						const timeStr = `timeStr=${Date.now()}`;
+						url = /\?/.test(url) ? url + "&" + timeStr : url + "?" + timeStr;
+						window.location.replace(url); // 跳转时添加了时间戳
+					}
+				},
+				true
+			);
 		</script>
 		<link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
 	</head>