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