user-behavior-monitor 4.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,22 +87,6 @@ module.exports =
87
87
  /************************************************************************/
88
88
  /******/ ({
89
89
 
90
- /***/ "0c60":
91
- /***/ (function(module, exports, __webpack_require__) {
92
-
93
- // style-loader: Adds some css to the DOM by adding a <style> tag
94
-
95
- // load the styles
96
- var content = __webpack_require__("d167");
97
- if(content.__esModule) content = content.default;
98
- if(typeof content === 'string') content = [[module.i, content, '']];
99
- if(content.locals) module.exports = content.locals;
100
- // add the styles to the DOM
101
- var add = __webpack_require__("499e").default
102
- var update = add("9677a646", content, true, {"sourceMap":false,"shadowMode":false});
103
-
104
- /***/ }),
105
-
106
90
  /***/ "2350":
107
91
  /***/ (function(module, exports) {
108
92
 
@@ -184,6 +168,17 @@ function toComment(sourceMap) {
184
168
  }
185
169
 
186
170
 
171
+ /***/ }),
172
+
173
+ /***/ "2cd8":
174
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
175
+
176
+ "use strict";
177
+ /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("89b5");
178
+ /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
179
+ /* unused harmony reexport * */
180
+
181
+
187
182
  /***/ }),
188
183
 
189
184
  /***/ "499e":
@@ -452,7 +447,23 @@ function applyToTag (styleElement, obj) {
452
447
 
453
448
  /***/ }),
454
449
 
455
- /***/ "d167":
450
+ /***/ "89b5":
451
+ /***/ (function(module, exports, __webpack_require__) {
452
+
453
+ // style-loader: Adds some css to the DOM by adding a <style> tag
454
+
455
+ // load the styles
456
+ var content = __webpack_require__("9f1b");
457
+ if(content.__esModule) content = content.default;
458
+ if(typeof content === 'string') content = [[module.i, content, '']];
459
+ if(content.locals) module.exports = content.locals;
460
+ // add the styles to the DOM
461
+ var add = __webpack_require__("499e").default
462
+ var update = add("9b2fa8ce", content, true, {"sourceMap":false,"shadowMode":false});
463
+
464
+ /***/ }),
465
+
466
+ /***/ "9f1b":
456
467
  /***/ (function(module, exports, __webpack_require__) {
457
468
 
458
469
  exports = module.exports = __webpack_require__("2350")(false);
@@ -465,17 +476,6 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
465
476
  // exports
466
477
 
467
478
 
468
- /***/ }),
469
-
470
- /***/ "d1a8":
471
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
472
-
473
- "use strict";
474
- /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("0c60");
475
- /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
476
- /* unused harmony reexport * */
477
-
478
-
479
479
  /***/ }),
480
480
 
481
481
  /***/ "fb15":
@@ -503,12 +503,12 @@ if (typeof window !== 'undefined') {
503
503
  // Indicate to webpack that this file can be concatenated
504
504
  /* harmony default export */ var setPublicPath = (null);
505
505
 
506
- // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"14550f6a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
506
+ // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"14550f6a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=template&id=91790b00
507
507
  var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{ref:"behaviorMonitor",staticClass:"user-behavior-monitor"},[_c('el-dialog',{attrs:{"title":"提示","visible":_vm.showWarning,"show-close":false,"modal":true,"width":"30%","center":"","custom-class":"behavior-warning-dialog"},on:{"update:visible":function($event){_vm.showWarning=$event}}},[_c('span',[_vm._v(_vm._s(_vm.warningMessage))])])],1)}
508
508
  var staticRenderFns = []
509
509
 
510
510
 
511
- // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
511
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=91790b00
512
512
 
513
513
  // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
514
514
  //
@@ -712,7 +712,7 @@ var staticRenderFns = []
712
712
 
713
713
  // 设置连接成功回调
714
714
  this.socket.onopen = () => {
715
- console.log('WebSocket连接已建立');
715
+ // console.log('WebSocket连接已建立');
716
716
  this.sendUserBehavior();
717
717
  this.$emit('websocket-open');
718
718
  // 连接成功时重置重连尝试次数
@@ -723,17 +723,17 @@ var staticRenderFns = []
723
723
  this.socket.onmessage = (event) => {
724
724
  try {
725
725
  const data = JSON.parse(event.data);
726
- console.log('收到用户活动状态消息:', data);
726
+ // console.log('收到用户活动状态消息:', data);
727
727
  this.handleActivityStatus(data);
728
728
  this.$emit('websocket-message', data);
729
729
  } catch (e) {
730
- console.error('解析WebSocket消息失败:', e);
730
+ // console.error('解析WebSocket消息失败:', e);
731
731
  }
732
732
  };
733
733
 
734
734
  // 设置连接关闭回调
735
735
  this.socket.onclose = (event) => {
736
- console.log('WebSocket连接已断开:', event.reason);
736
+ // console.log('WebSocket连接已断开:', event.reason);
737
737
  this.$emit('websocket-close');
738
738
 
739
739
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -749,7 +749,7 @@ var staticRenderFns = []
749
749
 
750
750
  // 设置连接错误回调
751
751
  this.socket.onerror = (error) => {
752
- console.error('WebSocket错误:', error);
752
+ // console.error('WebSocket错误:', error);
753
753
  this.$emit('websocket-error', error);
754
754
 
755
755
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -764,7 +764,7 @@ var staticRenderFns = []
764
764
  };
765
765
 
766
766
  } catch (error) {
767
- console.error('WebSocket初始化失败:', error);
767
+ // console.error('WebSocket初始化失败:', error);
768
768
  this.$emit('websocket-error', error);
769
769
 
770
770
  // 初始化失败时也可以尝试重连(如果不是在登录页面)
@@ -790,23 +790,23 @@ var staticRenderFns = []
790
790
  attemptReconnect() {
791
791
  // 再次检查是否为登录页面
792
792
  if (this.isLoginRoute()) {
793
- console.log('当前在登录页面,取消重连');
793
+ // console.log('当前在登录页面,取消重连');
794
794
  return;
795
795
  }
796
796
 
797
797
  this.reconnectAttempts++;
798
- console.log(`尝试第${this.reconnectAttempts}次重连...`);
798
+ // console.log(`尝试第${this.reconnectAttempts}次重连...`);
799
799
 
800
800
  // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
801
801
  if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
802
- console.log('本地开发环境,重连失败但不跳转到登录页');
802
+ // console.log('本地开发环境,重连失败但不跳转到登录页');
803
803
  this.$emit('websocket-reconnect-failed');
804
804
  return;
805
805
  }
806
806
 
807
807
  // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
808
808
  if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
809
- console.log('线上环境,重连失败,跳转到登录页');
809
+ // console.log('线上环境,重连失败,跳转到登录页');
810
810
  this.handleReconnectFailure();
811
811
  return;
812
812
  }
@@ -823,7 +823,8 @@ var staticRenderFns = []
823
823
  sessionStorage.clear();
824
824
 
825
825
  // 跳转到登录页
826
- window.location.href = '/login';
826
+
827
+ location.reload();
827
828
 
828
829
  // 触发登出事件
829
830
  this.$emit('logout');
@@ -868,7 +869,9 @@ var staticRenderFns = []
868
869
  //this.$router.push('/login');
869
870
 
870
871
  // 或者使用window.location
871
- window.location.href = '/login';
872
+
873
+ location.reload();
874
+ // window.location.href = '/login';
872
875
 
873
876
  // 触发登出事件
874
877
  this.$emit('logout');
@@ -881,7 +884,7 @@ var staticRenderFns = []
881
884
  "type": "HEARTBEAT",
882
885
  "message": "心跳",
883
886
  };
