feat: 视频中心, 仪表盘开发
This commit is contained in:
parent
648ca2d7ff
commit
7308148b69
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="page-container">
|
<div class="wrapper">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="title">{{ title }}</div>
|
<div class="title">{{ title }}</div>
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
|
|
@ -13,18 +13,28 @@
|
||||||
<a-radio-button value="month">近一月</a-radio-button>
|
<a-radio-button value="month">近一月</a-radio-button>
|
||||||
<a-radio-button value="year">近一年</a-radio-button>
|
<a-radio-button value="year">近一年</a-radio-button>
|
||||||
</a-radio-group>
|
</a-radio-group>
|
||||||
<a-range-picker v-model:value="dateRange" />
|
<a-range-picker
|
||||||
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
valueFormat="x"
|
||||||
|
v-model:value="dateRange"
|
||||||
|
/>
|
||||||
</a-space>
|
</a-space>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chart" ref="chartRef"></div>
|
<div v-if="chartData.length" class="chart" ref="chartRef"></div>
|
||||||
|
<a-empty v-else class="no-data" description="暂无数据"></a-empty>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import * as echarts from 'echarts';
|
import * as echarts from 'echarts';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
// const { proxy } = <any>getCurrentInstance();
|
// const { proxy } = <any>getCurrentInstance();
|
||||||
|
type Emits = {
|
||||||
|
(e: 'change', data: any): void;
|
||||||
|
};
|
||||||
|
const emits = defineEmits<Emits>();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
title: { type: String, default: '' },
|
title: { type: String, default: '' },
|
||||||
|
|
@ -34,7 +44,10 @@ const props = defineProps({
|
||||||
|
|
||||||
// 统计时间维度
|
// 统计时间维度
|
||||||
const dimension = ref('week');
|
const dimension = ref('week');
|
||||||
const dateRange = ref<any>([]);
|
const dateRange = ref<any>([
|
||||||
|
moment().subtract(1, 'week').format('x'),
|
||||||
|
moment().format('x'),
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绘制图表
|
* 绘制图表
|
||||||
|
|
@ -92,6 +105,7 @@ const createChart = () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
myChart.setOption(options);
|
myChart.setOption(options);
|
||||||
window.addEventListener('resize', function () {
|
window.addEventListener('resize', function () {
|
||||||
myChart.resize();
|
myChart.resize();
|
||||||
|
|
@ -101,24 +115,73 @@ const createChart = () => {
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.chartData,
|
() => props.chartData,
|
||||||
() => createChart(),
|
(val) => {
|
||||||
|
console.log('createChart', val);
|
||||||
|
|
||||||
|
createChart();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => dateRange.value,
|
||||||
|
(val) => {
|
||||||
|
emits('change', {
|
||||||
|
time: {
|
||||||
|
start: val[0],
|
||||||
|
end: val[1],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
{ immediate: true, deep: true },
|
{ immediate: true, deep: true },
|
||||||
);
|
);
|
||||||
|
watch(
|
||||||
|
() => dimension.value,
|
||||||
|
(val) => {
|
||||||
|
if (val === 'today') {
|
||||||
|
dateRange[0] = moment().startOf('day').format('x');
|
||||||
|
}
|
||||||
|
if (val === 'week') {
|
||||||
|
dateRange[0] = moment().subtract(1, 'week').format('x');
|
||||||
|
}
|
||||||
|
if (val === 'month') {
|
||||||
|
dateRange[0] = moment().subtract(1, 'month').format('x');
|
||||||
|
}
|
||||||
|
if (val === 'year') {
|
||||||
|
dateRange[0] = moment().subtract(1, 'year').format('x');
|
||||||
|
}
|
||||||
|
dateRange[1] = moment().format('x');
|
||||||
|
emits('change', {
|
||||||
|
time: {
|
||||||
|
start: dateRange[0],
|
||||||
|
end: dateRange[1],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
.page-container {
|
.wrapper {
|
||||||
|
padding: 24px;
|
||||||
|
background-color: #fff;
|
||||||
.card-header {
|
.card-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
margin-bottom: 24px;
|
||||||
.title {
|
.title {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.chart {
|
.chart,
|
||||||
|
.no-data {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
min-height: calc(100vh - 430px);
|
||||||
|
}
|
||||||
|
.no-data {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,12 @@
|
||||||
:value="aggPlayingTotal"
|
:value="aggPlayingTotal"
|
||||||
/>
|
/>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :span="24">
|
<a-col :span="24" class="dash-board-bottom">
|
||||||
<Card title="播放数量(人次)" :chartData="chartData" />
|
<Card
|
||||||
|
title="播放数量(人次)"
|
||||||
|
:chartData="chartData"
|
||||||
|
@change="getPlayCount"
|
||||||
|
/>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -50,6 +54,7 @@ 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 encodeQuery from '@/utils/encodeQuery';
|
||||||
import { timestampFormat } from '@/utils/utils';
|
import { timestampFormat } from '@/utils/utils';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
// 设备
|
// 设备
|
||||||
const deviceFooter = ref<Footer[]>([]);
|
const deviceFooter = ref<Footer[]>([]);
|
||||||
|
|
@ -114,10 +119,12 @@ 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({
|
aggFooter.value = [
|
||||||
title: '总时长',
|
{
|
||||||
value: timestampFormat(res.result.duration),
|
title: '总时长',
|
||||||
});
|
value: timestampFormat(res.result.duration),
|
||||||
|
},
|
||||||
|
];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
getAggData();
|
getAggData();
|
||||||
|
|
@ -128,10 +135,12 @@ 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({
|
aggPlayingFooter.value = [
|
||||||
title: '播放人数',
|
{
|
||||||
value: res.result.playerTotal,
|
title: '播放人数',
|
||||||
});
|
value: res.result.playerTotal,
|
||||||
|
},
|
||||||
|
];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
getAggPlayingData();
|
getAggPlayingData();
|
||||||
|
|
@ -140,24 +149,61 @@ getAggPlayingData();
|
||||||
* 获取播放数量(人次)
|
* 获取播放数量(人次)
|
||||||
*/
|
*/
|
||||||
const chartData = ref([]);
|
const chartData = ref([]);
|
||||||
const getPlayCount = async () => {
|
const getPlayCount = async (params: any) => {
|
||||||
const params = {};
|
let _time = '1h';
|
||||||
dashboardApi.getPlayCount(params).then((res) => {
|
let _limit = 12;
|
||||||
let result: any = [];
|
const dt = params.time.end - params.time.start;
|
||||||
res.result.forEach((item: any) => {
|
const hour = 60 * 60 * 1000;
|
||||||
result = [...result, ...item.data];
|
const day = hour * 24;
|
||||||
|
const month = day * 30;
|
||||||
|
const year = 365 * day;
|
||||||
|
if (dt <= day) {
|
||||||
|
_limit = Math.abs(Math.ceil(dt / hour));
|
||||||
|
} else if (dt > day && dt < year) {
|
||||||
|
_limit = Math.abs(Math.ceil(dt / day));
|
||||||
|
_time = '1d';
|
||||||
|
} else if (dt >= year) {
|
||||||
|
_limit = Math.abs(Math.floor(dt / month));
|
||||||
|
_time = '1M';
|
||||||
|
}
|
||||||
|
dashboardApi
|
||||||
|
.getPlayCount([
|
||||||
|
{
|
||||||
|
dashboard: 'media_stream',
|
||||||
|
object: 'play_count',
|
||||||
|
measurement: 'quantity',
|
||||||
|
dimension: 'agg',
|
||||||
|
group: 'playCount',
|
||||||
|
params: {
|
||||||
|
time: _time,
|
||||||
|
from: moment(Number(params.time.start)).format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
),
|
||||||
|
to: moment(Number(params.time.end)).format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
),
|
||||||
|
limit: _limit,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.then((res) => {
|
||||||
|
let result: any = [];
|
||||||
|
res.result.forEach((item: any) => {
|
||||||
|
result = [...result, ...item.data];
|
||||||
|
});
|
||||||
|
chartData.value = result.map((m: any) => ({
|
||||||
|
x: m.timeString,
|
||||||
|
value: m.value,
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
chartData.value = result.map((m: any) => ({
|
|
||||||
x: m.timeString,
|
|
||||||
value: m.value,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
getPlayCount();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.page-container {
|
.page-container {
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
|
.dash-board-bottom {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ export type AggPlaying = {
|
||||||
export type Footer = {
|
export type Footer = {
|
||||||
title: string;
|
title: string;
|
||||||
value: number | string;
|
value: number | string;
|
||||||
status?: "default" | "error" | "success" | "warning" | "processing"
|
status?: "default" | "error" | "success" | "warning" | "processing" | ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const getData = () => {
|
const getData = () => {
|
||||||
homeApi.deviceCount().then((resp) => {
|
homeApi.deviceCount({}).then((resp) => {
|
||||||
deviceCount.value = resp.result;
|
deviceCount.value = resp.result;
|
||||||
});
|
});
|
||||||
homeApi.channelCount().then((resp) => {
|
homeApi.channelCount({}).then((resp) => {
|
||||||
channelCount.value = resp.result;
|
channelCount.value = resp.result;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue