feat: 视频中心仪表盘

This commit is contained in:
JiangQiming 2023-02-02 11:51:06 +08:00
parent eaea45668c
commit e67d9519a8
5 changed files with 86 additions and 7 deletions

View File

@ -2,8 +2,8 @@ import server from '@/utils/request'
export default { export default {
// 设备数量 // 设备数量
deviceCount: () => server.get<number>(`/media/device/_count`), deviceCount: (params: any) => server.get<number>(`/media/device/_count`, params),
// 通道数量 // 通道数量
channelCount: () => server.post<number>(`/media/channel/_count`), channelCount: (data: any) => server.post<number>(`/media/channel/_count`, data),
} }

View File

@ -84,3 +84,34 @@ export const randomString = (length?: number) => {
} }
return pwd; return pwd;
}; };
/**
*
* @param time
* @returns
*/
export const timestampFormat = (time: number) => {
let hour = 0;
let minute = 0;
let second = 0;
const timeStr = 'hh小时mm分钟ss秒';
if (time) {
if (time >= 60 * 60 * 1000) {
hour = Math.trunc(time / (60 * 60 * 1000));
}
if (time >= 60 * 1000) {
minute = Math.trunc((time - hour * 60 * 60 * 1000) / (60 * 1000));
}
second = Math.trunc(
(time - hour * (60 * 60 * 1000) - minute * 60 * 1000) / 1000,
);
}
return timeStr
.replace('hh', hour.toString())
.replace('mm', minute.toString())
.replace('ss', second.toString());
};

View File

@ -19,7 +19,8 @@
</div> </div>
<div class="top-card-footer"> <div class="top-card-footer">
<template v-for="(item, index) in footer" :key="index"> <template v-for="(item, index) in footer" :key="index">
<a-badge :text="item.title" :status="item.status" /> <span v-if="!item.status">{{ item.title }}</span>
<a-badge v-else :text="item.title" :status="item.status" />
<div class="footer-item-value">{{ item.value }}</div> <div class="footer-item-value">{{ item.value }}</div>
</template> </template>
</div> </div>

View File

@ -39,19 +39,40 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import TopCard from '@/views/media/DashBoard/components/TopCard.vue' import TopCard from '@/views/media/DashBoard/components/TopCard.vue';
import { getImage } from '@/utils/comm'; import { getImage } from '@/utils/comm';
import homeApi from '@/api/media/home'; import homeApi from '@/api/media/home';
import dashboardApi from '@/api/media/dashboard'; import dashboardApi from '@/api/media/dashboard';
import type { Footer } from '@/views/media/DashBoard/typings'; import type { Footer } from '@/views/media/DashBoard/typings';
import encodeQuery from '@/utils/encodeQuery';
import { timestampFormat } from '@/utils/utils';
// //
const deviceFooter = ref<Footer[]>([]); const deviceFooter = ref<Footer[]>([]);
const deviceTotal = ref(0); const deviceTotal = ref(0);
const getDeviceData = () => { const getDeviceData = () => {
homeApi.deviceCount().then((res) => { homeApi.deviceCount({}).then((res) => {
deviceTotal.value = res.result; deviceTotal.value = res.result;
}); });
homeApi
.deviceCount(encodeQuery({ terms: { state: 'online' } }))
.then((res) => {
deviceFooter.value[0] = {
title: '在线',
value: res.result,
status: 'success',
};
});
homeApi
.deviceCount(encodeQuery({ terms: { state: 'offline' } }))
.then((res) => {
deviceFooter.value[1] = {
title: '离线',
value: res.result,
status: 'error',
};
});
}; };
getDeviceData(); getDeviceData();
@ -59,9 +80,27 @@ getDeviceData();
const channelFooter = ref<Footer[]>([]); const channelFooter = ref<Footer[]>([]);
const channelTotal = ref(0); const channelTotal = ref(0);
const getChannelData = () => { const getChannelData = () => {
homeApi.channelCount().then((res) => { homeApi.channelCount({}).then((res) => {
channelTotal.value = res.result; channelTotal.value = res.result;
}); });
homeApi
.channelCount({ terms: [{ column: 'status', value: 'online' }] })
.then((res) => {
channelFooter.value[0] = {
title: '在线',
value: res.result,
status: 'success',
};
});
homeApi
.channelCount({ terms: [{ column: 'status$not', value: 'online' }] })
.then((res) => {
channelFooter.value[1] = {
title: '离线',
value: res.result,
status: 'error',
};
});
}; };
getChannelData(); getChannelData();
@ -71,6 +110,10 @@ const aggTotal = ref(0);
const getAggData = () => { const getAggData = () => {
dashboardApi.agg().then((res) => { dashboardApi.agg().then((res) => {
aggTotal.value = res.result.total; aggTotal.value = res.result.total;
aggFooter.value.push({
title: '总时长',
value: timestampFormat(res.result.duration),
});
}); });
}; };
getAggData(); getAggData();
@ -81,6 +124,10 @@ const aggPlayingTotal = ref(0);
const getAggPlayingData = () => { const getAggPlayingData = () => {
dashboardApi.aggPlaying().then((res) => { dashboardApi.aggPlaying().then((res) => {
aggTotal.value = res.result.playingTotal; aggTotal.value = res.result.playingTotal;
aggPlayingFooter.value.push({
title: '播放人数',
value: res.result.playerTotal,
});
}); });
}; };
getAggPlayingData(); getAggPlayingData();

View File

@ -10,7 +10,7 @@ export type AggPlaying = {
export type Footer = { export type Footer = {
title: string; title: string;
value: number; value: number | string;
status?: "default" | "error" | "success" | "warning" | "processing" status?: "default" | "error" | "success" | "warning" | "processing"
} }