user-behavior-monitor 2.0.0 → 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.
- package/dist/user-behavior-monitor.common.js +145 -40
- package/dist/user-behavior-monitor.umd.js +145 -40
- package/dist/user-behavior-monitor.umd.min.js +1 -2
- package/package.json +1 -1
- package/src/components/UserBehaviorMonitor.vue +120 -14
- package/src/components/UserBehaviorMonitor2.vue +259 -96
- package/dist/user-behavior-monitor.common.js.map +0 -1
- package/dist/user-behavior-monitor.umd.js.map +0 -1
- package/dist/user-behavior-monitor.umd.min.js.map +0 -1
|
@@ -170,12 +170,12 @@ function toComment(sourceMap) {
|
|
|
170
170
|
|
|
171
171
|
/***/ }),
|
|
172
172
|
|
|
173
|
-
/***/ "
|
|
173
|
+
/***/ "2cd8":
|
|
174
174
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
175
175
|
|
|
176
176
|
"use strict";
|
|
177
|
-
/* harmony import */ var
|
|
178
|
-
/* harmony import */ var
|
|
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
179
|
/* unused harmony reexport * */
|
|
180
180
|
|
|
181
181
|
|
|
@@ -447,7 +447,23 @@ function applyToTag (styleElement, obj) {
|
|
|
447
447
|
|
|
448
448
|
/***/ }),
|
|
449
449
|
|
|
450
|
-
/***/ "
|
|
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":
|
|
451
467
|
/***/ (function(module, exports, __webpack_require__) {
|
|
452
468
|
|
|
453
469
|
exports = module.exports = __webpack_require__("2350")(false);
|
|
@@ -460,22 +476,6 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
|
|
|
460
476
|
// exports
|
|
461
477
|
|
|
462
478
|
|
|
463
|
-
/***/ }),
|
|
464
|
-
|
|
465
|
-
/***/ "f079":
|
|
466
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
467
|
-
|
|
468
|
-
// style-loader: Adds some css to the DOM by adding a <style> tag
|
|
469
|
-
|
|
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
|
-
|
|
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=
|
|
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=
|
|
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
|
//
|
|
@@ -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();
|
|
@@ -693,39 +712,122 @@ var staticRenderFns = []
|
|
|
693
712
|
|
|
694
713
|
// 设置连接成功回调
|
|
695
714
|
this.socket.onopen = () => {
|
|
696
|
-
console.log('WebSocket连接已建立');
|
|
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
|
// 设置接收消息回调
|
|
702
723
|
this.socket.onmessage = (event) => {
|
|
703
724
|
try {
|
|
704
725
|
const data = JSON.parse(event.data);
|
|
705
|
-
console.log('收到用户活动状态消息:', data);
|
|
726
|
+
// console.log('收到用户活动状态消息:', data);
|
|
706
727
|
this.handleActivityStatus(data);
|
|
707
728
|
this.$emit('websocket-message', data);
|
|
708
729
|
} catch (e) {
|
|
709
|
-
console.error('解析WebSocket消息失败:', e);
|
|
730
|
+
// console.error('解析WebSocket消息失败:', e);
|
|
710
731
|
}
|
|
711
732
|
};
|
|
712
733
|
|
|
713
734
|
// 设置连接关闭回调
|
|
714
735
|
this.socket.onclose = (event) => {
|
|
715
|
-
console.log('WebSocket连接已断开:', event.reason);
|
|
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
|
-
console.error('WebSocket错误:', error);
|
|
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
|
-
console.error('WebSocket初始化失败:', error);
|
|
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;
|
|
728
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;
|
|
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
|
+
|
|
827
|
+
location.reload();
|
|
828
|
+
|
|
829
|
+
// 触发登出事件
|
|
830
|
+
this.$emit('logout');
|
|
729
831
|
},
|
|
730
832
|
|
|
731
833
|
// 处理活动状态信息
|
|
@@ -767,7 +869,9 @@ var staticRenderFns = []
|
|
|
767
869
|
//this.$router.push('/login');
|
|
768
870
|
|
|
769
871
|
// 或者使用window.location
|
|
770
|
-
|
|
872
|
+
|
|
873
|
+
location.reload();
|
|
874
|
+
// window.location.href = '/login';
|
|
771
875
|
|
|
772
876
|
// 触发登出事件
|
|
773
877
|
this.$emit('logout');
|
|
@@ -775,14 +879,12 @@ var staticRenderFns = []
|
|
|
775
879
|
|
|
776
880
|
// 发送用户行为数据到后端
|
|
777
881
|
sendUserBehavior(data) {
|
|
778
|
-
console.log('用户行为监测:')
|
|
779
|
-
if (this.warningTimer) clearTimeout(this.warningTimer);
|
|
780
882
|
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
781
883
|
const message = {
|
|
782
884
|
"type": "HEARTBEAT",
|
|
783
885
|
"message": "心跳",
|
|
784
886
|
};
|
|
785
|
-
console.log('用户行为监测:', JSON.stringify(message));
|
|
887
|
+
// console.log('用户行为监测:', JSON.stringify(message));
|
|
786
888
|
this.socket.send(JSON.stringify(message));
|
|
787
889
|
}
|
|
788
890
|
},
|
|
@@ -904,6 +1006,7 @@ var staticRenderFns = []
|
|
|
904
1006
|
resetTimer() {
|
|
905
1007
|
this.lastActivityTime = Date.now();
|
|
906
1008
|
this.showWarning = false;
|
|
1009
|
+
this.reconnectAttempts = 0; // 重置重连尝试次数
|
|
907
1010
|
|
|
908
1011
|
// 清除警告定时器
|
|
909
1012
|
if (this.warningTimer) {
|
|
@@ -941,15 +1044,15 @@ var staticRenderFns = []
|
|
|
941
1044
|
|
|
942
1045
|
// 显示超时警告
|
|
943
1046
|
showWarningWarning(timeoutMinutes) {
|
|
944
|
-
let time=timeoutMinutes||
|
|
945
|
-
console.log('Setting showWarning to true');
|
|
1047
|
+
let time=timeoutMinutes||50000;
|
|
1048
|
+
// console.log('Setting showWarning to true');
|
|
946
1049
|
this.showWarning = true;
|
|
947
1050
|
this.$emit('timeout-warning');
|
|
948
1051
|
if (this.warningTimer) clearTimeout(this.warningTimer);
|
|
949
1052
|
// 设置超时处理
|
|
950
1053
|
this.warningTimer = setTimeout(() => {
|
|
951
1054
|
this.handleTimeout();
|
|
952
|
-
},
|
|
1055
|
+
}, time);
|
|
953
1056
|
},
|
|
954
1057
|
|
|
955
1058
|
// 处理超时
|
|
@@ -1019,6 +1122,9 @@ var staticRenderFns = []
|
|
|
1019
1122
|
return;
|
|
1020
1123
|
}
|
|
1021
1124
|
|
|
1125
|
+
// 重置重连尝试次数
|
|
1126
|
+
this.reconnectAttempts = 0;
|
|
1127
|
+
|
|
1022
1128
|
if (this.socket) {
|
|
1023
1129
|
this.socket.close();
|
|
1024
1130
|
}
|
|
@@ -1029,8 +1135,8 @@ var staticRenderFns = []
|
|
|
1029
1135
|
|
|
1030
1136
|
// CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
|
|
1031
1137
|
/* 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=
|
|
1033
|
-
var
|
|
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");
|
|
1034
1140
|
|
|
1035
1141
|
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
|
|
1036
1142
|
/* globals __VUE_SSR_CONTEXT__ */
|
|
@@ -1178,5 +1284,4 @@ if (typeof window !== 'undefined' && window.Vue) {
|
|
|
1178
1284
|
|
|
1179
1285
|
/***/ })
|
|
1180
1286
|
|
|
1181
|
-
/******/ });
|
|
1182
|
-
//# sourceMappingURL=user-behavior-monitor.common.js.map
|
|
1287
|
+
/******/ });
|
|
@@ -179,12 +179,12 @@ function toComment(sourceMap) {
|
|
|
179
179
|
|
|
180
180
|
/***/ }),
|
|
181
181
|
|
|
182
|
-
/***/ "
|
|
182
|
+
/***/ "2cd8":
|
|
183
183
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
184
184
|
|
|
185
185
|
"use strict";
|
|
186
|
-
/* harmony import */ var
|
|
187
|
-
/* harmony import */ var
|
|
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
188
|
/* unused harmony reexport * */
|
|
189
189
|
|
|
190
190
|
|
|
@@ -456,7 +456,23 @@ function applyToTag (styleElement, obj) {
|
|
|
456
456
|
|
|
457
457
|
/***/ }),
|
|
458
458
|
|
|
459
|
-
/***/ "
|
|
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":
|
|
460
476
|
/***/ (function(module, exports, __webpack_require__) {
|
|
461
477
|
|
|
462
478
|
exports = module.exports = __webpack_require__("2350")(false);
|
|
@@ -469,22 +485,6 @@ exports.push([module.i, ".behavior-warning-dialog.el-dialog.el-dialog--center{te
|
|
|
469
485
|
// exports
|
|
470
486
|
|
|
471
487
|
|
|
472
|
-
/***/ }),
|
|
473
|
-
|
|
474
|
-
/***/ "f079":
|
|
475
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
476
|
-
|
|
477
|
-
// style-loader: Adds some css to the DOM by adding a <style> tag
|
|
478
|
-
|
|
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
|
-
|
|
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=
|
|
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=
|
|
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
|
//
|
|
@@ -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();
|
|
@@ -702,39 +721,122 @@ var staticRenderFns = []
|
|
|
702
721
|
|
|
703
722
|
// 设置连接成功回调
|
|
704
723
|
this.socket.onopen = () => {
|
|
705
|
-
console.log('WebSocket连接已建立');
|
|
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
|
// 设置接收消息回调
|
|
711
732
|
this.socket.onmessage = (event) => {
|
|
712
733
|
try {
|
|
713
734
|
const data = JSON.parse(event.data);
|
|
714
|
-
console.log('收到用户活动状态消息:', data);
|
|
735
|
+
// console.log('收到用户活动状态消息:', data);
|
|
715
736
|
this.handleActivityStatus(data);
|
|
716
737
|
this.$emit('websocket-message', data);
|
|
717
738
|
} catch (e) {
|
|
718
|
-
console.error('解析WebSocket消息失败:', e);
|
|
739
|
+
// console.error('解析WebSocket消息失败:', e);
|
|
719
740
|
}
|
|
720
741
|
};
|
|
721
742
|
|
|
722
743
|
// 设置连接关闭回调
|
|
723
744
|
this.socket.onclose = (event) => {
|
|
724
|
-
console.log('WebSocket连接已断开:', event.reason);
|
|
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
|
-
console.error('WebSocket错误:', error);
|
|
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
|
-
console.error('WebSocket初始化失败:', error);
|
|
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;
|
|
737
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;
|
|
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
|
+
|
|
836
|
+
location.reload();
|
|
837
|
+
|
|
838
|
+
// 触发登出事件
|
|
839
|
+
this.$emit('logout');
|
|
738
840
|
},
|
|
739
841
|
|
|
740
842
|
// 处理活动状态信息
|
|
@@ -776,7 +878,9 @@ var staticRenderFns = []
|
|
|
776
878
|
//this.$router.push('/login');
|
|
777
879
|
|
|
778
880
|
// 或者使用window.location
|
|
779
|
-
|
|
881
|
+
|
|
882
|
+
location.reload();
|
|
883
|
+
// window.location.href = '/login';
|
|
780
884
|
|
|
781
885
|
// 触发登出事件
|
|
782
886
|
this.$emit('logout');
|
|
@@ -784,14 +888,12 @@ var staticRenderFns = []
|
|
|
784
888
|
|
|
785
889
|
// 发送用户行为数据到后端
|
|
786
890
|
sendUserBehavior(data) {
|
|
787
|
-
console.log('用户行为监测:')
|
|
788
|
-
if (this.warningTimer) clearTimeout(this.warningTimer);
|
|
789
891
|
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
790
892
|
const message = {
|
|
791
893
|
"type": "HEARTBEAT",
|
|
792
894
|
"message": "心跳",
|
|
793
895
|
};
|
|
794
|
-
console.log('用户行为监测:', JSON.stringify(message));
|
|
896
|
+
// console.log('用户行为监测:', JSON.stringify(message));
|
|
795
897
|
this.socket.send(JSON.stringify(message));
|
|
796
898
|
}
|
|
797
899
|
},
|
|
@@ -913,6 +1015,7 @@ var staticRenderFns = []
|
|
|
913
1015
|
resetTimer() {
|
|
914
1016
|
this.lastActivityTime = Date.now();
|
|
915
1017
|
this.showWarning = false;
|
|
1018
|
+
this.reconnectAttempts = 0; // 重置重连尝试次数
|
|
916
1019
|
|
|
917
1020
|
// 清除警告定时器
|
|
918
1021
|
if (this.warningTimer) {
|
|
@@ -950,15 +1053,15 @@ var staticRenderFns = []
|
|
|
950
1053
|
|
|
951
1054
|
// 显示超时警告
|
|
952
1055
|
showWarningWarning(timeoutMinutes) {
|
|
953
|
-
let time=timeoutMinutes||
|
|
954
|
-
console.log('Setting showWarning to true');
|
|
1056
|
+
let time=timeoutMinutes||50000;
|
|
1057
|
+
// console.log('Setting showWarning to true');
|
|
955
1058
|
this.showWarning = true;
|
|
956
1059
|
this.$emit('timeout-warning');
|
|
957
1060
|
if (this.warningTimer) clearTimeout(this.warningTimer);
|
|
958
1061
|
// 设置超时处理
|
|
959
1062
|
this.warningTimer = setTimeout(() => {
|
|
960
1063
|
this.handleTimeout();
|
|
961
|
-
},
|
|
1064
|
+
}, time);
|
|
962
1065
|
},
|
|
963
1066
|
|
|
964
1067
|
// 处理超时
|
|
@@ -1028,6 +1131,9 @@ var staticRenderFns = []
|
|
|
1028
1131
|
return;
|
|
1029
1132
|
}
|
|
1030
1133
|
|
|
1134
|
+
// 重置重连尝试次数
|
|
1135
|
+
this.reconnectAttempts = 0;
|
|
1136
|
+
|
|
1031
1137
|
if (this.socket) {
|
|
1032
1138
|
this.socket.close();
|
|
1033
1139
|
}
|
|
@@ -1038,8 +1144,8 @@ var staticRenderFns = []
|
|
|
1038
1144
|
|
|
1039
1145
|
// CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
|
|
1040
1146
|
/* 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=
|
|
1042
|
-
var
|
|
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");
|
|
1043
1149
|
|
|
1044
1150
|
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
|
|
1045
1151
|
/* globals __VUE_SSR_CONTEXT__ */
|
|
@@ -1188,5 +1294,4 @@ if (typeof window !== 'undefined' && window.Vue) {
|
|
|
1188
1294
|
/***/ })
|
|
1189
1295
|
|
|
1190
1296
|
/******/ });
|
|
1191
|
-
});
|
|
1192
|
-
//# sourceMappingURL=user-behavior-monitor.umd.js.map
|
|
1297
|
+
});
|