user-behavior-monitor 2.0.0 → 4.0.1

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,6 +87,22 @@ 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
+
90
106
  /***/ "2350":
91
107
  /***/ (function(module, exports) {
92
108
 
@@ -168,17 +184,6 @@ function toComment(sourceMap) {
168
184
  }
169
185
 
170
186
 
171
- /***/ }),
172
-
173
- /***/ "3505":
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_4f34cec0_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("f079");
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_4f34cec0_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_4f34cec0_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
179
- /* unused harmony reexport * */
180
-
181
-
182
187
  /***/ }),
183
188
 
184
189
  /***/ "499e":
@@ -447,7 +452,7 @@ function applyToTag (styleElement, obj) {
447
452
 
448
453
  /***/ }),
449
454
 
450
- /***/ "a042":
455
+ /***/ "d167":
451
456
  /***/ (function(module, exports, __webpack_require__) {
452
457
 
453
458
  exports = module.exports = __webpack_require__("2350")(false);
@@ -462,19 +467,14 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
462
467
 
463
468
  /***/ }),
464
469
 
465
- /***/ "f079":
466
- /***/ (function(module, exports, __webpack_require__) {
470
+ /***/ "d1a8":
471
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
467
472
 
468
- // style-loader: Adds some css to the DOM by adding a <style> tag
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 * */
469
477
 
470
- // load the styles
471
- var content = __webpack_require__("a042");
472
- if(content.__esModule) content = content.default;
473
- if(typeof content === 'string') content = [[module.i, content, '']];
474
- if(content.locals) module.exports = content.locals;
475
- // add the styles to the DOM
476
- var add = __webpack_require__("499e").default
477
- var update = add("1c569d63", content, true, {"sourceMap":false,"shadowMode":false});
478
478
 
479
479
  /***/ }),
480
480
 
@@ -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=4f34cec0
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
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=4f34cec0
511
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
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
  //
@@ -560,7 +560,11 @@ var staticRenderFns = []
560
560
  lastActivityTime: null,
561
561
  isMonitoring: false,
562
562
  currentTimeoutMinutes: 10,
563
- currentWarningMinutes: 1
563
+ currentWarningMinutes: 1,
564
+ reconnectAttempts: 0,
565
+ maxReconnectAttempts: 3,
566
+ reconnectDelay: 3000,
567
+ isLocalDevelopment: this.checkIfLocalDevelopment()
564
568
  };
565
569
  },
566
570
  mounted() {
@@ -610,6 +614,20 @@ var staticRenderFns = []
610
614
 
611
615
  return false;
612
616
  },
617
+
618
+ // 检查是否为本地开发环境
619
+ checkIfLocalDevelopment() {
620
+ if (typeof window !== 'undefined') {
621
+ const hostname = window.location.hostname;
622
+ return hostname === 'localhost' ||
623
+ hostname === '127.0.0.1' ||
624
+ hostname === '0.0.0.0' ||
625
+ /^192\.168\./.test(hostname) || // 局域网IP
626
+ /^10\./.test(hostname) || // 局域网IP
627
+ /^172\.(1[6-9]|2[0-9]|3[01])\./.test(hostname); // 局域网IP
628
+ }
629
+ return false;
630
+ },
613
631
 