884
- console.log('用户行为监测:', JSON.stringify(message));
887
+ // console.log('用户行为监测:', JSON.stringify(message));
885
888
  this.socket.send(JSON.stringify(message));
886
889
  }
887
890
  },
@@ -1042,7 +1045,7 @@ var staticRenderFns = []
1042
1045
  // 显示超时警告
1043
1046
  showWarningWarning(timeoutMinutes) {
1044
1047
  let time=timeoutMinutes||50000;
1045
- console.log('Setting showWarning to true');
1048
+ // console.log('Setting showWarning to true');
1046
1049
  this.showWarning = true;
1047
1050
  this.$emit('timeout-warning');
1048
1051
  if (this.warningTimer) clearTimeout(this.warningTimer);
@@ -1132,8 +1135,8 @@ var staticRenderFns = []
1132
1135
 
1133
1136
  // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
1134
1137
  /* harmony default export */ var components_UserBehaviorMonitorvue_type_script_lang_js = (UserBehaviorMonitorvue_type_script_lang_js);
1135
- // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=0335f60c&prod&lang=css
1136
- var UserBehaviorMonitorvue_type_style_index_0_id_0335f60c_prod_lang_css = __webpack_require__("d1a8");
1138
+ // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=91790b00&prod&lang=css
1139
+ var UserBehaviorMonitorvue_type_style_index_0_id_91790b00_prod_lang_css = __webpack_require__("2cd8");
1137
1140
 
1138
1141
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
1139
1142
  /* globals __VUE_SSR_CONTEXT__ */
@@ -96,22 +96,6 @@ return /******/ (function(modules) { // webpackBootstrap
96
96
  /************************************************************************/
97
97
  /******/ ({
98
98
 
99
- /***/ "0c60":
100
- /***/ (function(module, exports, __webpack_require__) {
101
-
102
- // style-loader: Adds some css to the DOM by adding a <style> tag
103
-
104
- // load the styles
105
- var content = __webpack_require__("d167");
106
- if(content.__esModule) content = content.default;
107
- if(typeof content === 'string') content = [[module.i, content, '']];
108
- if(content.locals) module.exports = content.locals;
109
- // add the styles to the DOM
110
- var add = __webpack_require__("499e").default
111
- var update = add("9677a646", content, true, {"sourceMap":false,"shadowMode":false});
112
-
113
- /***/ }),
114
-
115
99
  /***/ "2350":
116
100
  /***/ (function(module, exports) {
117
101
 
@@ -193,6 +177,17 @@ function toComment(sourceMap) {
193
177
  }
194
178
 
195
179
 
180
+ /***/ }),
181
+
182
+ /***/ "2cd8":
183
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
184
+
185
+ "use strict";
186
+ /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("89b5");
187
+ /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_91790b00_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
188
+ /* unused harmony reexport * */
189
+
190
+
196
191
  /***/ }),
197
192
 
198
193
  /***/ "499e":
@@ -461,7 +456,23 @@ function applyToTag (styleElement, obj) {
461
456
 
462
457
  /***/ }),
463
458
 
464
- /***/ "d167":
459
+ /***/ "89b5":
460
+ /***/ (function(module, exports, __webpack_require__) {
461
+
462
+ // style-loader: Adds some css to the DOM by adding a <style> tag
463
+
464
+ // load the styles
465
+ var content = __webpack_require__("9f1b");
466
+ if(content.__esModule) content = content.default;
467
+ if(typeof content === 'string') content = [[module.i, content, '']];
468
+ if(content.locals) module.exports = content.locals;
469
+ // add the styles to the DOM
470
+ var add = __webpack_require__("499e").default
471
+ var update = add("9b2fa8ce", content, true, {"sourceMap":false,"shadowMode":false});
472
+
473
+ /***/ }),
474
+
475
+ /***/ "9f1b":
465
476
  /***/ (function(module, exports, __webpack_require__) {
466
477
 
467
478
  exports = module.exports = __webpack_require__("2350")(false);
@@ -474,17 +485,6 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
474
485
  // exports
475
486
 
476
487
 
477
- /***/ }),
478
-
479
- /***/ "d1a8":
480
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
481
-
482
- "use strict";
483
- /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("0c60");
484
- /* harmony import */ var _node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_vue_style_loader_index_js_ref_6_oneOf_1_0_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_UserBehaviorMonitor_vue_vue_type_style_index_0_id_0335f60c_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
485
- /* unused harmony reexport * */
486
-
487
-
488
488
  /***/ }),
489
489
 
490
490
  /***/ "fb15":
@@ -512,12 +512,12 @@ if (typeof window !== 'undefined') {
512
512
  // Indicate to webpack that this file can be concatenated
513
513
  /* harmony default export */ var setPublicPath = (null);
514
514
 
515
- // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"14550f6a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
515
+ // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"14550f6a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=template&id=91790b00
516
516
  var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{ref:"behaviorMonitor",staticClass:"user-behavior-monitor"},[_c('el-dialog',{attrs:{"title":"提示","visible":_vm.showWarning,"show-close":false,"modal":true,"width":"30%","center":"","custom-class":"behavior-warning-dialog"},on:{"update:visible":function($event){_vm.showWarning=$event}}},[_c('span',[_vm._v(_vm._s(_vm.warningMessage))])])],1)}
517
517
  var staticRenderFns = []
518
518
 
519
519
 
520
- // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
520
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=91790b00
521
521
 
522
522
  // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
523
523
  //
@@ -721,7 +721,7 @@ var staticRenderFns = []
721
721
 
722
722
  // 设置连接成功回调
723
723
  this.socket.onopen = () => {
724
- console.log('WebSocket连接已建立');
724
+ // console.log('WebSocket连接已建立');
725
725
  this.sendUserBehavior();
726
726
  this.$emit('websocket-open');
727
727
  // 连接成功时重置重连尝试次数
@@ -732,17 +732,17 @@ var staticRenderFns = []
732
732
  this.socket.onmessage = (event) => {
733
733
  try {
734
734
  const data = JSON.parse(event.data);
735
- console.log('收到用户活动状态消息:', data);
735
+ // console.log('收到用户活动状态消息:', data);
736
736
  this.handleActivityStatus(data);
737
737
  this.$emit('websocket-message', data);
738
738
  } catch (e) {
739
- console.error('解析WebSocket消息失败:', e);
739
+ // console.error('解析WebSocket消息失败:', e);
740
740
  }
741
741
  };
742
742
 
743
743
  // 设置连接关闭回调
744
744
  this.socket.onclose = (event) => {
745
- console.log('WebSocket连接已断开:', event.reason);
745
+ // console.log('WebSocket连接已断开:', event.reason);
746
746
  this.$emit('websocket-close');
747
747
 
748
748
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -758,7 +758,7 @@ var staticRenderFns = []
758
758
 
759
759
  // 设置连接错误回调
760
760
  this.socket.onerror = (error) => {
761
- console.error('WebSocket错误:', error);
761
+ // console.error('WebSocket错误:', error);
762
762
  this.$emit('websocket-error', error);
763
763
 
764
764
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -773,7 +773,7 @@ var staticRenderFns = []
773
773
  };
774
774
 
775
775
  } catch (error) {
776
- console.error('WebSocket初始化失败:', error);
776
+ // console.error('WebSocket初始化失败:', error);
777
777
  this.$emit('websocket-error', error);
778
778
 
779
779
  // 初始化失败时也可以尝试重连(如果不是在登录页面)
@@ -799,23 +799,23 @@ var staticRenderFns = []
799
799
  attemptReconnect() {
800
800
  // 再次检查是否为登录页面
801
801
  if (this.isLoginRoute()) {
802
- console.log('当前在登录页面,取消重连');
802
+ // console.log('当前在登录页面,取消重连');
803
803
  return;
804
804
  }
805
805
 
806
806
  this.reconnectAttempts++;
807
- console.log(`尝试第${this.reconnectAttempts}次重连...`);
807
+ // console.log(`尝试第${this.reconnectAttempts}次重连...`);
808
808
 
809
809
  // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
810
810
  if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
811
- console.log('本地开发环境,重连失败但不跳转到登录页');
811
+ // console.log('本地开发环境,重连失败但不跳转到登录页');
812
812
  this.$emit('websocket-reconnect-failed');
813
813
  return;
814
814
  }
815
815
 
816
816
  // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
817
817
  if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
818
- console.log('线上环境,重连失败,跳转到登录页');
818
+ // console.log('线上环境,重连失败,跳转到登录页');
819
819
  this.handleReconnectFailure();
820
820
  return;
821
821
  }
@@ -832,7 +832,8 @@ var staticRenderFns = []
832
832
  sessionStorage.clear();
833
833
 
834
834
  // 跳转到登录页
835
- window.location.href = '/login';
835
+
836
+ location.reload();
836
837
 
837
838
  // 触发登出事件
838
839
  this.$emit('logout');
@@ -877,7 +878,9 @@ var staticRenderFns = []
877
878
  //this.$router.push('/login');
878
879
 
879
880
  // 或者使用window.location
880
- window.location.href = '/login';
881
+
882
+ location.reload();
883
+ // window.location.href = '/login';
881
884
 
882
885
  // 触发登出事件
883
886
  this.$emit('logout');
@@ -890,7 +893,7 @@ var staticRenderFns = []
890
893
  "type": "HEARTBEAT",
891
894
  "message": "心跳",
892
895
  };
