123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- var app = getApp(); //获取应用实例
- const util = require('@/static/utils/util.js');
- const config = require('@/static/config.js');
- import requestConfig from '@/static/lib/requestConfig';
- export default {
- data() {
- return {
- isSendImg: false, //当前页面是否正在处于选择本地图片的状态-选择图片会触发小程序的隐藏事件,需要单独处理
- previewFlag: false, //当前页面是否预览了图片-预览图片会触发小程序的隐藏事件,需要单独处理
- loadPromise: new Promise((resolve) => {
- this.loadedCompleteFun = function() {
- console.log('onload结束');
- resolve()
- }
- }),
- }
- },
- watch: {},
- async onLoad(options) {
- let shareCity = ''; //分享携带的城市信息
- let houseId = ''; //分享携带的项目id
- let shareUserId = ''; //分享携带的助力发起人id
- if (!options) { //如果不存在则直接返回
- this.loadedCompleteFun();//通告加载已经结束
- return false;
- }
- // let lastPage = getCurrentPages()[getCurrentPages().length-2] ? getCurrentPages()[getCurrentPages().length-2].$vm : null;
- // if(lastPage){
- // if(lastPage.componentId){
- // options.componentId = lastPage.componentId;
- // }
- // if(lastPage.componentType){
- // options.componentType = lastPage.componentType;
- // }
- // if(lastPage.diyArea){
- // options.diyArea = lastPage.diyArea;
- // }
- // }
- if(app.globalData.componentId){
- options.componentId = app.globalData.componentId;
- options.componentType = app.globalData.componentType;
- options.diyArea = app.globalData.diyArea;
- app.globalData.componentId = '';//清空该值
- app.globalData.componentType = '';//清空该值
- app.globalData.diyArea = false;//清空该值
- }
- this.pvCurPageParams = JSON.stringify(options);
-
- if (options.gdt_vid) { //从朋友圈广告进入的带有clickid
- app.globalData.clickId = options.gdt_vid;
- }
- if (options.scene) { //如果存在该参数,则说明是通过数量无限制的小程序码进来的
- const scene = decodeURIComponent(options.scene); // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
- options.shareToken = scene; //说明用户携带分享信息
- console.log('被scene先覆盖了')
- }
- //将渠道存至全局,留电接口需要用
- if (options.shareToken && options.shareToken != "null" && options.shareToken != "undefined") {
- app.globalData.fromChannel = options.shareToken;
- // #ifdef H5
- var userInfo = uni.getStorageSync('userInfo');
- if(userInfo){
- userInfo.fromChannel = options.shareToken;
- uni.setStorageSync('userInfo', userInfo);
- }
- // #endif
- }
- // 解密对应的客户来源-同时防止重复解密
- if (app.globalData.fromChannel && app.globalData.oldFromChannel != app.globalData.fromChannel) {
- console.log("***开始解密来源信息***", app.globalData.fromChannel);
- var param = {
- shareSign: app.globalData.fromChannel
- };
- const res = await requestConfig('decryptShareSign', param, true);
- console.log("***decryptHandle***", res);
- if (res && res.success) {
- app.globalData.oldFromChannel = app.globalData.fromChannel;//解密成功后记录
- console.log("***解密来源信息成功***", res.single);
- if (res.single) {
- // app.globalData.shareId = res.single.customerId;
- if (res.single.attrs) {// attrs 是字符串形式存储在数据库服务器上
- res.single.attrs = JSON.parse(res.single.attrs);
- }
- shareCity = res.single.attrs ? res.single.attrs.shareCity : '';//赋值分享者城市
- shareUserId = res.single.attrs ? res.single.attrs.shareUserId : '';
- houseId = res.single.houseId || options.houseId || '';
- app.globalData.exchangedFromChannel = JSON.stringify(res.single);//解密后的明文
- app.globalData.isZhuanFaFromProject = houseId;
- }
- } else {
- let trackparam = {
- type: 'mini-program-Error', //埋点类型
- pvCurPageName: 'app.js-decrypt', //当前页面名称
- expand: JSON.stringify(res) + ";brandId=" + config.brandId + ";param=" + JSON.stringify(
- param), //扩展字段
- };
- util.trackRequest(trackparam);
- }
- }
- //检查如果不触发解密的情况(相邻几次的秘钥是一样的)
- //或者 不存在解密时 即 fromChannel 和 oldFromChannel 都为空
- //则比对最新的城市解密记录情况,匹配的上,则取最新解密记录的城市刷新当前城市
- if (app.globalData.oldFromChannel == app.globalData.fromChannel) {
- let single = app.globalData.exchangedFromChannel ? JSON.parse(app.globalData.exchangedFromChannel) : {};
- shareCity = single.attrs ? single.attrs.shareCity : '';
- shareUserId = single.attrs ? single.attrs.shareUserId : '';
- }
- if(options.shareCity){
- shareCity = options.shareCity;
- }
- if(shareCity){//存在分享城市,则更新为分享人所在的城市
- app.addCustomerCity(shareCity);
- }
- if(options.houseId){
- houseId = options.houseId;
- }
- let currPage = getCurrentPages()[getCurrentPages().length - 1] ? getCurrentPages()[getCurrentPages().length - 1].$vm : null;
- if(currPage){
- currPage.shareUserId = shareUserId ? shareUserId : '';
- currPage.houseId = houseId ? houseId : '';
- }
- let shareOpenId = options.shareOpenId ? options.shareOpenId : '';
- if (app.globalData.exchangedFromChannel) {
- var _t = JSON.parse(app.globalData.exchangedFromChannel);
- if (_t) {
- _t.shareOpenId = shareOpenId;
- app.globalData.exchangedFromChannel = JSON.stringify(_t);
- }
- } else {
- let params = {
- shareOpenId: shareOpenId
- };
- app.globalData.exchangedFromChannel = JSON.stringify(params);
- }
- console.warn("---loadedCompleteFun---")
- this.loadedCompleteFun();//通告加载已经结束
- },
- onShow() {
- // this.isSendImg = false; //还原默认值-这里不能还原,因为微信在处理拍照选择图片时,是分两个阶段的
- // 阶段1:拍照,开始时,会把小程序退到后台,会触发onhide;拍照结束后,会回到小程序的当前页面-页面执行onshow
- // 阶段2:选择图片,会进入选择图片的原生组件-小程序退到后台执行onhide;图片选择完毕后,会执行onshow
- // 上述两个阶段存在onshow事件,重置的话,会导致阶段2会执行断开socket的方法-详见App.vue 的onhide方法
- },
- onUnload() {
- console.warn("---onUnload---")
- app.hidePage();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- console.warn("---onhide---")
- app.hidePage();
- },
- methods: {
- // 通告加载完成事件
- loadedCompleteFun() {},
- /**
- * 获取当前页面的数据,为埋点用
- */
- getCurrentPageParam() {
- return this.pvCurPageParams
- },
- // 处理分享路径的公共方法
- shareInitPath(){
- let path = '';
- let shareToken = app.globalData.shareToken || '';//当前用户的openid
- let shareOpenId = app.globalData.openid || '';//当前用户的openid
- let houseId = this.houseId || '';//当前用户的openid
- let pageId = this.pageId || '';//当前页面的pageId
- let activityId = this.activityId || '';//当前页面的activityId
- let liveStreams = this.liveStreams || '';//当前页面的直播地址
- let layoutId = this.layoutId || '';//当前页面的户型id
- // 当前的分享参数
- // 为了判断返回是到项目首页 还是集团页面 同时,也具有判断当前用户是来自分享的功能
- let fromProject = houseId ? app.globalData.projectShare : app.globalData.brandShare;
- path = "shareToken=" + shareToken
- + "&shareOpenId=" + shareOpenId
- + "&houseId=" + houseId
- + '&fromProject=' + fromProject
- + "&pageId=" + pageId;
- if(activityId){
- path += "&activityId=" + activityId;
- }
- if(liveStreams){
- path += "&liveStreams=" + liveStreams;
- }
- if(layoutId){
- path += "&layoutId=" + layoutId;
- }
- console.warn("***shareInitPath***",path);
- return path;
- },
- }
- }
|