Sfoglia il codice sorgente

对接访问量、徽章数相关接口

任一存 2 anni fa
parent
commit
2c66c1a05f
3 ha cambiato i file con 39 aggiunte e 5 eliminazioni
  1. 13 0
      src/api.js
  2. 12 0
      src/main.js
  3. 14 5
      src/views/gui/RuleDesc.vue

+ 13 - 0
src/api.js

@@ -31,6 +31,19 @@ async function fetchBadgeAndVisitData() {
 }
 
 export default {
+  async reportVisit() {
+    const res = await axios({
+      method: 'get',
+      url: `${process.env.VUE_APP_API_PREFIX}/api/show/addVisit`,
+    })
+  },
+  async fetchVisitInfo() {
+    const res = await axios({
+      method: 'get',
+      url: `${process.env.VUE_APP_API_PREFIX}/api/show/getVisit`,
+    })
+    return res.data.data
+  },
   async login(userName, password) {
     const pwdEncrypted = encodeStr(Base64.encode(password))
     const res = await axios({

+ 12 - 0
src/main.js

@@ -31,3 +31,15 @@ new Vue({
   store,
   render: h => h(App)
 }).$mount('#app')
+
+// 访问量(每天最多一次)埋点
+const lastReportTimeInfo = localStorage.getItem("WLG-report-visit-time")
+if (lastReportTimeInfo) {
+  if (Date.now() - Number(lastReportTimeInfo) >= 24 * 60 * 60 * 1000) {
+    localStorage.setItem('WLG-report-visit-time', Date.now())
+    globalApi.reportVisit()
+  }
+} else {
+  localStorage.setItem('WLG-report-visit-time', Date.now())
+  globalApi.reportVisit()
+}

+ 14 - 5
src/views/gui/RuleDesc.vue

@@ -76,7 +76,7 @@
         </div>
       </template>
       <p class="statistics">
-        当前访客{{ visitNum }}人次,已发放[营造专家]徽章{{ yingZaoZhuanJiaNum }}枚,[历史达人]{{ liShiDaRen }}枚徽章,[护书使者]徽章{{ liShiDaRen }}枚
+        当前访客{{ visitNum !== undefined ? visitNum : '' }}人次,已发放[营造专家]徽章{{ yingZaoZhuanJiaNum !== undefined ? yingZaoZhuanJiaNum : '' }}枚,[历史达人]{{ liShiDaRen !== undefined ? liShiDaRen : '' }}枚徽章,[护书使者]徽章{{ huShuShiZhe !== undefined ? huShuShiZhe : '' }}枚
       </p>
     </div>
   </div>
@@ -86,16 +86,25 @@
 export default {
   data() {
     return {
-      visitNum: 1939,
-      yingZaoZhuanJiaNum: 56,
-      liShiDaRen: 424,
-      huShuShiZhe: 32,
+      visitNum: undefined,
+      yingZaoZhuanJiaNum: undefined,
+      liShiDaRen: undefined,
+      huShuShiZhe: undefined,
     }
   },
   computed: {
     ...globalMapState([
       'loginStatus',
     ])
+  },
+  mounted() {
+    globalApi.fetchVisitInfo().then((res) => {
+      console.log(res)
+      this.visitNum = res.visit
+      this.yingZaoZhuanJiaNum = res['1']
+      this.liShiDaRen = res['2']
+      this.huShuShiZhe = res['3']
+    })
   }
 }
 </script>