1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // 统计数据
- import Vue from 'vue'
- const defaultParams = {
- pagePath: '', //页面路径
- accessDuration: 0, //浏览时长初始值为 0
- pageType: '', //页面类型
- pageLabel: '', //页面标签
- userId: 0, //用户Id
- productId: 0 //商品Id
- }
- const cmSysMixins = {
- data() {
- return {
- cmSysParams:Object.assign({}, defaultParams),
- clearTimeSet: null,
- enterTime:null,
- outTime:null
- }
- },
- onLoad() {
- let that = this
- // this.cmSysVitaSetTime() // 页面加载完成后开始计时
- // uni.addInterceptor('navigateTo', { //监听跳转
- // success(e) {
- // console.log('navigateTo============')
- // that.cmSysVitaMixins()
- // }
- // })
- // uni.addInterceptor('redirectTo', { //监听关闭本页面跳转
- // success(e) {
- // console.log('redirectTo============')
- // that.cmSysVitaMixins()
- // }
- // })
- // uni.addInterceptor('switchTab', { //监听tabBar跳转
- // success(e) {
- // console.log('switchTab============')
- // that.cmSysVitaMixins()
- // }
- // })
- // uni.addInterceptor('navigateBack', { //监听tabBar跳转
- // success(e) {
- // console.log('navigateBack============')
- // that.cmSysVitaMixins()
- // }
- // })
- },
- methods: {
- async cmSysVitaSetTime() {
- //设置定时器
- const userInfo = await this.$api.getStorage()
- const pages = getCurrentPages()
- const currentPage = pages[pages.length - 1]
- this.cmSysParams.pagePath = `/${currentPage.route}`
- this.cmSysParams.userId = userInfo ? userInfo.userId : 0
- this.clearTimeSet = setInterval(() => {
- this.cmSysParams.accessDuration++
- }, 1000)
- },
- cmSysVitaMixins() { // 上送后台接口,将浏览时长等信息传到后台,离开当前路由后调用
- console.log(`页面路径:${this.cmSysParams.pagePath}`, `停留:${this.cmSysParams.accessDuration}s`,
- `标签:${this.cmSysParams.pageLabel}`)
- console.log('上送用户参数', this.cmSysParams)
- // this.userRecordStatistics(this.cmSysParams)
- this.cmSysParams = Object.assign({}, defaultParams)
- clearInterval(this.clearTimeSet) // 离开页面后清除定时器
- },
- userRecordStatistics(cmSysParams){// 上送用户行为记录接口
- this.UserService.userRecordStatistics(cmSysParams)
- .then(response => {
- console.log('<-------上送用户行为记录成功------>')
- })
- .catch(error => {
- console.log('<-------上送用户行为记录异常------>')
- })
- },
- // onHide(){
- // this.cmSysVitaMixins()
- // },
- // onUnload(){
- // this.cmSysVitaMixins()
- // }
- }
- }
- export default cmSysMixins
|