zjs_project hai 1 ano
pai
achega
3726467fec
Modificáronse 4 ficheiros con 35 adicións e 14 borrados
  1. 5 0
      src/App.vue
  2. 13 0
      src/mixins/commonPageMethod.js
  3. 1 0
      src/static/globlShowModel.js
  4. 16 14
      src/utils/util.js

+ 5 - 0
src/App.vue

@@ -19,6 +19,7 @@
 
 <script>
 	import {
+		setStorage,
 		getStorage,
 		pxoveItem
 	} from '@/utils/localStorage';
@@ -44,6 +45,7 @@
 		created() {
 			let userId = this.$route.query.leavePhoneCustomerId ? this.$route.query.leavePhoneCustomerId : '129130';
 			let xcxHouseId = this.$route.query.xcxHouseId ? this.$route.query.xcxHouseId : $config.xcxHouseId;
+			let query = this.$route.query;
 			// let xcxHouseId = '100296';
 			if (userId) { //如果存在用户id
 				this.$store.dispatch('setUserId', userId);
@@ -51,6 +53,9 @@
 			if (xcxHouseId) { //如果存在houseid
 				this.$store.dispatch('setHouseId', xcxHouseId);
 			}
+			if (query) { //如果存在入参
+				setStorage('queryObj', query);
+			}
 			let isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
 			this.isIOS = isIOS;
 			window.addEventListener('error', (error) => {

+ 13 - 0
src/mixins/commonPageMethod.js

@@ -8,6 +8,7 @@ export default {
 	mounted() {
 		console.warn("---mounted---",this.pvId,this.$route.meta.keepAlive)
 		if(this.pvId && !this.$route.meta.keepAlive){
+			window.currentPage = this;
 			let param = {
 				type: 'PV',
 				pvId: this.pvId,
@@ -16,11 +17,13 @@ export default {
 			};
 			util.trackRequest(param);//发送统一PV埋点
 			window.addEventListener('beforeunload', this.pvCloseHandle);
+			window.addEventListener('visibilitychange', this.visibilitychange);
 		}
 	},
 	//页面销毁时,注销监听程序|返回上一页,去往下一页等
 	destroyed(){
 		window.removeEventListener('beforeunload', this.pvCloseHandle);
+		window.removeEventListener('visibilitychange', this.visibilitychange);
 	},
 	// beforeDestroy() {
 	// 	console.warn("---beforeDestroy---")
@@ -39,6 +42,7 @@ export default {
 		// 例如保存表单数据、清理定时器等操作
 		this.pvCloseHandle();
 		window.removeEventListener('beforeunload', this.pvCloseHandle);//注销监听刷新事件
+		window.removeEventListener('visibilitychange', this.visibilitychange);
 		next();
 	},
 	beforeRouteEnter(to, from, next) {
@@ -48,6 +52,7 @@ export default {
 	activated(){
 		console.warn("activated:",this.pvId);
 		if(this.pvId && this.$route.meta.keepAlive){
+			window.currentPage = this;
 			let param = {
 				type: 'PV',
 				pvId: this.pvId,
@@ -56,9 +61,17 @@ export default {
 			};
 			util.trackRequest(param);//发送统一PV埋点
 			window.addEventListener('beforeunload', this.pvCloseHandle);
+			window.addEventListener('visibilitychange', this.visibilitychange);
 		}
 	},
 	methods: {
+		visibilitychange(){
+			if (document.visibilityState !== 'visible') { // 离开页面
+			   this.pvCloseHandle()
+			} else { // 进入页面
+			   this.pvShowHandle()
+			}
+		},
 		pvShowHandle(){
 			if(this.pvId){
 				let param = {

+ 1 - 0
src/static/globlShowModel.js

@@ -82,6 +82,7 @@ var globlShowModel = [
 	'BP_XSPACE_painting_05',
 	'BP_T_1PeopleBasin03',
 	'BP_AutoWall_51M',
+	'BP_G_grass01',
 ];
 
 module.exports = globlShowModel;

+ 16 - 14
src/utils/util.js

@@ -1,5 +1,6 @@
 import {
-	getStorage
+	getStorage,
+	setStorage
 } from '@/utils/localStorage';
 window.sessionTime = new Date();
 var util = {
@@ -157,7 +158,6 @@ var util = {
 			return
 		}
 		try {
-			var session = Number(getStorage('sessionNumber')) + 1;
 			
 			if(typeof (para.clkParams) == 'object'){
 			    let obj = {
@@ -172,13 +172,14 @@ var util = {
 			}else{
 				pvCurPageParams = {};
 			}
-			let urlObj = util.getUrlParams(location.href) || {};
-			let brandId = urlObj.special_ID || urlObj.brandId || ''
+			let queryObj = getStorage('queryObj') ? JSON.parse(getStorage('queryObj')) : null;
+			let urlObj = queryObj || util.getUrlParams(location.href) || {};
+			let brandId = urlObj.special_ID || $config.brandId || ''
 			//在页面参数里面手动添加path参数
 			pvCurPageParams.brandId = brandId;
-			pvCurPageParams.locusBehaviorName = para.locusBehaviorName || '';
-			pvCurPageParams.locusValue = para.locusValue || '';
-			pvCurPageParams.locusName = para.locusName || '';
+			pvCurPageParams.locusBehaviorName = para.locusBehaviorName || currentPage.locusBehaviorName || '';
+			pvCurPageParams.locusValue = para.locusValue || currentPage.locusValue || '';
+			pvCurPageParams.locusName = para.locusName || currentPage.locusName || '';
 			let data = {
 				session: '',
 				userAgent: navigator.userAgent.substring(0, 255) || '',
@@ -194,7 +195,7 @@ var util = {
 				createTime: this.formatTime(new Date()),
 				uploadTime: this.formatTime(new Date()),
 				product: 'h5', //iframeUrl代表是顾问分享的外链
-				project: para.project || urlObj.xcxHouseId || '',
+				project: para.project || urlObj.xcxHouseId || $config.xcxHouseId || '',
 				brandId: brandId,
 				expand: JSON.stringify(urlObj), //扩展字段
 				imTalkId: para.imTalkId || '', //IM对话编号
@@ -205,7 +206,7 @@ var util = {
 				clkName: para.clkName || '',
 				pvId: para.pvId || '', //PV埋点ID
 				clkParams: typeof para.clkParams === 'object' ? JSON.stringify(para.clkParams) : (para.clkParams || ''), //点击参数
-				pvCurPageName: para.pvCurPageName || '', //当前页面名称
+				pvCurPageName: para.pvCurPageName || currentPage.pvCurPageName || '', //当前页面名称
 				pvCurPageParams: typeof pvCurPageParams === 'object' ? JSON.stringify(pvCurPageParams) : (pvCurPageParams ||''), //当前页面参数
 				pvLastPageName: para.pvLastPageName || '', //上一页页面名称
 				pvLastPageParams: para.pvLastPageParams || '', //上一页页面参数
@@ -213,13 +214,14 @@ var util = {
 				type: para.type || '', //埋点类型
 			}
 			let timeNow = new Date().getTime();
-			if (timeNow - sessionTime > 180000 && !from_session) {
+			let session = getStorage('sessionNumber') ? Number(getStorage('sessionNumber')) : timeNow;
+			if (timeNow - sessionTime > 180000 && !urlObj.session) {
 				// session++;
-				getStorage('sessionNumber', session)
+				session = timeNow;
+				setStorage('sessionNumber', session)
 			}
-			session = Number(getStorage('sessionNumber')) + 1;
-			data.session = from_session || getStorage("cookie_id") + "_" + session || '';
-			sessionTime = timeNow
+			data.session = urlObj.session || data.userId + "_" + session || '';
+			sessionTime = timeNow;
 			// return data;
 			// app.globalData.session_id = data.session
 			// app.globalData.sessionTime = timeNow;