zhao_js
2023-11-15 b44e169dd8a6e0f15d3788970176922e96aec6e1
uniapp/App.vue
@@ -11,11 +11,14 @@
   // #endif
   export default {
      onLaunch: function() {
         // #ifdef APP-PLUS
         //推送开始
         /* var info = plus.push.getClientInfo()
         console.log(info);
         // 获取当前设备的客户端id,传给后台,实现指定用户
         info && uni.setStorageSync('clientInfo', info)
         info && uni.setStorageSync('clientInfo', info) */
         this.getPushCid();
         // 使用5+App的方式进行监听消息推送
         //消息点击事件  
         //【APP在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。  
@@ -30,10 +33,12 @@
               } else { //APP在线,收到消息不会包含type属性,这时的payload是JSON字符串,需要转为JSON对象  
                  payload = JSON.parse(msg.payload);
               }
               if (payload != null || payload != undefined) {
                  // var messageType = payload.messageType; 
                  // onLaunch 生命周期里,页面跳转有问题,跳不过去
                  // 应该是页面还没加载,加上定时后,就可以了;
                  console.log(payload);
                  setTimeout(() => {
                     uni.navigateTo({
                        url: payload
@@ -42,6 +47,7 @@
               }
            } else { // Android
               var payload = msg.payload;
               console.log(payload);
               if (payload != null || payload != undefined) {
                  // onLaunch 生命周期里,页面跳转有问题,跳不过去
                  // 应该是页面还没加载,加上定时后,就可以了; 
@@ -56,6 +62,7 @@
         //收到透传消息  
         //只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息  
         plus.push.addEventListener("receive", function(msg) {
            console.log('receive', JSON.stringify(msg))
            //业务代码
            // IOS
            if (uni.getSystemInfoSync().platform == 'ios') {
@@ -64,25 +71,33 @@
               if (msg.type == "receive") {
                  //创建本地消息,发送的本地消息也会被receive方法接收到,但没有type属性,且aps是null  
                  plus.push.createMessage(msg.content, JSON.stringify(msg), {
                     title: messageTitle
                     title: messageTitle,
                     //icon:'/static/images/app/pushlogo.png'
                  });
               }
            } else { // Android
               var payload = JSON.parse(msg.content);
               console.log(msg.content);
               plus.push.createMessage(msg.content, msg.payload, {
                  title: messageTitle
                  //icon:'/static/images/app/pushlogo.png'
               });
               /* var payload = JSON.parse(msg.content);
               var messageTitle = payload.title;
               var messageContent = payload.content;
               plus.push.createMessage(messageContent, payload, {
                  title: messageTitle
               })
               }) */
            }
         }, false);
         //消息推送结束
         plus.push.addEventListener('click', res => {
            console.log(res);
         }); */
         });
         APPUpdate();
         // #endif
         this.getAppInfo()
         this.getAppInfo();
         //this.that.bcInit();
         let userInfo = uni.getStorageSync('userInfo')
         if (userInfo.id) {
            this.login(userInfo)
@@ -123,9 +138,11 @@
                  this.globalData.systemLevel = e.system;
                  this.globalData.equipmentNumber = idfa.value()
               };
               this.getArgument(true);
               // #endif
            }
         })
      },
      globalData: {
@@ -136,25 +153,34 @@
         canlisten: true,
         appinfo: {},
         ifwt: 0,
         hasinit:false,
         hasinit: false,
         hasbcinit: false,
         isLaunch: false,
         argumentStr: ''
      },
      data() {
         return {
         }
      },
      onShow: function() {
         var that = this;
         uni.getNetworkType({
            success:function(res){
            success: function(res) {
               if (res.networkType == 'none') {
                  uni.showModal({
                     title: '网络链接失败',
                     content: '检测到网络权限可能设置为关闭,您可以在“设置”中检查无线数据及蜂窝移动网络'
                  })
               }else{
                  console.log("是否请求过:"+that.globalData.hasinit)
                  if(!that.globalData.hasinit)
                  {
               } else {
                  if (!that.globalData.hasinit) {
                     that.getAppInfo();
                  }
                  if (!that.globalData.hasbcinit) {
                     console.log("初始化百川插件")
                     that.bcInit();
                  }
                  /* let appInfo = utils.getCacheSync('appInfo')
                  if(appInfo == "" || appInfo == undefined){
                     console.log("获取方法")
@@ -168,28 +194,112 @@
            var route = routes[routes.length - 1].route
         }
         // #ifdef APP-PLUS
         console.log(this.globalData.canlisten)
         if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain') {
         if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain' && route !=
            'pages/rankinglist/compareprice') {
            getClipboard()
         }
         that.getArgument();
         // #endif
      },
      onHide: function() {},
      methods: {
         ...mapMutations(['login']),
         bcInit: function() {
            var that = this;
            //uni.getSystemInfoSync().platform == 'ios'
            if (true) {
               const plug = uni.requireNativePlugin('xiguazhu-baichuan');
               plug.init({}, result => {
                  //console.log('1111111111111111111');
                  console.log(result); // code等于0就是初始化成功
                  if (result.code == 0) {
                     that.globalData.hasbcinit = true;
                  }
               });
            } else {
               that.globalData.hasbcinit = true;
            }
         },
         targetArgument(args) {
            var toarg = args.replace('dafanguan://', '');
            uni.navigateTo({
               url: toarg
            });
            /* var argObj = JSON.parse(decodeURIComponent(toarg));
            switch (argObj.totype) {
               case "0": //内链
                  if (argObj.url) {
                     uni.navigateTo({
                        url: argObj.url
                     });
                  }
                  break;
               default:
                  break;
            } */
         },
         getArgument(isload = false) {
            if (this.globalData.argumentStr && this.globalData.argumentStr.length > 0) {
               return;
            }
            try {
               var args = plus.runtime.arguments;
               console.log(args);
               if (args) {
                  if (isload) {
                     this.globalData.argumentStr = args;
                     return;
                  }
                  plus.runtime.arguments = "";
                  plus.runtime.arguments = null;
                  this.targetArgument(args);
               }
            } catch (es) {
               console.log(es)
            }
         },
         getPushCid: function() {
            // #ifdef APP-PLUS
            var info = plus.push.getClientInfo()
            if (info && info.clientid != 'null') { // 获取当前设备的客户端id,传给后台,实现指定用户
               uni.setStorageSync('clientInfo', info);
               this.updatePushCid();
            } else {
               console.log('没有获取到');
               setTimeout(() => {
                  this.getPushCid();
               }, 1000)
            }
            // #endif
         },
         updatePushCid: function() {
            let clientInfo = uni.getStorageSync('clientInfo');
            if (clientInfo && clientInfo != 'null' && clientInfo.clientid) {
               console.log('开始更新:' + clientInfo.clientid);
               this.$u.api.updateCid({
                  pushcid: clientInfo.clientid
               }).then(e => {}).catch(function(err) {})
            } else {
               this.getPushCid();
            }
         },
         getAppInfo: function() {
            var that = this;
            that.globalData.hasinit = true;
            this.$u.api.comminInt({}).then(e => {
               console.log(e)
               if (e.code != 0) return that.$alert(e.msg)
               that.globalData.hasinit=true;
               if (e.code != 0) {
                  that.globalData.hasinit = false;
                  return that.$alert(e.msg)
               }
               that.globalData.appinfo = e.data.basic
               utils.setCache('appInfo', e.data.basic)
               utils.setCache('baseUrl', this.$u.http.config.baseUrl)
               // #ifdef APP-PLUS
                if (plus.os.name == 'iOS') {
                  if (that.globalData.appinfo.iosExamine && plus.runtime.version == e.data.basic.IosExamineV) {
               if (plus.os.name == 'iOS') {
                  if (that.globalData.appinfo.iosExamine && plus.runtime.version == e.data.basic
                     .IosExamineV) {
                     that.globalData.ifwt = 0
                  } else {
                     if (plus.runtime.isApplicationExist({
@@ -203,35 +313,39 @@
                     }
                  }
               } else {
                  if (plus.runtime.isApplicationExist({pname:'com.tencent.mm',
                  if (plus.runtime.isApplicationExist({
                        pname: 'com.tencent.mm',
                        action: 'weixin://'
                     })) {
                        console.log("安卓端已安装微信")
                     that.globalData.ifwt = 1 //是否安装微信 1代表安装
                  } else {
                     console.log("安卓端未安装微信")
                     that.globalData.ifwt = 0
                  }
               }
               // #endif
            }).catch(function(err) {})
            }).catch(function(err) {
               that.globalData.hasinit = false;
            })
         },
          watch:function(method,istr){
                         var obj=this.globalData
                         console.log(obj)
                         Object.defineProperty(obj,istr,{
                         configurable:true,
                         enumerable:true,
                         set:function(value){
                             this._consumerGoodsStatus=value
                             method(value)
                         },
                         get:function(value){
                                     return this._consumerGoodsStatus
                                 }
                             })
                         },
         watch: function(method, istr) {
            var obj = this.globalData
            console.log(obj)
            Object.defineProperty(obj, istr, {
               configurable: true,
               enumerable: true,
               set: function(value) {
                  this._consumerGoodsStatus = value
                  method(value)
               },
               get: function(value) {
                  return this._consumerGoodsStatus
               }
            })
         },
      },
   }
</script>
@@ -253,4 +367,4 @@
   }
   /* #endif */
</style>
</style>