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: {
...@@ -33,22 +34,22 @@ export default { ...@@ -33,22 +34,22 @@ export default {
* @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,
...@@ -56,121 +57,130 @@ export default { ...@@ -56,121 +57,130 @@ 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)
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) {
recordList = [item];
} else {
recordList = JSON.parse(recordList);
recordList.push(item);
} }
localStorage.setItem("recordList", JSON.stringify(recordList)) localStorage.setItem("recordList", JSON.stringify(recordList));
if (!window.TRACK_TIMER) { if (!window.TRACK_TIMER) {
console.log('---------------- 重新打开定时埋点 ----------------') console.log("---------------- 重新打开定时埋点 ----------------");
this.sendTrack() //开启定时埋点 this.sendTrack(); // 开启定时埋点
} }
if (recordList.length > 9) this.sendTrackData() if (recordList.length > 9)
this.sendTrackData();
}, },
getRandomString (length = 30) { getRandomString(length = 30) {
const characters = const characters
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "" let result = "";
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
result += characters.charAt( result += characters.charAt(
Math.floor(Math.random() * characters.length) 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) { if (!this.track_batchId) {
this.track_batchId = `DJ_${this.getRandomString()}_${Date.now()}` 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) {
clearTimeout(this.track_timer_out) clearTimeout(this.track_timer_out);
this.track_timer_out = null this.track_timer_out = null;
} }
setTimeout(() => { setTimeout(() => {
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 {
// || (this.$route.path != "/qualityControlList" && this.$route.path != "/shopConfig") // || (this.$route.path != "/qualityControlList" && this.$route.path != "/shopConfig")
if (!this.track_timerFlag && !this.track_event_code) { //无eventcode时不上报 if (!this.track_timerFlag && !this.track_event_code) { // 无eventcode时不上报
return return;
} else { } else {
this.track_timer_out = setTimeout(() => { this.track_timer_out = setTimeout(() => {
this.setBrowseTrackData() this.setBrowseTrackData();
}, 10e3) }, 10e3);
} }
let trackParams = {} let trackParams = {};
if(this.track_businessParam_key) trackParams = this[this.track_businessParam_key] || {} if (this.track_businessParam_key)
trackParams = this[this.track_businessParam_key] || {};
this.setReportTrackData( this.setReportTrackData(
2, 2,
this.track_event_code, this.track_event_code,
trackParams, trackParams,
this.track_batchId 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 "";
}, },
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 { } else {
clearInterval(window.TRACK_TIMER) clearInterval(window.TRACK_TIMER);
window.TRACK_TIMER = null window.TRACK_TIMER = null;
console.log('---------------- 暂停定时埋点 ----------------') 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!