App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-10-22 40711118c33369ccad7ceda0fdd729bd9f117f65
pages/adgl/adhj.html
@@ -21,9 +21,14 @@
      <script type="text/javascript" src="../../js/global.js"></script>
      <script src="http://121.196.36.24:8001/Scripts/jquery-3.4.1.min.js"></script>
      <script src="http://121.196.36.24:8001/Scripts/jquery.signalR-2.2.2.min.js"></script>
      <script src="http://121.196.36.24:8001/SignalR/Hubs"></script>
      <!-- <script src="http://121.196.36.24:8001/Scripts/jquery-3.4.1.min.js"></script> -->
      <!-- <script src="http://121.196.36.24:8001/Scripts/jquery.signalR-2.2.2.min.js"></script> -->
      <!-- <script src="http://121.196.36.24:8001/SignalR/Hubs"></script> -->
      <script src="../../js/jquery-3.4.1.min.js"></script>
      <script src="../../js/jquery.signalR-2.2.2.min.js"></script>
      <script src="../../js/Hubs.js"></script>
      <script type="text/javascript">
         var pushServer = "http://demo.dcloud.net.cn/push/?";
@@ -183,15 +188,61 @@
         function CreateNotification(msg, n) {
            console.log(msg, n)
            vant.Notify(msg, n, 9999999999)
            var NotifyID = n;
            var Context = plus.android.importClass("android.content.Context");
            var main = plus.android.runtimeMainActivity();
            var Noti = plus.android.importClass("android.app.Notification");
            var NotificationManager = plus.android.importClass("android.app.NotificationManager");
            var nm = main.getSystemService(Context.NOTIFICATION_SERVICE)
            var Notification = plus.android.importClass("android.app.Notification");
            var mNotification = new Notification.Builder(main);
            var pending = plus.android.importClass("android.app.PendingIntent");
            var intent = plus.android.importClass("android.content.Intent");
            //mNotification.setOngoing(true);
            mNotification.setContentTitle("您有一条未读消息"); //标题
            mNotification.setContentText(msg); //内容
            mNotification.setSmallIcon(17301620); //图标
            mNotification.setTicker("First Time"); //通知首次出现在通知栏时的效果
            mNotification.setNumber(5); //通知集合的数量
            //var str = dateToStr(new Date());
            //mNotification.setWhen(str);//通知产生时间
            //mNotification.setContentIntent();//通知栏点击事件
            mNotification.setDefaults(Noti.DEFAULT_VIBRATE); //声音、闪灯、震动效果,可叠加
            mNotification.setPriority(Noti.PRIORITY_DEFAULT); //通知优先级
            mNotification.flags = Notification.FLAG_ONLY_ALERT_ONCE; //发起通知时震动
            var mNb = mNotification.build()
            nm.notify(NotifyID, mNb);
         }
         // wakeLock()
         // var g_wakelock = null;
         // //允许程序后台运行,以持续获取GPS位置
         // function wakeLock() {
         //    //Android
         //    var main = plus.android.runtimeMainActivity();
         //    var Context = plus.android.importClass("android.content.Context");
         //    var PowerManager = plus.android.importClass("android.os.PowerManager");
         //    var pm = main.getSystemService(Context.POWER_SERVICE);
         //    g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
         //    g_wakelock.acquire();
         // }
         $(function() {
            //前端Hub的使用,注意的是,Hub的名字是ChatHub,这里使用时首字母小写
            var work = $.connection.chatHub;
            // work
            console.log(work, 1)
            //对应后端的SendMessage函数,消息接收函数
            // console.log(work.client.sendMessage)
            work.client.sendMessage = function(msg) {
               console.log(msg, 1)
               // console.log(msg, 1)
               // CreateNotification(msg, Math.random())
               createLocalPushMsg(msg)
            };
@@ -204,12 +255,10 @@
            $.connection.hub.url = 'http://121.196.36.24:8001/signalr'
            //hub连接开启
            $.connection.hub.start().done(function() {
               // $.connection.serverTimeoutInMilliseconds = 1000 * 60 * 30
               var username = localStorage.getItem('username');
               //发送上线信息
               work.server.sendLogin(username);
               // const aaa = [{
               //    "code": "Q",
               //    "name": "呼叫质量",
@@ -218,9 +267,7 @@
               //       "username": "楼先生"
               //    }]
               // }]
               // work.server.sendByGroupList('楼先生', 'CJ002', 'SB001', aaa)
               $('#submit').click(function() {
                  // vant.Notify('点击了')
                  // const data = {
@@ -270,10 +317,13 @@
                  //          })
                  //       }
                  //    })
               })
            });
         });
@@ -331,6 +381,8 @@
                  falseArray.push({
                     id: '1'
                  })
               } else {
                  topContentClick(topContent[0].code, topContent[0].wksp_code)
               }
            })
@@ -588,7 +640,7 @@
                           })
                           if (topContent.length >= 1) {
                              radioValue = topContent[0].code
                              topContentClick(radioValue, topContent.find(i => i.code ===
                              this.topContentClick(radioValue, topContent.find(i => i.code ===
                                 radioValue).wksp_code)
                           }
@@ -599,33 +651,30 @@
               }, 100)
            },
            // topContentClick(code, wksp_code) {
            //    radioValue = code
            //    this.$forceUpdate()
            topContentClick(code, wksp_code) {
               radioValue = code
               const data = {
                  eqpcode: code,
                  wkshpcode: wksp_code
               }
               post('AppDeviceManage/AppDeviceAnDengCallItemSearch' + formatParams(data)).then(res => {
                  if (res.code === '200') {
                     centerContent = res.data
            //    const data = {
            //       eqpcode: code,
            //       wkshpcode: wksp_code
            //    }
            //    post('AppDeviceManage/AppDeviceAnDengCallItemSearch' + formatParams(data)).then(res => {
            //       if (res.code === '200') {
            //          centerContent = res.data
                     currentValue = centerContent.map(r => {
                        if (r.flag === 'Y') {
                           return r.code
                        }
                     })
            //          currentValue = centerContent.map(r => {
            //             if (r.flag === 'Y') {
            //                return r.code
            //             }
            //          })
            //          centerContent.forEach(i => {
            //             i.isTrue = i.flag === 'Y'
            //          })
                     centerContent.forEach(i => {
                        i.isTrue = i.flag === 'Y'
                     })
            //          this.$forceUpdate()
            //       }
            //    })
            // },
                     this.$forceUpdate()
                  }
               })
            },
            topScanClick() {