893
- console.log('用户行为监测:', JSON.stringify(message));
896
+ // console.log('用户行为监测:', JSON.stringify(message));
894
897
  this.socket.send(JSON.stringify(message));
895
898
  }
896
899
  },
@@ -1051,7 +1054,7 @@ var staticRenderFns = []
1051
1054
  // 显示超时警告
1052
1055
  showWarningWarning(timeoutMinutes) {
1053
1056
  let time=timeoutMinutes||50000;
1054
- console.log('Setting showWarning to true');
1057
+ // console.log('Setting showWarning to true');
1055
1058
  this.showWarning = true;
1056
1059
  this.$emit('timeout-warning');
1057
1060
  if (this.warningTimer) clearTimeout(this.warningTimer);
@@ -1141,8 +1144,8 @@ var staticRenderFns = []
1141
1144
 
1142
1145
  // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
1143
1146
  /* harmony default export */ var components_UserBehaviorMonitorvue_type_script_lang_js = (UserBehaviorMonitorvue_type_script_lang_js);
1144
- // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=0335f60c&prod&lang=css
1145
- var UserBehaviorMonitorvue_type_style_index_0_id_0335f60c_prod_lang_css = __webpack_require__("d1a8");
1147
+ // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=91790b00&prod&lang=css
1148
+ var UserBehaviorMonitorvue_type_style_index_0_id_91790b00_prod_lang_css = __webpack_require__("2cd8");
1146
1149
 
1147
1150
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
1148
1151
  /* globals __VUE_SSR_CONTEXT__ */
@@ -1 +1 @@
1
- (function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["user-behavior-monitor"]=t():e["user-behavior-monitor"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="fb15")}({"0c60":function(e,t,n){var i=n("d167");i.__esModule&&(i=i.default),"string"===typeof i&&(i=[[e.i,i,""]]),i.locals&&(e.exports=i.locals);var o=n("499e").default;o("9677a646",i,!0,{sourceMap:!1,shadowMode:!1})},2350:function(e,t){function n(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"===typeof btoa){var s=i(o),r=o.sources.map((function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"}));return[n].concat(r).concat([s]).join("\n")}return[n].join("\n")}function i(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),n="sourceMappingURL=data:application/json;charset=utf-8;base64,"+t;return"/*# "+n+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var i=n(t,e);return t[2]?"@media "+t[2]+"{"+i+"}":i})).join("")},t.i=function(e,n){"string"===typeof e&&(e=[[null,e,""]]);for(var i={},o=0;o<this.length;o++){var s=this[o][0];"number"===typeof s&&(i[s]=!0)}for(o=0;o<e.length;o++){var r=e[o];"number"===typeof r[0]&&i[r[0]]||(n&&!r[2]?r[2]=n:n&&(r[2]="("+r[2]+") and ("+n+")"),t.push(r))}},t}},"499e":function(e,t,n){"use strict";function i(e,t){for(var n=[],i={},o=0;o<t.length;o++){var s=t[o],r=s[0],a=s[1],c=s[2],u=s[3],l={id:e+":"+o,css:a,media:c,sourceMap:u};i[r]?i[r].parts.push(l):n.push(i[r]={id:r,parts:[l]})}return n}n.r(t),n.d(t,"default",(function(){return v}));var o="undefined"!==typeof document;if("undefined"!==typeof DEBUG&&DEBUG&&!o)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var s={},r=o&&(document.head||document.getElementsByTagName("head")[0]),a=null,c=0,u=!1,l=function(){},h=null,d="data-vue-ssr-id",m="undefined"!==typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function v(e,t,n,o){u=n,h=o||{};var r=i(e,t);return f(r),function(t){for(var n=[],o=0;o<r.length;o++){var a=r[o],c=s[a.id];c.refs--,n.push(c)}t?(r=i(e,t),f(r)):r=[];for(o=0;o<n.length;o++){c=n[o];if(0===c.refs){for(var u=0;u<c.parts.length;u++)c.parts[u]();delete s[c.id]}}}}function f(e){for(var t=0;t<e.length;t++){var n=e[t],i=s[n.id];if(i){i.refs++;for(var o=0;o<i.parts.length;o++)i.parts[o](n.parts[o]);for(;o<n.parts.length;o++)i.parts.push(g(n.parts[o]));i.parts.length>n.parts.length&&(i.parts.length=n.parts.length)}else{var r=[];for(o=0;o<n.parts.length;o++)r.push(g(n.parts[o]));s[n.id]={id:n.id,refs:1,parts:r}}}}function p(){var e=document.createElement("style");return e.type="text/css",r.appendChild(e),e}function g(e){var t,n,i=document.querySelector("style["+d+'~="'+e.id+'"]');if(i){if(u)return l;i.parentNode.removeChild(i)}if(m){var o=c++;i=a||(a=p()),t=w.bind(null,i,o,!1),n=w.bind(null,i,o,!0)}else i=p(),t=b.bind(null,i),n=function(){i.parentNode.removeChild(i)};return t(e),function(i){if(i){if(i.css===e.css&&i.media===e.media&&i.sourceMap===e.sourceMap)return;t(e=i)}else n()}}var y=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}();function w(e,t,n,i){var o=n?"":i.css;if(e.styleSheet)e.styleSheet.cssText=y(t,o);else{var s=document.createTextNode(o),r=e.childNodes;r[t]&&e.removeChild(r[t]),r.length?e.insertBefore(s,r[t]):e.appendChild(s)}}function b(e,t){var n=t.css,i=t.media,o=t.sourceMap;if(i&&e.setAttribute("media",i),h.ssrId&&e.setAttribute(d,t.id),o&&(n+="\n/*# sourceURL="+o.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */"),e.styleSheet)e.styleSheet.cssText=n;else{while(e.firstChild)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}},d167:function(e,t,n){t=e.exports=n("2350")(!1),t.push([e.i,".behavior-warning-dialog.el-dialog.el-dialog--center{text-align:left}",""])},d1a8:function(e,t,n){"use strict";n("0c60")},fb15:function(e,t,n){"use strict";var i;(n.r(t),n.d(t,"UserBehaviorMonitor",(function(){return l})),"undefined"!==typeof window)&&((i=window.document.currentScript)&&(i=i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))&&(n.p=i[1]));var o=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"behaviorMonitor",staticClass:"user-behavior-monitor"},[n("el-dialog",{attrs:{title:"提示",visible:e.showWarning,"show-close":!1,modal:!0,width:"30%",center:"","custom-class":"behavior-warning-dialog"},on:{"update:visible":function(t){e.showWarning=t}}},[n("span",[e._v(e._s(e.warningMessage))])])],1)},s=[],r={name:"UserBehaviorMonitor",props:{timeoutMinutes:{type:Number,default:10},warningMinutes:{type:Number,default:1}},data(){return{mouseMoveThrottled:!1,socket:null,countdownTimer:null,warningTimer:null,showWarning:!1,warningMessage:`您已${this.timeoutMinutes}分钟未操作,将在1分钟后自动退出`,lastActivityTime:null,isMonitoring:!1,currentTimeoutMinutes:10,currentWarningMinutes:1,reconnectAttempts:0,maxReconnectAttempts:3,reconnectDelay:3e3,isLocalDevelopment:this.checkIfLocalDevelopment()}},mounted(){this.isLoginRoute()||this.initMonitor()},beforeDestroy(){this.destroyMonitor()},watch:{$route(e,t){const n=t.path.includes("/login")||t.href&&t.href.includes("/login"),i=this.isLoginRoute();!n||i||this.isMonitoring?!n&&i&&this.isMonitoring&&this.destroyMonitor():this.initMonitor()}},methods:{isLoginRoute(){return!!(this.$route&&this.$route.path&&this.$route.path.includes("/login"))||"undefined"!==typeof window&&(window.location.pathname.includes("/login")||window.location.href.includes("/login"))},checkIfLocalDevelopment(){if("undefined"!==typeof window){const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"0.0.0.0"===e||/^192\.168\./.test(e)||/^10\./.test(e)||/^172\.(1[6-9]|2[0-9]|3[01])\./.test(e)}return!1},updateTimeoutSettings(e,t){void 0!==e&&(this.currentTimeoutMinutes=e,localStorage.setItem("userBehavior_timeoutMinutes",e.toString())),void 0!==t&&(this.currentWarningMinutes=t,localStorage.setItem("userBehavior_warningMinutes",t.toString())),this.warningMessage=`您已${this.currentTimeoutMinutes}分钟未操作,将在1分钟后自动退出`,this.resetTimer()},initMonitor(){this.isLoginRoute()?this.destroyMonitor():this.isMonitoring||(this.isMonitoring=!0,this.lastActivityTime=Date.now(),this.reconnectAttempts=0,this.initWebSocket(),this.bindEventListeners())},destroyMonitor(){this.isMonitoring=!1,this.countdownTimer&&clearInterval(this.countdownTimer),this.warningTimer&&clearTimeout(this.warningTimer),this.socket&&(this.socket.close(),this.socket=null),this.unbindEventListeners()},initWebSocket(){try{const t=`wss://${location.host}/xy-api/auth-server/ws/user-activity`;let n="";try{const e=localStorage.getItem("api_header");e&&(n=JSON.parse(e).Authorization||"")}catch(e){n=localStorage.getItem("token")||""}this.socket=new WebSocket(`${t}?token=${encodeURIComponent(n)}`),this.socket.onopen=()=>{console.log("WebSocket连接已建立"),this.sendUserBehavior(),this.$emit("websocket-open"),this.reconnectAttempts=0},this.socket.onmessage=t=>{try{const e=JSON.parse(t.data);console.log("收到用户活动状态消息:",e),this.handleActivityStatus(e),this.$emit("websocket-message",e)}catch(e){console.error("解析WebSocket消息失败:",e)}},this.socket.onclose=e=>{console.log("WebSocket连接已断开:",e.reason),this.$emit("websocket-close"),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())},this.socket.onerror=e=>{console.error("WebSocket错误:",e),this.$emit("websocket-error",e),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())}}catch(t){console.error("WebSocket初始化失败:",t),this.$emit("websocket-error",t),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())}},shouldAttemptReconnect(){return this.isMonitoring&&!this.isLoginRoute()&&this.reconnectAttempts<this.maxReconnectAttempts},attemptReconnect(){if(!this.isLoginRoute())return this.reconnectAttempts++,console.log(`尝试第${this.reconnectAttempts}次重连...`),this.isLocalDevelopment&&this.reconnectAttempts>=this.maxReconnectAttempts?(console.log("本地开发环境,重连失败但不跳转到登录页"),void this.$emit("websocket-reconnect-failed")):!this.isLocalDevelopment&&this.reconnectAttempts>=this.maxReconnectAttempts?(console.log("线上环境,重连失败,跳转到登录页"),void this.handleReconnectFailure()):void setTimeout(()=>{this.initWebSocket()},this.reconnectDelay);console.log("当前在登录页面,取消重连")},handleReconnectFailure(){localStorage.clear(),sessionStorage.clear(),window.location.href="/login",this.$emit("logout")},handleActivityStatus(e){if("ACTIVITY_STATUS"===e.type&&e.data){const t=e.data;this.currentTimeoutMinutes=t.timeoutMinutes||10,this.currentWarningMinutes=t.reminderMinutes||1,this.warningMessage=`您已${this.currentTimeoutMinutes}分钟未操作,将在${this.currentWarningMinutes}分钟后自动退出`,t.needReminder&&this.showWarningWarning(t.remainingMillis)}},handleInactiveStatus(){localStorage.clear(),sessionStorage.clear(),window.location.href="/login",this.$emit("logout")},sendUserBehavior(e){if(this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"HEARTBEAT",message:"心跳"};console.log("用户行为监测:",JSON.stringify(e)),this.socket.send(JSON.stringify(e))}},bindEventListeners(){document.addEventListener("click",this.handleUserActivity,!0),document.addEventListener("dblclick",this.handleUserActivity,!0),document.addEventListener("mousedown",this.handleUserActivity,!0),document.addEventListener("mouseup",this.handleUserActivity,!0),document.addEventListener("mousemove",this.handleMouseMove,!0),document.addEventListener("mouseover",this.handleUserActivity,!0),document.addEventListener("mouseout",this.handleUserActivity,!0),document.addEventListener("keydown",this.handleUserActivity,!0),document.addEventListener("keyup",this.handleUserActivity,!0),document.addEventListener("input",this.handleUserActivity,!0),document.addEventListener("change",this.handleUserActivity,!0),document.addEventListener("focus",this.handleUserActivity,!0),document.addEventListener("blur",this.handleUserActivity,!0),document.addEventListener("scroll",this.debounce(this.handleUserActivity,300),!0),window.addEventListener("resize",this.handleUserActivity,!0),window.addEventListener("beforeunload",this.handleBeforeUnload)},unbindEventListeners(){document.removeEventListener("click",this.handleUserActivity,!0),document.removeEventListener("dblclick",this.handleUserActivity,!0),document.removeEventListener("mousedown",this.handleUserActivity,!0),document.removeEventListener("mouseup",this.handleUserActivity,!0),document.removeEventListener("mousemove",this.handleMouseMove,!0),document.removeEventListener("mouseover",this.handleUserActivity,!0),document.removeEventListener("mouseout",this.handleUserActivity,!0),document.removeEventListener("keydown",this.handleUserActivity,!0),document.removeEventListener("keyup",this.handleUserActivity,!0),document.removeEventListener("input",this.handleUserActivity,!0),document.removeEventListener("change",this.handleUserActivity,!0),document.removeEventListener("focus",this.handleUserActivity,!0),document.removeEventListener("blur",this.handleUserActivity,!0),document.removeEventListener("scroll",this.debounce(this.handleUserActivity,300),!0),window.removeEventListener("resize",this.handleUserActivity,!0),window.removeEventListener("beforeunload",this.handleBeforeUnload)},handleUserActivity(e){if(this.isAutomaticEvent(e))return;this.resetTimer();const t={eventType:e.type,target:e.target.tagName,timestamp:Date.now(),url:window.location.href};"click"===e.type?(t.clientX=e.clientX,t.clientY=e.clientY):"keydown"===e.type&&(t.key=e.key,t.ctrlKey=e.ctrlKey,t.altKey=e.altKey,t.shiftKey=e.shiftKey),this.sendUserBehavior(t)},handleMouseMove(e){this.mouseMoveThrottled||(this.handleUserActivity(e),this.mouseMoveThrottled=!0,setTimeout(()=>{this.mouseMoveThrottled=!1},500))},isAutomaticEvent(e){return"scroll"===e.type&&!this.isUserScrolling},debounce(e,t){let n;return function(...i){const o=()=>{clearTimeout(n),e.apply(this,i)};clearTimeout(n),n=setTimeout(o,t)}},resetTimer(){this.lastActivityTime=Date.now(),this.showWarning=!1,this.reconnectAttempts=0,this.warningTimer&&(clearTimeout(this.warningTimer),this.warningTimer=null),this.$emit("user-active")},startCountdown(){this.countdownTimer&&clearInterval(this.countdownTimer),this.countdownTimer=setInterval(()=>{const e=Date.now(),t=(e-this.lastActivityTime)/5e4;t>=this.currentTimeoutMinutes-this.currentWarningMinutes&&!this.warningTimer&&this.showWarningWarning(),t>=this.currentTimeoutMinutes&&this.handleTimeout()},1e3)},showWarningWarning(e){let t=e||5e4;console.log("Setting showWarning to true"),this.showWarning=!0,this.$emit("timeout-warning"),this.warningTimer&&clearTimeout(this.warningTimer),this.warningTimer=setTimeout(()=>{this.handleTimeout()},t)},handleTimeout(){this.showWarning=!1,this.$emit("timeout"),this.logout()},logout(){if(localStorage.clear(),sessionStorage.clear(),location.reload(),this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"logout",timestamp:Date.now()};this.socket.send(JSON.stringify(e))}this.$emit("logout"),this.countdownTimer&&clearInterval(this.countdownTimer),this.warningTimer&&clearTimeout(this.warningTimer)},handleBeforeUnload(e){if(this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"page_unload",timestamp:Date.now()};this.socket.send(JSON.stringify(e))}},reset(){this.isLoginRoute()?this.destroyMonitor():this.resetTimer()},reconnect(){this.isLoginRoute()?this.destroyMonitor():(this.reconnectAttempts=0,this.socket&&this.socket.close(),this.initWebSocket())}}},a=r;n("d1a8");function c(e,t,n,i,o,s,r,a){var c,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),s&&(u._scopeId="data-v-"+s),r?(c=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(r)},u._ssrRegister=c):o&&(c=a?function(){o.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:o),c)if(u.functional){u._injectStyles=c;var l=u.render;u.render=function(e,t){return c.call(t),l(e,t)}}else{var h=u.beforeCreate;u.beforeCreate=h?[].concat(h,c):[c]}return{exports:e,options:u}}var u=c(a,o,s,!1,null,null,null),l=u.exports;l.install=function(e){e.component(l.name,l)};var h=l;"undefined"!==typeof window&&window.Vue&&l.install(window.Vue);t["default"]=h}})}));
1
+ (function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["user-behavior-monitor"]=t():e["user-behavior-monitor"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="fb15")}({2350:function(e,t){function n(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"===typeof btoa){var s=i(o),r=o.sources.map((function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"}));return[n].concat(r).concat([s]).join("\n")}return[n].join("\n")}function i(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),n="sourceMappingURL=data:application/json;charset=utf-8;base64,"+t;return"/*# "+n+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var i=n(t,e);return t[2]?"@media "+t[2]+"{"+i+"}":i})).join("")},t.i=function(e,n){"string"===typeof e&&(e=[[null,e,""]]);for(var i={},o=0;o<this.length;o++){var s=this[o][0];"number"===typeof s&&(i[s]=!0)}for(o=0;o<e.length;o++){var r=e[o];"number"===typeof r[0]&&i[r[0]]||(n&&!r[2]?r[2]=n:n&&(r[2]="("+r[2]+") and ("+n+")"),t.push(r))}},t}},"2cd8":function(e,t,n){"use strict";n("89b5")},"499e":function(e,t,n){"use strict";function i(e,t){for(var n=[],i={},o=0;o<t.length;o++){var s=t[o],r=s[0],a=s[1],c=s[2],u=s[3],h={id:e+":"+o,css:a,media:c,sourceMap:u};i[r]?i[r].parts.push(h):n.push(i[r]={id:r,parts:[h]})}return n}n.r(t),n.d(t,"default",(function(){return v}));var o="undefined"!==typeof document;if("undefined"!==typeof DEBUG&&DEBUG&&!o)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var s={},r=o&&(document.head||document.getElementsByTagName("head")[0]),a=null,c=0,u=!1,h=function(){},l=null,d="data-vue-ssr-id",m="undefined"!==typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function v(e,t,n,o){u=n,l=o||{};var r=i(e,t);return f(r),function(t){for(var n=[],o=0;o<r.length;o++){var a=r[o],c=s[a.id];c.refs--,n.push(c)}t?(r=i(e,t),f(r)):r=[];for(o=0;o<n.length;o++){c=n[o];if(0===c.refs){for(var u=0;u<c.parts.length;u++)c.parts[u]();delete s[c.id]}}}}function f(e){for(var t=0;t<e.length;t++){var n=e[t],i=s[n.id];if(i){i.refs++;for(var o=0;o<i.parts.length;o++)i.parts[o](n.parts[o]);for(;o<n.parts.length;o++)i.parts.push(g(n.parts[o]));i.parts.length>n.parts.length&&(i.parts.length=n.parts.length)}else{var r=[];for(o=0;o<n.parts.length;o++)r.push(g(n.parts[o]));s[n.id]={id:n.id,refs:1,parts:r}}}}function p(){var e=document.createElement("style");return e.type="text/css",r.appendChild(e),e}function g(e){var t,n,i=document.querySelector("style["+d+'~="'+e.id+'"]');if(i){if(u)return h;i.parentNode.removeChild(i)}if(m){var o=c++;i=a||(a=p()),t=w.bind(null,i,o,!1),n=w.bind(null,i,o,!0)}else i=p(),t=b.bind(null,i),n=function(){i.parentNode.removeChild(i)};return t(e),function(i){if(i){if(i.css===e.css&&i.media===e.media&&i.sourceMap===e.sourceMap)return;t(e=i)}else n()}}var y=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}();function w(e,t,n,i){var o=n?"":i.css;if(e.styleSheet)e.styleSheet.cssText=y(t,o);else{var s=document.createTextNode(o),r=e.childNodes;r[t]&&e.removeChild(r[t]),r.length?e.insertBefore(s,r[t]):e.appendChild(s)}}function b(e,t){var n=t.css,i=t.media,o=t.sourceMap;if(i&&e.setAttribute("media",i),l.ssrId&&e.setAttribute(d,t.id),o&&(n+="\n/*# sourceURL="+o.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */"),e.styleSheet)e.styleSheet.cssText=n;else{while(e.firstChild)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}},"89b5":function(e,t,n){var i=n("9f1b");i.__esModule&&(i=i.default),"string"===typeof i&&(i=[[e.i,i,""]]),i.locals&&(e.exports=i.locals);var o=n("499e").default;o("9b2fa8ce",i,!0,{sourceMap:!1,shadowMode:!1})},"9f1b":function(e,t,n){t=e.exports=n("2350")(!1),t.push([e.i,".behavior-warning-dialog.el-dialog.el-dialog--center{text-align:left}",""])},fb15:function(e,t,n){"use strict";var i;(n.r(t),n.d(t,"UserBehaviorMonitor",(function(){return h})),"undefined"!==typeof window)&&((i=window.document.currentScript)&&(i=i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))&&(n.p=i[1]));var o=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"behaviorMonitor",staticClass:"user-behavior-monitor"},[n("el-dialog",{attrs:{title:"提示",visible:e.showWarning,"show-close":!1,modal:!0,width:"30%",center:"","custom-class":"behavior-warning-dialog"},on:{"update:visible":function(t){e.showWarning=t}}},[n("span",[e._v(e._s(e.warningMessage))])])],1)},s=[],r={name:"UserBehaviorMonitor",props:{timeoutMinutes:{type:Number,default:10},warningMinutes:{type:Number,default:1}},data(){return{mouseMoveThrottled:!1,socket:null,countdownTimer:null,warningTimer:null,showWarning:!1,warningMessage:`您已${this.timeoutMinutes}分钟未操作,将在1分钟后自动退出`,lastActivityTime:null,isMonitoring:!1,currentTimeoutMinutes:10,currentWarningMinutes:1,reconnectAttempts:0,maxReconnectAttempts:3,reconnectDelay:3e3,isLocalDevelopment:this.checkIfLocalDevelopment()}},mounted(){this.isLoginRoute()||this.initMonitor()},beforeDestroy(){this.destroyMonitor()},watch:{$route(e,t){const n=t.path.includes("/login")||t.href&&t.href.includes("/login"),i=this.isLoginRoute();!n||i||this.isMonitoring?!n&&i&&this.isMonitoring&&this.destroyMonitor():this.initMonitor()}},methods:{isLoginRoute(){return!!(this.$route&&this.$route.path&&this.$route.path.includes("/login"))||"undefined"!==typeof window&&(window.location.pathname.includes("/login")||window.location.href.includes("/login"))},checkIfLocalDevelopment(){if("undefined"!==typeof window){const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"0.0.0.0"===e||/^192\.168\./.test(e)||/^10\./.test(e)||/^172\.(1[6-9]|2[0-9]|3[01])\./.test(e)}return!1},updateTimeoutSettings(e,t){void 0!==e&&(this.currentTimeoutMinutes=e,localStorage.setItem("userBehavior_timeoutMinutes",e.toString())),void 0!==t&&(this.currentWarningMinutes=t,localStorage.setItem("userBehavior_warningMinutes",t.toString())),this.warningMessage=`您已${this.currentTimeoutMinutes}分钟未操作,将在1分钟后自动退出`,this.resetTimer()},initMonitor(){this.isLoginRoute()?this.destroyMonitor():this.isMonitoring||(this.isMonitoring=!0,this.lastActivityTime=Date.now(),this.reconnectAttempts=0,this.initWebSocket(),this.bindEventListeners())},destroyMonitor(){this.isMonitoring=!1,this.countdownTimer&&clearInterval(this.countdownTimer),this.warningTimer&&clearTimeout(this.warningTimer),this.socket&&(this.socket.close(),this.socket=null),this.unbindEventListeners()},initWebSocket(){try{const t=`wss://${location.host}/xy-api/auth-server/ws/user-activity`;let n="";try{const e=localStorage.getItem("api_header");e&&(n=JSON.parse(e).Authorization||"")}catch(e){n=localStorage.getItem("token")||""}this.socket=new WebSocket(`${t}?token=${encodeURIComponent(n)}`),this.socket.onopen=()=>{this.sendUserBehavior(),this.$emit("websocket-open"),this.reconnectAttempts=0},this.socket.onmessage=t=>{try{const e=JSON.parse(t.data);this.handleActivityStatus(e),this.$emit("websocket-message",e)}catch(e){}},this.socket.onclose=e=>{this.$emit("websocket-close"),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())},this.socket.onerror=e=>{this.$emit("websocket-error",e),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())}}catch(t){this.$emit("websocket-error",t),this.shouldAttemptReconnect()?this.attemptReconnect():!this.isLoginRoute()&&this.isMonitoring&&(this.isLocalDevelopment||this.handleReconnectFailure())}},shouldAttemptReconnect(){return this.isMonitoring&&!this.isLoginRoute()&&this.reconnectAttempts<this.maxReconnectAttempts},attemptReconnect(){this.isLoginRoute()||(this.reconnectAttempts++,this.isLocalDevelopment&&this.reconnectAttempts>=this.maxReconnectAttempts?this.$emit("websocket-reconnect-failed"):!this.isLocalDevelopment&&this.reconnectAttempts>=this.maxReconnectAttempts?this.handleReconnectFailure():setTimeout(()=>{this.initWebSocket()},this.reconnectDelay))},handleReconnectFailure(){localStorage.clear(),sessionStorage.clear(),location.reload(),this.$emit("logout")},handleActivityStatus(e){if("ACTIVITY_STATUS"===e.type&&e.data){const t=e.data;this.currentTimeoutMinutes=t.timeoutMinutes||10,this.currentWarningMinutes=t.reminderMinutes||1,this.warningMessage=`您已${this.currentTimeoutMinutes}分钟未操作,将在${this.currentWarningMinutes}分钟后自动退出`,t.needReminder&&this.showWarningWarning(t.remainingMillis)}},handleInactiveStatus(){localStorage.clear(),sessionStorage.clear(),location.reload(),this.$emit("logout")},sendUserBehavior(e){if(this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"HEARTBEAT",message:"心跳"};this.socket.send(JSON.stringify(e))}},bindEventListeners(){document.addEventListener("click",this.handleUserActivity,!0),document.addEventListener("dblclick",this.handleUserActivity,!0),document.addEventListener("mousedown",this.handleUserActivity,!0),document.addEventListener("mouseup",this.handleUserActivity,!0),document.addEventListener("mousemove",this.handleMouseMove,!0),document.addEventListener("mouseover",this.handleUserActivity,!0),document.addEventListener("mouseout",this.handleUserActivity,!0),document.addEventListener("keydown",this.handleUserActivity,!0),document.addEventListener("keyup",this.handleUserActivity,!0),document.addEventListener("input",this.handleUserActivity,!0),document.addEventListener("change",this.handleUserActivity,!0),document.addEventListener("focus",this.handleUserActivity,!0),document.addEventListener("blur",this.handleUserActivity,!0),document.addEventListener("scroll",this.debounce(this.handleUserActivity,300),!0),window.addEventListener("resize",this.handleUserActivity,!0),window.addEventListener("beforeunload",this.handleBeforeUnload)},unbindEventListeners(){document.removeEventListener("click",this.handleUserActivity,!0),document.removeEventListener("dblclick",this.handleUserActivity,!0),document.removeEventListener("mousedown",this.handleUserActivity,!0),document.removeEventListener("mouseup",this.handleUserActivity,!0),document.removeEventListener("mousemove",this.handleMouseMove,!0),document.removeEventListener("mouseover",this.handleUserActivity,!0),document.removeEventListener("mouseout",this.handleUserActivity,!0),document.removeEventListener("keydown",this.handleUserActivity,!0),document.removeEventListener("keyup",this.handleUserActivity,!0),document.removeEventListener("input",this.handleUserActivity,!0),document.removeEventListener("change",this.handleUserActivity,!0),document.removeEventListener("focus",this.handleUserActivity,!0),document.removeEventListener("blur",this.handleUserActivity,!0),document.removeEventListener("scroll",this.debounce(this.handleUserActivity,300),!0),window.removeEventListener("resize",this.handleUserActivity,!0),window.removeEventListener("beforeunload",this.handleBeforeUnload)},handleUserActivity(e){if(this.isAutomaticEvent(e))return;this.resetTimer();const t={eventType:e.type,target:e.target.tagName,timestamp:Date.now(),url:window.location.href};"click"===e.type?(t.clientX=e.clientX,t.clientY=e.clientY):"keydown"===e.type&&(t.key=e.key,t.ctrlKey=e.ctrlKey,t.altKey=e.altKey,t.shiftKey=e.shiftKey),this.sendUserBehavior(t)},handleMouseMove(e){this.mouseMoveThrottled||(this.handleUserActivity(e),this.mouseMoveThrottled=!0,setTimeout(()=>{this.mouseMoveThrottled=!1},500))},isAutomaticEvent(e){return"scroll"===e.type&&!this.isUserScrolling},debounce(e,t){let n;return function(...i){const o=()=>{clearTimeout(n),e.apply(this,i)};clearTimeout(n),n=setTimeout(o,t)}},resetTimer(){this.lastActivityTime=Date.now(),this.showWarning=!1,this.reconnectAttempts=0,this.warningTimer&&(clearTimeout(this.warningTimer),this.warningTimer=null),this.$emit("user-active")},startCountdown(){this.countdownTimer&&clearInterval(this.countdownTimer),this.countdownTimer=setInterval(()=>{const e=Date.now(),t=(e-this.lastActivityTime)/5e4;t>=this.currentTimeoutMinutes-this.currentWarningMinutes&&!this.warningTimer&&this.showWarningWarning(),t>=this.currentTimeoutMinutes&&this.handleTimeout()},1e3)},showWarningWarning(e){let t=e||5e4;this.showWarning=!0,this.$emit("timeout-warning"),this.warningTimer&&clearTimeout(this.warningTimer),this.warningTimer=setTimeout(()=>{this.handleTimeout()},t)},handleTimeout(){this.showWarning=!1,this.$emit("timeout"),this.logout()},logout(){if(localStorage.clear(),sessionStorage.clear(),location.reload(),this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"logout",timestamp:Date.now()};this.socket.send(JSON.stringify(e))}this.$emit("logout"),this.countdownTimer&&clearInterval(this.countdownTimer),this.warningTimer&&clearTimeout(this.warningTimer)},handleBeforeUnload(e){if(this.socket&&this.socket.readyState===WebSocket.OPEN){const e={type:"page_unload",timestamp:Date.now()};this.socket.send(JSON.stringify(e))}},reset(){this.isLoginRoute()?this.destroyMonitor():this.resetTimer()},reconnect(){this.isLoginRoute()?this.destroyMonitor():(this.reconnectAttempts=0,this.socket&&this.socket.close(),this.initWebSocket())}}},a=r;n("2cd8");function c(e,t,n,i,o,s,r,a){var c,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),s&&(u._scopeId="data-v-"+s),r?(c=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(r)},u._ssrRegister=c):o&&(c=a?function(){o.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:o),c)if(u.functional){u._injectStyles=c;var h=u.render;u.render=function(e,t){return c.call(t),h(e,t)}}else{var l=u.beforeCreate;u.beforeCreate=l?[].concat(l,c):[c]}return{exports:e,options:u}}var u=c(a,o,s,!1,null,null,null),h=u.exports;h.install=function(e){e.component(h.name,h)};var l=h;"undefined"!==typeof window&&window.Vue&&h.install(window.Vue);t["default"]=l}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "user-behavior-monitor",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "Vue component for monitoring user behavior and auto-logout",
5
5
  "main": "dist/user-behavior-monitor.umd.min.js",
6
6
  "files": [
@@ -199,7 +199,7 @@ export default {
199
199
 
200
200
  // 设置连接成功回调
201
201
  this.socket.onopen = () => {
202
- console.log('WebSocket连接已建立');
202
+ // console.log('WebSocket连接已建立');
203
203
  this.sendUserBehavior();
204
204
  this.$emit('websocket-open');
205
205
  // 连接成功时重置重连尝试次数
@@ -210,17 +210,17 @@ export default {
210
210
  this.socket.onmessage = (event) => {
211
211
  try {
212
212
  const data = JSON.parse(event.data);
213
- console.log('收到用户活动状态消息:', data);
213
+ // console.log('收到用户活动状态消息:', data);
214
214
  this.handleActivityStatus(data);
215
215
  this.$emit('websocket-message', data);
216
216
  } catch (e) {
217
- console.error('解析WebSocket消息失败:', e);
217
+ // console.error('解析WebSocket消息失败:', e);
218
218
  }
219
219
  };
220
220
 
221
221
  // 设置连接关闭回调
222
222
  this.socket.onclose = (event) => {
223
- console.log('WebSocket连接已断开:', event.reason);
223
+ // console.log('WebSocket连接已断开:', event.reason);
224
224
  this.$emit('websocket-close');
225
225
 
226
226
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -236,7 +236,7 @@ export default {
236
236
 
237
237
  // 设置连接错误回调
238
238
  this.socket.onerror = (error) => {
239
- console.error('WebSocket错误:', error);
239
+ // console.error('WebSocket错误:', error);
240
240
  this.$emit('websocket-error', error);
241
241
 
242
242
  // 如果不是在登录页面且监控仍在运行,尝试重连
@@ -251,7 +251,7 @@ export default {
251
251
  };
252
252
 
253
253
  } catch (error) {
254
- console.error('WebSocket初始化失败:', error);
254
+ // console.error('WebSocket初始化失败:', error);
255
255
  this.$emit('websocket-error', error);
256
256
 
257
257
  // 初始化失败时也可以尝试重连(如果不是在登录页面)
@@ -277,23 +277,23 @@ export default {
277
277
  attemptReconnect() {
278
278
  // 再次检查是否为登录页面
279
279
  if (this.isLoginRoute()) {
280
- console.log('当前在登录页面,取消重连');
280
+ // console.log('当前在登录页面,取消重连');
281
281
  return;
282
282
  }
283
283
 
284
284
  this.reconnectAttempts++;
285
- console.log(`尝试第${this.reconnectAttempts}次重连...`);
285
+ // console.log(`尝试第${this.reconnectAttempts}次重连...`);
286
286
 
287
287
  // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
288
288
  if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
289
- console.log('本地开发环境,重连失败但不跳转到登录页');
289
+ // console.log('本地开发环境,重连失败但不跳转到登录页');
290
290
  this.$emit('websocket-reconnect-failed');
291
291
  return;
292
292
  }
293
293
 
294
294
  // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
295
295
  if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
296
- console.log('线上环境,重连失败,跳转到登录页');
296
+ // console.log('线上环境,重连失败,跳转到登录页');
297
297
  this.handleReconnectFailure();
298
298
  return;
299
299
  }
@@ -310,7 +310,8 @@ export default {
310
310
  sessionStorage.clear();
311
311
 
312
312
  // 跳转到登录页
313
- window.location.href = '/login';
313
+
314
+ location.reload();
314
315
 
315
316
  // 触发登出事件
316
317
  this.$emit('logout');
@@ -355,7 +356,9 @@ export default {
355
356
  //this.$router.push('/login');
356
357
 
357
358
  // 或者使用window.location
358
- window.location.href = '/login';
359
+
360
+ location.reload();
361
+ // window.location.href = '/login';
359
362
 
360
363
  // 触发登出事件
361
364
  this.$emit('logout');
@@ -368,7 +371,7 @@ export default {
368
371
  "type": "HEARTBEAT",
369
372
  "message": "心跳",
370
373
  };
371
- console.log('用户行为监测:', JSON.stringify(message));
374
+ // console.log('用户行为监测:', JSON.stringify(message));
372
375
  this.socket.send(JSON.stringify(message));
373
376
  }
374
377
  },
@@ -529,7 +532,7 @@ export default {
529
532
  // 显示超时警告
530
533
  showWarningWarning(timeoutMinutes) {
531
534
  let time=timeoutMinutes||50000;
532
- console.log('Setting showWarning to true');
535
+ // console.log('Setting showWarning to true');
533
536
  this.showWarning = true;
534
537
  this.$emit('timeout-warning');
535
538
  if (this.warningTimer) clearTimeout(this.warningTimer);
@@ -47,7 +47,11 @@ export default {
47
47
  lastActivityTime: null,
48
48
  isMonitoring: false,
49
49
  currentTimeoutMinutes: 10,
50
- currentWarningMinutes: 1
50
+ currentWarningMinutes: 1,
51
+ reconnectAttempts: 0,
52
+ maxReconnectAttempts: 3,
53
+ reconnectDelay: 3000,
54
+ isLocalDevelopment: this.checkIfLocalDevelopment()
51
55
  };
52
56
  },
53
57
  mounted() {
@@ -97,6 +101,20 @@ export default {
97
101
 
98
102
  return false;
99
103
  },
104
+
105
+ // 检查是否为本地开发环境
106
+ checkIfLocalDevelopment() {
107
+ if (typeof window !== 'undefined') {
108
+ const hostname = window.location.hostname;
109
+ return hostname === 'localhost' ||
110
+ hostname === '127.0.0.1' ||
111
+ hostname === '0.0.0.0' ||
112
+ /^192\.168\./.test(hostname) || // 局域网IP
113
+ /^10\./.test(hostname) || // 局域网IP
114
+ /^172\.(1[6-9]|2[0-9]|3[01])\./.test(hostname); // 局域网IP
115
+ }
116
+ return false;
117
+ },
100
118
 
101
119
  updateTimeoutSettings(timeoutMinutes, warningMinutes) {
102
120
  if (timeoutMinutes !== undefined) {
@@ -129,6 +147,7 @@ export default {
129
147
 
130
148
  this.isMonitoring = true;
131
149
  this.lastActivityTime = Date.now();
150
+ this.reconnectAttempts = 0; // 重置重连尝试次数
132
151
 
133
152
  // 初始化WebSocket连接
134
153
  this.initWebSocket();
@@ -183,6 +202,8 @@ export default {
183
202
  console.log('WebSocket连接已建立');
184
203
  this.sendUserBehavior();
185
204
  this.$emit('websocket-open');
205
+ // 连接成功时重置重连尝试次数
206
+ this.reconnectAttempts = 0;
186
207
  };
187
208
 
188
209
  // 设置接收消息回调
@@ -201,18 +222,99 @@ export default {
201
222
  this.socket.onclose = (event) => {
202
223
  console.log('WebSocket连接已断开:', event.reason);
203
224
  this.$emit('websocket-close');
225
+
226
+ // 如果不是在登录页面且监控仍在运行,尝试重连
227
+ if (this.shouldAttemptReconnect()) {
228
+ this.attemptReconnect();
229
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
230
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
231
+ if (!this.isLocalDevelopment) {
232
+ this.handleReconnectFailure();
233
+ }
234
+ }
204
235
  };
205
236
 
206
237
  // 设置连接错误回调
207
238
  this.socket.onerror = (error) => {
208
239
  console.error('WebSocket错误:', error);
209
240
  this.$emit('websocket-error', error);
241
+
242
+ // 如果不是在登录页面且监控仍在运行,尝试重连
243
+ if (this.shouldAttemptReconnect()) {
244
+ this.attemptReconnect();
245
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
246
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
247
+ if (!this.isLocalDevelopment) {
248
+ this.handleReconnectFailure();
249
+ }
250
+ }
210
251
  };
211
252
 
212
253
  } catch (error) {
213
254
  console.error('WebSocket初始化失败:', error);
214
255
  this.$emit('websocket-error', error);
256
+
257
+ // 初始化失败时也可以尝试重连(如果不是在登录页面)
258
+ if (this.shouldAttemptReconnect()) {
259
+ this.attemptReconnect();
260
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
261
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
262
+ if (!this.isLocalDevelopment) {
263
+ this.handleReconnectFailure();
264
+ }
265
+ }
266
+ }
267
+ },
268
+
269
+ // 判断是否应该尝试重连
270
+ shouldAttemptReconnect() {
271
+ return this.isMonitoring &&
272
+ !this.isLoginRoute() &&
273
+ this.reconnectAttempts < this.maxReconnectAttempts;
274
+ },
275
+
276
+ // 添加重连方法
277
+ attemptReconnect() {
278
+ // 再次检查是否为登录页面
279
+ if (this.isLoginRoute()) {
280
+ console.log('当前在登录页面,取消重连');
281
+ return;
282
+ }
283
+
284
+ this.reconnectAttempts++;
285
+ console.log(`尝试第${this.reconnectAttempts}次重连...`);
286
+
287
+ // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
288
+ if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
289
+ console.log('本地开发环境,重连失败但不跳转到登录页');
290
+ this.$emit('websocket-reconnect-failed');
291
+ return;
215
292
  }
293
+
294
+ // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
295
+ if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
296
+ console.log('线上环境,重连失败,跳转到登录页');
297
+ this.handleReconnectFailure();
298
+ return;
299
+ }
300
+
301
+ setTimeout(() => {
302
+ this.initWebSocket();
303
+ }, this.reconnectDelay);
304
+ },
305
+
306
+ // 处理重连失败
307
+ handleReconnectFailure() {
308
+ // 清空缓存
309
+ localStorage.clear();
310
+ sessionStorage.clear();
311
+
312
+ // 跳转到登录页
313
+
314
+ location.reload();
315
+
316
+ // 触发登出事件
317
+ this.$emit('logout');
216
318
  },
217
319
 
218
320
  // 处理活动状态信息
@@ -254,7 +356,9 @@ export default {
254
356
  //this.$router.push('/login');
255
357
 
256
358
  // 或者使用window.location
257
- window.location.href = '/login';
359
+
360
+ location.reload();
361
+ // window.location.href = '/login';
258
362
 
259
363
  // 触发登出事件
260
364
  this.$emit('logout');
@@ -262,8 +366,6 @@ export default {
262
366
 
263
367
  // 发送用户行为数据到后端
264
368
  sendUserBehavior(data) {
265
- console.log('用户行为监测:')
266
- if (this.warningTimer) clearTimeout(this.warningTimer);
267
369
  if (this.socket && this.socket.readyState === WebSocket.OPEN) {
268
370
  const message = {
269
371
  "type": "HEARTBEAT",
@@ -391,6 +493,7 @@ export default {
391
493
  resetTimer() {
392
494
  this.lastActivityTime = Date.now();
393
495
  this.showWarning = false;
496
+ this.reconnectAttempts = 0; // 重置重连尝试次数
394
497
 
395
498
  // 清除警告定时器
396
499
  if (this.warningTimer) {
@@ -428,7 +531,7 @@ export default {
428
531
 
429
532
  // 显示超时警告
430
533
  showWarningWarning(timeoutMinutes) {
431
- let time=timeoutMinutes||50;
534
+ let time=timeoutMinutes||50000;
432
535
  console.log('Setting showWarning to true');
433
536
  this.showWarning = true;
434
537
  this.$emit('timeout-warning');
@@ -436,7 +539,7 @@ export default {
436
539
  // 设置超时处理
437
540
  this.warningTimer = setTimeout(() => {
438
541
  this.handleTimeout();
439
- }, 1 * time * 1000);
542
+ }, time);
440
543
  },
441
544
 
442
545
  // 处理超时
@@ -506,6 +609,9 @@ export default {
506
609
  return;
507
610
  }
508
611
 
612
+ // 重置重连尝试次数
613
+ this.reconnectAttempts = 0;
614
+
509
615
  if (this.socket) {
510
616
  this.socket.close();
511
617
  }