user-behavior-monitor 1.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.
@@ -0,0 +1,991 @@
1
+ module.exports =
2
+ /******/ (function(modules) { // webpackBootstrap
3
+ /******/ // The module cache
4
+ /******/ var installedModules = {};
5
+ /******/
6
+ /******/ // The require function
7
+ /******/ function __webpack_require__(moduleId) {
8
+ /******/
9
+ /******/ // Check if module is in cache
10
+ /******/ if(installedModules[moduleId]) {
11
+ /******/ return installedModules[moduleId].exports;
12
+ /******/ }
13
+ /******/ // Create a new module (and put it into the cache)
14
+ /******/ var module = installedModules[moduleId] = {
15
+ /******/ i: moduleId,
16
+ /******/ l: false,
17
+ /******/ exports: {}
18
+ /******/ };
19
+ /******/
20
+ /******/ // Execute the module function
21
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
+ /******/
23
+ /******/ // Flag the module as loaded
24
+ /******/ module.l = true;
25
+ /******/
26
+ /******/ // Return the exports of the module
27
+ /******/ return module.exports;
28
+ /******/ }
29
+ /******/
30
+ /******/
31
+ /******/ // expose the modules object (__webpack_modules__)
32
+ /******/ __webpack_require__.m = modules;
33
+ /******/
34
+ /******/ // expose the module cache
35
+ /******/ __webpack_require__.c = installedModules;
36
+ /******/
37
+ /******/ // define getter function for harmony exports
38
+ /******/ __webpack_require__.d = function(exports, name, getter) {
39
+ /******/ if(!__webpack_require__.o(exports, name)) {
40
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
+ /******/ }
42
+ /******/ };
43
+ /******/
44
+ /******/ // define __esModule on exports
45
+ /******/ __webpack_require__.r = function(exports) {
46
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ /******/ }
49
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
+ /******/ };
51
+ /******/
52
+ /******/ // create a fake namespace object
53
+ /******/ // mode & 1: value is a module id, require it
54
+ /******/ // mode & 2: merge all properties of value into the ns
55
+ /******/ // mode & 4: return value when already ns object
56
+ /******/ // mode & 8|1: behave like require
57
+ /******/ __webpack_require__.t = function(value, mode) {
58
+ /******/ if(mode & 1) value = __webpack_require__(value);
59
+ /******/ if(mode & 8) return value;
60
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
+ /******/ var ns = Object.create(null);
62
+ /******/ __webpack_require__.r(ns);
63
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
+ /******/ return ns;
66
+ /******/ };
67
+ /******/
68
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
69
+ /******/ __webpack_require__.n = function(module) {
70
+ /******/ var getter = module && module.__esModule ?
71
+ /******/ function getDefault() { return module['default']; } :
72
+ /******/ function getModuleExports() { return module; };
73
+ /******/ __webpack_require__.d(getter, 'a', getter);
74
+ /******/ return getter;
75
+ /******/ };
76
+ /******/
77
+ /******/ // Object.prototype.hasOwnProperty.call
78
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
+ /******/
80
+ /******/ // __webpack_public_path__
81
+ /******/ __webpack_require__.p = "";
82
+ /******/
83
+ /******/
84
+ /******/ // Load entry module and return exports
85
+ /******/ return __webpack_require__(__webpack_require__.s = "fb15");
86
+ /******/ })
87
+ /************************************************************************/
88
+ /******/ ({
89
+
90
+ /***/ "2350":
91
+ /***/ (function(module, exports) {
92
+
93
+ /*
94
+ MIT License http://www.opensource.org/licenses/mit-license.php
95
+ Author Tobias Koppers @sokra
96
+ */
97
+ // css base code, injected by the css-loader
98
+ module.exports = function(useSourceMap) {
99
+ var list = [];
100
+
101
+ // return the list of modules as css string
102
+ list.toString = function toString() {
103
+ return this.map(function (item) {
104
+ var content = cssWithMappingToString(item, useSourceMap);
105
+ if(item[2]) {
106
+ return "@media " + item[2] + "{" + content + "}";
107
+ } else {
108
+ return content;
109
+ }
110
+ }).join("");
111
+ };
112
+
113
+ // import a list of modules into the list
114
+ list.i = function(modules, mediaQuery) {
115
+ if(typeof modules === "string")
116
+ modules = [[null, modules, ""]];
117
+ var alreadyImportedModules = {};
118
+ for(var i = 0; i < this.length; i++) {
119
+ var id = this[i][0];
120
+ if(typeof id === "number")
121
+ alreadyImportedModules[id] = true;
122
+ }
123
+ for(i = 0; i < modules.length; i++) {
124
+ var item = modules[i];
125
+ // skip already imported module
126
+ // this implementation is not 100% perfect for weird media query combinations
127
+ // when a module is imported multiple times with different media queries.
128
+ // I hope this will never occur (Hey this way we have smaller bundles)
129
+ if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
130
+ if(mediaQuery && !item[2]) {
131
+ item[2] = mediaQuery;
132
+ } else if(mediaQuery) {
133
+ item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
134
+ }
135
+ list.push(item);
136
+ }
137
+ }
138
+ };
139
+ return list;
140
+ };
141
+
142
+ function cssWithMappingToString(item, useSourceMap) {
143
+ var content = item[1] || '';
144
+ var cssMapping = item[3];
145
+ if (!cssMapping) {
146
+ return content;
147
+ }
148
+
149
+ if (useSourceMap && typeof btoa === 'function') {
150
+ var sourceMapping = toComment(cssMapping);
151
+ var sourceURLs = cssMapping.sources.map(function (source) {
152
+ return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
153
+ });
154
+
155
+ return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
156
+ }
157
+
158
+ return [content].join('\n');
159
+ }
160
+
161
+ // Adapted from convert-source-map (MIT)
162
+ function toComment(sourceMap) {
163
+ // eslint-disable-next-line no-undef
164
+ var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
165
+ var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
166
+
167
+ return '/*# ' + data + ' */';
168
+ }
169
+
170
+
171
+ /***/ }),
172
+
173
+ /***/ "499e":
174
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
175
+
176
+ "use strict";
177
+ // ESM COMPAT FLAG
178
+ __webpack_require__.r(__webpack_exports__);
179
+
180
+ // EXPORTS
181
+ __webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ addStylesClient; });
182
+
183
+ // CONCATENATED MODULE: ./node_modules/vue-style-loader/lib/listToStyles.js
184
+ /**
185
+ * Translates the list format produced by css-loader into something
186
+ * easier to manipulate.
187
+ */
188
+ function listToStyles (parentId, list) {
189
+ var styles = []
190
+ var newStyles = {}
191
+ for (var i = 0; i < list.length; i++) {
192
+ var item = list[i]
193
+ var id = item[0]
194
+ var css = item[1]
195
+ var media = item[2]
196
+ var sourceMap = item[3]
197
+ var part = {
198
+ id: parentId + ':' + i,
199
+ css: css,
200
+ media: media,
201
+ sourceMap: sourceMap
202
+ }
203
+ if (!newStyles[id]) {
204
+ styles.push(newStyles[id] = { id: id, parts: [part] })
205
+ } else {
206
+ newStyles[id].parts.push(part)
207
+ }
208
+ }
209
+ return styles
210
+ }
211
+
212
+ // CONCATENATED MODULE: ./node_modules/vue-style-loader/lib/addStylesClient.js
213
+ /*
214
+ MIT License http://www.opensource.org/licenses/mit-license.php
215
+ Author Tobias Koppers @sokra
216
+ Modified by Evan You @yyx990803
217
+ */
218
+
219
+
220
+
221
+ var hasDocument = typeof document !== 'undefined'
222
+
223
+ if (typeof DEBUG !== 'undefined' && DEBUG) {
224
+ if (!hasDocument) {
225
+ throw new Error(
226
+ 'vue-style-loader cannot be used in a non-browser environment. ' +
227
+ "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment."
228
+ ) }
229
+ }
230
+
231
+ /*
232
+ type StyleObject = {
233
+ id: number;
234
+ parts: Array<StyleObjectPart>
235
+ }
236
+
237
+ type StyleObjectPart = {
238
+ css: string;
239
+ media: string;
240
+ sourceMap: ?string
241
+ }
242
+ */
243
+
244
+ var stylesInDom = {/*
245
+ [id: number]: {
246
+ id: number,
247
+ refs: number,
248
+ parts: Array<(obj?: StyleObjectPart) => void>
249
+ }
250
+ */}
251
+
252
+ var head = hasDocument && (document.head || document.getElementsByTagName('head')[0])
253
+ var singletonElement = null
254
+ var singletonCounter = 0
255
+ var isProduction = false
256
+ var noop = function () {}
257
+ var options = null
258
+ var ssrIdKey = 'data-vue-ssr-id'
259
+
260
+ // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
261
+ // tags it will allow on a page
262
+ var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase())
263
+
264
+ function addStylesClient (parentId, list, _isProduction, _options) {
265
+ isProduction = _isProduction
266
+
267
+ options = _options || {}
268
+
269
+ var styles = listToStyles(parentId, list)
270
+ addStylesToDom(styles)
271
+
272
+ return function update (newList) {
273
+ var mayRemove = []
274
+ for (var i = 0; i < styles.length; i++) {
275
+ var item = styles[i]
276
+ var domStyle = stylesInDom[item.id]
277
+ domStyle.refs--
278
+ mayRemove.push(domStyle)
279
+ }
280
+ if (newList) {
281
+ styles = listToStyles(parentId, newList)
282
+ addStylesToDom(styles)
283
+ } else {
284
+ styles = []
285
+ }
286
+ for (var i = 0; i < mayRemove.length; i++) {
287
+ var domStyle = mayRemove[i]
288
+ if (domStyle.refs === 0) {
289
+ for (var j = 0; j < domStyle.parts.length; j++) {
290
+ domStyle.parts[j]()
291
+ }
292
+ delete stylesInDom[domStyle.id]
293
+ }
294
+ }
295
+ }
296
+ }
297
+
298
+ function addStylesToDom (styles /* Array<StyleObject> */) {
299
+ for (var i = 0; i < styles.length; i++) {
300
+ var item = styles[i]
301
+ var domStyle = stylesInDom[item.id]
302
+ if (domStyle) {
303
+ domStyle.refs++
304
+ for (var j = 0; j < domStyle.parts.length; j++) {
305
+ domStyle.parts[j](item.parts[j])
306
+ }
307
+ for (; j < item.parts.length; j++) {
308
+ domStyle.parts.push(addStyle(item.parts[j]))
309
+ }
310
+ if (domStyle.parts.length > item.parts.length) {
311
+ domStyle.parts.length = item.parts.length
312
+ }
313
+ } else {
314
+ var parts = []
315
+ for (var j = 0; j < item.parts.length; j++) {
316
+ parts.push(addStyle(item.parts[j]))
317
+ }
318
+ stylesInDom[item.id] = { id: item.id, refs: 1, parts: parts }
319
+ }
320
+ }
321
+ }
322
+
323
+ function createStyleElement () {
324
+ var styleElement = document.createElement('style')
325
+ styleElement.type = 'text/css'
326
+ head.appendChild(styleElement)
327
+ return styleElement
328
+ }
329
+
330
+ function addStyle (obj /* StyleObjectPart */) {
331
+ var update, remove
332
+ var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]')
333
+
334
+ if (styleElement) {
335
+ if (isProduction) {
336
+ // has SSR styles and in production mode.
337
+ // simply do nothing.
338
+ return noop
339
+ } else {
340
+ // has SSR styles but in dev mode.
341
+ // for some reason Chrome can't handle source map in server-rendered
342
+ // style tags - source maps in <style> only works if the style tag is
343
+ // created and inserted dynamically. So we remove the server rendered
344
+ // styles and inject new ones.
345
+ styleElement.parentNode.removeChild(styleElement)
346
+ }
347
+ }
348
+
349
+ if (isOldIE) {
350
+ // use singleton mode for IE9.
351
+ var styleIndex = singletonCounter++
352
+ styleElement = singletonElement || (singletonElement = createStyleElement())
353
+ update = applyToSingletonTag.bind(null, styleElement, styleIndex, false)
354
+ remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true)
355
+ } else {
356
+ // use multi-style-tag mode in all other cases
357
+ styleElement = createStyleElement()
358
+ update = applyToTag.bind(null, styleElement)
359
+ remove = function () {
360
+ styleElement.parentNode.removeChild(styleElement)
361
+ }
362
+ }
363
+
364
+ update(obj)
365
+
366
+ return function updateStyle (newObj /* StyleObjectPart */) {
367
+ if (newObj) {
368
+ if (newObj.css === obj.css &&
369
+ newObj.media === obj.media &&
370
+ newObj.sourceMap === obj.sourceMap) {
371
+ return
372
+ }
373
+ update(obj = newObj)
374
+ } else {
375
+ remove()
376
+ }
377
+ }
378
+ }
379
+
380
+ var replaceText = (function () {
381
+ var textStore = []
382
+
383
+ return function (index, replacement) {
384
+ textStore[index] = replacement
385
+ return textStore.filter(Boolean).join('\n')
386
+ }
387
+ })()
388
+
389
+ function applyToSingletonTag (styleElement, index, remove, obj) {
390
+ var css = remove ? '' : obj.css
391
+
392
+ if (styleElement.styleSheet) {
393
+ styleElement.styleSheet.cssText = replaceText(index, css)
394
+ } else {
395
+ var cssNode = document.createTextNode(css)
396
+ var childNodes = styleElement.childNodes
397
+ if (childNodes[index]) styleElement.removeChild(childNodes[index])
398
+ if (childNodes.length) {
399
+ styleElement.insertBefore(cssNode, childNodes[index])
400
+ } else {
401
+ styleElement.appendChild(cssNode)
402
+ }
403
+ }
404
+ }
405
+
406
+ function applyToTag (styleElement, obj) {
407
+ var css = obj.css
408
+ var media = obj.media
409
+ var sourceMap = obj.sourceMap
410
+
411
+ if (media) {
412
+ styleElement.setAttribute('media', media)
413
+ }
414
+ if (options.ssrId) {
415
+ styleElement.setAttribute(ssrIdKey, obj.id)
416
+ }
417
+
418
+ if (sourceMap) {
419
+ // https://developer.chrome.com/devtools/docs/javascript-debugging
420
+ // this makes source maps inside style tags work properly in Chrome
421
+ css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */'
422
+ // http://stackoverflow.com/a/26603875
423
+ css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */'
424
+ }
425
+
426
+ if (styleElement.styleSheet) {
427
+ styleElement.styleSheet.cssText = css
428
+ } else {
429
+ while (styleElement.firstChild) {
430
+ styleElement.removeChild(styleElement.firstChild)
431
+ }
432
+ styleElement.appendChild(document.createTextNode(css))
433
+ }
434
+ }
435
+
436
+
437
+ /***/ }),
438
+
439
+ /***/ "533e":
440
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
441
+
442
+ "use strict";
443
+ /* 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_06a138e4_prod_scoped_true_lang_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("d1b1");
444
+ /* 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_06a138e4_prod_scoped_true_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_06a138e4_prod_scoped_true_lang_css__WEBPACK_IMPORTED_MODULE_0__);
445
+ /* unused harmony reexport * */
446
+
447
+
448
+ /***/ }),
449
+
450
+ /***/ "9cfc":
451
+ /***/ (function(module, exports, __webpack_require__) {
452
+
453
+ exports = module.exports = __webpack_require__("2350")(false);
454
+ // imports
455
+
456
+
457
+ // module
458
+ exports.push([module.i, ".user-behavior-monitor[data-v-06a138e4]{display:none}.behavior-warning-dialog[data-v-06a138e4] .el-dialog__body{text-align:center;font-size:16px;padding:30px 20px}.behavior-warning-dialog[data-v-06a138e4]{z-index:9999!important}", ""]);
459
+
460
+ // exports
461
+
462
+
463
+ /***/ }),
464
+
465
+ /***/ "d1b1":
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__("9cfc");
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("2c53b590", content, true, {"sourceMap":false,"shadowMode":false});
478
+
479
+ /***/ }),
480
+
481
+ /***/ "fb15":
482
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
483
+
484
+ "use strict";
485
+ // ESM COMPAT FLAG
486
+ __webpack_require__.r(__webpack_exports__);
487
+
488
+ // EXPORTS
489
+ __webpack_require__.d(__webpack_exports__, "UserBehaviorMonitor", function() { return /* reexport */ UserBehaviorMonitor; });
490
+
491
+ // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
492
+ // This file is imported into lib/wc client bundles.
493
+
494
+ if (typeof window !== 'undefined') {
495
+ if (false) {}
496
+
497
+ var i
498
+ if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) {
499
+ __webpack_require__.p = i[1] // eslint-disable-line
500
+ }
501
+ }
502
+
503
+ // Indicate to webpack that this file can be concatenated
504
+ /* harmony default export */ var setPublicPath = (null);
505
+
506
+ // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"7caff2c6-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=06a138e4&scoped=true
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:{"visible":_vm.showWarning,"show-close":false,"modal":true,"width":"30%","center":"","custom-class":"behavior-warning-dialog","append-to-body":true,"modal-append-to-body":true,"close-on-click-modal":false,"close-on-press-escape":false},on:{"update:visible":function($event){_vm.showWarning=$event}}},[_c('span',[_vm._v(_vm._s(_vm.warningMessage))])]),_c('button',{staticStyle:{"position":"fixed","top":"10px","right":"10px","z-index":"10000"},on:{"click":_vm.testWarning}},[_vm._v("\n 测试警告\n ")])],1)}
508
+ var staticRenderFns = []
509
+
510
+
511
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=template&id=06a138e4&scoped=true
512
+
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
+ //
515
+ //
516
+ //
517
+ //
518
+ //
519
+ //
520
+ //
521
+ //
522
+ //
523
+ //
524
+ //
525
+ //
526
+ //
527
+ //
528
+ //
529
+ //
530
+ //
531
+ //
532
+ //
533
+ //
534
+ //
535
+ //
536
+ //
537
+ //
538
+ //
539
+
540
+ /* harmony default export */ var UserBehaviorMonitorvue_type_script_lang_js = ({
541
+ name: 'UserBehaviorMonitor',
542
+ props: {
543
+ // WebSocket服务器地址
544
+ websocketUrl: {
545
+ type: String,
546
+ required: true
547
+ },
548
+ // 倒计时时长(分钟)
549
+ timeoutMinutes: {
550
+ type: Number,
551
+ default: 10
552
+ },
553
+ // 警告提前时间(分钟)
554
+ warningMinutes: {
555
+ type: Number,
556
+ default: 1
557
+ }
558
+ },
559
+ data() {
560
+ return {
561
+ mouseMoveThrottled:false,
562
+ websocket: null,
563
+ countdownTimer: null,
564
+ warningTimer: null,
565
+ showWarning: false,
566
+ warningMessage: `您已${this.timeoutMinutes}分钟未操作,将在${this.warningMinutes}分钟后自动退出`,
567
+ lastActivityTime: null,
568
+ isMonitoring: false
569
+ };
570
+ },
571
+ mounted() {
572
+ console.log('开始开始! mounted');
573
+ this.initMonitor();
574
+ },
575
+ beforeDestroy() {
576
+ console.log('开始开始! beforeDestroy');
577
+ this.destroyMonitor();
578
+ },
579
+ methods: {
580
+ testWarning() {
581
+ console.log('Testing warning display');
582
+ this.showWarning = true;
583
+ },
584
+ // 初始化监控
585
+ initMonitor() {
586
+ console.log('Initializing monitor');
587
+ if (this.isMonitoring) return;
588
+
589
+ this.isMonitoring = true;
590
+ this.lastActivityTime = Date.now();
591
+
592
+ // 启动倒计时
593
+ this.startCountdown();
594
+
595
+ // 绑定事件监听器
596
+ this.bindEventListeners();
597
+ },
598
+
599
+ // 销毁监控
600
+ destroyMonitor() {
601
+ this.isMonitoring = false;
602
+
603
+ // 清除定时器
604
+ if (this.countdownTimer) clearInterval(this.countdownTimer);
605
+ if (this.warningTimer) clearTimeout(this.warningTimer);
606
+
607
+ // 解绑事件监听器
608
+ this.unbindEventListeners();
609
+ },
610
+
611
+ // 发送用户行为数据到后端
612
+ sendUserBehavior(data) {
613
+ // 用于测试:在控制台输出用户行为信息
614
+ console.log('用户行为监测:', data);
615
+ },
616
+
617
+ // 绑定事件监听器
618
+ bindEventListeners() {
619
+ console.log('Binding event listeners');
620
+ // 使用箭头函数或bind来保持this上下文
621
+ // 鼠标事件
622
+ document.addEventListener('click', this.handleUserActivity.bind(this), true);
623
+ document.addEventListener('dblclick', this.handleUserActivity.bind(this), true);
624
+ document.addEventListener('mousedown', this.handleUserActivity.bind(this), true);
625
+ document.addEventListener('mouseup', this.handleUserActivity.bind(this), true);
626
+ document.addEventListener('mousemove', this.handleMouseMove.bind(this), true);
627
+ document.addEventListener('mouseover', this.handleUserActivity.bind(this), true);
628
+ document.addEventListener('mouseout', this.handleUserActivity.bind(this), true);
629
+
630
+ // 键盘事件
631
+ document.addEventListener('keydown', this.handleUserActivity.bind(this), true);
632
+ document.addEventListener('keyup', this.handleUserActivity.bind(this), true);
633
+
634
+ // 表单事件
635
+ document.addEventListener('input', this.handleUserActivity.bind(this), true);
636
+ document.addEventListener('change', this.handleUserActivity.bind(this), true);
637
+ document.addEventListener('focus', this.handleUserActivity.bind(this), true);
638
+ document.addEventListener('blur', this.handleUserActivity.bind(this), true);
639
+
640
+ // 滚动事件(防抖处理)
641
+ document.addEventListener('scroll', this.debounce(this.handleUserActivity, 300).bind(this), true);
642
+
643
+ // 窗口事件
644
+ window.addEventListener('resize', this.handleUserActivity.bind(this), true);
645
+ window.addEventListener('beforeunload', this.handleBeforeUnload.bind(this));
646
+ },
647
+
648
+ // 解绑事件监听器
649
+ unbindEventListeners() {
650
+ console.log('Unbinding event listeners');
651
+ // 解绑时也要使用相同的方式
652
+ document.removeEventListener('click', this.handleUserActivity.bind(this), true);
653
+ document.removeEventListener('dblclick', this.handleUserActivity.bind(this), true);
654
+ document.removeEventListener('mousedown', this.handleUserActivity.bind(this), true);
655
+ document.removeEventListener('mouseup', this.handleUserActivity.bind(this), true);
656
+ document.removeEventListener('mousemove', this.handleMouseMove.bind(this), true);
657
+ document.removeEventListener('mouseover', this.handleUserActivity.bind(this), true);
658
+ document.removeEventListener('mouseout', this.handleUserActivity.bind(this), true);
659
+
660
+ document.removeEventListener('keydown', this.handleUserActivity.bind(this), true);
661
+ document.removeEventListener('keyup', this.handleUserActivity.bind(this), true);
662
+
663
+ document.removeEventListener('input', this.handleUserActivity.bind(this), true);
664
+ document.removeEventListener('change', this.handleUserActivity.bind(this), true);
665
+ document.removeEventListener('focus', this.handleUserActivity.bind(this), true);
666
+ document.removeEventListener('blur', this.handleUserActivity.bind(this), true);
667
+
668
+ document.removeEventListener('scroll', this.debounce(this.handleUserActivity, 300).bind(this), true);
669
+
670
+ window.removeEventListener('resize', this.handleUserActivity.bind(this), true);
671
+ window.removeEventListener('beforeunload', this.handleBeforeUnload.bind(this));
672
+ },
673
+
674
+ // 处理用户活动
675
+ handleUserActivity(event) {
676
+ // 过滤掉自动触发的事件
677
+ if (this.isAutomaticEvent(event)) return;
678
+
679
+ this.resetTimer();
680
+
681
+ // 发送用户行为数据
682
+ const behaviorData = {
683
+ eventType: event.type,
684
+ target: event.target.tagName,
685
+ timestamp: Date.now(),
686
+ url: window.location.href
687
+ };
688
+
689
+ // 添加特定事件的额外信息
690
+ if (event.type === 'click') {
691
+ behaviorData.clientX = event.clientX;
692
+ behaviorData.clientY = event.clientY;
693
+ } else if (event.type === 'keydown') {
694
+ behaviorData.key = event.key;
695
+ behaviorData.ctrlKey = event.ctrlKey;
696
+ behaviorData.altKey = event.altKey;
697
+ behaviorData.shiftKey = event.shiftKey;
698
+ }
699
+
700
+ this.sendUserBehavior(behaviorData);
701
+ },
702
+ handleMouseMove(event) {
703
+ if (!this.mouseMoveThrottled) {
704
+ this.handleUserActivity(event);
705
+ this.mouseMoveThrottled = true;
706
+ setTimeout(() => {
707
+ this.mouseMoveThrottled = false;
708
+ }, 500);
709
+ }
710
+ },
711
+
712
+ // 处理鼠标移动(降低频率)
713
+ // handleMouseMove: function() {
714
+ // let isThrottled = false;
715
+ // return (event) => {
716
+ // if (!isThrottled) {
717
+ // this.handleUserActivity(event);
718
+ // isThrottled = true;
719
+ // setTimeout(() => {
720
+ // isThrottled = false;
721
+ // }, 500);
722
+ // }
723
+ // };
724
+ // }(),
725
+
726
+ // 判断是否为自动触发事件
727
+ isAutomaticEvent(event) {
728
+ // 自动刷新等非用户主动触发的事件
729
+ if (event.type === 'scroll' && !this.isUserScrolling) {
730
+ return true;
731
+ }
732
+ return false;
733
+ },
734
+
735
+ // 防抖函数
736
+ debounce(func, wait) {
737
+ let timeout;
738
+ return function executedFunction(...args) {
739
+ const later = () => {
740
+ clearTimeout(timeout);
741
+ func.apply(this, args);
742
+ };
743
+ clearTimeout(timeout);
744
+ timeout = setTimeout(later, wait);
745
+ };
746
+ },
747
+
748
+ // 重置计时器
749
+ resetTimer() {
750
+ console.log('Resetting timer');
751
+ this.lastActivityTime = Date.now();
752
+ this.showWarning = false;
753
+
754
+ // 清除警告定时器
755
+ if (this.warningTimer) {
756
+ clearTimeout(this.warningTimer);
757
+ this.warningTimer = null;
758
+ }
759
+
760
+ // 重新启动倒计时
761
+ this.startCountdown();
762
+
763
+ this.$emit('user-active');
764
+ },
765
+
766
+ // 启动倒计时
767
+ startCountdown() {
768
+ console.log('Starting countdown');
769
+ // 清除现有定时器
770
+ if (this.countdownTimer) clearInterval(this.countdownTimer);
771
+
772
+ // 设置新的倒计时
773
+ this.countdownTimer = setInterval(() => {
774
+ const now = Date.now();
775
+ const elapsedMinutes = (now - this.lastActivityTime) / (1000 * 60);
776
+ console.log('Elapsed minutes:', elapsedMinutes);
777
+
778
+ // 检查是否需要显示警告
779
+ if (elapsedMinutes >= (this.timeoutMinutes - this.warningMinutes) && !this.warningTimer) {
780
+ console.log('Showing warning');
781
+ this.showWarningWarning();
782
+ }
783
+
784
+ // 检查是否超时
785
+ if (elapsedMinutes >= this.timeoutMinutes) {
786
+ console.log('Handling timeout');
787
+ this.handleTimeout();
788
+ }
789
+ }, 1000);
790
+ },
791
+
792
+ // 显示超时警告
793
+ showWarningWarning() {
794
+ console.log('Setting showWarning to true');
795
+ this.showWarning = true;
796
+ this.$emit('timeout-warning');
797
+
798
+ // 设置超时处理
799
+ this.warningTimer = setTimeout(() => {
800
+ this.handleTimeout();
801
+ }, this.warningMinutes * 60 * 1000);
802
+ },
803
+
804
+ // 处理超时
805
+ handleTimeout() {
806
+ console.log('Handling timeout');
807
+ this.showWarning = false;
808
+ this.$emit('timeout');
809
+
810
+ // 执行登出逻辑
811
+ this.logout();
812
+ },
813
+
814
+ // 登出操作
815
+ logout() {
816
+ // 用于测试:在控制台输出登出信息
817
+ console.log('用户超时登出');
818
+
819
+ this.$emit('logout');
820
+
821
+ // 清除定时器
822
+ if (this.countdownTimer) clearInterval(this.countdownTimer);
823
+ if (this.warningTimer) clearTimeout(this.warningTimer);
824
+ },
825
+
826
+ // 处理页面卸载前的操作
827
+ handleBeforeUnload(event) {
828
+ // 用于测试:在控制台输出页面卸载信息
829
+ console.log('页面即将卸载');
830
+ },
831
+
832
+ // 手动重置监控
833
+ reset() {
834
+ this.resetTimer();
835
+ }
836
+ }
837
+ });
838
+
839
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=script&lang=js
840
+ /* harmony default export */ var components_UserBehaviorMonitorvue_type_script_lang_js = (UserBehaviorMonitorvue_type_script_lang_js);
841
+ // EXTERNAL MODULE: ./src/components/UserBehaviorMonitor.vue?vue&type=style&index=0&id=06a138e4&prod&scoped=true&lang=css
842
+ var UserBehaviorMonitorvue_type_style_index_0_id_06a138e4_prod_scoped_true_lang_css = __webpack_require__("533e");
843
+
844
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
845
+ /* globals __VUE_SSR_CONTEXT__ */
846
+
847
+ // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
848
+ // This module is a runtime utility for cleaner component module output and will
849
+ // be included in the final webpack user bundle.
850
+
851
+ function normalizeComponent(
852
+ scriptExports,
853
+ render,
854
+ staticRenderFns,
855
+ functionalTemplate,
856
+ injectStyles,
857
+ scopeId,
858
+ moduleIdentifier /* server only */,
859
+ shadowMode /* vue-cli only */
860
+ ) {
861
+ // Vue.extend constructor export interop
862
+ var options =
863
+ typeof scriptExports === 'function' ? scriptExports.options : scriptExports
864
+
865
+ // render functions
866
+ if (render) {
867
+ options.render = render
868
+ options.staticRenderFns = staticRenderFns
869
+ options._compiled = true
870
+ }
871
+
872
+ // functional template
873
+ if (functionalTemplate) {
874
+ options.functional = true
875
+ }
876
+
877
+ // scopedId
878
+ if (scopeId) {
879
+ options._scopeId = 'data-v-' + scopeId
880
+ }
881
+
882
+ var hook
883
+ if (moduleIdentifier) {
884
+ // server build
885
+ hook = function (context) {
886
+ // 2.3 injection
887
+ context =
888
+ context || // cached call
889
+ (this.$vnode && this.$vnode.ssrContext) || // stateful
890
+ (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
891
+ // 2.2 with runInNewContext: true
892
+ if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
893
+ context = __VUE_SSR_CONTEXT__
894
+ }
895
+ // inject component styles
896
+ if (injectStyles) {
897
+ injectStyles.call(this, context)
898
+ }
899
+ // register component module identifier for async chunk inferrence
900
+ if (context && context._registeredComponents) {
901
+ context._registeredComponents.add(moduleIdentifier)
902
+ }
903
+ }
904
+ // used by ssr in case component is cached and beforeCreate
905
+ // never gets called
906
+ options._ssrRegister = hook
907
+ } else if (injectStyles) {
908
+ hook = shadowMode
909
+ ? function () {
910
+ injectStyles.call(
911
+ this,
912
+ (options.functional ? this.parent : this).$root.$options.shadowRoot
913
+ )
914
+ }
915
+ : injectStyles
916
+ }
917
+
918
+ if (hook) {
919
+ if (options.functional) {
920
+ // for template-only hot-reload because in that case the render fn doesn't
921
+ // go through the normalizer
922
+ options._injectStyles = hook
923
+ // register for functional component in vue file
924
+ var originalRender = options.render
925
+ options.render = function renderWithStyleInjection(h, context) {
926
+ hook.call(context)
927
+ return originalRender(h, context)
928
+ }
929
+ } else {
930
+ // inject component registration as beforeCreate hook
931
+ var existing = options.beforeCreate
932
+ options.beforeCreate = existing ? [].concat(existing, hook) : [hook]
933
+ }
934
+ }
935
+
936
+ return {
937
+ exports: scriptExports,
938
+ options: options
939
+ }
940
+ }
941
+
942
+ // CONCATENATED MODULE: ./src/components/UserBehaviorMonitor.vue
943
+
944
+
945
+
946
+
947
+
948
+
949
+ /* normalize component */
950
+
951
+ var component = normalizeComponent(
952
+ components_UserBehaviorMonitorvue_type_script_lang_js,
953
+ render,
954
+ staticRenderFns,
955
+ false,
956
+ null,
957
+ "06a138e4",
958
+ null
959
+
960
+ )
961
+
962
+ /* harmony default export */ var UserBehaviorMonitor = (component.exports);
963
+ // CONCATENATED MODULE: ./src/index.js
964
+
965
+
966
+ // 为使用 CDN 方式引入的用户提供组件注册方法
967
+ UserBehaviorMonitor.install = function(Vue) {
968
+ Vue.component(UserBehaviorMonitor.name, UserBehaviorMonitor);
969
+ };
970
+
971
+ // 导出组件
972
+ /* harmony default export */ var src = (UserBehaviorMonitor);
973
+
974
+ // 如果是直接引入文件,则自动注册组件
975
+ if (typeof window !== 'undefined' && window.Vue) {
976
+ UserBehaviorMonitor.install(window.Vue);
977
+ }
978
+
979
+ // 同时支持按需导入
980
+
981
+ // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
982
+
983
+
984
+ /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (src);
985
+
986
+
987
+
988
+ /***/ })
989
+
990
+ /******/ });
991
+ //# sourceMappingURL=user-behavior-monitor.common.js.map