Commit 4eaa9ed7ea7c597beee8fb2c2e18bedbe613ca25

Authored by loveumiko
1 parent f280184c

fix: 修改参数设置命令下发的问题

@@ -4,6 +4,8 @@ export interface ProductAndDevice { @@ -4,6 +4,8 @@ export interface ProductAndDevice {
4 name: string 4 name: string
5 profileName?: string 5 profileName?: string
6 profileId: string 6 profileId: string
  7 + transportType?: string
  8 + deviceType?: string
7 deviceList: { 9 deviceList: {
8 deviceId: string 10 deviceId: string
9 name: string 11 name: string
@@ -12,6 +12,15 @@ import { ThingsModelForm } from '@/core/Library/components/ThingsModelForm' @@ -12,6 +12,15 @@ import { ThingsModelForm } from '@/core/Library/components/ThingsModelForm'
12 import { useMessage } from '@/hooks/web/useMessage' 12 import { useMessage } from '@/hooks/web/useMessage'
13 import type { StructJSON } from '@/api/device/model' 13 import type { StructJSON } from '@/api/device/model'
14 14
  15 +interface ServiceInfo {
  16 + title?: string
  17 + serviceCommand?: Object
  18 + inputData?: []
  19 + transportType?: string
  20 + callType?: string
  21 + code?: string
  22 +}
  23 +
15 const visible = ref<boolean>(false) 24 const visible = ref<boolean>(false)
16 25
17 const { createMessage } = useMessage() 26 const { createMessage } = useMessage()
@@ -33,12 +42,13 @@ const deviceTitle = ref<string | undefined>()// 设备名称 @@ -33,12 +42,13 @@ const deviceTitle = ref<string | undefined>()// 设备名称
33 42
34 const isPasswordInfo = ref<{ checked?: boolean; value?: string | number; label?: string }>({})// 是否需要操作密码才进行命令下发 43 const isPasswordInfo = ref<{ checked?: boolean; value?: string | number; label?: string }>({})// 是否需要操作密码才进行命令下发
35 44
36 -const serviceInfo = reactive<any>({ 45 +const serviceInfo = reactive<ServiceInfo>({
37 title: '', 46 title: '',
38 serviceCommand: {}, 47 serviceCommand: {},
39 inputData: [], 48 inputData: [],
40 transportType: '', 49 transportType: '',
41 callType: '', 50 callType: '',
  51 + code: '',
42 }) 52 })
43 53
44 const [register, { getFieldsValue, validate, setFieldsValue, updateSchema, setProps }] = useForm({ // 自定义下发值 54 const [register, { getFieldsValue, validate, setFieldsValue, updateSchema, setProps }] = useForm({ // 自定义下发值
@@ -64,13 +74,12 @@ const [registerPassword, { getFieldsValue: getPasswordValue, validate: validateP @@ -64,13 +74,12 @@ const [registerPassword, { getFieldsValue: getPasswordValue, validate: validateP
64 labelWidth: 110, 74 labelWidth: 110,
65 }) 75 })
66 76
67 -const getServiceInfo = async (deviceProfileId: string, transportType: string, service?: string, serviceCommand?: Recordable) => { 77 +const getServiceInfo = async (deviceProfileId: string, service?: string, serviceCommand?: Recordable) => {
68 isInputData.value = true 78 isInputData.value = true
69 const functionJson: any = await getThingsModelServices(deviceProfileId) 79 const functionJson: any = await getThingsModelServices(deviceProfileId)
70 serviceInfo.inputData = functionJson.filter((item: any) => item.identifier === service)?.[0].functionJson.inputData 80 serviceInfo.inputData = functionJson.filter((item: any) => item.identifier === service)?.[0].functionJson.inputData
71 serviceInfo.title = functionJson[0].functionName 81 serviceInfo.title = functionJson[0].functionName
72 serviceInfo.serviceCommand = serviceCommand 82 serviceInfo.serviceCommand = serviceCommand
73 - serviceInfo.transportType = transportType  
74 } 83 }
75 84
76 // 获取设备信息 85 // 获取设备信息
@@ -102,11 +111,14 @@ const open = async (_data: SingleClickEventDataType) => { @@ -102,11 +111,14 @@ const open = async (_data: SingleClickEventDataType) => {
102 isShowActionType.value = !!actionType // 判断modBUS类型时 物模型是否填写扩展描述 111 isShowActionType.value = !!actionType // 判断modBUS类型时 物模型是否填写扩展描述
103 serviceInfo.callType = callType // 服务命令调用方式 是同步还是异步 112 serviceInfo.callType = callType // 服务命令调用方式 是同步还是异步
104 113
  114 + serviceInfo.transportType = transportType
  115 + serviceInfo.code = code
  116 +
105 visible.value = true 117 visible.value = true
106 118
107 if (transportType === TransportTypeEnum.TCP) { 119 if (transportType === TransportTypeEnum.TCP) {
108 if (commandWay === CommandDeliveryWayEnum.SERVICE) { // 命令下发方式是服务或则自定义调用 120 if (commandWay === CommandDeliveryWayEnum.SERVICE) { // 命令下发方式是服务或则自定义调用
109 - getServiceInfo(deviceProfileId, transportType, service, serviceCommand) 121 + getServiceInfo(deviceProfileId, service, serviceCommand)
110 } 122 }
111 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) { // 自定义 123 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) { // 自定义
112 await nextTick() 124 await nextTick()
@@ -138,7 +150,7 @@ const open = async (_data: SingleClickEventDataType) => { @@ -138,7 +150,7 @@ const open = async (_data: SingleClickEventDataType) => {
138 isShowModBUS.value = false 150 isShowModBUS.value = false
139 151
140 // 命令下发方式是服务或则自定义调用 152 // 命令下发方式是服务或则自定义调用
141 - if (commandWay === CommandDeliveryWayEnum.SERVICE) { getServiceInfo(deviceProfileId, transportType, service, serviceCommand) } 153 + if (commandWay === CommandDeliveryWayEnum.SERVICE) { getServiceInfo(deviceProfileId, service, serviceCommand) }
142 154
143 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) { 155 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) {
144 await nextTick() 156 await nextTick()
@@ -173,7 +185,6 @@ const handleSubmit = async () => { @@ -173,7 +185,6 @@ const handleSubmit = async () => {
173 return 185 return
174 } 186 }
175 } 187 }
176 -  
177 if (serviceInfo.callType === 'SYNC') { // 服务命令调用方式 是同步 需要调用设备是否在线才能下发 188 if (serviceInfo.callType === 'SYNC') { // 服务命令调用方式 是同步 需要调用设备是否在线才能下发
178 const res = await getDeviceActiveTime(dataSourceJson.value.deviceId) 189 const res = await getDeviceActiveTime(dataSourceJson.value.deviceId)
179 const { value } = res 190 const { value } = res
@@ -191,6 +202,11 @@ const handleSubmit = async () => { @@ -191,6 +202,11 @@ const handleSubmit = async () => {
191 createMessage.warning('当前物模型扩展描述没有填写') 202 createMessage.warning('当前物模型扩展描述没有填写')
192 return 203 return
193 } 204 }
  205 +
  206 + if (!serviceInfo.code) {
  207 + createMessage.error('当前缺少设备地址码')
  208 + return
  209 + }
194 const oldValue = getFieldsValue()[unref(formField)] 210 const oldValue = getFieldsValue()[unref(formField)]
195 modBUSForm.value.registerNumber = 1 211 modBUSForm.value.registerNumber = 1
196 modBUSForm.value.registerValues = [oldValue] 212 modBUSForm.value.registerValues = [oldValue]
@@ -237,7 +253,7 @@ const handleSubmit = async () => { @@ -237,7 +253,7 @@ const handleSubmit = async () => {
237 sendValue.value = values 253 sendValue.value = values
238 } 254 }
239 else { 255 else {
240 - const values = typeof JSON.parse(getFieldsValue().sendValue) ? JSON.parse(getFieldsValue().sendValue) : getFieldsValue().sendValue || {} 256 + const values = serviceInfo.transportType === TransportTypeEnum.TCP ? getFieldsValue().sendValue : JSON.parse(getFieldsValue().sendValue) || {}
241 sendValue.value = values 257 sendValue.value = values
242 } 258 }
243 } 259 }
@@ -37,8 +37,6 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { @@ -37,8 +37,6 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
37 const { deviceProfileId, deviceInfo } = dataSourceJson || {} 37 const { deviceProfileId, deviceInfo } = dataSourceJson || {}
38 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型 38 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型
39 const { transportType, deviceType } = deviceInfo || {} 39 const { transportType, deviceType } = deviceInfo || {}
40 - // if (!deviceProfileId)  
41 - // createMessage.warn('请先绑定数据源')  
42 40
43 return [ 41 return [
44 { 42 {