|
|
@@ -20,7 +20,7 @@
|
|
|
<a-select
|
|
|
v-model:value="state.searchDeviceLabel"
|
|
|
show-search
|
|
|
- placeholder="请输入设备名"
|
|
|
+ placeholder="输入设备名检索设备"
|
|
|
:default-active-first-option="false"
|
|
|
style="width: 170px"
|
|
|
:show-arrow="false"
|
|
|
@@ -28,13 +28,14 @@
|
|
|
:not-found-content="null"
|
|
|
:options="state.dataSource"
|
|
|
@search="getDeviceLabel"
|
|
|
+ @change="selectDevice"
|
|
|
>
|
|
|
<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-range-picker v-model:value="times" @change="changeRangePicker" />
|
|
|
</a-space>
|
|
|
</a-col>
|
|
|
<a-col :span="24">
|
|
|
@@ -102,16 +103,20 @@ const state = reactive<{
|
|
|
[key: string]: any
|
|
|
}>({
|
|
|
deviceId: '',
|
|
|
- searchDeviceLabel: '',
|
|
|
+ searchDeviceLabel: null,
|
|
|
start: 0,
|
|
|
end: '',
|
|
|
dataSource: [],
|
|
|
attrSource: [],
|
|
|
loading: false,
|
|
|
analysisType: '',
|
|
|
- spinning: false
|
|
|
+ spinning: false,
|
|
|
+ onlineNum: 0,
|
|
|
+ offlineNum: 0
|
|
|
})
|
|
|
|
|
|
+const times = ref([dayjs(), dayjs()])
|
|
|
+
|
|
|
state.deviceId = route.query.id as string
|
|
|
|
|
|
const onTabChange = (key: 'session' | 'attr') => activeTabKey.value = key
|
|
|
@@ -121,75 +126,81 @@ watch(
|
|
|
() => activeTabKey.value === 'session' ? getDeviceSession() : getDeviceAttr()
|
|
|
)
|
|
|
|
|
|
-// 获取当前时间到半小时之前
|
|
|
-// const get
|
|
|
-
|
|
|
-// watch(
|
|
|
-// () => state.attrSource,
|
|
|
-// () => {
|
|
|
-// nextTick(() => {
|
|
|
-// Object.keys(state.attrSource).forEach(key => {
|
|
|
-// const chartDom = document.getElementById('device-attr-' + key)
|
|
|
-
|
|
|
-// const myChart = echarts.init(chartDom!)
|
|
|
-// const attrItem = state.attrSource[key]
|
|
|
-
|
|
|
-// attrEchartsJson.xAxis.data = (attrItem.map(item => dayjs(item.ts).format('HH:MM:ss')) || []) as never[]
|
|
|
-
|
|
|
-// attrEchartsJson.series[0].data = attrItem.map(item => item.longValue)
|
|
|
-
|
|
|
-// attrEchartsJson.title.text = key
|
|
|
-
|
|
|
-// 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'
|
|
|
-// }
|
|
|
-// ]
|
|
|
+// 获取设备属性分析数据
|
|
|
+watch(
|
|
|
+ () => state.attrSource,
|
|
|
+ () => {
|
|
|
+ nextTick(() => {
|
|
|
+ Object.keys(state.attrSource).forEach(key => {
|
|
|
+ const chartDom = document.getElementById('device-attr-' + key)
|
|
|
|
|
|
-// scatterOption.series[0].data = state.dataSource.filter(item => item.sessionType === 'CONNECT').map(item => [0, connectCount])
|
|
|
+ const myChart = echarts.init(chartDom!)
|
|
|
+ const attrItem = state.attrSource[key]
|
|
|
|
|
|
-// scatterOption.series[1].data = state.dataSource.filter(item => item.sessionType !== 'CONNECT').map(item => [1, disconnectCount])
|
|
|
+ attrEchartsJson.xAxis.data = (attrItem.map(item => dayjs(item.ts).format('HH:MM:ss')) || []) as never[]
|
|
|
|
|
|
-// let currentOption = scatterOption
|
|
|
+ attrEchartsJson.series[0].data = attrItem.map(item => item.longValue)
|
|
|
|
|
|
-// setInterval(function () {
|
|
|
-// currentOption = currentOption === scatterOption ? barOption : scatterOption
|
|
|
-// chartDomScatterChart.setOption(currentOption, true)
|
|
|
-// }, 2000)
|
|
|
+ attrEchartsJson.title.text = key
|
|
|
|
|
|
-// chartDomScatterChart.setOption(currentOption)
|
|
|
-// myChart.setOption(sessionEchartsJson)
|
|
|
+ myChart.setOption(attrEchartsJson)
|
|
|
+ })
|
|
|
+ state.loading = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
-// state.loading = false
|
|
|
-// }
|
|
|
-// }
|
|
|
-// )
|
|
|
+// 获取上下线分析图表数据
|
|
|
+// state.dataSource
|
|
|
+watch(
|
|
|
+ () => state.deviceId,
|
|
|
+ () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ if (activeTabKey.value === 'session') {
|
|
|
+ const chartDom = document.getElementById('device-session')
|
|
|
+ const chartDomScatter = document.getElementById('device-session-scatter')
|
|
|
+ console.log('chartDom:', chartDom)
|
|
|
+
|
|
|
+ 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'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+
|
|
|
+ sessionEchartsJson.legend.data = [`上线数量 ${state.onlineNum}`, `下线数量 ${state.offlineNum}`]
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }, 3000)
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
watch(
|
|
|
() => state.deviceId,
|
|
|
@@ -197,21 +208,21 @@ watch(
|
|
|
)
|
|
|
|
|
|
const changeRangePicker = (time) => {
|
|
|
- const [startTime, endTime] = time
|
|
|
-
|
|
|
- state.start = new Date(startTime).getTime()
|
|
|
- state.end = new Date(endTime).getTime()
|
|
|
-
|
|
|
activeTabKey.value === 'session' ? getDeviceSession() : getDeviceAttr()
|
|
|
}
|
|
|
|
|
|
+const selectDevice = async (value: records) => {
|
|
|
+ const device = await DeviceContriller.byId(value)
|
|
|
+ state.deviceId = device.id
|
|
|
+ console.log('device:', state.deviceId)
|
|
|
+}
|
|
|
+
|
|
|
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 }))
|
|
|
+ state.dataSource = data.map(item => ({ value: item.id, label: item.deviceLabel }))
|
|
|
console.log(data)
|
|
|
}
|
|
|
|
|
|
@@ -219,13 +230,16 @@ const getDeviceSession = async () => {
|
|
|
if (!state.deviceId) return
|
|
|
state.loading = true
|
|
|
const { data } = await DeviceContriller.getSession({ deviceId: state.deviceId, start: state.start, end: state.end })
|
|
|
- state.dataSource = data
|
|
|
+ state.dataSource = data.sessionEntities
|
|
|
+ state.offlineNum = data.offlineNum
|
|
|
+ state.onlineNum = data.onlineNum
|
|
|
}
|
|
|
|
|
|
const getDeviceAttr = async () => {
|
|
|
if (!state.deviceId) return
|
|
|
state.loading = true
|
|
|
- const { data } = await DeviceContriller.getAttr({ deviceId: state.deviceId, start: state.start, end: state.end })
|
|
|
+
|
|
|
+ const { data } = await DeviceContriller.getAttr({ deviceId: state.deviceId, start: 1, end: state.end })
|
|
|
state.attrSource = data
|
|
|
}
|
|
|
|
|
|
@@ -237,7 +251,7 @@ const getDeviceList = async () => {
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
- getDeviceList()
|
|
|
+ // getDeviceList()
|
|
|
if (state.deviceId) {
|
|
|
getDeviceSession()
|
|
|
}
|