xs-common-plugins 1.3.8 → 1.3.9

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/README.md CHANGED
@@ -327,4 +327,10 @@
327
327
  ```
328
328
  1.3.8
329
329
  1. Navbar 新增 ChangeLog 组件
330
- ```
330
+ ```
331
+
332
+ ```
333
+ 1.3.9
334
+ 1. 新增UpdateChecker组件, 用于检测更新
335
+ 2. 优化了买点发送函数
336
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xs-common-plugins",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "private": false,
5
5
  "description": "向上公共代码部分",
6
6
  "author": "祝玲云 <1902733517@qq.com>",
package/src/App.vue CHANGED
@@ -2,10 +2,18 @@
2
2
  <div id="app">
3
3
  <router-view/>
4
4
  <router-view name="websocket"/>
5
+ <UpdateChecker />
5
6
  </div>
6
7
  </template>
7
8
 
8
9
  <script>
10
+ import UpdateChecker from './components/UpdateChecker'
11
+ export default {
12
+ name: 'App',
13
+ components: {
14
+ UpdateChecker
15
+ }
16
+ }
9
17
 
10
18
  </script>
11
19
 
@@ -0,0 +1,88 @@
1
+ <script>
2
+ import md5 from 'js-md5'
3
+ import { defineComponent } from 'vue'
4
+ import trackerSend from "@/router/ca";
5
+
6
+ function trackerSendUpdateChecker({action} = {}) {
7
+ trackerSend({
8
+ title: "检测到新版本",
9
+ action
10
+ })
11
+ }
12
+
13
+ const DURATION = 1000 * 60 * 60 * 2
14
+ export default {
15
+ name: 'UpdateChecker',
16
+ data () {
17
+ return {
18
+ md5: '',
19
+ interval: null
20
+ }
21
+ },
22
+ methods: {
23
+ check() {
24
+ return fetch(`${location.origin}${location.pathname}`, {
25
+ cache: 'no-cache',
26
+ }).then(async (res) => {
27
+ return res.text()
28
+ })
29
+ },
30
+ start() {
31
+ this.stop()
32
+ this.interval = setInterval(() => {
33
+ this.check().then(text => {
34
+ const newMd5 = md5(text)
35
+ if (newMd5 !== this.md5) {
36
+ this.stop()
37
+ this.notify()
38
+ trackerSendUpdateChecker({action: "检测到新版本通知用户"})
39
+ }
40
+ })
41
+ }, DURATION)
42
+ },
43
+ stop() {
44
+ if (!this.interval) return
45
+ clearInterval(this.interval)
46
+ },
47
+ refresh() {
48
+ trackerSendUpdateChecker({action: "检测到新版本刷新页面"})
49
+ window.location.reload()
50
+ },
51
+ onClose() {
52
+ this.start()
53
+ trackerSendUpdateChecker({action: "检测到新版本关闭提示"})
54
+ },
55
+ notify() {
56
+ this.$common.popup({
57
+ title: '检测到新版本',
58
+ component: defineComponent({
59
+ template: `<div>
60
+ <div style="font-size: 14px;color: #606266;line-height: 20px;padding: 10px 20px">
61
+ 检测到有新版本已经发布,请刷新页面
62
+ </div>
63
+ <div style="text-align: center"><el-button type="primary" @click="refresh">刷新</el-button></div>
64
+ </div>`,
65
+ methods: {
66
+ refresh: () => this.refresh(),
67
+ beforeClose: (done) => {done(); this.onClose()}
68
+ },
69
+ }),
70
+ dialogCfg: {
71
+ closeOnClickModal: false,
72
+ closeOnPressEscape: false
73
+ }
74
+ })
75
+ }
76
+ },
77
+ mounted() {
78
+ this.check().then(text => {
79
+ this.md5 = md5(text)
80
+ this.start()
81
+ })
82
+ },
83
+ render() {
84
+ return null
85
+ }
86
+ }
87
+
88
+ </script>
package/src/router/ca.js CHANGED
@@ -1,21 +1,40 @@
1
1
  import tracker from "./tracker";
2
2
  import moment from "moment";
3
- export default function trackerSend({userName, router = {}, clientId}) {
4
- tracker.send({
5
- title: "页面访问",
6
- action: "后台页面路由跳转",
7
- url: location.href,
8
- qt: {
9
- clientId,
10
- userName,
11
- date: moment(Date.now()).format("YYYY-MM-DD HH:mm:ss"),
12
- fullPath: router.fullPath,
13
- title: getRouterBreadcrumbs(router)
14
- }
15
- });
3
+ import { getToken } from "@/utils/auth"; // get token from cookie
4
+ import { getConfig } from "@/utils/global-config";
5
+
6
+ /**
7
+ * Sends tracking data to the tracker.
8
+ *
9
+ * @param {Object} options - The options for tracking.
10
+ * @param {string} options.title - The title of the tracking event.
11
+ * @param {string} options.action - The action being tracked.
12
+ * @param {Object} [options.qt] - Additional tracking data.
13
+ * @return {void}
14
+ */
15
+ export default function trackerSend({title, action, qt}) {
16
+ try {
17
+ tracker.send({
18
+ title,
19
+ action,
20
+ url: location.href,
21
+ qt: {
22
+ clientId: getConfig("CLIENT_ID"),
23
+ userName: getToken("LoginUserName"),
24
+ date: moment(Date.now()).format("YYYY-MM-DD HH:mm:ss"),
25
+ ...qt
26
+ }
27
+ });
28
+ } catch (error) {}
16
29
  }
17
30
 
18
- function getRouterBreadcrumbs(router) {
31
+ /**
32
+ * Returns a string representing the breadcrumbs of the current router.
33
+ *
34
+ * @param {Object} router - The router object.
35
+ * @return {string} The breadcrumbs string.
36
+ */
37
+ export function getRouterBreadcrumbs(router) {
19
38
  return router.matched
20
39
  .map((item) => (item.meta && item.meta.title) || item.name)
21
40
  .filter((item) => item && item !== "首页")
@@ -10,7 +10,7 @@ import "nprogress/nprogress.css"; // progress bar style
10
10
  import Oidc from "oidc-client";
11
11
  import { requestApi as HTTP } from "xs-request";
12
12
  import router from "./index";
13
- import trackerSend from "./ca";
13
+ import trackerSend, {getRouterBreadcrumbs} from "./ca";
14
14
 
15
15
  NProgress.configure({
16
16
  showSpinner: false,
@@ -73,9 +73,12 @@ router.beforeEach((to, from, next) => {
73
73
  } // 没登录 & 没在登录页 => 跳转到登录页
74
74
 
75
75
  trackerSend({
76
- clientId: id4config.client_id,
77
- userName: getToken("LoginUserName"),
78
- router: to
76
+ title: "页面访问",
77
+ action: "前台页面路由跳转",
78
+ qt: {
79
+ fullPath: to.fullPath,
80
+ title: getRouterBreadcrumbs(to)
81
+ }
79
82
  })
80
83
  });
81
84