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 import { BasicPageParams } from '/@/api/model/baseModel'; 2 import { BasicPageParams } from '/@/api/model/baseModel';
3 import { AlarmStatus } from '/@/views/alarm/log/config/detail.config'; 3 import { AlarmStatus } from '/@/views/alarm/log/config/detail.config';
4 export enum DeviceState { 4 export enum DeviceState {
@@ -90,5 +90,5 @@ export interface DeviceRecord { @@ -90,5 +90,5 @@ export interface DeviceRecord {
90 export interface DeviceModelOfMatterAttrs { 90 export interface DeviceModelOfMatterAttrs {
91 name: string; 91 name: string;
92 identifier: string; 92 identifier: string;
93 - detail: DataType; 93 + detail: StructJSON;
94 } 94 }
@@ -17,7 +17,7 @@ export interface Specs { @@ -17,7 +17,7 @@ export interface Specs {
17 17
18 export interface DataType { 18 export interface DataType {
19 type: string; 19 type: string;
20 - specs?: Partial<Specs> | ModelOfMatterParams[]; 20 + specs?: Partial<Specs> | StructJSON[];
21 } 21 }
22 22
23 export interface StructJSON { 23 export interface StructJSON {
@@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
16 import { getDeviceAttrs } from '/@/api/device/deviceManager'; 16 import { getDeviceAttrs } from '/@/api/device/deviceManager';
17 import { DeviceModelOfMatterAttrs } from '/@/api/device/model/deviceModel'; 17 import { DeviceModelOfMatterAttrs } from '/@/api/device/model/deviceModel';
18 import { computed } from '@vue/reactivity'; 18 import { computed } from '@vue/reactivity';
  19 + import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel';
  20 + import { isObject } from '/@/utils/is';
19 21
20 interface ReceiveMessage { 22 interface ReceiveMessage {
21 data: { 23 data: {
@@ -122,11 +124,21 @@ @@ -122,11 +124,21 @@
122 124
123 const { createMessage } = useMessage(); 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 const { send, close, data } = useWebSocket(socketInfo.origin, { 138 const { send, close, data } = useWebSocket(socketInfo.origin, {
126 async onConnected() { 139 async onConnected() {
127 const { id, profileId } = props.deviceDetail; 140 const { id, profileId } = props.deviceDetail;
128 const value = await getDeviceAttrs(profileId, id); 141 const value = await getDeviceAttrs(profileId, id);
129 - console.log(value);  
130 socketInfo.attrKeys = value; 142 socketInfo.attrKeys = value;
131 send(JSON.stringify(unref(getSendValue))); 143 send(JSON.stringify(unref(getSendValue)));
132 }, 144 },
@@ -140,11 +152,11 @@ @@ -140,11 +152,11 @@
140 socketInfo.message[key] = value.data[key]; 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 const [time, value] = socketInfo.message[key].at(0) || []; 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 await nextTick(); 162 await nextTick();
@@ -153,7 +165,6 @@ @@ -153,7 +165,6 @@
153 } catch (error) {} 165 } catch (error) {}
154 }, 166 },
155 onDisconnected() { 167 onDisconnected() {
156 - console.log('断开连接了');  
157 close(); 168 close();
158 }, 169 },
159 onError() { 170 onError() {
@@ -212,16 +223,17 @@ @@ -212,16 +223,17 @@
212 <List.Item> 223 <List.Item>
213 <Card class="shadow-md"> 224 <Card class="shadow-md">
214 <template #title> 225 <template #title>
215 - <span class="text-base font-normal">{{ item.key }}</span> 226 + <span class="text-base font-normal">{{ item.name }}</span>
216 </template> 227 </template>
217 <template #extra> 228 <template #extra>
218 <Button type="link" class="!p-0" @click="handleShowDetail(item)">历史数据</Button> 229 <Button type="link" class="!p-0" @click="handleShowDetail(item)">历史数据</Button>
219 </template> 230 </template>
220 <section class="min-h-16 flex flex-col justify-between"> 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 </div> 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 </section> 237 </section>
226 </Card> 238 </Card>
227 </List.Item> 239 </List.Item>