From 585cc85df536bb2337892953725c86a4ccacf316 Mon Sep 17 00:00:00 2001 From: alwayssuper <191763414@qq.com> Date: Mon, 14 Apr 2025 10:44:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat=EF=BC=9Biothome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/home/components/ComparisonCard.vue | 33 +++++++ src/views/iot/home/index.vue | 89 ++++++------------- 2 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 src/views/iot/home/components/ComparisonCard.vue diff --git a/src/views/iot/home/components/ComparisonCard.vue b/src/views/iot/home/components/ComparisonCard.vue new file mode 100644 index 000000000..d7aa5d5f8 --- /dev/null +++ b/src/views/iot/home/components/ComparisonCard.vue @@ -0,0 +1,33 @@ + + + diff --git a/src/views/iot/home/index.vue b/src/views/iot/home/index.vue index bee4116bf..aa129d1c6 100644 --- a/src/views/iot/home/index.vue +++ b/src/views/iot/home/index.vue @@ -2,72 +2,40 @@ - -
-
- 分类数量 - -
- - {{ statsData.productCategoryCount }} - - -
- 今日新增 - +{{ statsData.productCategoryTodayCount }} -
-
-
+
- -
-
- 产品数量 - -
- {{ statsData.productCount }} - -
- 今日新增 - +{{ statsData.productTodayCount }} -
-
-
+
- -
-
- 设备数量 - -
- {{ statsData.deviceCount }} - -
- 今日新增 - +{{ statsData.deviceTodayCount }} -
-
-
+
- -
-
- 设备消息数 - -
- - {{ statsData.deviceMessageCount }} - - -
- 今日新增 - +{{ statsData.deviceMessageTodayCount }} -
-
-
+
@@ -165,6 +133,7 @@ import { ProductCategoryApi } from '@/api/iot/statistics' import { formatDate } from '@/utils/formatTime' +import ComparisonCard from './components/ComparisonCard.vue' // TODO @super:参考下 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/home/index.vue,拆一拆组件 -- Gitee From fc3018bfb27714352dcc0f6d52907e062681eb47 Mon Sep 17 00:00:00 2001 From: alwayssuper <191763414@qq.com> Date: Mon, 14 Apr 2025 11:25:01 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat=EF=BC=9Biothome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/home/components/DeviceCountCard.vue | 87 ++++++++++++ .../home/components/DeviceStateCountCard.vue | 119 ++++++++++++++++ .../iot/home/components/MessageTrendCard.vue | 0 src/views/iot/home/index.vue | 133 +----------------- 4 files changed, 210 insertions(+), 129 deletions(-) create mode 100644 src/views/iot/home/components/DeviceCountCard.vue create mode 100644 src/views/iot/home/components/DeviceStateCountCard.vue create mode 100644 src/views/iot/home/components/MessageTrendCard.vue diff --git a/src/views/iot/home/components/DeviceCountCard.vue b/src/views/iot/home/components/DeviceCountCard.vue new file mode 100644 index 000000000..5b7ea5d42 --- /dev/null +++ b/src/views/iot/home/components/DeviceCountCard.vue @@ -0,0 +1,87 @@ + + + diff --git a/src/views/iot/home/components/DeviceStateCountCard.vue b/src/views/iot/home/components/DeviceStateCountCard.vue new file mode 100644 index 000000000..33415ea33 --- /dev/null +++ b/src/views/iot/home/components/DeviceStateCountCard.vue @@ -0,0 +1,119 @@ + + + diff --git a/src/views/iot/home/components/MessageTrendCard.vue b/src/views/iot/home/components/MessageTrendCard.vue new file mode 100644 index 000000000..e69de29bb diff --git a/src/views/iot/home/index.vue b/src/views/iot/home/index.vue index aa129d1c6..e88b219c3 100644 --- a/src/views/iot/home/index.vue +++ b/src/views/iot/home/index.vue @@ -42,43 +42,10 @@ - - -
-
+
- - - - -
-
- 在线设备 -
-
- -
-
- 离线设备 -
-
- -
-
- 待激活设备 -
-
-
-
+
@@ -134,6 +101,8 @@ import { } from '@/api/iot/statistics' import { formatDate } from '@/utils/formatTime' import ComparisonCard from './components/ComparisonCard.vue' +import DeviceCountCard from './components/DeviceCountCard.vue' +import DeviceStateCountCard from './components/DeviceStateCountCard.vue' // TODO @super:参考下 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/home/index.vue,拆一拆组件 @@ -252,104 +221,10 @@ const getStats = async () => { /** 初始化图表 */ const initCharts = () => { - // 设备数量统计 - echarts.init(deviceCountChartRef.value).setOption({ - tooltip: { - trigger: 'item' - }, - legend: { - top: '5%', - right: '10%', - align: 'left', - orient: 'vertical', - icon: 'circle' - }, - series: [ - { - name: 'Access From', - type: 'pie', - radius: ['50%', '80%'], - avoidLabelOverlap: false, - center: ['30%', '50%'], - label: { - show: false, - position: 'outside' - }, - emphasis: { - label: { - show: true, - fontSize: 20, - fontWeight: 'bold' - } - }, - labelLine: { - show: false - }, - data: Object.entries(statsData.value.productCategoryDeviceCounts).map(([name, value]) => ({ - name, - value - })) - } - ] - }) - - // 在线设备统计 - initGaugeChart(deviceOnlineCountChartRef.value, statsData.value.deviceOnlineCount, '#0d9') - // 离线设备统计 - initGaugeChart(deviceOfflineChartRef.value, statsData.value.deviceOfflineCount, '#f50') - // 待激活设备统计 - initGaugeChart(deviceActiveChartRef.value, statsData.value.deviceInactiveCount, '#05b') - // 消息量统计 initMessageChart() } -/** 初始化仪表盘图表 */ -const initGaugeChart = (el: any, value: number, color: string) => { - echarts.init(el).setOption({ - series: [ - { - type: 'gauge', - startAngle: 360, - endAngle: 0, - min: 0, - max: statsData.value.deviceCount || 100, // 使用设备总数作为最大值 - progress: { - show: true, - width: 12, - itemStyle: { - color: color - } - }, - axisLine: { - lineStyle: { - width: 12, - color: [[1, '#E5E7EB']] - } - }, - axisTick: { show: false }, - splitLine: { show: false }, - axisLabel: { show: false }, - pointer: { show: false }, - anchor: { show: false }, - title: { show: false }, - detail: { - valueAnimation: true, - fontSize: 24, - fontWeight: 'bold', - fontFamily: 'Inter, sans-serif', - color: color, - offsetCenter: [0, '0'], - formatter: (value: number) => { - return `${value} 个` - } - }, - data: [{ value: value }] - } - ] - }) -} - /** 初始化消息统计图表 */ const initMessageChart = () => { // 获取所有时间戳并排序 -- Gitee From feab54c11ef5363d6533f8821ed545c751480b3a Mon Sep 17 00:00:00 2001 From: alwayssuper <191763414@qq.com> Date: Mon, 14 Apr 2025 15:25:12 +0800 Subject: [PATCH 3/5] feat:iot messge --- pnpm-lock.yaml | 19 -- .../iot/home/components/MessageTrendCard.vue | 232 +++++++++++++++++ src/views/iot/home/index.vue | 236 +----------------- 3 files changed, 241 insertions(+), 246 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7ace92dc..032358ebb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1397,42 +1397,36 @@ packages: engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] - libc: [glibc] '@parcel/watcher-linux-arm-musl@2.5.0': resolution: {integrity: sha512-6uHywSIzz8+vi2lAzFeltnYbdHsDm3iIB57d4g5oaB9vKwjb6N6dRIgZMujw4nm5r6v9/BQH0noq6DzHrqr2pA==} engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] - libc: [musl] '@parcel/watcher-linux-arm64-glibc@2.5.0': resolution: {integrity: sha512-BfNjXwZKxBy4WibDb/LDCriWSKLz+jJRL3cM/DllnHH5QUyoiUNEp3GmL80ZqxeumoADfCCP19+qiYiC8gUBjA==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@parcel/watcher-linux-arm64-musl@2.5.0': resolution: {integrity: sha512-S1qARKOphxfiBEkwLUbHjCY9BWPdWnW9j7f7Hb2jPplu8UZ3nes7zpPOW9bkLbHRvWM0WDTsjdOTUgW0xLBN1Q==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] - libc: [musl] '@parcel/watcher-linux-x64-glibc@2.5.0': resolution: {integrity: sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] - libc: [glibc] '@parcel/watcher-linux-x64-musl@2.5.0': resolution: {integrity: sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] - libc: [musl] '@parcel/watcher-win32-arm64@2.5.0': resolution: {integrity: sha512-twtft1d+JRNkM5YbmexfcH/N4znDtjgysFaV9zvZmmJezQsKpkfLYJ+JFV3uygugK6AtIM2oADPkB2AdhBrNig==} @@ -1536,55 +1530,46 @@ packages: resolution: {integrity: sha512-9OwUnK/xKw6DyRlgx8UizeqRFOfi9mf5TYCw1uolDaJSbUmBxP85DE6T4ouCMoN6pXw8ZoTeZCSEfSaYo+/s1w==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.27.4': resolution: {integrity: sha512-Vgdo4fpuphS9V24WOV+KwkCVJ72u7idTgQaBoLRD0UxBAWTF9GWurJO9YD9yh00BzbkhpeXtm6na+MvJU7Z73A==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.27.4': resolution: {integrity: sha512-pleyNgyd1kkBkw2kOqlBx+0atfIIkkExOTiifoODo6qKDSpnc6WzUY5RhHdmTdIJXBdSnh6JknnYTtmQyobrVg==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.27.4': resolution: {integrity: sha512-caluiUXvUuVyCHr5DxL8ohaaFFzPGmgmMvwmqAITMpV/Q+tPoaHZ/PWa3t8B2WyoRcIIuu1hkaW5KkeTDNSnMA==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.27.4': resolution: {integrity: sha512-FScrpHrO60hARyHh7s1zHE97u0KlT/RECzCKAdmI+LEoC1eDh/RDji9JgFqyO+wPDb86Oa/sXkily1+oi4FzJQ==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.27.4': resolution: {integrity: sha512-qyyprhyGb7+RBfMPeww9FlHwKkCXdKHeGgSqmIXw9VSUtvyFZ6WZRtnxgbuz76FK7LyoN8t/eINRbPUcvXB5fw==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.27.4': resolution: {integrity: sha512-PFz+y2kb6tbh7m3A7nA9++eInGcDVZUACulf/KzDtovvdTizHpZaJty7Gp0lFwSQcrnebHOqxF1MaKZd7psVRg==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.27.4': resolution: {integrity: sha512-Ni8mMtfo+o/G7DVtweXXV/Ol2TFf63KYjTtoZ5f078AUgJTmaIJnj4JFU7TK/9SVWTaSJGxPi5zMDgK4w+Ez7Q==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.27.4': resolution: {integrity: sha512-5AeeAF1PB9TUzD+3cROzFTnAJAcVUGLuR8ng0E0WXGkYhp6RD6L+6szYVX+64Rs0r72019KHZS1ka1q+zU/wUw==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.27.4': resolution: {integrity: sha512-yOpVsA4K5qVwu2CaS3hHxluWIK5HQTjNV4tWjQXluMiiiu4pJj4BN98CvxohNCpcjMeTXk/ZMJBRbgRg8HBB6A==} @@ -1630,28 +1615,24 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [linux] - libc: [glibc] '@swc/core-linux-arm64-musl@1.9.3': resolution: {integrity: sha512-tzVH480RY6RbMl/QRgh5HK3zn1ZTFsThuxDGo6Iuk1MdwIbdFYUY034heWUTI4u3Db97ArKh0hNL0xhO3+PZdg==} engines: {node: '>=10'} cpu: [arm64] os: [linux] - libc: [musl] '@swc/core-linux-x64-gnu@1.9.3': resolution: {integrity: sha512-ivXXBRDXDc9k4cdv10R21ccBmGebVOwKXT/UdH1PhxUn9m/h8erAWjz5pcELwjiMf27WokqPgaWVfaclDbgE+w==} engines: {node: '>=10'} cpu: [x64] os: [linux] - libc: [glibc] '@swc/core-linux-x64-musl@1.9.3': resolution: {integrity: sha512-ILsGMgfnOz1HwdDz+ZgEuomIwkP1PHT6maigZxaCIuC6OPEhKE8uYna22uU63XvYcLQvZYDzpR3ms47WQPuNEg==} engines: {node: '>=10'} cpu: [x64] os: [linux] - libc: [musl] '@swc/core-win32-arm64-msvc@1.9.3': resolution: {integrity: sha512-e+XmltDVIHieUnNJHtspn6B+PCcFOMYXNJB1GqoCcyinkEIQNwC8KtWgMqUucUbEWJkPc35NHy9k8aCXRmw9Kg==} diff --git a/src/views/iot/home/components/MessageTrendCard.vue b/src/views/iot/home/components/MessageTrendCard.vue index e69de29bb..4e4e5e3b0 100644 --- a/src/views/iot/home/components/MessageTrendCard.vue +++ b/src/views/iot/home/components/MessageTrendCard.vue @@ -0,0 +1,232 @@ + + + diff --git a/src/views/iot/home/index.vue b/src/views/iot/home/index.vue index e88b219c3..489e6c4a0 100644 --- a/src/views/iot/home/index.vue +++ b/src/views/iot/home/index.vue @@ -52,30 +52,10 @@ - - -
-
+
@@ -83,17 +63,6 @@ + + diff --git a/src/views/iot/home/components/DeviceCountCard.vue b/src/views/iot/home/components/DeviceCountCard.vue index 5b7ea5d42..a09706ff4 100644 --- a/src/views/iot/home/components/DeviceCountCard.vue +++ b/src/views/iot/home/components/DeviceCountCard.vue @@ -1,11 +1,17 @@ @@ -16,6 +22,7 @@ import { CanvasRenderer } from 'echarts/renderers' import { TooltipComponent, LegendComponent } from 'echarts/components' import { LabelLayout } from 'echarts/features' import { IotStatisticsSummaryRespVO } from '@/api/iot/statistics' +import type { PropType } from 'vue' /** 设备数量统计卡片 */ defineOptions({ name: 'DeviceCountCard' }) @@ -24,64 +31,97 @@ const props = defineProps({ statsData: { type: Object as PropType, required: true + }, + loading: { + type: Boolean, + default: false } }) const deviceCountChartRef = ref() +// 是否有数据 +const hasData = computed(() => { + if (!props.statsData) return false + + const categories = Object.entries(props.statsData.productCategoryDeviceCounts || {}) + return categories.length > 0 && props.statsData.deviceCount !== -1 +}) + // 初始化图表 const initChart = () => { + // 如果没有数据,则不初始化图表 + if (!hasData.value) return + + // 确保 DOM 元素存在且已渲染 + if (!deviceCountChartRef.value) { + console.warn('图表DOM元素不存在') + return + } + echarts.use([TooltipComponent, LegendComponent, PieChart, CanvasRenderer, LabelLayout]) - const chart = echarts.init(deviceCountChartRef.value) - chart.setOption({ - tooltip: { - trigger: 'item' - }, - legend: { - top: '5%', - right: '10%', - align: 'left', - orient: 'vertical', - icon: 'circle' - }, - series: [ - { - name: 'Access From', - type: 'pie', - radius: ['50%', '80%'], - avoidLabelOverlap: false, - center: ['30%', '50%'], - label: { - show: false, - position: 'outside' - }, - emphasis: { + try { + const chart = echarts.init(deviceCountChartRef.value) + chart.setOption({ + tooltip: { + trigger: 'item' + }, + legend: { + top: '5%', + right: '10%', + align: 'left', + orient: 'vertical', + icon: 'circle' + }, + series: [ + { + name: 'Access From', + type: 'pie', + radius: ['50%', '80%'], + avoidLabelOverlap: false, + center: ['30%', '50%'], label: { - show: true, - fontSize: 20, - fontWeight: 'bold' - } - }, - labelLine: { - show: false - }, - data: Object.entries(props.statsData.productCategoryDeviceCounts).map(([name, value]) => ({ - name, - value - })) - } - ] - }) + show: false, + position: 'outside' + }, + emphasis: { + label: { + show: true, + fontSize: 20, + fontWeight: 'bold' + } + }, + labelLine: { + show: false + }, + data: Object.entries(props.statsData.productCategoryDeviceCounts).map(([name, value]) => ({ + name, + value + })) + } + ] + }) + return chart + } catch (error) { + console.error('初始化图表失败:', error) + return null + } } // 监听数据变化 watch(() => props.statsData, () => { - initChart() + // 使用 nextTick 确保 DOM 已更新 + nextTick(() => { + initChart() + }) }, { deep: true }) // 组件挂载时初始化图表 onMounted(() => { - initChart() + // 使用 nextTick 确保 DOM 已更新 + nextTick(() => { + initChart() + }) }) diff --git a/src/views/iot/home/components/DeviceStateCountCard.vue b/src/views/iot/home/components/DeviceStateCountCard.vue index 33415ea33..849a3b899 100644 --- a/src/views/iot/home/components/DeviceStateCountCard.vue +++ b/src/views/iot/home/components/DeviceStateCountCard.vue @@ -1,11 +1,17 @@