|
|
@@ -1,57 +1,66 @@
|
|
|
<template>
|
|
|
-<a-card
|
|
|
- title="设备分析"
|
|
|
- :tab-list="tabListNoTitle"
|
|
|
- :active-tab-key="activeTabKey"
|
|
|
- @tabChange="key => onTabChange(key)"
|
|
|
->
|
|
|
- <a-row :gutter="[8, 8]" style="margin-top: 20px;" >
|
|
|
- <a-col :span="24" >
|
|
|
- <a-space>
|
|
|
- <a-select
|
|
|
- style="width: 170px;"
|
|
|
- v-model:value="state.deviceId"
|
|
|
- >
|
|
|
- <a-select-option
|
|
|
- v-for="item in deviceState.dataSource"
|
|
|
- :key="item.id"
|
|
|
- :value="item.id"
|
|
|
- >
|
|
|
- {{item.deviceLabel}}
|
|
|
- </a-select-option>
|
|
|
- </a-select>
|
|
|
- <a-range-picker @change="changeRangePicker" format="YYYY/MM/DD" />
|
|
|
- </a-space>
|
|
|
- </a-col>
|
|
|
- <a-col :span="24">
|
|
|
- <a-spin :spinning="state.loading" >
|
|
|
- <a-empty style="margin: 0 auto;" v-if="!state.deviceId" description="请选择设备" ></a-empty>
|
|
|
- <span v-else>
|
|
|
- <a-col :span="24" v-if="activeTabKey === 'session'">
|
|
|
- <a-row>
|
|
|
- <a-col :xs="24" :md="24" :xl="12" >
|
|
|
- <div id="device-session" style="width: 600px;height: 400px;" ></div>
|
|
|
- </a-col>
|
|
|
- <a-col :xs="24" :md="24" :xl="12">
|
|
|
- <div id="device-session-scatter" style="width: 600px;height: 400px;" ></div>
|
|
|
- </a-col>
|
|
|
- </a-row>
|
|
|
- </a-col>
|
|
|
- <a-col :span="24" v-else>
|
|
|
- <div
|
|
|
- :id="`device-attr-` + key"
|
|
|
- style="width: 1000px; height: 400px;"
|
|
|
- v-for="key in attrKeys"
|
|
|
- :key="key"
|
|
|
+
|
|
|
+ <a-card
|
|
|
+ title="设备分析"
|
|
|
+ :tab-list="tabListNoTitle"
|
|
|
+ :active-tab-key="activeTabKey"
|
|
|
+ @tabChange="key => onTabChange(key)"
|
|
|
+ >
|
|
|
+ <a-row :gutter="[8, 8]" style="margin-top: 20px;" >
|
|
|
+ <a-col :span="24" >
|
|
|
+ <a-space>
|
|
|
+ <a-spin
|
|
|
+ :spinning="state.spinning"
|
|
|
>
|
|
|
- </div>
|
|
|
- </a-col>
|
|
|
- </span>
|
|
|
- </a-spin>
|
|
|
- </a-col>
|
|
|
-
|
|
|
- </a-row>
|
|
|
-</a-card>
|
|
|
+ <a-select
|
|
|
+ v-model:value="state.searchDeviceLabel"
|
|
|
+ show-search
|
|
|
+ placeholder="请输入设备名"
|
|
|
+ :default-active-first-option="false"
|
|
|
+ style="width: 170px"
|
|
|
+ :show-arrow="false"
|
|
|
+ :filter-option="false"
|
|
|
+ :not-found-content="null"
|
|
|
+ :options="state.dataSource"
|
|
|
+ @search="getDeviceLabel"
|
|
|
+ >
|
|
|
+ <template v-if="state.fetching" #notFoundContent>
|
|
|
+ <a-spin size="small" />
|
|
|
+ </template>
|
|
|
+ </a-select>
|
|
|
+ </a-spin>
|
|
|
+ <a-range-picker @change="changeRangePicker" format="YYYY/MM/DD" />
|
|
|
+ </a-space>
|
|
|
+ </a-col>
|
|
|
+ <a-col :span="24">
|
|
|
+ <a-spin :spinning="state.loading" >
|
|
|
+ <a-empty style="margin: 0 auto;" v-if="!state.deviceId" description="请选择设备" ></a-empty>
|
|
|
+ <span v-else>
|
|
|
+ <a-col :span="24" v-if="activeTabKey === 'session'">
|
|
|
+ <a-row>
|
|
|
+ <a-col :xs="24" :md="24" :xl="12" >
|
|
|
+ <div id="device-session" style="width: 600px;height: 400px;" ></div>
|
|
|
+ </a-col>
|
|
|
+ <a-col :xs="24" :md="24" :xl="12">
|
|
|
+ <div id="device-session-scatter" style="width: 600px;height: 400px;" ></div>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ </a-col>
|
|
|
+ <a-col :span="24" v-else>
|
|
|
+ <div
|
|
|
+ :id="`device-attr-` + key"
|
|
|
+ style="width: 1000px; height: 400px;"
|
|
|
+ v-for="key in attrKeys"
|
|
|
+ :key="key"
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </a-col>
|
|
|
+ </span>
|
|
|
+ </a-spin>
|
|
|
+ </a-col>
|
|
|
+
|
|
|
+ </a-row>
|
|
|
+ </a-card>
|
|
|
</template>
|
|
|
<script lang='ts' setup >
|
|
|
import { DeviceContriller } from '@/controller'
|
|
|
@@ -60,7 +69,6 @@ import * as echarts from 'echarts'
|
|
|
import { useRoute } from 'vue-router'
|
|
|
import { sessionEchartsJson, attrEchartsJson, scatterOption, barOption, calculateAverage } from './json/echartsJson'
|
|
|
import dayjs from 'dayjs'
|
|
|
-import { useSchedulerOnce } from '@/hooks'
|
|
|
|
|
|
const tabListNoTitle = [{
|
|
|
key: 'session',
|
|
|
@@ -88,12 +96,14 @@ const state = reactive<{
|
|
|
[key: string]: any
|
|
|
}>({
|
|
|
deviceId: '',
|
|
|
+ searchDeviceLabel: '',
|
|
|
start: 0,
|
|
|
end: '',
|
|
|
dataSource: [],
|
|
|
attrSource: [],
|
|
|
loading: false,
|
|
|
- analysisType: ''
|
|
|
+ analysisType: '',
|
|
|
+ spinning: false
|
|
|
})
|
|
|
|
|
|
state.deviceId = route.query.id as string
|
|
|
@@ -105,72 +115,75 @@ watch(
|
|
|
() => activeTabKey.value === 'session' ? getDeviceSession() : getDeviceAttr()
|
|
|
)
|
|
|
|
|
|
-watch(
|
|
|
- () => state.attrSource,
|
|
|
- () => {
|
|
|
- nextTick(() => {
|
|
|
- Object.keys(state.attrSource).forEach(key => {
|
|
|
- const chartDom = document.getElementById('device-attr-' + key)
|
|
|
+// 获取当前时间到半小时之前
|
|
|
+// const get
|
|
|
|
|
|
- const myChart = echarts.init(chartDom!)
|
|
|
- const attrItem = state.attrSource[key]
|
|
|
+// watch(
|
|
|
+// () => state.attrSource,
|
|
|
+// () => {
|
|
|
+// nextTick(() => {
|
|
|
+// Object.keys(state.attrSource).forEach(key => {
|
|
|
+// const chartDom = document.getElementById('device-attr-' + key)
|
|
|
|
|
|
- attrEchartsJson.xAxis.data = (attrItem.map(item => dayjs(item.ts).format('HH:MM:ss')) || []) as never[]
|
|
|
+// const myChart = echarts.init(chartDom!)
|
|
|
+// const attrItem = state.attrSource[key]
|
|
|
|
|
|
- attrEchartsJson.series[0].data = attrItem.map(item => item.longValue)
|
|
|
+// attrEchartsJson.xAxis.data = (attrItem.map(item => dayjs(item.ts).format('HH:MM:ss')) || []) as never[]
|
|
|
|
|
|
- attrEchartsJson.title.text = key
|
|
|
+// attrEchartsJson.series[0].data = attrItem.map(item => item.longValue)
|
|
|
|
|
|
- myChart.setOption(attrEchartsJson)
|
|
|
- })
|
|
|
- state.loading = false
|
|
|
- })
|
|
|
- }
|
|
|
-)
|
|
|
+// attrEchartsJson.title.text = key
|
|
|
|
|
|
-watch(
|
|
|
- () => state.dataSource,
|
|
|
- () => {
|
|
|
- if (activeTabKey.value === 'session') {
|
|
|
- const chartDom = document.getElementById('device-session')
|
|
|
- const chartDomScatter = document.getElementById('device-session-scatter')
|
|
|
- const myChart = echarts.init(chartDom!)
|
|
|
- const chartDomScatterChart = echarts.init(chartDomScatter!)
|
|
|
- sessionEchartsJson.xAxis.data = state.dataSource.map(item => item.createAt) as never[]
|
|
|
- sessionEchartsJson.series[0].data = state.dataSource.map(item => item.sessionType === 'CONNECT' ? '上线' : '下线')
|
|
|
-
|
|
|
- const connectCount = state.dataSource.filter(item => item.sessionType === 'CONNECT').length
|
|
|
- const disconnectCount = state.dataSource.length - connectCount
|
|
|
-
|
|
|
- barOption.series[0].data = [
|
|
|
- {
|
|
|
- value: calculateAverage(connectCount),
|
|
|
- groupId: 'male'
|
|
|
- },
|
|
|
- {
|
|
|
- value: calculateAverage(disconnectCount),
|
|
|
- groupId: 'female'
|
|
|
- }
|
|
|
- ]
|
|
|
-
|
|
|
- scatterOption.series[0].data = state.dataSource.filter(item => item.sessionType === 'CONNECT').map(item => [0, connectCount])
|
|
|
-
|
|
|
- scatterOption.series[1].data = state.dataSource.filter(item => item.sessionType !== 'CONNECT').map(item => [1, disconnectCount])
|
|
|
-
|
|
|
- let currentOption = scatterOption
|
|
|
-
|
|
|
- setInterval(function () {
|
|
|
- currentOption = currentOption === scatterOption ? barOption : scatterOption
|
|
|
- chartDomScatterChart.setOption(currentOption, true)
|
|
|
- }, 2000)
|
|
|
-
|
|
|
- chartDomScatterChart.setOption(currentOption)
|
|
|
- myChart.setOption(sessionEchartsJson)
|
|
|
-
|
|
|
- state.loading = false
|
|
|
- }
|
|
|
- }
|
|
|
-)
|
|
|
+// myChart.setOption(attrEchartsJson)
|
|
|
+// })
|
|
|
+// state.loading = false
|
|
|
+// })
|
|
|
+// }
|
|
|
+// )
|
|
|
+
|
|
|
+// watch(
|
|
|
+// () => state.dataSource,
|
|
|
+// () => {
|
|
|
+// if (activeTabKey.value === 'session') {
|
|
|
+// const chartDom = document.getElementById('device-session')
|
|
|
+// const chartDomScatter = document.getElementById('device-session-scatter')
|
|
|
+// const myChart = echarts.init(chartDom!)
|
|
|
+// const chartDomScatterChart = echarts.init(chartDomScatter!)
|
|
|
+// sessionEchartsJson.xAxis.data = state.dataSource.map(item => item.createAt) as never[]
|
|
|
+// sessionEchartsJson.series[0].data = state.dataSource.map(item => item.sessionType === 'CONNECT' ? '上线' : '下线')
|
|
|
+
|
|
|
+// const connectCount = state.dataSource.filter(item => item.sessionType === 'CONNECT').length
|
|
|
+// const disconnectCount = state.dataSource.length - connectCount
|
|
|
+
|
|
|
+// barOption.series[0].data = [
|
|
|
+// {
|
|
|
+// value: calculateAverage(connectCount),
|
|
|
+// groupId: 'male'
|
|
|
+// },
|
|
|
+// {
|
|
|
+// value: calculateAverage(disconnectCount),
|
|
|
+// groupId: 'female'
|
|
|
+// }
|
|
|
+// ]
|
|
|
+
|
|
|
+// scatterOption.series[0].data = state.dataSource.filter(item => item.sessionType === 'CONNECT').map(item => [0, connectCount])
|
|
|
+
|
|
|
+// scatterOption.series[1].data = state.dataSource.filter(item => item.sessionType !== 'CONNECT').map(item => [1, disconnectCount])
|
|
|
+
|
|
|
+// let currentOption = scatterOption
|
|
|
+
|
|
|
+// setInterval(function () {
|
|
|
+// currentOption = currentOption === scatterOption ? barOption : scatterOption
|
|
|
+// chartDomScatterChart.setOption(currentOption, true)
|
|
|
+// }, 2000)
|
|
|
+
|
|
|
+// chartDomScatterChart.setOption(currentOption)
|
|
|
+// myChart.setOption(sessionEchartsJson)
|
|
|
+
|
|
|
+// state.loading = false
|
|
|
+// }
|
|
|
+// }
|
|
|
+// )
|
|
|
|
|
|
watch(
|
|
|
() => state.deviceId,
|
|
|
@@ -179,7 +192,6 @@ watch(
|
|
|
|
|
|
const changeRangePicker = (time) => {
|
|
|
const [startTime, endTime] = time
|
|
|
- console.log(startTime, endTime)
|
|
|
|
|
|
state.start = new Date(startTime).getTime()
|
|
|
state.end = new Date(endTime).getTime()
|
|
|
@@ -187,6 +199,16 @@ const changeRangePicker = (time) => {
|
|
|
activeTabKey.value === 'session' ? getDeviceSession() : getDeviceAttr()
|
|
|
}
|
|
|
|
|
|
+const getDeviceLabel = async (val: string) => {
|
|
|
+ console.log('val:', val)
|
|
|
+ if (!val) return
|
|
|
+ state.spinning = true
|
|
|
+ const { data } = await DeviceContriller.labelsByLabel(val)
|
|
|
+ state.spinning = false
|
|
|
+ state.dataSource = data.map(item => ({ value: item, label: item }))
|
|
|
+ console.log(data)
|
|
|
+}
|
|
|
+
|
|
|
const getDeviceSession = async () => {
|
|
|
if (!state.deviceId) return
|
|
|
state.loading = true
|
|
|
@@ -202,7 +224,9 @@ const getDeviceAttr = async () => {
|
|
|
}
|
|
|
|
|
|
const getDeviceList = async () => {
|
|
|
+ state.spinning = true
|
|
|
const { data } = await DeviceContriller.list()
|
|
|
+ state.spinning = false
|
|
|
deviceState.dataSource = data
|
|
|
}
|
|
|
|