Browse Source

commit -m 用户行为记录轨迹

zhengjinyi 2 years ago
parent
commit
2fe3486382

+ 0 - 1
App.vue

@@ -1,5 +1,4 @@
 <script>
-	// import cmSysMixins from '@/mixins/cmSysMixins.js'
 	import appMixins from '@/mixins/appMixins.js'
 	export default {
 		mixins: [appMixins],

+ 0 - 38
js_sdk/pocky-route-gurads/lib/hackRoute.js

@@ -1,38 +0,0 @@
-/**
- * hack uniapp的路由函数b
- * @param {Function} callback
- * @return {never}
- */
-export const hackUniRoute = function (callback) {
-    // 路由跳转的函数key值
-    const UNI_ROUTE_ACTIONS = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab', 'navigateBack'];
-
-    // 函数缓存容器
-    const cacheFunc = {};
-
-    // 保存原函数引用
-    UNI_ROUTE_ACTIONS.forEach((key) => {
-        cacheFunc[key] = uni[key];
-    });
-
-    // 重写方法
-    UNI_ROUTE_ACTIONS.forEach((key) => {
-        uni[key] = (opts, routeGuardsOpts) => {
-            // 取消拦截并直接运行
-            if (routeGuardsOpts === false) {
-                cacheFunc[key](opts);
-            } else {
-                // 处理所有钩子
-                const defaultOpts = { action: key };
-                const newOpts = Object.assign(defaultOpts, opts);
-                const actionFunc = function (customOpts) {
-                    const lastOpts = Object.assign(newOpts, customOpts);
-
-                    cacheFunc[lastOpts.action](lastOpts);
-                };
-
-                callback.call(this, newOpts, actionFunc);
-            }
-        };
-    });
-};

+ 0 - 124
js_sdk/pocky-route-gurads/lib/handleHooks.js

@@ -1,124 +0,0 @@
-import { isError, getCurStack, print } from './utils';
-
-/**
- * 处理 全局钩子队列
- * @param {Object} to
- * @param {Function} uniRunRoute 被hack的uniapp路由方法
- */
-export const handleGlobalHooksQueue = function (to, uniRunRoute) {
-    // 跳过 h5环境中, 调用系统的tabbar功能('tabbar')或系统的navbar上的返回功能('backbutton'), 会触发uni的路由方法
-    if (['tabBar', 'backbutton'].includes(to.from)) return uniRunRoute();
-
-    // 获取当前路由栈信息
-    const from = getCurStack();
-
-    // 跳过 app端 首次进入页面会调用uni路由方法, 导致获取当前路由栈(from)为空,所有直接运行,不进行拦截
-    if (from === false) return uniRunRoute();
-
-    iteratorHook(
-        this.beforeHooks,
-        handleNextPipe.bind(this),
-        () => {
-            uniRunRoute();
-            handleAfterHook.call(this, to, from);
-        },
-        {
-            to,
-            from,
-            uniRunRoute
-        }
-    );
-};
-
-/**
- * 处理 全局后置钩子
- * @param {Object} to
- * @param {Object} from
- */
-const handleAfterHook = function (to, from) {
-    this.afterHooks.forEach((hook) => {
-        hook(to, from);
-    });
-};
-
-/**
- * 处理 错误信息
- * @param {Object|string} err 错误信息、错误栈
- */
-const handleAbort = function (err) {
-    if (this.errorCbs.length > 0) {
-        this.errorCbs.forEach((cb) => {
-            cb(err);
-        });
-    } else {
-        print('error:' + err, 'error');
-    }
-};
-
-/**
- * 遍历并运行 钩子
- * @param {Function[]} hookQueue 钩子队列
- * @param {Function} everyCb 每次遍历都会运行的回调函数
- * @param {Function} endCb 队列运行结束后运行的回调函数
- * @param {Object} hookOpts 钩子运行需要的参数
- */
-const iteratorHook = function (hookQueue, everyCb, endCb, hookOpts) {
-    const step = (i) => {
-        // 队列运行结束,运行回调函数
-        if (i >= hookQueue.length) {
-            endCb.call(this);
-        } else {
-            // 遍历运行钩子
-            everyCb.call(this, hookQueue[i], hookOpts, (val) => {
-                // 结束钩子遍历
-                if (val === false) return;
-
-                step(++i);
-            });
-        }
-    };
-
-    step(0);
-};
-
-/**
- * 处理 有next参数的钩子(前置钩子)
- * @param {Function} hookCb 钩子函数
- * @param {Object} hookOpts 钩子运行需要的参数
- * @param {Function} iteratorNextHook 运行下一个钩子
- */
-const handleNextPipe = function (hookCb, hookOpts, iteratorNextHook) {
-    hookCb(hookOpts.to, hookOpts.from, (nextVal) => {
-        try {
-            // next(false) or next(new Error('xxx')) 中断当前的路径跳转,或中断且注册错误回调
-            if (nextVal === false || isError(nextVal)) {
-                handleAbort.call(this, nextVal);
-            }
-
-            // next('/pages/a') or next({ url: '/pages/a' }) 修改 路由
-            else if (
-                typeof nextVal === 'string' ||
-                (typeof nextVal === 'object' && typeof nextVal.url === 'string')
-            ) {
-                // 处理字符串路径
-                typeof nextVal === 'string' && (nextVal = { url: nextVal });
-
-                hookOpts.uniRunRoute(nextVal);
-                handleAfterHook.call(this, hookOpts.to, hookOpts.from);
-
-                // 更新引用,替换原来的`url`字段数据
-                hookOpts.to = Object.assign(hookOpts.to, nextVal);
-
-                // 结束钩子遍历
-                iteratorNextHook(false);
-            }
-
-            // next() 运行下一个管道(next)
-            else {
-                iteratorNextHook();
-            }
-        } catch (err) {
-            handleAbort.call(this, err);
-        }
-    });
-};

+ 0 - 41
js_sdk/pocky-route-gurads/lib/index.js

@@ -1,41 +0,0 @@
-import { install } from './install';
-import { hackUniRoute } from './hackRoute';
-import { handleGlobalHooksQueue } from './handleHooks';
-import { registerHook } from './utils';
-
-export default class uniRouteGuards {
-    constructor() {
-        // 初始化数据
-        this.beforeHooks = [];
-        this.afterHooks = [];
-        this.errorCbs = [];
-        hackUniRoute.call(this, handleGlobalHooksQueue);
-    }
-
-    /**
-     * 注册 全局前置守卫
-     * @param {Function} callback 回调函数
-     */
-    beforeEach(callback) {
-        return registerHook(this.beforeHooks, callback);
-    }
-
-    /**
-     * 注册 全局后置守卫
-     * @param {Function} callback 回调函数
-     */
-    afterEach(callback) {
-        return registerHook(this.afterHooks, callback);
-    }
-
-    /**
-     * 注册 错误回调
-     * @param {Function} errCb 错误回调函数
-     */
-    onError(errCb) {
-        return registerHook(this.errorCbs, errCb);
-    }
-}
-
-// 添加 Vue.use 功能
-uniRouteGuards.install = install;

+ 0 - 6
js_sdk/pocky-route-gurads/lib/install.js

@@ -1,6 +0,0 @@
-/**
- * Vue.use 插件安装
- * @param {Object} Vue
- * @param {*} opts
- */
-export function install(Vue, opts = {}) {}

+ 0 - 53
js_sdk/pocky-route-gurads/lib/utils.js

@@ -1,53 +0,0 @@
-/**
- * 控制台打印内容
- * @param {string} msg 内容
- * @param {string} action ['log'] 打印类型
- * @param {never}
- */
-export const print = function (msg, action = 'log') {
-    console[action]('[route-guards] ' + msg);
-};
-
-/**
- * 判断错误对象是否是由`Error`对象实例化出来的
- * @param {Error|Object} errObj
- * @return {boolean}
- */
-export const isError = function (errObj) {
-    return Object.prototype.toString.call(errObj).includes('Error');
-};
-
-/**
- * 获取并封装当前路由栈的信息
- * @return {Object}
- */
-export const getCurStack = function () {
-    const stackAll = getCurrentPages();
-    const stackLen = stackAll.length;
-
-    // 跳过路由栈为空的情况(App端)
-    if (stackLen === 0) {
-        return false;
-    }
-
-    const curStack = stackAll[stackLen - 1];
-    const from = { url: '/' + curStack.route };
-
-    return from;
-};
-
-/**
- * 注册 钩子
- * @param {Function[]} list 钩子列表
- * @param {Function} callback 回调函数
- * @returns {Function} 用于注销当前注册钩子的闭包函数
- */
-export const registerHook = function (list, callback) {
-    list.push(callback);
-
-    return () => {
-        const index = list.indexOf(callback);
-
-        if (index !== -1) list.splice(index, 1);
-    };
-};

+ 0 - 2
main.js

@@ -4,8 +4,6 @@ import App from './App'
 import './services/index.js'
 import * as Api from '@/common/config/caimeiApi.js'
 import * as Regs from '@/common/config/common.js'
-import cmSysMixins from '@/mixins/cmSysMixins.js'
-// import './utils/router.js'
 import ResidenceTime from './plugins/simple-residence-time'
 import residence from './utils/residence.js'
 

+ 3 - 4
pages/goods/good-hot.vue

@@ -257,9 +257,8 @@
 import { mapState, mapMutations } from 'vuex'
 import uniGrader from '@/components/uni-grade/uni-grade.vue'
 import cmsMixins from '@/mixins/cmsMixins.js'
-import cmSysMixins from '@/mixins/cmSysMixins.js'
 export default{
-	mixins: [cmsMixins,cmSysMixins],
+	mixins: [cmsMixins],
 	components: {
 		uniGrader
 	},
@@ -312,6 +311,7 @@ export default{
 			this.listQuery.userId = userInfo.userId ? userInfo.userId : 0
 			this.vipFlag = userInfo.vipFlag ? userInfo.vipFlag : 0
 			this.userIdentity = userInfo.userIdentity ? userInfo.userIdentity : 0
+			uni.setStorageSync('pageLabel','新品')
 			this.GetHomeRecommend()
 			this.GetHomeNewBrandNames()
 			this.GetHomeNewFloorList()
@@ -480,8 +480,7 @@ export default{
 		}
 	},
 	onShow() {
-		this.cmSysParams.pageType = '新品橱窗'
-		this.cmSysParams.pageLabel = '新品'
+		
 	}
 }
 </script>

+ 1 - 0
pages/goods/goods-classify.vue

@@ -462,6 +462,7 @@ export default {
 			this.listQuery.id = this.pathQueryId = this.brandParam.id = option.id
 			this.listQuery.identity = this.identity
 			this.listQuery.idType = this.classifyType = this.brandParam.idType = Number(option.classType)
+			uni.setStorageSync('pageLabel',option.title)
 			uni.setNavigationBarTitle({ title: option.title })
 			this.userId = userInfo.userId ? userInfo.userId : 0
 			this.shopId = userInfo.shopId ? userInfo.shopId : 0

+ 2 - 5
pages/search/search-supplier.vue

@@ -78,14 +78,12 @@
 	import tuiNomore from '@/components/tui-components/nomore/nomore'
 	import uniStars from '@/components/uni-stars/uni-stars.vue'
 	import authorize from '@/common/config/authorize.js'	
-	import cmSysMixins from '@/mixins/cmSysMixins.js'
 	export default {
 		components:{
 			tuiLoadmore,
 			tuiNomore,
 			uniStars
 		},
-		mixins: [cmSysMixins],
 		data() {
 			return {
 				iconClass:'icon-aixin',
@@ -127,11 +125,10 @@
 					this.listQuery.keyword = option.keyWord
 					this.GetSearchSupplierList()
 				}
-				this.cmSysParams.pageType = '供应商搜索'
-				
 			},	
 			searchsupplierList(){//搜索
 				this.listQuery.pageNum=1
+				uni.setStorageSync('pageLabel',this.listQuery.keyword)
 				this.GetSearchSupplierList()
 				// 友盟埋点供应商搜索点击
 				if(process.env.NODE_ENV != 'development'){
@@ -193,7 +190,7 @@
 				}else{					
 					this.isShowClose = false
 					this.listQuery.pageNum=1
-					this.cmSysParams.pageLabel = this.listQuery.keyword
+					uni.setStorageSync('pageLabel',this.listQuery.keyword)
 					this.GetSearchSupplierList()
 				}
 			},

+ 1 - 4
pages/second/form/form.vue

@@ -289,9 +289,7 @@
 	import { uploadFileImage , uploadFilePdf } from '@/services/public.js'
 	import authorize from '@/common/config/authorize.js'
 	import $reg from '@/common/config/common.js'
-	import cmSysMixins from '@/mixins/cmSysMixins.js'
 	export default{
-		mixins: [cmSysMixins],
 		components:{
 			mpvueCityPicker,
 		},
@@ -583,8 +581,7 @@
 		},
 		onShow() {
 			this.getBrandList()
-			this.cmSysParams.pageType = '发布二手'
-			this.cmSysParams.pageLabel = '发布二手'
+			uni.setStorageSync('pageLabel','发布二手')
 			this.$api.getComStorage('userInfo').then((resolve) =>{
 				this.userIdentity = resolve.userIdentity
 				console.log(this.userIdentity)

+ 1 - 5
pages/second/product/product-details.vue

@@ -150,10 +150,8 @@
 	import cmParameter from './components/secondParameters.vue' //相关参数
 	import wxLogin from '@/common/config/wxLogin.js'
 	import { debounce } from '@/common/config/common.js'
-	import cmSysMixins from '@/mixins/cmSysMixins.js'
 	var isPreviewImg
 	export default{
-		mixins: [cmSysMixins],
 		components:{
 			uniStars,
 			customP,
@@ -226,8 +224,6 @@
 			this.isShareType = option.type
 			this.linkPath = option.path
 			this.isHeaderPoduct = true
-			this.cmSysParams.pageType = '二手商品详情';
-			this.cmSysParams.productId = this.productId
 		},
 		methods:{
 			initData(){// 初始化商品详情查询
@@ -236,7 +232,7 @@
 					this.productImage=[]
 					this.shop = response.data.shop
 					this.product = response.data
-					this.cmSysParams.pageLabel = `${response.data.brandName}`;	
+					uni.setStorageSync('pageLabel', `${response.data.brandName}`)
 					//处理商品图片列表
 					this.product.imageList.forEach(item =>{
 						this.productImage.push(item)

+ 1 - 4
pages/second/product/product-list.vue

@@ -108,9 +108,7 @@
 	import authorize from '@/common/config/authorize.js'
 	import wxLogin from '@/common/config/wxLogin.js'
 	import modalLayer from '@/components/modal-layer'
-	import cmSysMixins from '@/mixins/cmSysMixins.js'
 	export default{
-		mixins: [cmSysMixins],
 		components:{
 			modalLayer
 		},
@@ -301,8 +299,7 @@
 			}
 		},	
 		onShow() {
-			this.cmSysParams.pageType = '二手市场'
-			this.cmSysParams.pageLabel = '二手市场'
+			uni.setStorageSync('pageLabel','二手市场')
 		}
 	}
 </script>

+ 1 - 0
pages/tabBar/home/index.vue

@@ -179,6 +179,7 @@ export default {
 					this.pageList = data.homePageFloor
 					this.hotListPageFloor = data.pageFloorList
 					this.supplierObj = data.supplierImage
+					uni.setStorageSync('pageLabel','首页')
 					setTimeout(() => {
 						this.isRequest = true
 					}, 500)

+ 55 - 0
plugins/simple-residence-time/behavior.js

@@ -0,0 +1,55 @@
+import { getCurrentRoute } from './utils.js'
+
+/*默认配置*/
+const defaultOptions = {
+    strict: false,
+    enter(current) {},
+    leave(prev) {},
+    routting(current, prev) {}
+}
+
+// 用于存放页面路由信息
+const map = new Map()
+
+// 用于存放上一个页面路由信息
+let prev = null
+
+function behavior(options) {
+    const mixin = {}
+
+    options = { ...defaultOptions, ...options }
+
+    // 页面打开
+    mixin.onLoad = function() {
+        const route = getCurrentRoute()
+        if (!route) return
+        if (map.has(route.path)) return
+        map.set(route.path, route)
+        options.enter(route)
+        options.routting(route, prev)
+    }
+    // 页面显示
+    mixin.onShow = function() {
+        if (options.strict) return
+        mixin.onLoad()
+    }
+    // 页面隐藏
+    mixin.onHide = function() {
+        if (options.strict) return
+        mixin.onUnload()
+    }
+    // 页面关闭
+    mixin.onUnload = function() {
+        prev = null
+        const route = getCurrentRoute()
+        if (!route) return
+        if (!map.has(route.path)) return
+        prev = map.get(route.path)
+        map.delete(prev.path)
+        options.leave(prev)
+    }
+
+    return mixin
+}
+
+export default behavior

+ 2 - 65
plugins/simple-residence-time/index.js

@@ -1,66 +1,3 @@
-import { getCurrentRoute, showLog } from './utils.js'
+import behavior from './behavior.js'
 
-// 用于存放页面相关信息
-const map = new Map()
-
-/* 保存页面进入时的时间及其它参数信息 */
-function addTime() {
-    const route = getCurrentRoute()
-    if (!route || map.has(route.path)) return
-    const currentTime = Date.now()
-    const data = { time: currentTime, ...route }
-    map.set(route.path, data)
-    return data
-}
-
-/* 获取页面离开时的时间及其它参数信息 */
-function getTime() {
-    const route = getCurrentRoute()
-    if (!map.has(route.path)) return
-    const data = map.get(route.path)
-    map.delete(route.path)
-    return data
-}
-
-export default function(Vue, options = {}) {
-    Vue.mixin({
-        onLoad() {
-            const res = addTime()
-            if (!res) return
-            if (typeof options.onEnter === 'function') {
-                options.onEnter(res, map, showLog)
-            }
-        },
-        onShow() {
-            const res = addTime()
-            if (!res) return
-            if (typeof options.onEnter === 'function') {
-                options.onEnter(res, map, showLog)
-            }
-        },
-        onHide() {
-            console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆onHide')
-            const res = getTime()
-            if (!res) return
-            if (typeof options.onLeave === 'function') {
-                options.onLeave(res, map, showLog)
-            }
-        },
-        onUnload() {
-            console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆onUnload')
-            const res = getTime()
-            if (!res) return
-            if (typeof options.onLeave === 'function') {
-                options.onLeave(res, map, showLog)
-            }
-        },
-        beforeDestroy() {
-            console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆beforeDestroy')
-            const res = getTime()
-            if (!res) return
-            if (typeof options.onLeave === 'function') {
-                options.onLeave(res, map, showLog)
-            }
-        }
-    })
-}
+export default (Vue, options) => Vue.mixin(behavior(options))

+ 4 - 12
plugins/simple-residence-time/utils.js

@@ -1,17 +1,9 @@
-/* 获取当前展示页面 */
+/** 获取当前页面路由信息 */
 export function getCurrentRoute() {
     const pages = getCurrentPages()
-    const page = pages[pages.length - 1]
+    const len = pages.length
+    const page = pages[len - 1]
     if (!page) return
-    const route = { path: `/${page.route}`, fullPath: page.$page?.fullPath, query: page.options }
+    const route = { path: '/' + page.route, fullPath: page.$page.fullPath, query: page.options, meta: {} }
     return route
 }
-
-/* 方便打印日志 */
-export function showLog(...args) {
-    console.log('\n')
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log(...args)
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('\n')
-}

+ 3 - 3
services/user.service.js

@@ -833,10 +833,10 @@ export default class UserService {
 	 */
     userRecordStatistics(data = {}) {
 	    return this.AjaxService.get({
-	        url: '/user/record/Statistics',
+	        url: '/user/record/StatisticsApp',
 	        data,
 	        isLoading: false,
-	    })
+	    }) 
     }
-	
+	 
 }

+ 39 - 27
utils/residence.js

@@ -25,36 +25,48 @@ const defaultParams = {
     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 enter = (current) => {
+    current.meta.enterTime = Date.now()
 }
 
 // 页面离开
-const onLeave = (route, map, log) => {
-    console.log('\n',route)
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('页面离开')
-    defaultParams.pageType = isIncludeType(route.path) ? isIncludeType(route.path).pageType : ''
-    defaultParams.productId = route.query.id ? route.query.id : 0
-    defaultParams.accessDuration = Date.now() - route.time
-    defaultParams.pageLabel = uni.getStorageSync('pageLabel')
-    userRecordStatistics(defaultParams)
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('\n')
+const leave = (prev) => {
+    prev.meta.leaveTime = Date.now()
+}
+
+// 页面切换
+const routting = async (current, prev) => {
+    await userBehavior(current, prev)
+}
+
+/* 用户停留时间 */
+async function userBehavior(current, prev) {
+    try {
+        if (!prev) return
+        if (!isInclude(prev.path)) return
+        console.log('\n')
+        console.log('------------------------')
+        // 停留时长参数设置
+        defaultParams.accessDuration = prev.meta.leaveTime - prev.meta.enterTime
+        console.log('当前页面:', current.path)
+        console.log('离开页面:', prev.path)
+        // 接口参数设置
+		 const pageData = isIncludeType(prev.path)
+        defaultParams.pagePath = prev.fullPath
+        defaultParams.pageType = pageData ? pageData.pageType : ''
+        defaultParams.productId = prev.query.id ? prev.query.id : 0
+        defaultParams.pageLabel = uni.getStorageSync('pageLabel')
+        // 调用接口
+        console.log('记录路径:', prev.path, '停留时间:', defaultParams.accessDuration,'ms','标签:', defaultParams.pageLabel)
+        await UserApi.userRecordStatistics(defaultParams)
+        console.log('---用户行为轨迹记录成功---')
+        console.log('------------------------')
+        console.log('\n')
+    } catch (e) {
+        console.log(e)
+        console.log('---用户行为轨迹记录异常---')
+    }
 }
 
-export default { onEnter, onLeave }
+export default { enter, leave, routting }

+ 9 - 8
utils/router.config.js

@@ -1,12 +1,13 @@
 // 配置需要统计的路径
 export const includeList = [
-    { url:'/pages/goods/product', pageType:'新商品详情',pageLabel:'' },
-    { url:'/pages/goods/good-hot', pageType:'新品橱窗' ,pageLabel:'新品'},
-    { url:'/pages/second/form/form', pageType:'发布二手' ,pageLabel:'发布二手'},
-    { url:'/pages/second/product/product-list', pageType:'二手市场',pageLabel:'二手市场' },
-    { url:'/pages/second/product/product-details', pageType:'二手商品详情',pageLabel:'' },
-    { url:'/pages/search/search', pageType:'商品搜索',pageLabel:'' },
-    { url:'/pages/search/search-supplier', pageType:'供应商搜索',pageLabel:'' },
-    { url:'/pages/goods/goods-classify', pageType:'分类列表',pageLabel:'' },
+    { url:'/pages/tabBar/home/index', pageType:1},
+    { url:'/pages/goods/product', pageType:6},
+    { url:'/pages/goods/good-hot', pageType:2},
+    { url:'/pages/second/form/form', pageType:4},
+    { url:'/pages/second/product/product-list', pageType:3},
+    { url:'/pages/second/product/product-details', pageType:7},
+    { url:'/pages/search/search', pageType:8},
+    { url:'/pages/search/search-supplier', pageType:9 },
+    { url:'/pages/goods/goods-classify', pageType:10 },
 ]
 

+ 0 - 119
utils/router.js

@@ -1,119 +0,0 @@
-import Vue from 'vue'
-import UniRouteGuards from '../js_sdk/pocky-route-gurads/lib/index.js' //  路由导航守卫
-import { includeList } from './router.config.js' // 配置信息
-import ajaxService from '@/services/ajax.service.js'
-import UserService from '@/services/user.service'
-const UserApi = new UserService(ajaxService)
-// 路由导航守卫
-Vue.use(UniRouteGuards)
-
-const map = new Map()
-
-const bucketStack = []
-
-const guard = new UniRouteGuards()
-// 截取路径参数
-const getUrlParams = (appPath) => {
-    const queryArr = appPath.split('?')
-    const queryStr = queryArr[1]
-    let query = queryStr.split('&')
-    let params = {}
-    for (let i = 0; i < query.length; i++) {
-        let q = query[i].split('=')
-        if (q.length === 2) {
-            params[q[0]] = q[1]
-        }
-    }
-    return params
-}
-// 校验是否为配置的路径
-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
-        })
-}
-
-// 跳过路由白名单拦截
-guard.beforeEach((to, from, next) => {
-    console.log('\n')
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('guard.beforeEach')
-    console.log('to:', to)
-    console.log('from:', from)
-    console.log('页面拦截状态:', isInclude(to.url))
-    // if (to.action !== 'navigateBack') {
-    //     bucketStack.push(to.url)
-    //     console.log('入栈:', to.url)
-    // }
-    if (isInclude(to.url)) {
-        console.log('stay time started')
-        defaultParams.pagePath = to.url
-        if (to.url.indexOf('?') != -1) {
-            map.set(to.url.split('?')[0], Date.now())
-            const urlParams = getUrlParams(to.url)
-            if (urlParams) {
-			    defaultParams.productId = urlParams ? urlParams.id : 0
-            }
-        }else{
-            map.set(to.url, Date.now())
-        }
-    }
-    // map.set(to.url.split('?')[0], Date.now())
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('\n')
-    next()
-})
-
-guard.afterEach((to, from) => {
-    console.log('\n')
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('guard.afterEach')
-    console.log('to:', to)
-    console.log('from:', from)
-    // if (to.action === 'navigateBack') {
-    //     const lastUrl = bucketStack.pop()
-    //     map.set(lastUrl.split('?')[0], Date.now())
-    //     const current = bucketStack[bucketStack.length - 1]
-    //     if(current){
-    //         map.set(current.split('?')[0], Date.now())
-    //     }
-    //     console.log('未关闭页面栈列表:', bucketStack)
-    // }
-    if (map.has(from.url)) {
-        const beginTime = map.get(from.url)
-        defaultParams.pageType = isIncludeType(from.url).pageType
-        defaultParams.accessDuration = Date.now() - beginTime
-        defaultParams.pageLabel =  uni.getStorageSync('pageLabel')
-        console.log('页面停留时间:', (Date.now() - beginTime), '毫秒')
-        // api
-        console.log('api is action ...')
-        userRecordStatistics(defaultParams)
-    }
-    console.log('◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆')
-    console.log('\n')
-})