Commit b6e750dc by chenwq

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

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