Commit 806534aa967f7f6b5ad309fa2d382498e9a2efc7

Authored by loveumiko
1 parent 5b3085cb

fix: 修改参数设置的问题i

@@ -91,6 +91,7 @@ export interface DeviceInfoType { @@ -91,6 +91,7 @@ export interface DeviceInfoType {
91 export interface NodeDataDataSourceJsonType { 91 export interface NodeDataDataSourceJsonType {
92 deviceId: string 92 deviceId: string
93 deviceProfileId: string 93 deviceProfileId: string
  94 + deviceProfileTemplateId?: string
94 attr: string 95 attr: string
95 attrInfo: ThingsModelItemType 96 attrInfo: ThingsModelItemType
96 97
@@ -29,7 +29,7 @@ const loading = ref<boolean>(false) @@ -29,7 +29,7 @@ const loading = ref<boolean>(false)
29 const dataSourceJson = ref<any>({}) 29 const dataSourceJson = ref<any>({})
30 const thingsModelElRef = ref() 30 const thingsModelElRef = ref()
31 31
32 -const isInputData = ref<boolean>(false)// 判断使用那个表单 32 +const isInputData = ref<boolean>(false)// 判断使用那个表单 true: 用封装的表单 false:用自己写的表单
33 33
34 const zoomFactorValue = ref<number>(1) // 缩放因子 34 const zoomFactorValue = ref<number>(1) // 缩放因子
35 const isShowMultiply = ref<boolean>(false) // 只有tcp --> int和double类型才相乘缩放因子 35 const isShowMultiply = ref<boolean>(false) // 只有tcp --> int和double类型才相乘缩放因子
@@ -100,7 +100,7 @@ const open = async (_data: SingleClickEventDataType) => { @@ -100,7 +100,7 @@ const open = async (_data: SingleClickEventDataType) => {
100 const { type } = dataType || {} 100 const { type } = dataType || {}
101 101
102 const { code, transportType, deviceProfileId, alias, name: deviceName } = await getDeviceDetail(deviceId) || {}// 设备信息 102 const { code, transportType, deviceProfileId, alias, name: deviceName } = await getDeviceDetail(deviceId) || {}// 设备信息
103 - deviceTitle.value = alias || deviceName 103 + deviceTitle.value = alias || deviceName// 产品名称
104 const { registerAddress, actionType, zoomFactor } = extensionDesc || {} // 获取扩展描述内容 104 const { registerAddress, actionType, zoomFactor } = extensionDesc || {} // 获取扩展描述内容
105 105
106 const schemas = [{ dataType, identifier, functionName: name } as StructJSON] 106 const schemas = [{ dataType, identifier, functionName: name } as StructJSON]
@@ -117,7 +117,7 @@ const open = async (_data: SingleClickEventDataType) => { @@ -117,7 +117,7 @@ const open = async (_data: SingleClickEventDataType) => {
117 visible.value = true 117 visible.value = true
118 118
119 if (transportType === TransportTypeEnum.TCP) { 119 if (transportType === TransportTypeEnum.TCP) {
120 - if (commandWay === CommandDeliveryWayEnum.SERVICE) { // 命令下发方式是服务或则自定义调用 120 + if (commandWay === CommandDeliveryWayEnum.SERVICE) { // 判断命令下发方式是服务或者自定义调用 服务调用用封装的组件 自定义和modbus就用输入框
121 getServiceInfo(deviceProfileId, service, serviceCommand) 121 getServiceInfo(deviceProfileId, service, serviceCommand)
122 } 122 }
123 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) { // 自定义 123 else if (commandWay === CommandDeliveryWayEnum.CUSTOM) { // 自定义
@@ -132,7 +132,7 @@ const open = async (_data: SingleClickEventDataType) => { @@ -132,7 +132,7 @@ const open = async (_data: SingleClickEventDataType) => {
132 ]) 132 ])
133 setFieldsValue({ sendValue: customCommand }) 133 setFieldsValue({ sendValue: customCommand })
134 } 134 }
135 - else { 135 + else { // modBus调用
136 isShowModBUS.value = true 136 isShowModBUS.value = true
137 modBUSForm.value = { 137 modBUSForm.value = {
138 crc: 'CRC_16_LOWER', 138 crc: 'CRC_16_LOWER',
@@ -174,7 +174,7 @@ const error = () => { @@ -174,7 +174,7 @@ const error = () => {
174 } 174 }
175 175
176 const handleSubmit = async () => { 176 const handleSubmit = async () => {
177 - unref(isPasswordInfo)?.checked && await validatePassword() 177 + unref(isPasswordInfo)?.checked && await validatePassword()// 操作密码
178 !unref(isInputData) && await validate() 178 !unref(isInputData) && await validate()
179 unref(isInputData) && await unref(thingsModelElRef).validate() 179 unref(isInputData) && await unref(thingsModelElRef).validate()
180 180
@@ -7,6 +7,7 @@ import { CommandWayEnum, CommandWayNameEnum } from '@/enums/commandEnum' @@ -7,6 +7,7 @@ import { CommandWayEnum, CommandWayNameEnum } from '@/enums/commandEnum'
7 import { CommandDeliveryWayEnum, CommandDeliveryWayNameEnum, DeviceTypeEnum, EventActionTypeEnum, EventActionTypeNameEnum, EventTypeEnum, EventTypeNameEnum, TransportTypeEnum } from '@/enums/datasource' 7 import { CommandDeliveryWayEnum, CommandDeliveryWayNameEnum, DeviceTypeEnum, EventActionTypeEnum, EventActionTypeNameEnum, EventTypeEnum, EventTypeNameEnum, TransportTypeEnum } from '@/enums/datasource'
8 import type { ThingsModel } from '@/api/device/model' 8 import type { ThingsModel } from '@/api/device/model'
9 import { PackageCategoryEnum } from '@/core/Library/enum' 9 import { PackageCategoryEnum } from '@/core/Library/enum'
  10 +import { useContentDataStoreWithOut } from '@/store/modules/contentData'
10 11
11 export enum FormFieldsEnum { 12 export enum FormFieldsEnum {
12 ACTION_TYPE = 'actionType', 13 ACTION_TYPE = 'actionType',
@@ -31,13 +32,15 @@ export enum FormFieldsNameEnum { @@ -31,13 +32,15 @@ export enum FormFieldsNameEnum {
31 SERVICE = '服务', 32 SERVICE = '服务',
32 } 33 }
33 34
  35 +const contentDataStore = useContentDataStoreWithOut()
  36 +
34 export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { 37 export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
35 const { getNodeData, getCellInfo } = usePublicFormContext() 38 const { getNodeData, getCellInfo } = usePublicFormContext()
36 const { dataSourceJson } = unref(getNodeData) || {} 39 const { dataSourceJson } = unref(getNodeData) || {}
37 const { deviceProfileId, deviceInfo } = dataSourceJson || {} 40 const { deviceProfileId, deviceInfo } = dataSourceJson || {}
38 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型 41 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型
39 - const { transportType, deviceType } = deviceInfo || {}  
40 - 42 + const { transportType, deviceType, codeType } = deviceInfo || {}
  43 + const isTemplate = contentDataStore.isTemplate // 判断是否是模板
41 return [ 44 return [
42 { 45 {
43 field: 'eventName', 46 field: 'eventName',
@@ -115,11 +118,25 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { @@ -115,11 +118,25 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
115 { label: CommandDeliveryWayNameEnum.MODBUS, value: CommandDeliveryWayEnum.MODBUS }, 118 { label: CommandDeliveryWayNameEnum.MODBUS, value: CommandDeliveryWayEnum.MODBUS },
116 ] 119 ]
117 let options = [...values] 120 let options = [...values]
118 - if (deviceType === DeviceTypeEnum.SENSOR && transportType === TransportTypeEnum.TCP)  
119 - options = values.filter(item => item.value !== CommandDeliveryWayEnum.SERVICE) 121 + if (transportType === TransportTypeEnum.TCP) { // 只有TCP类型的才有MODBUS
  122 + if (codeType === CommandDeliveryWayEnum.CUSTOM) {
  123 + if (deviceType !== DeviceTypeEnum.SENSOR)
  124 + options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS)
120 125
121 - if (transportType !== TransportTypeEnum.TCP) 126 + else
  127 + options = values.filter(item => item.value === CommandDeliveryWayEnum.CUSTOM)
  128 + }
  129 + else {
  130 + if (deviceType === DeviceTypeEnum.SENSOR)
  131 + options = values.filter(item => item.value !== CommandDeliveryWayEnum.SERVICE)
  132 + }
  133 + }
  134 + else {
122 options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS) 135 options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS)
  136 + }
  137 +
  138 + if (isTemplate)// 是模板的话选择不到设备标识符类型所以就判断为放开自定义命令
  139 + options = values.filter(item => item.value === CommandDeliveryWayEnum.CUSTOM)
123 140
124 return { 141 return {
125 options, 142 options,
@@ -43,7 +43,7 @@ const setFieldsValue = (record: Partial<Record<EventTypeEnum, boolean>>) => { @@ -43,7 +43,7 @@ const setFieldsValue = (record: Partial<Record<EventTypeEnum, boolean>>) => {
43 } 43 }
44 44
45 const getDisabledStatus = (key: EventTypeEnum) => { 45 const getDisabledStatus = (key: EventTypeEnum) => {
46 - const data = unref(getNodeData)?.eventJson[key] 46 + const data = unref(getNodeData)?.eventJson?.[key]
47 return !data 47 return !data
48 } 48 }
49 49
@@ -30,7 +30,7 @@ export const formSchemas = (componentKey?: string): FormSchema[] => { @@ -30,7 +30,7 @@ export const formSchemas = (componentKey?: string): FormSchema[] => {
30 placeholder: '请选择产品', 30 placeholder: '请选择产品',
31 onSelect(value: string, option: any) { 31 onSelect(value: string, option: any) {
32 formModel[ContentDataFieldsEnum.DEVICE_PROFILE_ID] = value 32 formModel[ContentDataFieldsEnum.DEVICE_PROFILE_ID] = value
33 - formModel[ContentDataFieldsEnum.DEVICE_INFO] = value && option ? { transportType: option.transportType, deviceType: option.deviceType } : null 33 + formModel[ContentDataFieldsEnum.DEVICE_INFO] = value && option ? { transportType: option.transportType, deviceType: option.deviceType, codeType: option?.codeType } : null
34 }, 34 },
35 getPopupContainer: () => document.body, 35 getPopupContainer: () => document.body,
36 } 36 }
@@ -56,11 +56,13 @@ export const formSchemas = (componentKey?: string): FormSchema[] => { @@ -56,11 +56,13 @@ export const formSchemas = (componentKey?: string): FormSchema[] => {
56 fieldNames: { label: 'name', value: 'tbDeviceId' }, 56 fieldNames: { label: 'name', value: 'tbDeviceId' },
57 onSelect(value: string, option: DeviceItemType) { 57 onSelect(value: string, option: DeviceItemType) {
58 formModel[ContentDataFieldsEnum.DEVICE_PROFILE_ID] = value ? option.deviceProfileId : null 58 formModel[ContentDataFieldsEnum.DEVICE_PROFILE_ID] = value ? option.deviceProfileId : null
59 - formModel[ContentDataFieldsEnum.DEVICE_INFO] = value && option ? { code: option.code, transportType: option.transportType, deviceType: option.deviceType, deviceProfileId: option.deviceProfileId, deviceName: option.alias || option.name } : null 59 + formModel[ContentDataFieldsEnum.DEVICE_INFO] = value && option ? { code: option.code, transportType: option.transportType, deviceType: option.deviceType, deviceProfileId: option.deviceProfileId, deviceName: option.alias || option.name, codeType: option?.codeType } : null
60 formModel[ContentDataFieldsEnum.ATTR] = null 60 formModel[ContentDataFieldsEnum.ATTR] = null
61 }, 61 },
62 - filterOption: (inputValue: string, option: DeviceItemType) =>  
63 - option.alias?.includes?.(inputValue) || option.name?.includes?.(inputValue), 62 + filterOption: (inputValue: string, option: DeviceItemType) => {
  63 + option.alias?.includes?.(inputValue) || option.name?.includes?.(inputValue)
  64 + },
  65 +
64 } 66 }
65 }, 67 },
66 }, 68 },
@@ -95,7 +95,7 @@ const handleSave = async () => { @@ -95,7 +95,7 @@ const handleSave = async () => {
95 if (operationPassword.checked) 95 if (operationPassword.checked)
96 await validatePassword() 96 await validatePassword()
97 if (contentDataStore.getIsTemplate)// 判断组态是不是模板 97 if (contentDataStore.getIsTemplate)// 判断组态是不是模板
98 - dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null, deviceInfo: null } 98 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
99 await saveNodeAllData({ dataSourceJson, eventJson: { ...eventJson, OPERATION_PASSWORD: unref(getCellInfo).category === PackageCategoryEnum.CONTROL ? operationPassword : undefined }, actJson }) 99 await saveNodeAllData({ dataSourceJson, eventJson: { ...eventJson, OPERATION_PASSWORD: unref(getCellInfo).category === PackageCategoryEnum.CONTROL ? operationPassword : undefined }, actJson })
100 createMessage.success('操作成功~') 100 createMessage.success('操作成功~')
101 savePageContent() 101 savePageContent()
@@ -51,9 +51,9 @@ const handleSubmit = async () => { @@ -51,9 +51,9 @@ const handleSubmit = async () => {
51 51
52 const handleSetFormValues = async () => { 52 const handleSetFormValues = async () => {
53 const { dataSourceJson } = unref(getNodeData) || {} 53 const { dataSourceJson } = unref(getNodeData) || {}
54 - const { deviceId, attr, chartOption, deviceProfileId, attrInfo } = dataSourceJson || {} 54 + const { deviceId, attr, chartOption, deviceProfileId, deviceProfileTemplateId, attrInfo } = dataSourceJson || {}
55 await nextTick() 55 await nextTick()
56 - unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, attrInfo }) 56 + unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, attrInfo, deviceProfileTemplateId })
57 setFieldsValue({ ...chartOption }) 57 setFieldsValue({ ...chartOption })
58 } 58 }
59 59
@@ -12,6 +12,7 @@ import type { ConfigComponentProps } from '@/core/Library/types' @@ -12,6 +12,7 @@ import type { ConfigComponentProps } from '@/core/Library/types'
12 import { createPublicFormContext } from '@/core/Library/components/PublicForm/usePublicFormContext' 12 import { createPublicFormContext } from '@/core/Library/components/PublicForm/usePublicFormContext'
13 import { useMessage } from '@/hooks/web/useMessage' 13 import { useMessage } from '@/hooks/web/useMessage'
14 import { useSavePageContent } from '@/core/Library/hook/useSavePageContent' 14 import { useSavePageContent } from '@/core/Library/hook/useSavePageContent'
  15 +import { useContentDataStoreWithOut } from '@/store/modules/contentData'
15 16
16 const props = defineProps<ConfigComponentProps>() 17 const props = defineProps<ConfigComponentProps>()
17 18
@@ -28,6 +29,7 @@ const [register, { getFieldsValue, setFieldsValue, validate }] = useForm({ @@ -28,6 +29,7 @@ const [register, { getFieldsValue, setFieldsValue, validate }] = useForm({
28 labelWidth: 70, 29 labelWidth: 70,
29 }) 30 })
30 31
  32 +const contentDataStore = useContentDataStoreWithOut()
31 const loading = ref(false) 33 const loading = ref(false)
32 const { createMessage } = useMessage() 34 const { createMessage } = useMessage()
33 const { savePageContent } = useSavePageContent() 35 const { savePageContent } = useSavePageContent()
@@ -38,7 +40,11 @@ const handleSubmit = async () => { @@ -38,7 +40,11 @@ const handleSubmit = async () => {
38 await validate() 40 await validate()
39 const value = unref(dataSourceElRef)?.getFieldsValue() 41 const value = unref(dataSourceElRef)?.getFieldsValue()
40 const values = getFieldsValue() 42 const values = getFieldsValue()
41 - await saveNodeAllData({ dataSourceJson: { ...value, chartOption: values } }) 43 + let dataSourceJson = value
  44 + if (contentDataStore.getIsTemplate)
  45 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
  46 +
  47 + await saveNodeAllData({ dataSourceJson: { ...dataSourceJson, chartOption: values } })
42 createMessage.success('操作成功~') 48 createMessage.success('操作成功~')
43 savePageContent() 49 savePageContent()
44 } 50 }
@@ -49,9 +55,9 @@ const handleSubmit = async () => { @@ -49,9 +55,9 @@ const handleSubmit = async () => {
49 55
50 const handleSetFormValues = async () => { 56 const handleSetFormValues = async () => {
51 const { dataSourceJson } = unref(getNodeData) || {} 57 const { dataSourceJson } = unref(getNodeData) || {}
52 - const { deviceId, attr, chartOption, deviceProfileId, attrInfo } = dataSourceJson || {} 58 + const { deviceId, attr, chartOption, deviceProfileId, attrInfo, deviceProfileTemplateId } = dataSourceJson || {}
53 await nextTick() 59 await nextTick()
54 - unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, attrInfo }) 60 + unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, attrInfo, deviceProfileTemplateId })
55 setFieldsValue({ ...chartOption }) 61 setFieldsValue({ ...chartOption })
56 } 62 }
57 63
@@ -32,9 +32,9 @@ const dataSourceElRef = ref<Nullable<InstanceType<typeof DataSourceForm>>>() @@ -32,9 +32,9 @@ const dataSourceElRef = ref<Nullable<InstanceType<typeof DataSourceForm>>>()
32 32
33 const handleSetFormValues = async () => { 33 const handleSetFormValues = async () => {
34 const { dataSourceJson } = unref(getNodeData) || {} 34 const { dataSourceJson } = unref(getNodeData) || {}
35 - const { deviceId, attr, chartOption, deviceProfileId, attrInfo } = dataSourceJson || {} 35 + const { deviceId, attr, chartOption, deviceProfileId, deviceProfileTemplateId, attrInfo } = dataSourceJson || {}
36 await nextTick() 36 await nextTick()
37 - unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, attrInfo }) 37 + unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, deviceProfileTemplateId, attrInfo })
38 setFieldsValue({ ...chartOption }) 38 setFieldsValue({ ...chartOption })
39 } 39 }
40 40