statistic_frm.html 17 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">
      <meta name="referrer" content="no-referrer">
      <title>统计分析_frm</title>
      <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/api.css"/>
      <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/aui.css"/>
      <link rel="stylesheet" type="text/css" href="http://iot.uccc.cc:9090/app/css/style.css"/>
      <style>
          html,
          body{
            background: #F4F6F9;
          }
      </style>
  </head>
  <body>
    <div class="store01001-statistic-statistic-history-panel">
      <div class="store01001-statistic-statistic-history-title">历史测量信息趋势变化</div>

      <div class="store01001-statistic-chart-panel">
        <div style="margin-left:10px;margin-right:10px;">
          <div class="store01001-statistic-wrap">
            <div class="store01001-statistic-cont">
              <div class="aui-tab store01001-statistic-state" id="tab">
                  <div class="aui-tab-item store01001-statistic-ati aui-active">电流</div>
                  <div class="aui-tab-item store01001-statistic-ati">剩余电流</div>
                  <div class="aui-tab-item store01001-statistic-ati">电压</div>
                  <div class="aui-tab-item store01001-statistic-ati">频率</div>
                  <div class="aui-tab-item store01001-statistic-ati">线缆温度</div>
                  <div class="aui-tab-item store01001-statistic-ati">内部温度</div>
              </div>
            </div>
          </div>
          <div style="height:1px;background:rgba(240,245,255,1);margin-bottom:5px;"></div>
          <div class="tab-view-list" id="echarts_view" style="height:11.5rem;">
          </div>
        </div>
      </div>

      <div class="store01001-statistic-statistic-history-title">报警及动作历史数据</div>

      <div class="store01001-statistic-btn-panel">
        <div class="store01001-statistic-info-inside-panel">
          <div class="aui-row aui-row-flex store01001-statistic-padding-top-21" tapmode onclick="todayAlarmList();">
            <div class="aui-col aui-col-span-3 aui-row-flex-start">
              <img src="http://iot.uccc.cc:9090/product/01001/statistics_icon_01.png" style="width:22px;height:22px;margin-top:0.1rem;" />
            </div>
            <div class="aui-col aui-col-span-10 aui-row-flex-start">
              <span class="store01001-statistic-measure-obj" style="margin-left:-0.4rem;">今日报警总数</span>
            </div>
            <div class="aui-col aui-col-span-9 aui-row-flex-end">
              <div class="store01001-statistic-alarm-area"><span class="store01001-statistic-count-num" id="curAlarmCount">0</span></div>
            </div>
            <div class="aui-col aui-col-span-2 aui-row-flex-end">
              <i class="aui-iconfont aui-icon-right" style="margin-top:0.2rem;"></i>
            </div>
          </div>
          <div class="store01001-statistic-panel-line store01001-statistic-margin-top-21"></div>
          <div class="aui-row aui-row-flex store01001-statistic-padding-top-21" tapmode onclick="historyAlarmChart();">
            <div class="aui-col aui-col-span-3 aui-row-flex-start">
              <img src="http://iot.uccc.cc:9090/product/01001/statistics_icon_02.png" style="width:22px;height:22px;margin-top:0.1rem;" />
            </div>
            <div class="aui-col aui-col-span-12 aui-row-flex-start">
              <span class="store01001-statistic-measure-obj" style="margin-left:-0.4rem;">历史报警数据统计分析</span>
            </div>
            <div class="aui-col aui-col-span-7 aui-row-flex-end">
            </div>
            <div class="aui-col aui-col-span-2 aui-row-flex-end">
              <i class="aui-iconfont aui-icon-right" style="margin-top:0.2rem;"></i>
            </div>
          </div>
          <div class="store01001-statistic-panel-line store01001-statistic-margin-top-21"></div>
          <div class="aui-row aui-row-flex store01001-statistic-padding-top-21" tapmode onclick="todayProtectList();">
            <div class="aui-col aui-col-span-3 aui-row-flex-start">
              <img src="http://iot.uccc.cc:9090/product/01001/statistics_icon_03.png" style="width:22px;height:22px;margin-top:0.15rem;" />
            </div>
            <div class="aui-col aui-col-span-10 aui-row-flex-start">
              <span class="store01001-statistic-measure-obj" style="margin-left:-0.4rem;">今日动作总数</span>
            </div>
            <div class="aui-col aui-col-span-9 aui-row-flex-end">
              <div class="store01001-statistic-alarm-area" id="curProtectCount">0</div>
            </div>
            <div class="aui-col aui-col-span-2 aui-row-flex-end">
              <i class="aui-iconfont aui-icon-right" style="margin-top:0.2rem;"></i>
            </div>
          </div>
          <div class="store01001-statistic-panel-line store01001-statistic-margin-top-21"></div>
          <div class="aui-row aui-row-flex store01001-statistic-padding-top-21" tapmode onclick="historyProtectChart();">
            <div class="aui-col aui-col-span-3 aui-row-flex-start">
              <img src="http://iot.uccc.cc:9090/product/01001/statistics_icon_04.png" style="width:22px;height:22px;margin-top:0.1rem;" />
            </div>
            <div class="aui-col aui-col-span-12 aui-row-flex-start">
              <span class="store01001-statistic-measure-obj" style="margin-left:-0.4rem;">历史动作数据统计分析</span>
            </div>
            <div class="aui-col aui-col-span-7 aui-row-flex-end">
            </div>
            <div class="aui-col aui-col-span-2 aui-row-flex-end">
              <i class="aui-iconfont aui-icon-right" style="margin-top:0.2rem;"></i>
            </div>
          </div>
          <div style="height:21px;"></div>
        </div>
      </div>
    </div>
    <div class="store01001-statistic-margin-top-21" style="height:1rem;"></div>
  </body>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/api.js"></script>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/ctrl.js"></script>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/common.js"></script>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/aui-tab.js" ></script>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/echarts.min.js"></script>
  <script type="text/javascript" src="http://iot.uccc.cc:9090/app/js/jquery-3.3.1.min.js"></script>
  <script type="text/javascript">
      var search_date = '';
      var token;
      var userId;
      var defaultImei;
      var chartTypeArr = ["current","rest_current", "voltage", "rate", "line_temp","temp1"];
      var chartTypeUnitArr = ["A", "mA", "V","Hz", "℃", "℃"];
      var chartNameArr = ["电流", "剩余电流", "电压","频率", "线缆温度", "内部温度"];

      apiready = function(){
        api.parseTapmode();
        defaultImei = api.pageParam.imei;
        token = api.getPrefs({sync: true,key: 'userToken'});
        userId = api.getPrefs({sync: true,key: 'userID'});
        //折线图方式切换
        var tab = new auiTab({
            element:document.getElementById("tab"),
        },function(ret){
          initChart(ret.index);
        })
        if (search_date == '') {
          var curDate = new Date();
          search_date = parseTime(new Date(curDate.getTime() - 24*60*60*1000),'{y}-{m}-{d}');
          api.sendEvent({
              name: 'initSearchDate',
              extra: {
                  selectTime: search_date,
              }
          });

        }

        api.addEventListener({
            name: 'chanegSearchDate'
        }, function(ret, err){
            if( ret && ret.value.selected_time ){
              search_date = ret.value.selected_time;
              initChart(1);
            }
        });

        initChart(1);
        initCount();
      };

      function initChart(index) {  //固定按日查询
        var echartDom = document.getElementById("echarts_view");
        var chartTitle = chartNameArr[index-1]+'趋势变化图';
        var chartTypeUnit = chartTypeUnitArr[index-1];
        var chartType = chartTypeArr[index-1];
        $.ajax({
            url: HOST + '/iot_api/v2/app/chart_history?imei=' + defaultImei + '&date=' + search_date + '&type=' + chartType,
            type: 'GET',
            dataType: 'json',
            headers: {
                'Content-Type': 'application/json;charset=utf-8',
                'token': token
            },
            success: function(ret) {
                if (ret.code == 0) {
                  var myChart = echarts.init(echartDom);
                  var option = {
                    // legend: {
                    //   data: chartName
                    // }
                    title: {
                        left: 'center',
                        text: chartTitle,
                    },
                    grid: {
                       x: 45,
                       x2: 20,
                       y: 50,
                    },
                  tooltip: {
                      trigger: 'axis',
                      position: 'top',
                      formatter: function (params) {
                            params = params[0];
                            return params.axisValue+'<br />'+params.marker+params.seriesName+'值 '+params.data+chartTypeUnit;
                        },
                  },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ret.data.date.map(function(item){
                          return item.substring(11,16)
                        }),
                        axisLine: {
                            lineStyle: {
                                color: '#B0C8FF'
                            }
                        },
                        axisLabel: {
                          textStyle: {
                            color: function (value, index) {
                                return '#818295';
                            }
                          },
                          rotate:330
                        }
                    },
                    yAxis: {
                        type: 'value',
                        boundaryGap: [0, '100%'],
                        //y轴颜色
                        axisLine: {
                           lineStyle: {
                               color: '#fff'
                           }
                        },
                        axisLabel: {
                            formatter: '{value}'+chartTypeUnit,
                            textStyle: {
                              color: function (value, index) {
                                  return value >= 0 ? '#818295' : 'red';
                              }
                            }
                        },
                        splitLine:{
                          show:true  ,
                          lineStyle:{
                            color:'#F0F5FF',
                            width: 1
                          }
                        }
                    },
                    dataZoom: [
                      {
                        type: 'slider',
                        fillerColor: '#B0C8FF',
                        backgroundColor: '#F0F5FF',
                        start: 0,
                        end: 100,
                        handleIcon: "M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z",
                        handleSize: '90%',
                        handleStyle: {
                            color: '#5B7FF8',
                            // shadowBlur: 1,
                            // shadowColor: 'rgba(0, 0, 0, 0.6)',
                            // shadowOffsetX: 2,
                            // shadowOffsetY: 2
                        },

                        dataBackground:{
                            lineStyle:{
                                color:'#F0F5FF'
                            },
                            areaStyle:{
                                color:'#F0F5FF',
                                opacity:1,
                            }
                        },
                        bottom:'0%'
                      },{
                          type: 'inside',//这个 dataZoom 组件是 inside 型 dataZoom 组件(能在坐标系内进行拖动,以及用滚轮(或移动触屏上的两指滑动)进行缩放)
                          xAxisIndex: 0,//控制x轴
                      }
                    ],
                    series: [{
                        data: ret.data[chartType],
                        name:chartTitle,
                        type:'line',
                        showSymbol: true,
                        hoverAnimation: false,
                        symbol: 'path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z M30.9,3.5C17.6,3.5,6.8,14.4,6.8,27.6c0,13.3,10.8,24.1,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z',
                        symbolSize: 8,
                        // 折线颜色
                        itemStyle: {
                         normal: {
                             color: '#5B7FF8',
                             lineStyle: {
                                 color: '#5B7FF8'
                             }
                         }
                        },
                    }]
                  };
                  if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                  }
                }
            },
            error: function() {
              api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
            }
        });
      }

      function historyAlarmChart() {
        api.openWin({
            name: 'historyAlarmChart_win',
            url: 'http://iot.uccc.cc:9090/app_html/store01001/historyAlarmChart_win.html',
            pageParam: {
              imei: api.pageParam.imei,
              productId: api.pageParam.productId
            }
        });

      }

      function historyProtectChart() {
        api.openWin({
            name: 'historyProtectChart_win',
            url: 'http://iot.uccc.cc:9090/app_html/store01001/historyProtectChart_win.html',
            pageParam: {
              imei: api.pageParam.imei,
              productId: api.pageParam.productId
            }
        });

      }

      async function initCount() {
        let params = {
          page: 1,
          limit: 1000,
          type: 'app',
          status: '未处理',
          keyword: api.pageParam.imei,
          userId: api.getPrefs({sync: true,key: 'userID'}),
          date: parseTime(new Date(),'{y}-{m}-{d}')
        }
        let res = await get_warning_list_by_user_id(params, api.pageParam.token)
        if (res.code == 0) {
          $api.html($api.byId('curAlarmCount'), res.data.count);
        }else {
          api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
        }
        

        $.ajax({
            url: HOST + '/iot_api/v2/app/get_action_list?page=1&limit=1000&imei=' + defaultImei + '&user_id=' + userId + '&date=' + parseTime(new Date(),'{y}-{m}-{d}'),
            type: 'GET',
            dataType: 'json',
            headers: {
                'Content-Type': 'application/json;charset=utf-8',
                'token': token
            },
            success: function(ret) {
              $api.html($api.byId('curProtectCount'), ret.data.count);
            },
            error: function() {
              console.log('222');
              api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
            }
        });
      }

      function todayAlarmList() {
        api.openWin({
            name:  'alarmInfo_win',
            url: 'http://iot.uccc.cc:9090/app_html/store01001/alarm_info_win.html',
            slidBackEnabled: false,
            pageParam: {
              staticToAlarm: parseTime(new Date(),'{y}-{m}-{d}'),
              imei: api.pageParam.imei,
              productId: api.pageParam.productId
            }
        });
      }

      function todayProtectList() {
        api.openWin({
            name:  'protectAction_win',
            url: 'http://iot.uccc.cc:9090/app_html/store01001/protect_action_win.html',
            slidBackEnabled: false,
            pageParam: {
              staticToProtect: parseTime(new Date(),'{y}-{m}-{d}'),
              imei: api.pageParam.imei,
              productId: api.pageParam.productId
            }
        });
      }
  </script>
</html>