Commit 51584c5a by 张立顺

feat 去掉埋点

1 parent c5826e91
import { Util } from "@/common/util" import { Util } from "@/common/util"
import { reportTrack } from "@api/resident" import { reportTrack } from "@api/resident"
export default { export default {
data () { data() {
return { return {
prePagePath: '', prePagePath: "",
track_timerFlag: false, track_timerFlag: false,
track_batchId: null, track_batchId: null,
track_page_view_flag: false, track_page_view_flag: false,
track_timer_out: null track_timer_out: null
} }
}, },
beforeRouteEnter (to, from, next) { beforeRouteEnter(to, from, next) {
next(vm => { next((vm) => {
vm.prePagePath = from.path vm.prePagePath = from.path
}) })
}, },
computed: { computed: {
loginAccount () { loginAccount() {
return this.$store.state.d2admin.user.info.loginAccount return this.$store.state.d2admin.user.info.loginAccount
} }
}, },
methods: { methods: {
setReportTrackData (eventType, eventCode = '', businessParam = '', batchId = '') { setReportTrackData(
let recordList = localStorage.getItem('recordList'), eventType,
eventCode = "",
businessParam = "",
batchId = ""
) {
let recordList = localStorage.getItem("recordList"),
route = this.$route, route = this.$route,
{ loginAccout, uuid, userType } = this.loginAccount, { loginAccout, uuid, userType } = this.loginAccount,
{ prePagePath } = this, { prePagePath } = this,
...@@ -34,10 +39,10 @@ export default { ...@@ -34,10 +39,10 @@ export default {
systemSource: 1, systemSource: 1,
eventTime: Util.dateFormate(Date.now(), "YYYY-MM-DD HH:mm:ss"), eventTime: Util.dateFormate(Date.now(), "YYYY-MM-DD HH:mm:ss"),
eventType, eventType,
pagePath: route.path, pagePath: route.path
} }
if (!prePagePath) prePagePath = this.getPrePagePath(this) if (!prePagePath) prePagePath = this.getPrePagePath(this)
item.prePagePath = prePagePath || '/index' item.prePagePath = prePagePath || "/index"
if (batchId) item.batchId = batchId if (batchId) item.batchId = batchId
if (eventCode) item.eventCode = eventCode if (eventCode) item.eventCode = eventCode
if (businessParam) item.businessParam = JSON.stringify(businessParam) if (businessParam) item.businessParam = JSON.stringify(businessParam)
...@@ -46,26 +51,31 @@ export default { ...@@ -46,26 +51,31 @@ export default {
recordList = JSON.parse(recordList) recordList = JSON.parse(recordList)
recordList.push(item) recordList.push(item)
} }
localStorage.setItem('recordList', JSON.stringify(recordList)) return
localStorage.setItem("recordList", JSON.stringify(recordList))
if (recordList.length > 9) { if (recordList.length > 9) {
reportTrack({ reportTrack({
recordList recordList
}).then(res => { }).then((res) => {
if (res) localStorage.removeItem('recordList') if (res) localStorage.removeItem("recordList")
}) })
} }
}, },
getRandomString (length = 30) { getRandomString(length = 30) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters =
let result = ''; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
let result = ""
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length)); result += characters.charAt(
Math.floor(Math.random() * characters.length)
)
} }
return result; return result
}, },
onPageShow () { onPageShow() {
if (this.track_page_view_flag) return if (this.track_page_view_flag) return
if (!this.track_batchId) this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}` if (!this.track_batchId)
this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}`
this.track_timerFlag = true this.track_timerFlag = true
this.track_page_view_flag = true this.track_page_view_flag = true
if (this.track_timer_out) { if (this.track_timer_out) {
...@@ -76,44 +86,51 @@ export default { ...@@ -76,44 +86,51 @@ export default {
this.setBrowseTrackData() this.setBrowseTrackData()
}, 300) }, 300)
}, },
onPageHide () { onPageHide() {
this.track_timerFlag = false this.track_timerFlag = false
this.track_batchId = null this.track_batchId = null
this.track_page_view_flag = false this.track_page_view_flag = false
clearTimeout(this.track_timer_out) clearTimeout(this.track_timer_out)
this.track_timer_out = null this.track_timer_out = null
}, },
setBrowseTrackData () { setBrowseTrackData() {
try { try {
if (!this.track_timerFlag || this.$route.path != '/qualityControlList') return if (!this.track_timerFlag || this.$route.path != "/qualityControlList")
else this.track_timer_out = setTimeout(() => { return
this.setBrowseTrackData() else
}, 10e3) this.track_timer_out = setTimeout(() => {
this.setReportTrackData(2, this.track_event_code, this[this.track_businessParam_key], this.track_batchId) this.setBrowseTrackData()
}, 10e3)
this.setReportTrackData(
2,
this.track_event_code,
this[this.track_businessParam_key],
this.track_batchId
)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
}, },
getPrePagePath (_this) { getPrePagePath(_this) {
let current = _this; let current = _this
const visited = new Set(); const visited = new Set()
while (current) { while (current) {
if (visited.has(current)) { if (visited.has(current)) {
// 防止无限循环 // 防止无限循环
console.error('Detected circular reference in parent chain'); console.error("Detected circular reference in parent chain")
return ''; return ""
} }
visited.add(current); visited.add(current)
if (current.$parent && current.$parent.prePagePath) { if (current.$parent && current.$parent.prePagePath) {
return current.$parent.prePagePath; return current.$parent.prePagePath
} }
current = current.$parent; current = current.$parent
} }
return ''; return ""
} }
} }
}
\ No newline at end of file \ No newline at end of file
}
import { reportTrack } from "@api/resident" import { reportTrack } from "@api/resident"
import reportTrackFunMixin from './reportTrackFunMixin' import reportTrackFunMixin from "./reportTrackFunMixin"
function getRandomString (length = 10) { function getRandomString(length = 10) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const characters =
let result = ''; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
let result = ""
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length)); result += characters.charAt(Math.floor(Math.random() * characters.length))
} }
return result; return result
} }
export default { export default {
mixins: [reportTrackFunMixin], mixins: [reportTrackFunMixin],
data () { data() {
return { return {
timerFlag: false, timerFlag: false,
track_set_timer: null track_set_timer: null
} }
}, },
beforeDestroy () { beforeDestroy() {
this.onPageHide() this.onPageHide()
window.removeEventListener('click', this.getTrackData) window.removeEventListener("click", this.getTrackData)
this.timerFlag = false this.timerFlag = false
clearTimeout(this.track_set_timer) clearTimeout(this.track_set_timer)
this.track_set_timer = null this.track_set_timer = null
}, },
mounted () { mounted() {
window.addEventListener('click', this.getTrackData) window.addEventListener("click", this.getTrackData)
this.timerFlag = true this.timerFlag = true
this.intervalRepoet() this.intervalRepoet()
}, },
methods: { methods: {
getTrackData (e) { getTrackData(e) {
setTimeout(() => { setTimeout(() => {
if (e.id == 'app') return if (e.id == "app") return
let target = e.target || e let target = e.target || e
if (target.dataset && Object.keys(target.dataset).length && target.dataset.eventCode) this.setReportTrackData(0, target.dataset.eventCode, JSON.parse(target.dataset.track)) if (
target.dataset &&
Object.keys(target.dataset).length &&
target.dataset.eventCode
)
this.setReportTrackData(
0,
target.dataset.eventCode,
JSON.parse(target.dataset.track)
)
else this.getTrackData(target.parentElement) else this.getTrackData(target.parentElement)
}, 100) }, 100)
}, },
intervalRepoet () { intervalRepoet() {
if (!this.timerFlag) return if (!this.timerFlag) return
this.track_set_timer = setTimeout(() => { this.track_set_timer = setTimeout(() => {
this.sendData() this.sendData()
...@@ -45,15 +55,16 @@ export default { ...@@ -45,15 +55,16 @@ export default {
}, 30 * 1e3) }, 30 * 1e3)
}, },
getRandomString: getRandomString, getRandomString: getRandomString,
sendData () { sendData() {
let recordList = localStorage.getItem('recordList') return
let recordList = localStorage.getItem("recordList")
if (recordList) { if (recordList) {
reportTrack({ reportTrack({
recordList: JSON.parse(recordList) recordList: JSON.parse(recordList)
}).then(res => { }).then((res) => {
if (res) localStorage.removeItem('recordList') if (res) localStorage.removeItem("recordList")
}) })
} }
} }
} }
}
\ No newline at end of file \ No newline at end of file
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!