614
632
  updateTimeoutSettings(timeoutMinutes, warningMinutes) {
615
633
  if (timeoutMinutes !== undefined) {
@@ -642,6 +660,7 @@ var staticRenderFns = []
642
660
 
643
661
  this.isMonitoring = true;
644
662
  this.lastActivityTime = Date.now();
663
+ this.reconnectAttempts = 0; // 重置重连尝试次数
645
664
 
646
665
  // 初始化WebSocket连接
647
666
  this.initWebSocket();
@@ -696,6 +715,8 @@ var staticRenderFns = []
696
715
  console.log('WebSocket连接已建立');
697
716
  this.sendUserBehavior();
698
717
  this.$emit('websocket-open');
718
+ // 连接成功时重置重连尝试次数
719
+ this.reconnectAttempts = 0;
699
720
  };
700
721
 
701
722
  // 设置接收消息回调
@@ -714,18 +735,98 @@ var staticRenderFns = []
714
735
  this.socket.onclose = (event) => {
715
736
  console.log('WebSocket连接已断开:', event.reason);
716
737
  this.$emit('websocket-close');
738
+
739
+ // 如果不是在登录页面且监控仍在运行,尝试重连
740
+ if (this.shouldAttemptReconnect()) {
741
+ this.attemptReconnect();
742
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
743
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
744
+ if (!this.isLocalDevelopment) {
745
+ this.handleReconnectFailure();
746
+ }
747
+ }
717
748
  };
718
749
 
719
750
  // 设置连接错误回调
720
751
  this.socket.onerror = (error) => {
721
752
  console.error('WebSocket错误:', error);
722
753
  this.$emit('websocket-error', error);
754
+
755
+ // 如果不是在登录页面且监控仍在运行,尝试重连
756
+ if (this.shouldAttemptReconnect()) {
757
+ this.attemptReconnect();
758
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
759
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
760
+ if (!this.isLocalDevelopment) {
761
+ this.handleReconnectFailure();
762
+ }
763
+ }
723
764
  };
724
765
 
725
766
  } catch (error) {
726
767
  console.error('WebSocket初始化失败:', error);
727
768
  this.$emit('websocket-error', error);
769
+
770
+ // 初始化失败时也可以尝试重连(如果不是在登录页面)
771
+ if (this.shouldAttemptReconnect()) {
772
+ this.attemptReconnect();
773
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
774
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
775
+ if (!this.isLocalDevelopment) {
776
+ this.handleReconnectFailure();
777
+ }
778
+ }
779
+ }
780
+ },
781
+
782
+ // 判断是否应该尝试重连
783
+ shouldAttemptReconnect() {
784
+ return this.isMonitoring &&
785
+ !this.isLoginRoute() &&
786
+ this.reconnectAttempts < this.maxReconnectAttempts;
787
+ },
788
+
789
+ // 添加重连方法
790
+ attemptReconnect() {
791
+ // 再次检查是否为登录页面
792
+ if (this.isLoginRoute()) {
793
+ console.log('当前在登录页面,取消重连');
794
+ return;
795
+ }
796
+
797
+ this.reconnectAttempts++;
798
+ console.log(`尝试第${this.reconnectAttempts}次重连...`);
799
+
800
+ // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
801
+ if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
802
+ console.log('本地开发环境,重连失败但不跳转到登录页');
803
+ this.$emit('websocket-reconnect-failed');
804
+ return;
728
805
  }
806
+
807
+ // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
808
+ if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
809
+ console.log('线上环境,重连失败,跳转到登录页');
810
+ this.handleReconnectFailure();
811
+ return;
812
+ }
813
+
814
+ setTimeout(() => {
815
+ this.initWebSocket();
816
+ }, this.reconnectDelay);
817
+ },
818
+
819
+ // 处理重连失败
820
+ handleReconnectFailure() {
821
+ // 清空缓存
822
+ localStorage.clear();
823
+ sessionStorage.clear();
824
+
825
+ // 跳转到登录页
826
+ window.location.href = '/login';
827
+
828
+ // 触发登出事件
829
+ this.$emit('logout');
729
830
  },
730
831
 
731
832
  // 处理活动状态信息
@@ -775,8 +876,6 @@ var staticRenderFns = []
775
876
 
776
877
  // 发送用户行为数据到后端
