xs-common-plugins 1.3.8 → 1.4.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/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.4.0",
4
4
  "private": false,
5
5
  "description": "向上公共代码部分",
6
6
  "author": "祝玲云 <1902733517@qq.com>",
package/src/App.vue CHANGED
@@ -6,6 +6,10 @@
6
6
  </template>
7
7
 
8
8
  <script>
9
+ export default {
10
+ name: 'App',
11
+ components: {}
12
+ }
9
13
 
10
14
  </script>
11
15
 
@@ -0,0 +1,145 @@
1
+ <script>
2
+ import trackerSend from '@/router/ca'
3
+ import md5 from 'js-md5'
4
+ import Vue from 'vue'
5
+
6
+ function trackerSendUpdateChecker({ action } = {}) {
7
+ trackerSend({
8
+ title: '检测到新版本',
9
+ action
10
+ })
11
+ }
12
+
13
+ const DURATION = 1000 * 60 * 30
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
+ let vm = new Vue({
57
+ template: `
58
+ <div class='update-box'>
59
+ <div class='update-box-content'>
60
+ <p class='title'>版本更新</p>
61
+ <p class='message'>检测到有新版本已经发布,请刷新页面</p>
62
+ <div class='update-box-btn'>
63
+ <button class='button-close' @click='close'>关闭</button>
64
+ <button @click='refresh'>刷新</button>
65
+ </div>
66
+ </div>
67
+ </div>`,
68
+ methods: {
69
+ refresh: () => this.refresh(),
70
+ close: () => {
71
+ vm.$el.remove()
72
+ this.onClose()
73
+ }
74
+ }
75
+ })
76
+ vm.$mount()
77
+ document.body.appendChild(vm.$el)
78
+ }
79
+ },
80
+ mounted() {
81
+ this.check().then(text => {
82
+ this.md5 = md5(text)
83
+ this.start()
84
+ })
85
+ },
86
+ render() {
87
+ return null
88
+ }
89
+ }
90
+ </script>
91
+
92
+ <style lang="scss">
93
+ .update-box {
94
+ position: fixed;
95
+ width: 300px;
96
+ right: 0;
97
+ bottom: 0;
98
+ background-color: #fff;
99
+ border-radius: 5px;
100
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
101
+ z-index: 100;
102
+ transform: translateY(0);
103
+ transition: transform 0.3s;
104
+
105
+ .update-box-content {
106
+ padding: 20px;
107
+
108
+ .title {
109
+ font-size: 16px;
110
+ color: #333;
111
+ text-align: left;
112
+ margin-bottom: 20px;
113
+ margin-top: 0px;
114
+ }
115
+
116
+ .message {
117
+ font-size: 14px;
118
+ color: #606266;
119
+ text-align: center;
120
+ margin-bottom: 20px;
121
+ }
122
+
123
+ .update-box-btn {
124
+ text-align: center;
125
+
126
+ .button-close {
127
+ padding: 5px 10px;
128
+ background-color: #f56c6c;
129
+ color: #fff;
130
+ cursor: pointer;
131
+ margin-right: 20px;
132
+ }
133
+
134
+ button {
135
+ padding: 5px 10px;
136
+ border: none;
137
+ background-color: #409eff;
138
+ color: #fff;
139
+ border-radius: 4px;
140
+ cursor: pointer;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ </style>
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
 
@@ -45,9 +45,6 @@
45
45
  />
46
46
  </el-badge>
47
47
  </div>
48
- <div class="changelog">
49
- <ChangeLog />
50
- </div>
51
48
  <div>
52
49
  <el-tag style="margin: 0 3px;">{{
53
50
  userProfile &&
@@ -119,7 +116,6 @@ import { mapGetters } from "vuex";
119
116
  import Breadcrumb from "@/components/Breadcrumb";
120
117
  import Hamburger from "@/components/Hamburger";
121
118
  import AllSearch from "./AllSearch";
122
- import ChangeLog from "./ChangeLog";
123
119
  import { getConfig } from "@/utils/global-config";
124
120
  import { getToken, removeToken, removeLocalToken } from "@/utils/auth"; // get token from cookie
125
121
  import ImCom from "@/components/im";
@@ -133,7 +129,6 @@ export default {
133
129
  Hamburger,
134
130
  AllSearch,
135
131
  ImCom,
136
- ChangeLog,
137
132
  },
138
133
  data() {
139
134
  return {
@@ -1,59 +0,0 @@
1
- <template>
2
- <div v-if="list.length > 0">
3
- <el-dropdown :hide-on-click="false" @command="handleCommand">
4
- <el-badge is-dot class="item">
5
- <i class="el-icon-bell"></i>
6
- </el-badge>
7
- <el-dropdown-menu slot="dropdown">
8
- <el-dropdown-item v-for="(item, index) in list" :key="index" :command="index">{{ item.title }}</el-dropdown-item>
9
- </el-dropdown-menu>
10
- </el-dropdown>
11
- </div>
12
- </template>
13
-
14
- <script>
15
- import {defineComponent, h} from "vue";
16
- import { getConfig } from "@/utils/global-config";
17
- export default {
18
- name: 'changeLog',
19
- data () {
20
- return {
21
- list: []
22
- }
23
- },
24
- methods: {
25
- handleCommand (command) {
26
- this.$common.popup({
27
- title: this.list[command].remark,
28
- component: defineComponent({
29
- template: `<div>
30
- <div style="font-size: 14px;color: #606266;line-height: 20px;padding: 10px 20px">${this.list[command].remark}</div>
31
- <div style="text-align: center"><el-button type="primary" @click="$emit('close')">关闭</el-button></div>
32
- </div>`
33
- })
34
- });
35
- },
36
- getChangeLog () {
37
- this.$ask.commng.api.commmng.Banner.Query.post({pageInfo: {
38
- page: 1,
39
- pageSize: 3
40
- },
41
- codeLike: `changelog#${getConfig('CLIENT_ID')}`
42
- }).then((result) => {
43
- if (result.code === 0 && result.data.data.length > 0) {
44
- this.list = result.data.data;
45
- }
46
- }).catch((err) => {
47
-
48
- }).finally(() => {
49
- setTimeout(() => {
50
- this.getChangeLog();
51
- }, 1000 * 60 * 60 * 12);
52
- })
53
- }
54
- },
55
- mounted () {
56
- this.getChangeLog();
57
- }
58
- }
59
- </script>