Commit ddadfbc5d6026a2e186307b54dadd349aceebe9f

Authored by ww
1 parent d62a76a0

feat: deivce list model of matter panel add unit

1   -import { DataType } from './modelOfMatterModel';
  1 +import { StructJSON } from './modelOfMatterModel';
2 2 import { BasicPageParams } from '/@/api/model/baseModel';
3 3 import { AlarmStatus } from '/@/views/alarm/log/config/detail.config';
4 4 export enum DeviceState {
... ... @@ -90,5 +90,5 @@ export interface DeviceRecord {
90 90 export interface DeviceModelOfMatterAttrs {
91 91 name: string;
92 92 identifier: string;
93   - detail: DataType;
  93 + detail: StructJSON;
94 94 }
... ...
... ... @@ -17,7 +17,7 @@ export interface Specs {
17 17
18 18 export interface DataType {
19 19 type: string;
20   - specs?: Partial<Specs> | ModelOfMatterParams[];
  20 + specs?: Partial<Specs> | StructJSON[];
21 21 }
22 22
23 23 export interface StructJSON {
... ...
... ... @@ -16,6 +16,8 @@
16 16 import { getDeviceAttrs } from '/@/api/device/deviceManager';
17 17 import { DeviceModelOfMatterAttrs } from '/@/api/device/model/deviceModel';
18 18 import { computed } from '@vue/reactivity';
  19 + import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel';
  20 + import { isObject } from '/@/utils/is';
19 21
20 22 interface ReceiveMessage {
21 23 data: {
... ... @@ -122,11 +124,21 @@
122 124
123 125 const { createMessage } = useMessage();
124 126
  127 + const getUnit = (record: StructJSON) => {
  128 + const { dataType } = record;
  129 + const { specs } = dataType! || {};
  130 +
  131 + return isObject(specs)
  132 + ? (specs as Specs).unitName && (specs as Specs).unit
  133 + ? `${(specs as Specs).unitName}/${(specs as Specs).unit}`
  134 + : ''
  135 + : '';
  136 + };
  137 +
125 138 const { send, close, data } = useWebSocket(socketInfo.origin, {
126 139 async onConnected() {
127 140 const { id, profileId } = props.deviceDetail;
128 141 const value = await getDeviceAttrs(profileId, id);
129   - console.log(value);
130 142 socketInfo.attrKeys = value;
131 143 send(JSON.stringify(unref(getSendValue)));
132 144 },
... ... @@ -140,11 +152,11 @@
140 152 socketInfo.message[key] = value.data[key];
141 153 });
142 154
143   - const allKeys = Object.keys(socketInfo.message);
144   -
145   - socketInfo.originData = socketInfo.dataSource = allKeys.map((key) => {
  155 + socketInfo.originData = socketInfo.dataSource = socketInfo.attrKeys.map((item) => {
  156 + const { identifier: key, name, detail } = item;
  157 + const unit = getUnit(detail);
146 158 const [time, value] = socketInfo.message[key].at(0) || [];
147   - return { key, value, time };
  159 + return { key, value, time, name, unit };
148 160 });
149 161
150 162 await nextTick();
... ... @@ -153,7 +165,6 @@
153 165 } catch (error) {}
154 166 },
155 167 onDisconnected() {
156   - console.log('断开连接了');
157 168 close();
158 169 },
159 170 onError() {
... ... @@ -212,16 +223,17 @@
212 223 <List.Item>
213 224 <Card class="shadow-md">
214 225 <template #title>
215   - <span class="text-base font-normal">{{ item.key }}</span>
  226 + <span class="text-base font-normal">{{ item.name }}</span>
216 227 </template>
217 228 <template #extra>
218 229 <Button type="link" class="!p-0" @click="handleShowDetail(item)">历史数据</Button>
219 230 </template>
220 231 <section class="min-h-16 flex flex-col justify-between">
221   - <div class="flex font-bold text-lg mb-4">
222   - <div>{{ item.value || '暂无数据' }}</div>
  232 + <div class="flex font-bold text-lg mb-4 gap-2">
  233 + <div>{{ item.value || '--' }}</div>
  234 + <div>{{ item.unit }}</div>
223 235 </div>
224   - <div class="text-dark-800 text-xs">{{ formatToDateTime(item.time) }}</div>
  236 + <div class="text-dark-800 text-xs">{{ formatToDateTime(item.time) || '--' }}</div>
225 237 </section>
226 238 </Card>
227 239 </List.Item>
... ...