Commit eae05685 by Jaxon

chron: 格式化

1 parent 9a7ef036
import { import {
Util reportTrack,
} from "@/common/util" } from "@api/resident";
import { import {
reportTrack Util,
} from "@api/resident" } from "@/common/util";
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: {
/** /**
* *
* @param {动作类型} eventType * @param {动作类型} eventType
* @param {事件别名} eventCode * @param {事件别名} eventCode
* @param {业务参数} businessParam * @param {业务参数} businessParam
* @param {浏览批次id} batchId * @param {浏览批次id} batchId
*/ */
setReportTrackData ( setReportTrackData(
eventType, eventType,
eventCode = "", eventCode = "",
businessParam = "", businessParam = "",
batchId = "" batchId = "",
) { ) {
let recordList = localStorage.getItem("recordList") let recordList = localStorage.getItem("recordList");
const route = this.$route const route = this.$route;
const { const {
loginAccout, loginAccout,
uuid, uuid,
userType userType,
} = this.loginAccount } = this.loginAccount;
let { let {
prePagePath prePagePath,
} = this } = this;
const item = { const item = {
loginAccount: loginAccout, loginAccount: loginAccout,
uuid, uuid,
userType, userType,
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)
item.prePagePath = prePagePath || "/index" prePagePath = this.getPrePagePath(this);
if (batchId) item.batchId = batchId item.prePagePath = prePagePath || "/index";
if (eventCode) item.eventCode = eventCode if (batchId)
if (businessParam) item.businessParam = JSON.stringify(businessParam) item.batchId = batchId;
if (!recordList) recordList = [item] if (eventCode)
else { item.eventCode = eventCode;
recordList = JSON.parse(recordList) if (businessParam)
recordList.push(item) item.businessParam = JSON.stringify(businessParam);
} if (!recordList) {
localStorage.setItem("recordList", JSON.stringify(recordList)) recordList = [item];
if (!window.TRACK_TIMER) { } else {
console.log('---------------- 重新打开定时埋点 ----------------') recordList = JSON.parse(recordList);
this.sendTrack() //开启定时埋点 recordList.push(item);
} }
if (recordList.length > 9) this.sendTrackData() localStorage.setItem("recordList", JSON.stringify(recordList));
}, if (!window.TRACK_TIMER) {
getRandomString (length = 30) { console.log("---------------- 重新打开定时埋点 ----------------");
const characters = this.sendTrack(); // 开启定时埋点
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" }
let result = "" if (recordList.length > 9)
for (let i = 0; i < length; i++) { this.sendTrackData();
result += characters.charAt( },
Math.floor(Math.random() * characters.length) getRandomString(length = 30) {
) const characters
} = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
return result let result = "";
}, for (let i = 0; i < length; i++) {
onPageShow () { result += characters.charAt(
if (this.track_page_view_flag) return Math.floor(Math.random() * characters.length),
if (!this.track_batchId) { );
this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}` }
} return result;
this.track_timerFlag = true },
this.track_page_view_flag = true onPageShow() {
if (this.track_timer_out) { if (this.track_page_view_flag)
clearTimeout(this.track_timer_out) return;
this.track_timer_out = null if (!this.track_batchId) {
} this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}`;
setTimeout(() => { }
this.setBrowseTrackData() this.track_timerFlag = true;
}, 300) this.track_page_view_flag = true;
}, if (this.track_timer_out) {
onPageHide () { clearTimeout(this.track_timer_out);
this.track_timerFlag = false this.track_timer_out = null;
this.track_batchId = null }
this.track_page_view_flag = false setTimeout(() => {
clearTimeout(this.track_timer_out) this.setBrowseTrackData();
this.track_timer_out = null }, 300);
}, },
setBrowseTrackData () { onPageHide() {
try { this.track_timerFlag = false;
// || (this.$route.path != "/qualityControlList" && this.$route.path != "/shopConfig") this.track_batchId = null;
if (!this.track_timerFlag && !this.track_event_code) { //无eventcode时不上报 this.track_page_view_flag = false;
return clearTimeout(this.track_timer_out);
} else { this.track_timer_out = null;
this.track_timer_out = setTimeout(() => { },
this.setBrowseTrackData() setBrowseTrackData() {
}, 10e3) try {
} // || (this.$route.path != "/qualityControlList" && this.$route.path != "/shopConfig")
let trackParams = {} if (!this.track_timerFlag && !this.track_event_code) { // 无eventcode时不上报
if(this.track_businessParam_key) trackParams = this[this.track_businessParam_key] || {} return;
this.setReportTrackData( } else {
2, this.track_timer_out = setTimeout(() => {
this.track_event_code, this.setBrowseTrackData();
trackParams, }, 10e3);
this.track_batchId }
) let trackParams = {};
} catch (error) { if (this.track_businessParam_key)
console.log(error) trackParams = this[this.track_businessParam_key] || {};
} this.setReportTrackData(
}, 2,
getPrePagePath (_this) { this.track_event_code,
let current = _this trackParams,
const visited = new Set() this.track_batchId,
);
} catch (error) {
console.log(error);
}
},
getPrePagePath(_this) {
let current = _this;
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 "";
}, },
sendTrackData () { sendTrackData() {
let recordList = localStorage.getItem('recordList') const recordList = localStorage.getItem("recordList");
if (recordList && recordList.length) { if (recordList && recordList.length) {
reportTrack({ reportTrack({
recordList: JSON.parse(recordList) recordList: JSON.parse(recordList),
}).then(res => { }).then((res) => {
if (res) localStorage.removeItem('recordList') if (res)
}) localStorage.removeItem("recordList");
} else { });
clearInterval(window.TRACK_TIMER) } else {
window.TRACK_TIMER = null clearInterval(window.TRACK_TIMER);
console.log('---------------- 暂停定时埋点 ----------------') window.TRACK_TIMER = null;
} console.log("---------------- 暂停定时埋点 ----------------");
}, }
},
/**定时发送埋点数据 */ /** 定时发送埋点数据 */
sendTrack () { sendTrack() {
window.TRACK_TIMER = setInterval(() => { window.TRACK_TIMER = setInterval(() => {
this.sendTrackData() this.sendTrackData();
}, 30e3) }, 30e3);
} },
} },
} };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!