App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-10-21 0ab4bf8f3982bdee9962076f29c5664185328517
unpackage/cache/wgt/H5EDA0853/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)
            };
@@ -555,48 +606,48 @@
               this.$forceUpdate()
            },
            submit() {
               setTimeout(() => {
                  const data = {
                     username: localStorage.getItem('username'),
                     eqpcode: topContent.find(i => i.code === radioValue).code,
                     wkshpcode: topContent.find(i => i.code === radioValue).wksp_code
                  }
                  const DATA = []
                  centerContent.forEach(i => {
                     if (i.isTrue && !currentValue.includes(i.code)) {
                        i.flag = i.isTrue ? 'Y' : 'N'
                        DATA.push(i)
                     }
                  })
               // setTimeout(() => {
               //    const data = {
               //       username: localStorage.getItem('username'),
               //       eqpcode: topContent.find(i => i.code === radioValue).code,
               //       wkshpcode: topContent.find(i => i.code === radioValue).wksp_code
               //    }
               //    const DATA = []
               //    centerContent.forEach(i => {
               //       if (i.isTrue && !currentValue.includes(i.code)) {
               //          i.flag = i.isTrue ? 'Y' : 'N'
               //          DATA.push(i)
               //       }
               //    })
                  submitIsDisabled = true
                  // falseArray.push({
                  //    id: '1'
                  // })
                  this.$forceUpdate()
                  post('AppDeviceManage/AppDeviceAnDengCallSave' + formatParams(data), DATA).then(
                     res => {
                        if (res.code === '200') {
                           vant.Notify({
                              type: 'primary',
                              message: '提交成功!'
                           })
                           topContent.forEach((r, i) => {
                              if (r.code === radioValue) {
                                 topContent.splice(i, 1)
                              }
                           })
                           if (topContent.length >= 1) {
                              radioValue = topContent[0].code
                              topContentClick(radioValue, topContent.find(i => i.code ===
                                 radioValue).wksp_code)
                           }
               //    submitIsDisabled = true
               //    // falseArray.push({
               //    //    id: '1'
               //    // })
               //    this.$forceUpdate()
               //    post('AppDeviceManage/AppDeviceAnDengCallSave' + formatParams(data), DATA).then(
               //       res => {
               //          if (res.code === '200') {
               //             vant.Notify({
               //                type: 'primary',
               //                message: '提交成功!'
               //             })
               //             topContent.forEach((r, i) => {
               //                if (r.code === radioValue) {
               //                   topContent.splice(i, 1)
               //                }
               //             })
               //             if (topContent.length >= 1) {
               //                radioValue = topContent[0].code
               //                topContentClick(radioValue, topContent.find(i => i.code ===
               //                   radioValue).wksp_code)
               //             }
                           submitIsDisabled = false
                           this.$forceUpdate()
                        }
                     })
               }, 100)
               //             submitIsDisabled = false
               //             this.$forceUpdate()
               //          }
               //       })
               // }, 100)
            },
            // topContentClick(code, wksp_code) {