Commit 7685e1c8ad215e054f43f9a5d92e7c9c209deed4
1 parent
128ed29a
feat: implement data board component data source bind gatewary device
Showing
7 changed files
with
26 additions
and
22 deletions
| @@ -75,7 +75,7 @@ export interface DataSource { | @@ -75,7 +75,7 @@ export interface DataSource { | ||
| 75 | attributeRename: string; | 75 | attributeRename: string; |
| 76 | deviceRename: string; | 76 | deviceRename: string; |
| 77 | slaveDeviceId: string; | 77 | slaveDeviceId: string; |
| 78 | - isGatewayDevice: boolean; | 78 | + gatewayDevice: boolean; |
| 79 | componentInfo: ComponentInfo; | 79 | componentInfo: ComponentInfo; |
| 80 | deviceName?: string; | 80 | deviceName?: string; |
| 81 | 81 |
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | import type { DataBoardRecord, UpdateDataBoardParams } from '/@/api/dataBoard/model'; | 8 | import type { DataBoardRecord, UpdateDataBoardParams } from '/@/api/dataBoard/model'; |
| 9 | import { ref, unref } from 'vue'; | 9 | import { ref, unref } from 'vue'; |
| 10 | 10 | ||
| 11 | - const emit = defineEmits(['change']); | 11 | + const emit = defineEmits(['change', 'register']); |
| 12 | 12 | ||
| 13 | const isEdit = ref(false); | 13 | const isEdit = ref(false); |
| 14 | const recordId = ref<Nullable<string>>(null); | 14 | const recordId = ref<Nullable<string>>(null); |
| @@ -62,6 +62,7 @@ | @@ -62,6 +62,7 @@ | ||
| 62 | 62 | ||
| 63 | const handleGetValue = () => { | 63 | const handleGetValue = () => { |
| 64 | unref(isEdit) ? handleEditPanel() : handleCreatePanel(); | 64 | unref(isEdit) ? handleEditPanel() : handleCreatePanel(); |
| 65 | + isEdit.value = false; | ||
| 65 | }; | 66 | }; |
| 66 | </script> | 67 | </script> |
| 67 | 68 |
| @@ -55,14 +55,12 @@ | @@ -55,14 +55,12 @@ | ||
| 55 | :style="{ width: `${100 / props.record.length}%` }" | 55 | :style="{ width: `${100 / props.record.length}%` }" |
| 56 | :key="index" | 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 | </div> | 64 | </div> |
| 67 | </div> | 65 | </div> |
| 68 | <div class="flex items-center w-10"> | 66 | <div class="flex items-center w-10"> |
| @@ -31,10 +31,11 @@ | @@ -31,10 +31,11 @@ | ||
| 31 | const componentRecord = ref<DataBoardLayoutInfo>({} as unknown as DataBoardLayoutInfo); | 31 | const componentRecord = ref<DataBoardLayoutInfo>({} as unknown as DataBoardLayoutInfo); |
| 32 | 32 | ||
| 33 | const [register, { closeModal, changeOkLoading }] = useModalInner( | 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,6 +48,7 @@ | ||
| 47 | const value = getAllDataSourceFieldValue(); | 48 | const value = getAllDataSourceFieldValue(); |
| 48 | unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value); | 49 | unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value); |
| 49 | isEdit.value = false; | 50 | isEdit.value = false; |
| 51 | + frontId.value = ''; | ||
| 50 | }; | 52 | }; |
| 51 | 53 | ||
| 52 | const handleAddComponent = async (value: Recordable) => { | 54 | const handleAddComponent = async (value: Recordable) => { |
| @@ -95,7 +97,7 @@ | @@ -95,7 +97,7 @@ | ||
| 95 | @register="register" | 97 | @register="register" |
| 96 | title="自定义组件" | 98 | title="自定义组件" |
| 97 | width="70%" | 99 | width="70%" |
| 98 | - destroy-on-close | 100 | + :destroy-on-close="true" |
| 99 | @ok="handleSubmit" | 101 | @ok="handleSubmit" |
| 100 | > | 102 | > |
| 101 | <section> | 103 | <section> |
| @@ -17,7 +17,7 @@ const getDeviceAttribute = async (deviceId: string) => { | @@ -17,7 +17,7 @@ const getDeviceAttribute = async (deviceId: string) => { | ||
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | export enum DataSourceField { | 19 | export enum DataSourceField { |
| 20 | - IS_GATEWAY_DEVICE = 'isGatewayDevice', | 20 | + IS_GATEWAY_DEVICE = 'gatewayDevice', |
| 21 | ORIGINATION_ID = 'organizationId', | 21 | ORIGINATION_ID = 'organizationId', |
| 22 | DEVICE_ID = 'deviceId', | 22 | DEVICE_ID = 'deviceId', |
| 23 | SLAVE_DEVICE_ID = 'slaveDeviceId', | 23 | SLAVE_DEVICE_ID = 'slaveDeviceId', |
| @@ -127,7 +127,7 @@ export const dataSourceSchema: FormSchema[] = [ | @@ -127,7 +127,7 @@ export const dataSourceSchema: FormSchema[] = [ | ||
| 127 | component: 'ApiSelect', | 127 | component: 'ApiSelect', |
| 128 | colProps: { span: 8 }, | 128 | colProps: { span: 8 }, |
| 129 | ifShow({ model }) { | 129 | ifShow({ model }) { |
| 130 | - return model['isGatewayDevice']; | 130 | + return model[DataSourceField.IS_GATEWAY_DEVICE]; |
| 131 | }, | 131 | }, |
| 132 | dynamicRules({ model }) { | 132 | dynamicRules({ model }) { |
| 133 | return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }]; | 133 | return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }]; |
| @@ -142,7 +142,7 @@ | @@ -142,7 +142,7 @@ | ||
| 142 | }; | 142 | }; |
| 143 | 143 | ||
| 144 | const handleOpenCreatePanel = () => { | 144 | const handleOpenCreatePanel = () => { |
| 145 | - openModal(true); | 145 | + openModal(true, { isEdit: false }); |
| 146 | }; | 146 | }; |
| 147 | 147 | ||
| 148 | const handleSaveLayoutInfo = async () => { | 148 | const handleSaveLayoutInfo = async () => { |
| @@ -214,7 +214,7 @@ | @@ -214,7 +214,7 @@ | ||
| 214 | 214 | ||
| 215 | const handleUpdate = async (id: string) => { | 215 | const handleUpdate = async (id: string) => { |
| 216 | const record = unref(dataBoardList).find((item) => item.i === id); | 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 | const handleCopy = async (id: string) => { | 220 | const handleCopy = async (id: string) => { |
| @@ -100,21 +100,24 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | @@ -100,21 +100,24 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { | ||
| 100 | const transformSocketMessageItem = () => { | 100 | const transformSocketMessageItem = () => { |
| 101 | const messageList: SocketMessageItem[] = []; | 101 | const messageList: SocketMessageItem[] = []; |
| 102 | let index = 0; | 102 | let index = 0; |
| 103 | + console.log(unref(dataSourceRef)); | ||
| 103 | unref(dataSourceRef).forEach((record, recordIndex) => { | 104 | unref(dataSourceRef).forEach((record, recordIndex) => { |
| 104 | const componentId = record.record.id; | 105 | const componentId = record.record.id; |
| 105 | record.record.dataSource.forEach((dataSource, dataSourceIndex) => { | 106 | record.record.dataSource.forEach((dataSource, dataSourceIndex) => { |
| 106 | - const { deviceId, attribute } = dataSource; | 107 | + const { deviceId, attribute, slaveDeviceId, gatewayDevice } = dataSource; |
| 107 | const cmdId = index; | 108 | const cmdId = index; |
| 108 | index++; | 109 | index++; |
| 109 | setCmdId(cmdId, { | 110 | setCmdId(cmdId, { |
| 110 | componentId, | 111 | componentId, |
| 111 | - deviceId, | 112 | + deviceId: gatewayDevice ? deviceId : slaveDeviceId, |
| 112 | recordIndex, | 113 | recordIndex, |
| 113 | dataSourceIndex, | 114 | dataSourceIndex, |
| 114 | attribute, | 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 | return { | 123 | return { |