index.html 6.19 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" />
</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;
    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) {
      NVTabBar.close();
      NVTabBar.open({
          styles: {
            bg: '#FFFFFF',
            h: 49,
            dividingLine: {     //(可选项)JSON对象;模块顶部的分割线配置
               width: 0.5,      //(可选项)数字类型;分割线粗细;默认:0.5
               color: '#000'    //(可选项)字符串类型;分割线颜色;默认:#000
            },
            badge: {
                bgColor: '#F26161',
                numColor: '#FFFFFF',
                size: 5,
            }
          },
          items: [{
              w: api.winWidth / 3.0,
              bg: {
                  marginB: 0,
                  image: '#FFFFFF'
              },
              iconRect: {
                  w: 21.5,
                  h: 21,
              },
              icon: {
                  normal: 'widget://image/tabar-home-normal.png',
                  highlight: 'widget://image/tabar-home-actived.png',
                  selected: 'widget://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: 0
      }, function(ret, err) {
          var goIndex = '';
          var currentIndex = $api.getStorage('curIndex');
          if (ret.index == currentIndex) {
            return;
          }
          switch (ret.index) {
            case 0:
              goIndex = 'home';
            break;
            case 1:
              goIndex = 'alarm';
            break;
            case 2:
              goIndex = 'mine';
            break;
            default:
              goIndex = 'home';
          }
          $api.setStorage('curIndex', ret.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
              },
              bgColor: '#f4f6f9',
          });
      });
    }

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