777
878
  sendUserBehavior(data) {
778
- console.log('用户行为监测:')
779
- if (this.warningTimer) clearTimeout(this.warningTimer);
780
879
  if (this.socket && this.socket.readyState === WebSocket.OPEN) {
781
880
  const message = {
782
881
  "type": "HEARTBEAT",
@@ -904,6 +1003,7 @@ var staticRenderFns = []
904
1003
  resetTimer() {
905
1004
  this.lastActivityTime = Date.now();
906
1005
  this.showWarning = false;
1006
+ this.reconnectAttempts = 0; // 重置重连尝试次数
907
1007
 
908
1008
  // 清除警告定时器
909
1009
  if (this.warningTimer) {
@@ -941,7 +1041,7 @@ var staticRenderFns = []
941
1041
 
942
1042
  // 显示超时警告
943
1043
  showWarningWarning(timeoutMinutes) {
944
- let time=timeoutMinutes||50;
1044
+ let time=timeoutMinutes||50000;
945
1045
  console.log('Setting showWarning to true');
946
1046
  this.showWarning = true;
947
1047
  this.$emit('timeout-warning');
@@ -949,7 +1049,7 @@ var staticRenderFns = []
949
1049
  // 设置超时处理
950
1050
  this.warningTimer = setTimeout(() => {
951
1051
  this.handleTimeout();
952
- }, 1 * time * 1000);
1052
+ }, time);
953
1053
  },
954
1054
 
955
1055
  // 处理超时
@@ -1019,6 +1119,9 @@ var staticRenderFns = []
1019
1119
  return;
1020
1120
  }
1021
1121
 
1122
+ // 重置重连尝试次数
1123
+ this.reconnectAttempts = 0;
1124
+
1022
1125
  if (this.socket) {
1023
1126
  this.socket.close();
1024
1127
  }
@@ -1029,8 +1132,8 @@ var staticRenderFns = []
1029
1132
 
1030
1133
  // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
1031
1134
  /* harmony default export */ var components_UserBehaviorMonitorvue_type_script_lang_js = (UserBehaviorMonitorvue_type_script_lang_js);
1032
- // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=4f34cec0&prod&lang=css
1033
- var UserBehaviorMonitorvue_type_style_index_0_id_4f34cec0_prod_lang_css = __webpack_require__("3505");
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");
1034
1137
 
1035
1138
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
1036
1139
  /* globals __VUE_SSR_CONTEXT__ */
@@ -1178,5 +1281,4 @@ if (typeof window !== 'undefined' && window.Vue) {
1178
1281
 
1179
1282
  /***/ })
1180
1283
 
1181
- /******/ });
1182
- //# sourceMappingURL=user-behavior-monitor.common.js.map
1284
+ /******/ });
@@ -96,6 +96,22 @@ 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
+
99
115
  /***/ "2350":
100
116
  /***/ (function(module, exports) {
101
117
 
@@ -177,17 +193,6 @@ function toComment(sourceMap) {
177
193
  }
178
194
 
179
195
 
180
- /***/ }),
181
-
182
- /***/ "3505":
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_4f34cec0_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("f079");
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_4f34cec0_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_4f34cec0_prod_lang_css__WEBPACK_IMPORTED_MODULE_0__);
188
- /* unused harmony reexport * */
189
-
190
-
191
196
  /***/ }),
192
197
 
193
198
  /***/ "499e":
@@ -456,7 +461,7 @@ function applyToTag (styleElement, obj) {
456
461
 
457
462
  /***/ }),
458
463
 
459
- /***/ "a042":
464
+ /***/ "d167":
460
465
  /***/ (function(module, exports, __webpack_require__) {
461
466
 
462
467
  exports = module.exports = __webpack_require__("2350")(false);
@@ -471,19 +476,14 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
471
476
 
472
477
  /***/ }),
473
478
 
474
- /***/ "f079":
475
- /***/ (function(module, exports, __webpack_require__) {
479
+ /***/ "d1a8":
480
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
476
481
 
477
- // style-loader: Adds some css to the DOM by adding a <style> tag
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 * */
478
486
 
479
- // load the styles
480
- var content = __webpack_require__("a042");
481
- if(content.__esModule) content = content.default;
482
- if(typeof content === 'string') content = [[module.i, content, '']];
483
- if(content.locals) module.exports = content.locals;
484
- // add the styles to the DOM
485
- var add = __webpack_require__("499e").default
486
- var update = add("1c569d63", content, true, {"sourceMap":false,"shadowMode":false});
487
487
 
488
488
  /***/ }),
489
489
 
@@ -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=4f34cec0
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
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=4f34cec0
520
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=0335f60c
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
  //
@@ -569,7 +569,11 @@ var staticRenderFns = []
569
569
  lastActivityTime: null,
570
570
  isMonitoring: false,
571
571
  currentTimeoutMinutes: 10,
572
- currentWarningMinutes: 1
572
+ currentWarningMinutes: 1,
573
+ reconnectAttempts: 0,
574
+ maxReconnectAttempts: 3,
575
+ reconnectDelay: 3000,
576
+ isLocalDevelopment: this.checkIfLocalDevelopment()
573
577
  };
