index.html 7.68 KB
<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>罗电物联网APP</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
  <style>
    /*html,body{
      background: #FFFFFF; /*linear-gradient(90deg,rgba(91,127,248,1) 0%,rgba(75,175,239,1) 90%)
    }*/
  </style>
</head>

<body>
  <footer>
  </footer>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    var NVTabBar;
    var badgeX = -10;
    apiready = function() {
      initHeaderH();
      var footer = $api.dom('footer'); // 获取 footer 标签元素
      var footerH = $api.fixTabBar(footer);
      api.addEventListener({
          name:'resume'
      }, function(ret, err){
        if (api.systemType == "ios") {
          var ajpush = api.require('ajpush');
          ajpush.setBadge({
              badge:0
          });
        }
      });

      // $api.clearStorage();
      if (!check()) {
        return false;
      }

      api.addEventListener({
          name:'keyback'
      },function(ret,err){
        api.confirm({
            title:'提示',
            msg:'是否退出罗电?',
            buttons:['确定','取消']
        },function(ret,err){
          if(ret.buttonIndex==1){
            api.closeWidget({
              silent: true
            });
          }
        });
      });

      api.addEventListener({
          name: 'change_device'
      }, function(ret, err){
          if( ret ){
            getAlarmCountByUser();
          }
      });

      initPush();//推送相关
      NVTabBar = api.require('NVTabBar');
      $api.setStorage('curIndex', 0);     //默认显示首页
      initTabBar(footerH); //底部导航
      $api.setStorage('indexFooterH', footerH);
    }

    function initTabBar(footerH) {
      // 解决不同系统badge的位置问题
      if (api.systemType != 'ios') {
          badgeX = 80;
      }
      NVTabBar.close();
      NVTabBar.open({
          styles: {
            bg: '#FFFFFF',
            h: 49,
            dividingLine: {     //(可选项)JSON对象;模块顶部的分割线配置
               width: 0.5,      //(可选项)数字类型;分割线粗细;默认:0.5
               color: 'rgba(255,255,255,1)'    //(可选项)字符串类型;分割线颜色;默认:#000
            },
            badge: {
                bgColor: '#F26161',
                numColor: '#FFFFFF',
                size: 6,
                centerX: badgeX,
                centerY: 5,
                rightMargin: 30
            }
          },
          items: [{
              w: api.winWidth / 3.0,
              bg: {
                  marginB: 0,
                  image: '#FFFFFF'
              },
              iconRect: {
                  w: 21.5,
                  h: 21,
              },
              icon: {
                  normal: '../image/tabar-home-normal.png',
                  highlight: '../image/tabar-home-actived.png',
                  selected: '../image/tabar-home-actived.png'
              },
              title: {
                  text: '首页',
                  size: 11.0,
                  normal: '#9EA9B6',
                  selected: '#1D2229',
                  marginB: 0
              }
          }, {
              w: api.winWidth / 3.0,
              bg: {
                  marginB: 0,
                  image: '#FFFFFF'
              },
              iconRect: {
                  w: 21.5,
                  h: 21,
              },
              icon: {
                  normal: 'widget://image/tabar-alarm-normal.png',
                  highlight: 'widget://image/tabar-alarm-actived.png',
                  selected: 'widget://image/tabar-alarm-actived.png'
              },
              title: {
                  text: '所有报警',
                  size: 11.0,
                  normal: '#9EA9B6',
                  selected: '#1D2229',
                  marginB: 0,
              }
          }, {
              w: api.winWidth / 3.0,
              bg: {
                  marginB: 0,
                  image: '#FFFFFF'
              },
              iconRect: {
                  w: 21.5,
                  h: 21,
              },
              icon: {
                  normal: 'widget://image/tabar-mine-normal.png',
                  highlight: 'widget://image/tabar-mine-actived.png',
                  selected: 'widget://image/tabar-mine-actived.png'
              },
              title: {
                  text: '我的',
                  size: 11.0,
                  normal: '#9EA9B6',
                  selected: '#1D2229',
                  marginB: 0
              }
          }],
          selectedIndex: 2
      }, function(ret, err) {
          var index;
          var goIndex = '';
          var currentIndex = $api.getStorage('curIndex');
          if (ret.index == currentIndex && ret.index != undefined) {
            return;
          }else if (ret.index == undefined) {
            index = 2;
          }else {
            index = ret.index;
          }

          switch (index) {
            case 0:
              goIndex = 'home';
              closeWins('alarm');
            break;
            case 1:
              goIndex = 'alarm';
              closeWins('home');
            break;
            case 2:
              goIndex = 'mine';
            break;
            default:
              goIndex = 'home';
          }

          $api.setStorage('curIndex', index);
          getAlarmCountByUser();
          api.openFrame({
              name: goIndex + 'Index',
              url: './' + goIndex + '/' + goIndex + '.html',
              reload: true,
              rect: {
                  x: 0,
                  y: 0,
                  w: api.winWidth,
                  h: api.winHeight-49-footerH
              },
              animation: {
                  type:"fade",                //动画类型(详见动画类型常量)
                  subType:"from_bottom",       //动画子类型(详见动画子类型常量)
                  duration:300                //动画过渡时间,默认300毫秒
              },
              bounces: false,
              bgColor: '#F4F6F9'
          });
      });
    }

    function closeWins(frm) {
      api.closeFrame({
          name: frm + 'Frm'
      });


      api.closeFrame({
          name: 'mineIndex'
      });

    }

    function getAlarmCountByUser() {

      NVTabBar.setBadge({
            index: 1,
          });

      //查询该用户下的所有未处理报警总数
      var userId = $api.getStorage('userID');
      var token = $api.getStorage('userToken');
      $.ajax({
          url: HOST + '/iot_api/v2/app/get_unsloved_warning_count?user_id='+userId,
          type: 'GET',
          dataType: 'json',
          headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'token': token
          },
          success: function(ret) {
            if (ret.code == 0) {
                var unReadCount = undefined;
                if (ret.data != 0) {
                  unReadCount = ret.data+'';
                }
                  NVTabBar.setBadge({
                        index: 1,
                        badge: unReadCount
                      });

            }
          },
          error: function() {
            api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
          }
      });
      //---
    }
</script>