Commit 51584c5a by 张立顺

feat 去掉埋点

1 parent c5826e91
import { Util } from "@/common/util"
import { reportTrack } from "@api/resident"
export default {
data () {
data() {
return {
prePagePath: '',
prePagePath: "",
track_timerFlag: false,
track_batchId: null,
track_page_view_flag: false,
track_timer_out: null
}
},
beforeRouteEnter (to, from, next) {
next(vm => {
beforeRouteEnter(to, from, next) {
next((vm) => {
vm.prePagePath = from.path
})
},
computed: {
loginAccount () {
loginAccount() {
return this.$store.state.d2admin.user.info.loginAccount
}
},
methods: {
setReportTrackData (eventType, eventCode = '', businessParam = '', batchId = '') {
let recordList = localStorage.getItem('recordList'),
setReportTrackData(
eventType,
eventCode = "",
businessParam = "",
batchId = ""
) {
let recordList = localStorage.getItem("recordList"),
route = this.$route,
{ loginAccout, uuid, userType } = this.loginAccount,
{ prePagePath } = this,
......@@ -34,10 +39,10 @@ export default {
systemSource: 1,
eventTime: Util.dateFormate(Date.now(), "YYYY-MM-DD HH:mm:ss"),
eventType,
pagePath: route.path,
pagePath: route.path
}
if (!prePagePath) prePagePath = this.getPrePagePath(this)
item.prePagePath = prePagePath || '/index'
item.prePagePath = prePagePath || "/index"
if (batchId) item.batchId = batchId
if (eventCode) item.eventCode = eventCode
if (businessParam) item.businessParam = JSON.stringify(businessParam)
......@@ -46,26 +51,31 @@ export default {
recordList = JSON.parse(recordList)
recordList.push(item)
}
localStorage.setItem('recordList', JSON.stringify(recordList))
return
localStorage.setItem("recordList", JSON.stringify(recordList))
if (recordList.length > 9) {
reportTrack({
recordList
}).then(res => {
if (res) localStorage.removeItem('recordList')
}).then((res) => {
if (res) localStorage.removeItem("recordList")
})
}
},
getRandomString (length = 30) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
getRandomString(length = 30) {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
let result = ""
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_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_page_view_flag = true
if (this.track_timer_out) {
......@@ -76,44 +86,51 @@ export default {
this.setBrowseTrackData()
}, 300)
},
onPageHide () {
onPageHide() {
this.track_timerFlag = false
this.track_batchId = null
this.track_page_view_flag = false
clearTimeout(this.track_timer_out)
this.track_timer_out = null
},
setBrowseTrackData () {
setBrowseTrackData() {
try {
if (!this.track_timerFlag || this.$route.path != '/qualityControlList') return
else this.track_timer_out = setTimeout(() => {
this.setBrowseTrackData()
}, 10e3)
this.setReportTrackData(2, this.track_event_code, this[this.track_businessParam_key], this.track_batchId)
if (!this.track_timerFlag || this.$route.path != "/qualityControlList")
return
else
this.track_timer_out = setTimeout(() => {
this.setBrowseTrackData()
}, 10e3)
this.setReportTrackData(
2,
this.track_event_code,
this[this.track_businessParam_key],
this.track_batchId
)
} catch (error) {
console.log(error)
}
},
getPrePagePath (_this) {
let current = _this;
const visited = new Set();
getPrePagePath(_this) {
let current = _this
const visited = new Set()
while (current) {
if (visited.has(current)) {
// 防止无限循环
console.error('Detected circular reference in parent chain');
return '';
console.error("Detected circular reference in parent chain")
return ""
}
visited.add(current);
visited.add(current)
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
}
import { reportTrack } from "@api/resident"
import reportTrackFunMixin from './reportTrackFunMixin'
function getRandomString (length = 10) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
import reportTrackFunMixin from "./reportTrackFunMixin"
function getRandomString(length = 10) {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
let result = ""
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 {
mixins: [reportTrackFunMixin],
data () {
data() {
return {
timerFlag: false,
track_set_timer: null
}
},
beforeDestroy () {
beforeDestroy() {
this.onPageHide()
window.removeEventListener('click', this.getTrackData)
window.removeEventListener("click", this.getTrackData)
this.timerFlag = false
clearTimeout(this.track_set_timer)
this.track_set_timer = null
},
mounted () {
window.addEventListener('click', this.getTrackData)
mounted() {
window.addEventListener("click", this.getTrackData)
this.timerFlag = true
this.intervalRepoet()
},
methods: {
getTrackData (e) {
getTrackData(e) {
setTimeout(() => {
if (e.id == 'app') return
if (e.id == "app") return
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)
}, 100)
},
intervalRepoet () {
intervalRepoet() {
if (!this.timerFlag) return
this.track_set_timer = setTimeout(() => {
this.sendData()
......@@ -45,15 +55,16 @@ export default {
}, 30 * 1e3)
},
getRandomString: getRandomString,
sendData () {
let recordList = localStorage.getItem('recordList')
sendData() {
return
let recordList = localStorage.getItem("recordList")
if (recordList) {
reportTrack({
recordList: JSON.parse(recordList)
}).then(res => {
if (res) localStorage.removeItem('recordList')
}).then((res) => {
if (res) localStorage.removeItem("recordList")
})
}
}
}
}
\ 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!