574
578
  },
575
579
  mounted() {
@@ -619,6 +623,20 @@ var staticRenderFns = []
619
623
 
620
624
  return false;
621
625
  },
626
+
627
+ // 检查是否为本地开发环境
628
+ checkIfLocalDevelopment() {
629
+ if (typeof window !== 'undefined') {
630
+ const hostname = window.location.hostname;
631
+ return hostname === 'localhost' ||
632
+ hostname === '127.0.0.1' ||
633
+ hostname === '0.0.0.0' ||
634
+ /^192\.168\./.test(hostname) || // 局域网IP
635
+ /^10\./.test(hostname) || // 局域网IP
636
+ /^172\.(1[6-9]|2[0-9]|3[01])\./.test(hostname); // 局域网IP
637
+ }
638
+ return false;
639
+ },
622
640
 
623
641
  updateTimeoutSettings(timeoutMinutes, warningMinutes) {
624
642
  if (timeoutMinutes !== undefined) {
@@ -651,6 +669,7 @@ var staticRenderFns = []
651
669
 
652
670
  this.isMonitoring = true;
653
671
  this.lastActivityTime = Date.now();
672
+ this.reconnectAttempts = 0; // 重置重连尝试次数
654
673
 
655
674
  // 初始化WebSocket连接
656
675
  this.initWebSocket();
@@ -705,6 +724,8 @@ var staticRenderFns = []
705
724
  console.log('WebSocket连接已建立');
706
725
  this.sendUserBehavior();
707
726
  this.$emit('websocket-open');
727
+ // 连接成功时重置重连尝试次数
728
+ this.reconnectAttempts = 0;
708
729
  };
709
730
 
710
731
  // 设置接收消息回调
@@ -723,18 +744,98 @@ var staticRenderFns = []
723
744
  this.socket.onclose = (event) => {
724
745
  console.log('WebSocket连接已断开:', event.reason);
725
746
  this.$emit('websocket-close');
747
+
748
+ // 如果不是在登录页面且监控仍在运行,尝试重连
749
+ if (this.shouldAttemptReconnect()) {
750
+ this.attemptReconnect();
751
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
752
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
753
+ if (!this.isLocalDevelopment) {
754
+ this.handleReconnectFailure();
755
+ }
756
+ }
726
757
  };
727
758
 
728
759
  // 设置连接错误回调
729
760
  this.socket.onerror = (error) => {
730
761
  console.error('WebSocket错误:', error);
731
762
  this.$emit('websocket-error', error);
763
+
764
+ // 如果不是在登录页面且监控仍在运行,尝试重连
765
+ if (this.shouldAttemptReconnect()) {
766
+ this.attemptReconnect();
767
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
768
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
769
+ if (!this.isLocalDevelopment) {
770
+ this.handleReconnectFailure();
771
+ }
772
+ }
732
773
  };
733
774
 
734
775
  } catch (error) {
735
776
  console.error('WebSocket初始化失败:', error);
736
777
  this.$emit('websocket-error', error);
778
+
779
+ // 初始化失败时也可以尝试重连(如果不是在登录页面)
780
+ if (this.shouldAttemptReconnect()) {
781
+ this.attemptReconnect();
782
+ } else if (!this.isLoginRoute() && this.isMonitoring) {
783
+ // 如果不应该重连但仍在监控状态,根据环境决定是否跳转
784
+ if (!this.isLocalDevelopment) {
785
+ this.handleReconnectFailure();
786
+ }
787
+ }
788
+ }
789
+ },
790
+
791
+ // 判断是否应该尝试重连
792
+ shouldAttemptReconnect() {
793
+ return this.isMonitoring &&
794
+ !this.isLoginRoute() &&
795
+ this.reconnectAttempts < this.maxReconnectAttempts;
796
+ },
797
+
798
+ // 添加重连方法
799
+ attemptReconnect() {
800
+ // 再次检查是否为登录页面
801
+ if (this.isLoginRoute()) {
802
+ console.log('当前在登录页面,取消重连');
803
+ return;
804
+ }
805
+
806
+ this.reconnectAttempts++;
807
+ console.log(`尝试第${this.reconnectAttempts}次重连...`);
808
+
809
+ // 如果是本地开发环境且重连次数已达到最大值,则不跳转登录页
810
+ if (this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
811
+ console.log('本地开发环境,重连失败但不跳转到登录页');
812
+ this.$emit('websocket-reconnect-failed');
813
+ return;
737
814
  }
815
+
816
+ // 如果是线上环境且重连次数已达到最大值,则跳转到登录页
817
+ if (!this.isLocalDevelopment && this.reconnectAttempts >= this.maxReconnectAttempts) {
818
+ console.log('线上环境,重连失败,跳转到登录页');
819
+ this.handleReconnectFailure();
820
+ return;
821
+ }
822
+
823
+ setTimeout(() => {
824
+ this.initWebSocket();
825
+ }, this.reconnectDelay);
826
+ },
827
+
828
+ // 处理重连失败
829
+ handleReconnectFailure() {
830
+ // 清空缓存
831
+ localStorage.clear();
832
+ sessionStorage.clear();
833
+
834
+ // 跳转到登录页
835
+ window.location.href = '/login';
836
+
837
+ // 触发登出事件
838
+ this.$emit('logout');
738
839
  },
