longyvfengyun
2023-11-16 b537c7bccbcc20644902ad6f0e309bbe9a6eda24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {ref} from "vue"
import {searchStatisticCreate, searchStatisticSum} from "./apis";
import getRecentDay from "@/util/getRecentDay";
 
/**
 * 最近几天新增摄像头数
 * @return {{getRecentDaysVideoNum: (function(*): Promise<*[]>), todayVideoNum: Ref<UnwrapRef<number>>}}
 */
export const recentDaysVideoModule = ()=>{
  const todayVideoNum = ref(0);
  /**
   * 查询最近几天摄像头新增数
   * @param num 天数
   * @return {Promise<*[]>}
   */
  const getRecentDaysVideoNum = async (num)=>{
    try {
      const res = await searchStatisticCreate();
      const rs = res.data;
      let data = [];
      if(rs.code === 1) {
        data = rs.data;
      }
      let recentDays = getRecentDay(num);
      for(let i=0; i<recentDays.length; i++) {
        let itemDay = recentDays[i];
        for(let j=0; j<data.length; j++) {
          let item = data[j];
          if(itemDay.date === item.date) {
            itemDay.value = item.num;
            break;
          }
        }
      }
      //recentDays[recentDays.length -1].value = 100;
      // 设置当天的在线数
      if(recentDays.length !== 0) {
        todayVideoNum.value = recentDays[recentDays.length -1].value;
      }
      return recentDays;
    }catch (e) {
      console.log(e);
      return []
    }
  }
 
  return {
    todayVideoNum,
    getRecentDaysVideoNum
  }
 
}
 
/**
 * 摄像头总数
 * @return {{totalVideoNum: Ref<UnwrapRef<number>>, getTotalVideoNum: (function(): Promise<number>)}}
 */
export const totalVideoNumModule = ()=>{
  const totalVideoNum = ref(0);
 
  /**
   * 获取摄像头的总数
   * @return {Promise<number>}
   */
  const getTotalVideoNum = async ()=>{
    try {
      const res = await searchStatisticSum();
      const rs = res.data;
      let num = 0;
      if(rs.code === 1) {
        num = rs.data;
      }
      totalVideoNum.value = num;
      return num;
    }catch (e) {
      console.log(e);
      return 0;
    }
  }
 
  return {
    totalVideoNum,
    getTotalVideoNum
  };
}