feat(property): 添加水电气表当前读数功能

- 新增 currentReading 函数获取水电气表当前读数和状态
- 更新 floor-tree 组件,增加 isMeter 属性控制是否显示电表数据
- 重构 electricitySituation 页面,展示电表当前读数和状态信息
- 优化 waterSituation 页面,引入 floor-tree 组件
This commit is contained in:
2025-08-31 12:48:27 +08:00
parent f951aeb520
commit 55e57eb219
4 changed files with 155 additions and 78 deletions

View File

@@ -1,6 +1,6 @@
import type { MeterInfoVO, MeterInfoForm, MeterInfoQuery } from './model' import type { MeterInfoVO, MeterInfoForm, MeterInfoQuery } from './model'
import type { ID, IDS, PageResult, TreeNode } from '#/api/common'; import type { ID, IDS, PageResult, TreeNode } from '#/api/common'
import { commonExport } from '#/api/helper' import { commonExport } from '#/api/helper'
import { requestClient } from '#/api/request' import { requestClient } from '#/api/request'
@@ -64,6 +64,13 @@ export function meterInfoRemove(id: ID | IDS) {
* @param level * @param level
* @returns 水电气树 * @returns 水电气树
*/ */
export function queryTree(meterType: number | string) { export function queryTree(params?: any) {
return requestClient.get<TreeNode<Number>[]>(`/property/meterInfo/tree/${meterType}`) return requestClient.get<TreeNode<Number>[]>(`/property/meterInfo/tree`, { params })
}
/**
* 获取水/电/气表当前读数/状态
*/
export function currentReading(params?: any) {
return requestClient.get<MeterInfoVO[]>(`/property/meterInfo/currentReading`, { params })
} }

View File

@@ -1,14 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
import type { PropType } from "vue"; import type { PropType } from 'vue';
import { onMounted, ref } from "vue"; import { onMounted, ref } from 'vue';
import { handleNode } from "@vben/utils"; import { handleNode } from '@vben/utils';
import { Empty, Skeleton, Tree } from "ant-design-vue"; import { Empty, Skeleton, Tree } from 'ant-design-vue';
import { queryTree } from "#/api/property/energyManagement/meterInfo"; import { queryTree } from '#/api/property/energyManagement/meterInfo';
import type { TreeNode } from "#/api/common"; import type { TreeNode } from '#/api/common';
defineOptions({ inheritAttrs: false }); defineOptions({ inheritAttrs: false });
withDefaults(defineProps<{ showSearch?: boolean }>(), { showSearch: true }); const props = defineProps({
isMeter: {
type: Boolean,
default: true,
},
});
const emit = defineEmits<{ const emit = defineEmits<{
/** /**
@@ -23,13 +28,13 @@ const emit = defineEmits<{
select: [selectedKeys: string[], info: any]; select: [selectedKeys: string[], info: any];
}>(); }>();
const selectTreeId = defineModel("selectTreeId", { const selectTreeId = defineModel('selectTreeId', {
type: Array as PropType<string[]>, type: Array as PropType<string[]>,
}); });
const searchValue = defineModel("searchValue", { const searchValue = defineModel('searchValue', {
type: String, type: String,
default: "", default: '',
}); });
const treeArray = ref<TreeNode[]>([]); const treeArray = ref<TreeNode[]>([]);
@@ -38,8 +43,8 @@ const showTreeSkeleton = ref<boolean>(true);
async function loadTree() { async function loadTree() {
showTreeSkeleton.value = true; showTreeSkeleton.value = true;
searchValue.value = ""; searchValue.value = '';
const ret = await queryTree(1); const ret = await queryTree({ meterType: 1, isMeter: props.isMeter });
handleNode(ret, 3); handleNode(ret, 3);
treeArray.value = ret; treeArray.value = ret;
showTreeSkeleton.value = false; showTreeSkeleton.value = false;
@@ -62,33 +67,46 @@ onMounted(loadTree);
<template> <template>
<div :class="$attrs.class"> <div :class="$attrs.class">
<Skeleton :loading="showTreeSkeleton" <Skeleton
:loading="showTreeSkeleton"
:paragraph="{ rows: 8 }" :paragraph="{ rows: 8 }"
active active
class="p-[8px] flex-1 min-h-0"> class="min-h-0 flex-1 p-[8px]"
<div class="bg-background flex h-full flex-col overflow-y-auto rounded-lg"> >
<div
class="bg-background flex h-full flex-col overflow-y-auto rounded-lg"
>
<div class="h-full overflow-x-hidden px-[8px]"> <div class="h-full overflow-x-hidden px-[8px]">
<Tree v-bind="$attrs" <Tree
v-bind="$attrs"
v-if="treeArray.length > 0" v-if="treeArray.length > 0"
v-model:selected-keys="selectTreeId" v-model:selected-keys="selectTreeId"
:show-line="{ showLeafIcon: false }" :show-line="{ showLeafIcon: false }"
:tree-data="treeArray" :tree-data="treeArray"
:virtual="false" :virtual="false"
default-expand-all default-expand-all
@select="(selectedKeys, info) => $emit('select', selectedKeys, info)"> @select="
(selectedKeys, info) => $emit('select', selectedKeys, info)
"
>
<template #title="{ label }"> <template #title="{ label }">
<span v-if="label.indexOf(searchValue) > -1"> <span v-if="label.indexOf(searchValue) > -1">
{{ label.substring(0, label.indexOf(searchValue)) }} {{ label.substring(0, label.indexOf(searchValue)) }}
<span style="color: #f50">{{ searchValue }}</span> <span style="color: #f50">{{ searchValue }}</span>
{{ label.substring(label.indexOf(searchValue) + searchValue.length) }} {{
label.substring(
label.indexOf(searchValue) + searchValue.length,
)
}}
</span> </span>
<span v-else>{{ label }}</span> <span v-else>{{ label }}</span>
</template> </template>
</Tree> </Tree>
<div v-else <div v-else class="mt-5">
class="mt-5"> <Empty
<Empty :image="Empty.PRESENTED_IMAGE_SIMPLE" :image="Empty.PRESENTED_IMAGE_SIMPLE"
description="暂无数据" /> description="暂无数据"
/>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,50 +1,91 @@
<script setup lang="ts"> <script setup lang="ts">
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
import { BackTop } from 'ant-design-vue'; import { BackTop, message, Spin } from 'ant-design-vue';
import { ref, onMounted, onBeforeUnmount, reactive } from 'vue'; import { ref, onMounted, onBeforeUnmount, reactive } from 'vue';
import FloorTree from '../components/floor-tree.vue'; import FloorTree from '../components/floor-tree.vue';
import { meterRecordTrend } from '#/api/property/energyManagement/meterRecord'; import { currentReading } from '#/api/property/energyManagement/meterInfo';
onMounted(() => {}); onMounted(() => {});
onBeforeUnmount(() => {}); onBeforeUnmount(() => {});
const trendData = ref<any>({}); const readingData = ref<any>({});
async function handleSelectFloor(selectedKeys, info) {} const readingTime = ref('');
let readingLoading = ref(false);
async function handleSelectFloor(selectedKeys, info) {
if (typeof selectedKeys[0] === 'undefined') {
return;
}
readingLoading.value = true;
const reading = await currentReading({
meterType: 1,
floorId: selectedKeys[0],
});
readingLoading.value = false;
if (reading === null) {
message.warn('当前楼层暂无电表数据!');
}
const nowTime =
new Date().toLocaleDateString().replace(/\//g, '-') +
' ' +
new Date().toLocaleTimeString();
readingTime.value = nowTime;
readingData.value = reading;
}
function targetFn() { function targetFn() {
return document.querySelector('.flex-1') return document.getElementById('right-panel');
} }
</script> </script>
<template> <template>
<Page :auto-content-height="true"> <Page :auto-content-height="true">
<div class="flex h-full gap-[8px]"> <div class="flex h-full gap-[8px]">
<FloorTree class="w-[260px]" @select="handleSelectFloor"></FloorTree> <FloorTree
<div class="flex-1"> :isMeter="false"
class="w-[260px]"
@select="handleSelectFloor"
></FloorTree>
<div class="flex-1" id="right-panel">
<Spin :spinning="readingLoading" size="large" style="height: 100px">
<div class="cards-container"> <div class="cards-container">
<div v-for="item in 50" class="plan-card"> <div v-for="item in readingData" class="meterInfo-card">
<h2>4楼电表1号<span>For business sedrvices</span></h2> <h2>
<div class="etiquet-price"> {{ item.meterName }}<span>{{ item.installLocation }}</span>
<p>254.99</p> </h2>
<div class="meterInfo-reading">
<p>{{ item.initReading }}</p>
<div></div> <div></div>
</div> </div>
<div class="benefits-list"> <div class="meterInfo-list">
<ul> <ul>
<li><span>Anlysis</span></li> <li>
<li><span>Consulting</span></li> <span>时间</span>
<li><span>Consulting</span></li> <span>{{ readingTime }}</span>
</li>
<li>
<span>采集器IP</span>
<span>{{ item.hostIp }}</span>
</li>
</ul> </ul>
</div> </div>
<div class="button-get-plan"> <div class="button-get-plan">
<a href="#"> <a
<span>START PROJECT</span> href="#"
v-if="item.communicationState !== 0"
style="background: #6bb1e3"
>
<span>在线</span>
</a>
<a href="#" v-else style="background: orange">
<span>离线</span>
</a> </a>
</div> </div>
</div> </div>
</div> </div>
<BackTop :target="targetFn"></BackTop> </Spin>
</div> </div>
<BackTop class="back-to-top" :target="targetFn"></BackTop>
</div> </div>
</Page> </Page>
</template> </template>
@@ -67,7 +108,7 @@ async function handleSelectFloor(selectedKeys, info) {}
gap: 20px; /* 使用gap替代margin控制间距 */ gap: 20px; /* 使用gap替代margin控制间距 */
} }
.plan-card { .meterInfo-card {
background: #fff; background: #fff;
width: 15rem; width: 15rem;
padding-left: 2rem; padding-left: 2rem;
@@ -78,18 +119,18 @@ async function handleSelectFloor(selectedKeys, info) {}
border-bottom: 4px solid #87ceeb; border-bottom: 4px solid #87ceeb;
box-shadow: 0 6px 30px rgba(173, 216, 230, 0.3); box-shadow: 0 6px 30px rgba(173, 216, 230, 0.3);
font-family: 'Poppins', sans-serif; font-family: 'Poppins', sans-serif;
height: 306px; height: 290px;
margin: 0 5px 20px 5px; margin: 0 5px 20px 5px;
} }
.plan-card h2 { .meterInfo-card h2 {
margin-bottom: 15px; margin-bottom: 15px;
font-size: 27px; font-size: 27px;
color: #5faee3; color: #5faee3;
font-weight: 600; font-weight: 600;
} }
.plan-card h2 span { .meterInfo-card h2 span {
display: block; display: block;
margin-top: -4px; margin-top: -4px;
color: #7eb8da; color: #7eb8da;
@@ -97,7 +138,7 @@ async function handleSelectFloor(selectedKeys, info) {}
font-weight: 400; font-weight: 400;
} }
.etiquet-price { .meterInfo-reading {
position: relative; position: relative;
background: #f0f8ff; background: #f0f8ff;
width: 14.46rem; width: 14.46rem;
@@ -106,7 +147,7 @@ async function handleSelectFloor(selectedKeys, info) {}
border-radius: 5px 0 0 5px; border-radius: 5px 0 0 5px;
} }
.etiquet-price p { .meterInfo-reading p {
margin: 0; margin: 0;
padding-top: 0.4rem; padding-top: 0.4rem;
display: flex; display: flex;
@@ -115,21 +156,21 @@ async function handleSelectFloor(selectedKeys, info) {}
color: #4a8cbb; color: #4a8cbb;
} }
.etiquet-price p:before { .meterInfo-reading p:before {
content: ''; content: '';
margin-right: 5px; margin-right: 5px;
font-size: 15px; font-size: 15px;
font-weight: 300; font-weight: 300;
} }
.etiquet-price p:after { .meterInfo-reading p:after {
content: '/ KW.H'; content: '/ KW.H';
margin-left: 5px; margin-left: 5px;
font-size: 15px; font-size: 15px;
font-weight: 300; font-weight: 300;
} }
.etiquet-price div { .meterInfo-reading div {
position: absolute; position: absolute;
bottom: -23px; bottom: -23px;
right: 0px; right: 0px;
@@ -141,16 +182,16 @@ async function handleSelectFloor(selectedKeys, info) {}
z-index: 1; z-index: 1;
} }
.benefits-list { .meterInfo-list {
margin-top: 16px; margin-top: 16px;
} }
.benefits-list ul { .meterInfo-list ul {
padding: 0; padding: 0;
font-size: 14px; font-size: 14px;
} }
.benefits-list ul li { .meterInfo-list ul li {
color: #5a7d9a; color: #5a7d9a;
list-style: none; list-style: none;
margin-bottom: 0.2rem; margin-bottom: 0.2rem;
@@ -159,12 +200,12 @@ async function handleSelectFloor(selectedKeys, info) {}
gap: 0.5rem; gap: 0.5rem;
} }
.benefits-list ul li svg { .meterInfo-list ul li svg {
width: 0.9rem; width: 0.9rem;
fill: currentColor; fill: currentColor;
} }
.benefits-list ul li span { .meterInfo-list ul li span {
font-weight: 300; font-weight: 300;
} }
@@ -178,7 +219,7 @@ async function handleSelectFloor(selectedKeys, info) {}
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background: #6bb1e3;
color: #fff; color: #fff;
padding: 10px 15px; padding: 10px 15px;
border-radius: 5px; border-radius: 5px;
@@ -200,4 +241,15 @@ async function handleSelectFloor(selectedKeys, info) {}
width: 0.9rem; width: 0.9rem;
fill: currentColor; fill: currentColor;
} }
.back-to-top {
width: 50px;
height: 50px;
}
/* 返回顶部按钮 */
.back-to-top:hover {
background-color: #6bb1e3;
transform: translateY(-5px);
}
</style> </style>

View File

@@ -81,7 +81,7 @@ import { Page } from '@vben/common-ui'
import { ref, onMounted, onBeforeUnmount, reactive } from 'vue' import { ref, onMounted, onBeforeUnmount, reactive } from 'vue'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import type { ECharts, EChartsOption } from 'echarts' import type { ECharts, EChartsOption } from 'echarts'
import FloorTree from "../../electricEnergy/components/floor-tree.vue" import FloorTree from "../components/floor-tree.vue"
const chainData = reactive({ const chainData = reactive({
currentMonthEnergy: '9', currentMonthEnergy: '9',