Commit a316e31e57c8a8b2b11dbb0ffe84029665717725

Authored by ww
2 parents 7d935277 39f28195

Merge remote-tracking branch 'origin/perf/main_dev' into perf/main_dev

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