zhaojs
2023-07-26 eb4d171a50e4940d4822ec57641ba24be7747afa
uniapp/App.vue
@@ -11,7 +11,7 @@
   // #endif
   export default {
      onLaunch: function() {
         // #ifdef APP-PLUS
         //推送开始
         /* var info = plus.push.getClientInfo()
@@ -142,27 +142,27 @@
         canlisten: true,
         appinfo: {},
         ifwt: 0,
         hasinit:false,
         hasbcinit:false,
         isLaunch:false
         hasinit: false,
         hasbcinit: false,
         isLaunch: false,
         argumentStr: ''
      },
      onShow: function() {
         var that = this;
         uni.getNetworkType({
            success:function(res){
            success: function(res) {
               if (res.networkType == 'none') {
                  uni.showModal({
                     title: '网络链接失败',
                     content: '检测到网络权限可能设置为关闭,您可以在“设置”中检查无线数据及蜂窝移动网络'
                  })
               }else{
                  if(!that.globalData.hasinit)
                  {
               } else {
                  if (!that.globalData.hasinit) {
                     that.getAppInfo();
                  }
                  if(!that.globalData.hasbcinit)
                  {
                  if (!that.globalData.hasbcinit) {
                     console.log("初始化百川插件")
                     that.bcInit();
                  }
@@ -179,44 +179,68 @@
            var route = routes[routes.length - 1].route
         }
         // #ifdef APP-PLUS
         if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain'&&route!='pages/rankinglist/compareprice') {
         if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain' && route !=
            'pages/rankinglist/compareprice') {
            getClipboard()
         }
         this.getArgument();
         // #endif
      },
      onHide: function() {},
      methods: {
         ...mapMutations(['login']),
          bcInit:function()
         {
         bcInit: function() {
            var that = this;
            if (uni.getSystemInfoSync().platform == 'ios')
            {
            if (uni.getSystemInfoSync().platform == 'ios') {
               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;
                  console.log(result); // code等于0就是初始化成功
                  if (result.code == 0) {
                     that.globalData.hasbcinit = true;
                  }
               });
            }
            else{
               that.globalData.hasbcinit=true;
            } else {
               that.globalData.hasbcinit = true;
            }
         },
         getPushCid:function()
         {
         getArgument() {
            try {
               var args = plus.runtime.arguments;
               if (args) {
                  /* if (this.globalData.argumentStr == args) {
                     return;
                  }
                  this.globalData.argumentStr = args; */
                  plus.runtime.arguments = "";
                  plus.runtime.arguments = null;
                  var toarg = args.replace('dafanguan://', '');
                  var argObj = JSON.parse(decodeURIComponent(toarg));
                  switch (argObj.totype) {
                     case "0": //内链
                        if(argObj.url)
                        {
                           uni.navigateTo({
                              url: argObj.url
                           });
                        }
                        break;
                     default:
                        break;
                  }
               }
            } catch (es) {
               console.log(es)
            }
         },
         getPushCid: function() {
            // #ifdef APP-PLUS
            var info = plus.push.getClientInfo()
            if(info&&info.clientid!='null')
            {// 获取当前设备的客户端id,传给后台,实现指定用户
            if (info && info.clientid != 'null') { // 获取当前设备的客户端id,传给后台,实现指定用户
               uni.setStorageSync('clientInfo', info);
               this.updatePushCid();
            }
            else{
            } else {
               console.log('没有获取到');
               setTimeout(() => {
                  this.getPushCid();
@@ -224,38 +248,33 @@
            }
            // #endif
         },
         updatePushCid:function()
         {
         updatePushCid: function() {
            let clientInfo = uni.getStorageSync('clientInfo');
            if(clientInfo&&clientInfo!='null'&&clientInfo.clientid)
            {
            if (clientInfo && clientInfo != 'null' && clientInfo.clientid) {
               console.log('开始更新');
               this.$u.api.updateCid({
                  pushcid:clientInfo.clientid
               }).then(e => {
               }).catch(function (err) {
               })
            }
            else{
                  pushcid: clientInfo.clientid
               }).then(e => {}).catch(function(err) {})
            } else {
               this.getPushCid();
            }
         },
         getAppInfo: function() {
            var that = this;
            that.globalData.hasinit=true;
            that.globalData.hasinit = true;
            this.$u.api.comminInt({}).then(e => {
               if (e.code != 0)
               {
                  that.globalData.hasinit=false;
               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({
@@ -269,7 +288,8 @@
                     }
                  }
               } else {
                  if (plus.runtime.isApplicationExist({pname:'com.tencent.mm',
                  if (plus.runtime.isApplicationExist({
                        pname: 'com.tencent.mm',
                        action: 'weixin://'
                     })) {
                     that.globalData.ifwt = 1 //是否安装微信 1代表安装
@@ -279,25 +299,27 @@
                  }
               }
               // #endif
            }).catch(function(err) {that.globalData.hasinit=false;})
            }).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>
@@ -319,4 +341,4 @@
   }
   /* #endif */
</style>
</style>