zhaojs
2023-07-13 70f5b82bc3fceafac2faf470280876b0eca6fac8
uniapp/App.vue
@@ -14,8 +14,10 @@
         // #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在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。  
@@ -56,6 +58,7 @@
         //收到透传消息  
         //只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息  
         plus.push.addEventListener("receive", function(msg) {
            console.log('receive', JSON.stringify(msg))
            //业务代码
            // IOS
            if (uni.getSystemInfoSync().platform == 'ios') {
@@ -64,7 +67,8 @@
               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
@@ -79,7 +83,7 @@
         //消息推送结束
         plus.push.addEventListener('click', res => {
            console.log(res);
         }); */
         });
         APPUpdate();
         // #endif
         this.getAppInfo();
@@ -139,6 +143,7 @@
         ifwt: 0,
         hasinit:false,
         hasbcinit:false,
         isLaunch:false
         
      },
      onShow: function() {
@@ -151,13 +156,13 @@
                     content: '检测到网络权限可能设置为关闭,您可以在“设置”中检查无线数据及蜂窝移动网络'
                  })
               }else{
                  console.log("是否请求过:"+that.globalData.hasinit)
                  if(!that.globalData.hasinit)
                  {
                     that.getAppInfo();
                  }
                  if(!that.globalData.hasbcinit)
                  {
                     console.log("初始化百川插件")
                     that.bcInit();
                  }
                  /* let appInfo = utils.getCacheSync('appInfo')
@@ -173,7 +178,6 @@
            var route = routes[routes.length - 1].route
         }
         // #ifdef APP-PLUS
         console.log(this.globalData.canlisten)
         if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain') {
            getClipboard()
         }
@@ -186,11 +190,9 @@
          bcInit:function()
         {
            var that = this;
            console.log(uni.getSystemInfoSync().platform);
            if (uni.getSystemInfoSync().platform == 'ios')
            {
               const plug = uni.requireNativePlugin('xiguazhu-baichuan');
               console.log(plug)
               plug.init({}, result => {
                  //console.log('1111111111111111111');
                  console.log(result);   // code等于0就是初始化成功
@@ -200,13 +202,53 @@
                  }
               });
            }
            else{
               that.globalData.hasbcinit=true;
            }
         },
         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('开始更新');
               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)
@@ -229,7 +271,6 @@
                  if (plus.runtime.isApplicationExist({pname:'com.tencent.mm',
                        action: 'weixin://'
                     })) {
                        console.log("安卓端已安装微信")
                     that.globalData.ifwt = 1 //是否安装微信 1代表安装
                  } else {
                     console.log("安卓端未安装微信")
@@ -237,7 +278,7 @@
                  }
               }
               // #endif
            }).catch(function(err) {})
            }).catch(function(err) {that.globalData.hasinit=false;})
            
         },