1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { includeList } from './router.config.js' // 配置信息
- import ajaxService from '@/services/ajax.service.js'
- import UserService from '@/services/user.service'
- const UserApi = new UserService(ajaxService)
- // 校验是否为配置的路径
- const isInclude = (url) => {
- if (!url) return false
- return includeList.some(item => url.indexOf(item.url) > -1)
- }
- // 校验返回页面类型
- const isIncludeType = (url) => {
- if (!url) return false
- return includeList.find(item => url === item.url)
- }
- // 参数
- const userSync = uni.getStorageSync('userInfo')
- const defaultParams = {
- pagePath: '', //页面路径
- accessDuration: 0, //浏览时长初始值为 0
- pageType: '', //页面类型
- pageLabel: '', //页面标签
- userId: userSync ? userSync.userId : 0, //用户Id
- productId: 0 //商品Id
- }
- // 上送接口Api
- const userRecordStatistics = (params) => {
- UserApi.userRecordStatistics(params)
- .then(response => {
- console.log('◆◇◆◇上送用户行为记录成功◇◆◇◆')
- })
- .catch(error => {
- console.log('◇◆◇◆上送用户行为记录异常◇◆◇◆')
- return
- })
- }
- // 页面进入
- const onEnter = (route, map, log) => {
- /* 需要什么东西就加载route里面 route.query可以获取到当前页面的参数 */
- log('页面进入:', route.path, route.query, map)
- }
- // 页面离开
- const onLeave = (route, map, log) => {
- console.log('\n')
- console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
- console.log('页面离开')
- defaultParams.pageType = isIncludeType(route.path).pageType
- defaultParams.accessDuration = Date.now() - route.time
- defaultParams.pageLabel = uni.getStorageSync('pageLabel')
- userRecordStatistics(defaultParams)
- console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
- console.log('\n')
- }
- export default { onEnter, onLeave }
|