739
840
 
740
841
  // 处理活动状态信息
@@ -784,8 +885,6 @@ var staticRenderFns = []
784
885
 
785
886
  // 发送用户行为数据到后端
786
887
  sendUserBehavior(data) {
787
- console.log('用户行为监测:')
788
- if (this.warningTimer) clearTimeout(this.warningTimer);
789
888
  if (this.socket && this.socket.readyState === WebSocket.OPEN) {
790
889
  const message = {
791
890
  "type": "HEARTBEAT",
@@ -913,6 +1012,7 @@ var staticRenderFns = []
913
1012
  resetTimer() {
914
1013
  this.lastActivityTime = Date.now();
915
1014
  this.showWarning = false;
1015
+ this.reconnectAttempts = 0; // 重置重连尝试次数
916
1016
 
917
1017
  // 清除警告定时器
918
1018
  if (this.warningTimer) {
@@ -950,7 +1050,7 @@ var staticRenderFns = []
950
1050
 
951
1051
  // 显示超时警告
952
1052
  showWarningWarning(timeoutMinutes) {
953
- let time=timeoutMinutes||50;
1053
+ let time=timeoutMinutes||50000;
954
1054
  console.log('Setting showWarning to true');
955
1055
  this.showWarning = true;
956
1056
  this.$emit('timeout-warning');
@@ -958,7 +1058,7 @@ var staticRenderFns = []
958
1058
  // 设置超时处理
959
1059
  this.warningTimer = setTimeout(() => {
960
1060
  this.handleTimeout();
961
- }, 1 * time * 1000);
1061
+ }, time);
962
1062
  },
963
1063
 
964
1064
  // 处理超时
@@ -1028,6 +1128,9 @@ var staticRenderFns = []
1028
1128
  return;
1029
1129
  }
1030
1130
 
1131
+ // 重置重连尝试次数
1132
+ this.reconnectAttempts = 0;
1133
+
1031
1134
  if (this.socket) {
1032
1135
  this.socket.close();
1033
1136
  }
@@ -1038,8 +1141,8 @@ var staticRenderFns = []
1038
1141
 
1039
1142
  // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
1040
1143
  /* harmony default export */ var components_UserBehaviorMonitorvue_type_script_lang_js = (UserBehaviorMonitorvue_type_script_lang_js);
1041
- // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=4f34cec0&prod&lang=css
1042
- var UserBehaviorMonitorvue_type_style_index_0_id_4f34cec0_prod_lang_css = __webpack_require__("3505");
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");
1043
1146
 
1044
1147
  // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
1045
1148
  /* globals __VUE_SSR_CONTEXT__ */
@@ -1188,5 +1291,4 @@ if (typeof window !== 'undefined' && window.Vue) {
1188
1291
  /***/ })
1189
1292
 
1190
1293
  /******/ });
1191
- });
1192
- //# sourceMappingURL=user-behavior-monitor.umd.js.map
1294
+ });