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
|
};
|
}
|