Commit 7685e1c8ad215e054f43f9a5d92e7c9c209deed4

Authored by ww
1 parent 128ed29a

feat: implement data board component data source bind gatewary device

... ... @@ -75,7 +75,7 @@ export interface DataSource {
75 75 attributeRename: string;
76 76 deviceRename: string;
77 77 slaveDeviceId: string;
78   - isGatewayDevice: boolean;
  78 + gatewayDevice: boolean;
79 79 componentInfo: ComponentInfo;
80 80 deviceName?: string;
81 81
... ...
... ... @@ -8,7 +8,7 @@
8 8 import type { DataBoardRecord, UpdateDataBoardParams } from '/@/api/dataBoard/model';
9 9 import { ref, unref } from 'vue';
10 10
11   - const emit = defineEmits(['change']);
  11 + const emit = defineEmits(['change', 'register']);
12 12
13 13 const isEdit = ref(false);
14 14 const recordId = ref<Nullable<string>>(null);
... ... @@ -62,6 +62,7 @@
62 62
63 63 const handleGetValue = () => {
64 64 unref(isEdit) ? handleEditPanel() : handleCreatePanel();
  65 + isEdit.value = false;
65 66 };
66 67 </script>
67 68
... ...
... ... @@ -55,14 +55,12 @@
55 55 :style="{ width: `${100 / props.record.length}%` }"
56 56 :key="index"
57 57 >
58   - <SvgIcon name="" prefix="iconfont" class="!fill-emerald-400" />
59   - {{ item.deviceName }}
60   - <!-- <div class="flex items-center">
61   - <Tooltip>
62   - <SvgIcon name="online" prefix="iconfont" class="!fill-emerald-400" />
63   - </Tooltip>
64   - <div class="truncate">{{ item.deviceName || item.deviceId }}</div>
65   - </div> -->
  58 + <Tooltip :title="item.deviceName" placement="topLeft">
  59 + <span>
  60 + <SvgIcon name="" prefix="iconfont" class="!fill-emerald-400" />
  61 + <span>{{ item.deviceName }}</span>
  62 + </span>
  63 + </Tooltip>
66 64 </div>
67 65 </div>
68 66 <div class="flex items-center w-10">
... ...
... ... @@ -31,10 +31,11 @@
31 31 const componentRecord = ref<DataBoardLayoutInfo>({} as unknown as DataBoardLayoutInfo);
32 32
33 33 const [register, { closeModal, changeOkLoading }] = useModalInner(
34   - (record: DataBoardLayoutInfo & { isEdit: boolean }) => {
35   - componentRecord.value = record;
36   - frontId.value = record.record.frontId;
37   - isEdit.value = record.isEdit || false;
  34 + (data: { isEdit: boolean; record?: DataBoardLayoutInfo }) => {
  35 + componentRecord.value = data.record || ({} as unknown as DataBoardLayoutInfo);
  36 + frontId.value = data.record?.record?.frontId || '';
  37 + isEdit.value = data.isEdit || false;
  38 + console.log(unref(isEdit));
38 39 }
39 40 );
40 41
... ... @@ -47,6 +48,7 @@
47 48 const value = getAllDataSourceFieldValue();
48 49 unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value);
49 50 isEdit.value = false;
  51 + frontId.value = '';
50 52 };
51 53
52 54 const handleAddComponent = async (value: Recordable) => {
... ... @@ -95,7 +97,7 @@
95 97 @register="register"
96 98 title="自定义组件"
97 99 width="70%"
98   - destroy-on-close
  100 + :destroy-on-close="true"
99 101 @ok="handleSubmit"
100 102 >
101 103 <section>
... ...
... ... @@ -17,7 +17,7 @@ const getDeviceAttribute = async (deviceId: string) => {
17 17 };
18 18
19 19 export enum DataSourceField {
20   - IS_GATEWAY_DEVICE = 'isGatewayDevice',
  20 + IS_GATEWAY_DEVICE = 'gatewayDevice',
21 21 ORIGINATION_ID = 'organizationId',
22 22 DEVICE_ID = 'deviceId',
23 23 SLAVE_DEVICE_ID = 'slaveDeviceId',
... ... @@ -127,7 +127,7 @@ export const dataSourceSchema: FormSchema[] = [
127 127 component: 'ApiSelect',
128 128 colProps: { span: 8 },
129 129 ifShow({ model }) {
130   - return model['isGatewayDevice'];
  130 + return model[DataSourceField.IS_GATEWAY_DEVICE];
131 131 },
132 132 dynamicRules({ model }) {
133 133 return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }];
... ...
... ... @@ -142,7 +142,7 @@
142 142 };
143 143
144 144 const handleOpenCreatePanel = () => {
145   - openModal(true);
  145 + openModal(true, { isEdit: false });
146 146 };
147 147
148 148 const handleSaveLayoutInfo = async () => {
... ... @@ -214,7 +214,7 @@
214 214
215 215 const handleUpdate = async (id: string) => {
216 216 const record = unref(dataBoardList).find((item) => item.i === id);
217   - openModal(true, { isEdit: true, ...record });
  217 + openModal(true, { isEdit: true, record });
218 218 };
219 219
220 220 const handleCopy = async (id: string) => {
... ...
... ... @@ -100,21 +100,24 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
100 100 const transformSocketMessageItem = () => {
101 101 const messageList: SocketMessageItem[] = [];
102 102 let index = 0;
  103 + console.log(unref(dataSourceRef));
103 104 unref(dataSourceRef).forEach((record, recordIndex) => {
104 105 const componentId = record.record.id;
105 106 record.record.dataSource.forEach((dataSource, dataSourceIndex) => {
106   - const { deviceId, attribute } = dataSource;
  107 + const { deviceId, attribute, slaveDeviceId, gatewayDevice } = dataSource;
107 108 const cmdId = index;
108 109 index++;
109 110 setCmdId(cmdId, {
110 111 componentId,
111   - deviceId,
  112 + deviceId: gatewayDevice ? deviceId : slaveDeviceId,
112 113 recordIndex,
113 114 dataSourceIndex,
114 115 attribute,
115 116 });
116 117
117   - messageList.push(generateMessage(deviceId, cmdId, attribute));
  118 + messageList.push(
  119 + generateMessage(gatewayDevice ? slaveDeviceId : deviceId, cmdId, attribute)
  120 + );
118 121 });
119 122 });
120 123 return {
... ...