Commit b6e750dc by chenwq

refactor(track): 重构统一埋点上报逻辑及相关代码

- 新增baseApi中的reportTrack埋点上报接口,更新request请求方法支持多HTTP客户端配置
- 抽离埋点逻辑为全局混入reportTrackFunMixin,替换各页面原有内联埋点代码
- 优化util工具类的日期格式化方法,修复样式问题(颜色值小写、安全区域间距)
- 统一所有页面的埋点事件命名规范,移除无用代码注释
1 parent 39025ff0
......@@ -4,5 +4,9 @@ export default {
// 获取周数据
getWeekSelectData(data) {
return api.post('dj.api.supervisor.mini.get.generateWeeklyRanges', data, 'supervisorUrl')
},
// 埋点
reportTrack(data) {
return api.post('clue.api.burial.point.record.batch.insert', data, 'clueUrl', {}, 'scrmHttp')
}
}
import { util } from 'utils'
const urlObj = {
djStaffUrl: '/rop-dj-staff-miniprogram/router',
supervisorUrl: '/rop-dj-supervisor-mini/router'
supervisorUrl: '/rop-dj-supervisor-mini/router',
clueUrl: '/rop-scrm-clue/router'
}
const httpObj = {
djHttp: '$DJ_HTTP',
scrmHttp: '$SCRM_HTTP'
}
/**
......@@ -15,16 +20,13 @@ const urlObj = {
* @param {Object} options - 额外的请求配置项
* @returns {Promise}
*/
function post(method, data = {}, url = 'djStaffUrl', options = {}) {
function post(method, data = {}, url = 'supervisorUrl', options = {}, httpType = 'djHttp') {
// 合并 method 到 data 中,适应后端要求的格式
const payload = {
method,
// technicalSupervisorName: util.getLocalStorage('ww_params_name') || '', // 技术督导姓名
// technicalSupervisorPhone: util.getLocalStorage('ww_params_phone') || '', // 技术督导手机号
// sessionId: '8bcad25d-8bfa-41a8-a5e8-ef06ace89ee8',
...data
}
return window.$DJ_HTTP({
return window[httpObj[httpType]]({
url: urlObj[url],
data: payload,
...options
......
......@@ -179,10 +179,6 @@ export default {
this.weekColumns = await weekColumnsPromise
},
selectDate(index) {
if (this.setTrackData && this.$track) {
const events = ['supervisor_dayTime_tab', 'supervisor_weekTime_tab', 'supervisor_monthTime_tab']
this.$track.setTrackData(0, events[index], {}, '')
}
this.dateCurrent = index
this.timeType = this.timeTypeEnum[index]
this.rightCurrent = true
......
import { Util } from '@/common/util'
import { reportTrack } from '@api/resident'
import { util } from 'utils'
import api from '../api/baseApi'
export default {
data() {
return {
......@@ -32,18 +32,15 @@ export default {
setReportTrackData(eventType, eventCode = '', businessParam = '', batchId = '') {
let recordList = localStorage.getItem('recordList')
const route = this.$route
// const { loginAccout, uuid, userType } = this.loginAccount
const userInfo = util.getLocalStorage('ww_userInfo')
let { prePagePath } = this
const item = {
loginAccount: userInfo.phone || '',
businessParam: userInfo || '',
// uuid,
// userType,
systemSource: 10,
eventTime: Util.dateFormate(Date.now(), 'YYYY-MM-DD HH:mm:ss'),
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'
......@@ -134,11 +131,13 @@ export default {
sendTrackData() {
let recordList = localStorage.getItem('recordList')
if (recordList && recordList.length) {
reportTrack({
recordList: JSON.parse(recordList)
}).then(res => {
if (res) localStorage.removeItem('recordList')
})
api
.reportTrack({
recordList: JSON.parse(recordList)
})
.then(res => {
if (res) localStorage.removeItem('recordList')
})
} else {
clearInterval(window.TRACK_TIMER)
window.TRACK_TIMER = null
......
......@@ -2,12 +2,12 @@ import { util } from 'utils'
import { Http } from 'glsx-common'
import { Notify } from 'vant'
import { ssoApi } from '@/api'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
const state = {
showWindow: false,
lastPath: ''
}
import router from '@/router'
const IS_PROD = ['production', 'prod'].includes(process.env.VUE_APP_ENV)
const mutations = {
......@@ -26,16 +26,16 @@ const actions = {
registerHttp({}, sessionId = '') {
const { scrmRequest, djRequest } = window.$fetchConfig
window.$SCRM_HTTP = new Http({ ...scrmRequest, alert: Notify })
window.$DJ_HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId }})
window.$DJ_HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } })
},
async login({ dispatch }) {
console.log('login')
// return
try {
const wwCode = getParams('code')
const { corpId, agentId } = util.getLocalStorage('ww_storage_info') || {}
const paramsPhone = util.getLocalStorage('ww_params_phone')
const { loginUrl } = window.$fetchConfig
const { corpId, agentId } = util.getLocalStorage('ww_storage_info') || {}
// const paramsPhone = util.getLocalStorage('ww_params_phone')
const { loginUrl } = window.$fetchConfig
if (wwCode) {
const { code, data, message } = await ssoApi.login({
code: wwCode,
......@@ -59,6 +59,7 @@ const actions = {
util.setLocalStorage('ww_userInfo', userInfo)
// util.setSessionId(res.sessionId)
// dispatch('registerHttp', res.sessionId)
reportTrackFunMixin.methods.setReportTrackData(0, 'supervisor_h5_login')
state.showWindow = true
console.log(jumpUrl)
window.location.replace(`${jumpUrl}/#/${route}`)
......@@ -75,7 +76,7 @@ const actions = {
},
navigation({ dispatch }, to) {
const { corpId, agentId, phone, name } = getParams()
const userInfo = util.getLocalStorage('ww_userInfo')
const userInfo = util.getLocalStorage('ww_userInfo')
if (phone) util.setLocalStorage('ww_params_phone', phone)
if (name) util.setLocalStorage('ww_params_name', name)
dispatch('registerHttp')
......@@ -83,6 +84,8 @@ const actions = {
* 开发环境,跳过企微登陆
*/
if (!IS_PROD) {
util.setLocalStorage('ww_userInfo', { phone: '13012345678' || '' })
// reportTrackFunMixin.methods.setReportTrackData(0, 'supervisor_h5_login')
state.showWindow = true
return
}
......
import Vue from 'vue'
import {
Toast,
Dialog
} from 'vant'
import dayjs from 'dayjs'
import { Toast, Dialog } from 'vant'
/**
* 日期格式化
* let time = new Date().format('yyyy-MM-dd hh:mm:ss')
*/
Date.prototype.format = function(fmt) {
Date.prototype.format = function (fmt) {
const o = {
'M+': this.getMonth() + 1, // 月份
'd+': this.getDate(), // 日
......@@ -17,32 +15,32 @@ Date.prototype.format = function(fmt) {
's+': this.getSeconds(), // 秒
// 季度
'q+': Math.floor((this.getMonth() + 3) / 3),
'S': this.getMilliseconds() // 毫秒
S: this.getMilliseconds() // 毫秒
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (const k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
}
}
return fmt
}
const throttle = (fn, gapTime) => {
if (gapTime == null || gapTime == undefined) {
gapTime = 1500
}
let _lastTime = null
return function() {
const _nowTime = +new Date()
if (_nowTime - _lastTime > gapTime || !_lastTime) {
fn.apply(this, arguments)
_lastTime = _nowTime
}
if (gapTime == null || gapTime == undefined) {
gapTime = 1500
}
let _lastTime = null
return function () {
const _nowTime = +new Date()
if (_nowTime - _lastTime > gapTime || !_lastTime) {
fn.apply(this, arguments)
_lastTime = _nowTime
}
}
/** 防止重复点击 */
}
/** 防止重复点击 */
const showLoading = (title = '加载中...', callBack, custom) => {
Toast({
type: 'loading',
......@@ -56,27 +54,27 @@ const showLoading = (title = '加载中...', callBack, custom) => {
}
}
const hideLoading = () => {
Toast.clear()
}
/** num:要转换的数值,fixed:精确几位小数 */
Toast.clear()
}
/** num:要转换的数值,fixed:精确几位小数 */
const decimal = (num, fixed) => {
const pow = Math.pow(10, fixed)
return Math.round(num * pow) / pow
}
const showToast = (message = '', callBack) => {
const params = {
message,
forbidClick: true,
duration: 1500
}
Toast(params)
if (callBack && typeof callBack === 'function') {
setTimeout(() => {
callBack()
}, 1500)
}
const params = {
message,
forbidClick: true,
duration: 1500
}
/** 触摸样式 */
Toast(params)
if (callBack && typeof callBack === 'function') {
setTimeout(() => {
callBack()
}, 1500)
}
}
/** 触摸样式 */
const touchstart = e => {
e.target.classList.add('btn-on-leave')
}
......@@ -85,21 +83,33 @@ const touchend = e => {
}
const setLocalStorage = (key, item) => {
window.localStorage.setItem(key, JSON.stringify(item))
// sessionStorage.setItem(key, JSON.stringify(item))
// sessionStorage.setItem(key, JSON.stringify(item))
}
const getLocalStorage = key => {
return JSON.parse(window.localStorage.getItem(key))
// return JSON.parse(sessionStorage.getItem(key))
// return JSON.parse(sessionStorage.getItem(key))
}
const removeLocalStorage = key => {
window.localStorage.removeItem(key)
// sessionStorage.removeItem(key)
// sessionStorage.removeItem(key)
}
const dialog = (params = {}) => {
if (!params.confirmButtonColor) params.confirmButtonColor = '#FF7336'
return Dialog.confirm(params)
/**
* 日期格式转换
*/
const dateFormate = (str, type) => {
let txt = 'YYYY-MM-DD'
if (type) {
txt = type
}
/** 拨打电话 */
const m = dayjs(str).format(txt)
return m == 'Invalid Date' ? '-' : m
}
const dialog = (params = {}) => {
if (!params.confirmButtonColor) params.confirmButtonColor = '#FF7336'
return Dialog.confirm(params)
}
/** 拨打电话 */
const makePhoneCall = phoneNumber => {
window.location.href = `tel://${phoneNumber}`
}
......@@ -154,7 +164,7 @@ const toTop = () => {
const getParams = () => {
return window.vm.$route.params
}
const getQuery = (name) => {
const getQuery = name => {
const [url, paramsList] = window.location.href.split('?')
if (!paramsList) return name ? null : {}
const param = paramsList.split('&')
......@@ -195,6 +205,7 @@ const utils = {
touchend,
throttle,
decimal,
dateFormate,
dialog,
toTop
}
......
......@@ -37,15 +37,21 @@
<script>
import api from '@/api/teamWork'
import constantData from './constantData.js'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
name: 'ReportDetail',
mixins: [reportTrackFunMixin], // 导入混入
data() {
return {
title: '督导日报',
itemData: {},
config: [],
taskIdKey: ''
taskIdKey: '',
eventCodeObj: {
dailyReport: 'supervisor_h5_day_detail',
monthReport: 'supervisor_h5_monthly_detail'
}
}
},
created() {
......@@ -53,6 +59,7 @@ export default {
const strategy = constantData.JUMP_STRATEGY_MAP[detailType] || {}
document.title = strategy.title || '督导日报'
this.taskIdKey = strategy.taskIdKey
this.setReportTrackData(0, this.eventCodeObj[this.taskIdKey], {})
try {
const storedItem = sessionStorage.getItem('reportDetailItem')
......@@ -134,11 +141,11 @@ export default {
.navigation-header {
:deep(.van-nav-bar__title) {
font-size: var(--fontSize34, 17px);
color: #000000E5;
color: #000000e5;
font-weight: 600;
}
:deep(.van-icon) {
color: #000000E5;
color: #000000e5;
}
}
......
......@@ -41,9 +41,11 @@
<script>
import constantData from './constantData.js'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
name: 'SpecialTaskDetail',
mixins: [reportTrackFunMixin], // 导入混入
data() {
return {
task: {},
......@@ -51,6 +53,7 @@ export default {
}
},
created() {
this.setReportTrackData(0, 'supervisor_h5_specificTask_detail', {})
try {
const storedItem = sessionStorage.getItem('specialTaskDetailItem')
if (storedItem) {
......
......@@ -35,9 +35,11 @@
<script>
import constantData from './constantData.js'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
name: 'SpecialTaskList',
mixins: [reportTrackFunMixin], // 导入混入
data() {
return {
title: '专项任务列表',
......@@ -48,6 +50,7 @@ export default {
created() {
this.title = this.$route.query.title || '专项任务列表'
this.setReportTrackData(0, 'supervisor_h5_specificTask_list', {})
try {
const storedItem = sessionStorage.getItem('reportDetailItem')
if (storedItem) {
......
<template>
<div class="team-list-page">
<!-- <van-nav-bar
title="工作台"
:border="false"
fixed
placeholder
class="navigation-header"
/> -->
<div class="bg" v-if="!isSticky"></div>
<div class="container">
......@@ -88,9 +80,11 @@ import dateSearch from '@/components/dateSearch/dateSearch.vue'
import SearchBar from '@/components/searchBar/index.vue'
import StaticInfo from '@/components/staticInfo/index.vue'
import constantData from './constantData.js'
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
name: 'TeamList',
mixins: [reportTrackFunMixin], // 导入混入
components: {
dateSearch,
SearchBar,
......@@ -230,10 +224,8 @@ export default {
return isNeg ? `-${res}` : res
},
tabClick(index) {
const eventCode = ['supervisor_dayTask_tab', 'supervisor_weeklyTask_tab', 'supervisor_monthlyTask_tab', 'supervisor_specificTask_tab']
if (this.$track) {
this.$track.setTrackData(0, eventCode[index], {}, '')
}
const eventCode = ['supervisor_h5_dayTask_tab', 'supervisor_h5_weeklyTask_tab', 'supervisor_h5_monthlyTask_tab', 'supervisor_h5_specificTask_tab']
this.setReportTrackData(0, eventCode[index], {})
this.tabIndex = index
// this.onRefresh()
},
......@@ -353,7 +345,7 @@ export default {
.data-container {
box-sizing: border-box;
height: calc(100vh - 90px);
// padding-bottom: env(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
overflow: auto;
.sticky-box {
&.is-sticky {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!