import {ref} from "vue"
|
import {searchStatisticCreate, searchStatisticSum} from "@/views/moudle/carInfo/apis";
|
import getRecentDay from "@/util/getRecentDay";
|
|
/**
|
* 最近几天在线车辆数
|
* @return {{todayCarNum: Ref<UnwrapRef<number>>, getRecentDaysCarNum: (function(*): Promise<*[]>)}}
|
*/
|
export const recentDaysCarModule = ()=>{
|
const todayCarNum = ref(0);
|
/**
|
* 查询最近几天车辆在线数
|
* @param num 天数
|
* @return {Promise<*[]>}
|
*/
|
const getRecentDaysCarNum = 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;
|
}
|
}
|
}
|
// 设置当天的在线数
|
if(recentDays.length !== 0) {
|
todayCarNum.value = recentDays[recentDays.length -1].value;
|
}
|
return recentDays;
|
}catch (e) {
|
console.log(e);
|
return []
|
}
|
}
|
|
return {
|
todayCarNum,
|
getRecentDaysCarNum
|
}
|
|
}
|
|
/**
|
* 车辆总数
|
* @return {{getTotalCarNum: (function(): Promise<number>), totalCarNum: Ref<UnwrapRef<number>>}}
|
*/
|
export const totalCarNumModule = ()=>{
|
const totalCarNum = ref(0);
|
|
/**
|
* 获取车辆的总数
|
* @return {Promise<number>}
|
*/
|
const getTotalCarNum = async ()=>{
|
try {
|
const res = await searchStatisticSum();
|
const rs = res.data;
|
let num = 0;
|
if(rs.code === 1) {
|
num = rs.data;
|
}
|
totalCarNum.value = num;
|
return num;
|
}catch (e) {
|
console.log(e);
|
return 0;
|
}
|
}
|
|
return {
|
totalCarNum,
|
getTotalCarNum
|
};
|
}
|