Commit eb4f2d6a4c89a5c9823e752041c8ddbc09e46365

Authored by 温伟
2 parents be8f1949 b68a8c5d

Merge branch 'fix/zfl' into 'perf/main_dev'

修改参数下发问题

See merge request yunteng/thingskit-scada!156
@@ -6,10 +6,13 @@ export interface ProductAndDevice { @@ -6,10 +6,13 @@ export interface ProductAndDevice {
6 profileId: string 6 profileId: string
7 transportType?: string 7 transportType?: string
8 deviceType?: string 8 deviceType?: string
9 - deviceList: {  
10 - deviceId: string  
11 - name: string  
12 - }[] 9 + deviceList: DeviceList[]
  10 +}
  11 +
  12 +interface DeviceList {
  13 + deviceId: string
  14 + name: string
  15 + codeType: string
13 } 16 }
14 17
15 export interface ConfigurationContentType { 18 export interface ConfigurationContentType {
@@ -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,17 @@ export enum FormFieldsNameEnum { @@ -31,13 +32,17 @@ 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, deviceId } = dataSourceJson || {}
38 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型 41 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型
39 - const { transportType, deviceType } = deviceInfo || {}  
40 - 42 + let codeType: string | null = ''
  43 + const { transportType, deviceType, codeType: deviceCodeType } = deviceInfo || {}
  44 + codeType = deviceCodeType || (deviceId ? contentDataStore.diveceDetailMap?.[deviceId].codeType : null)
  45 + const isTemplate = contentDataStore.isTemplate // 判断是否是模板
41 return [ 46 return [
42 { 47 {
43 field: 'eventName', 48 field: 'eventName',
@@ -115,11 +120,25 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { @@ -115,11 +120,25 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
115 { label: CommandDeliveryWayNameEnum.MODBUS, value: CommandDeliveryWayEnum.MODBUS }, 120 { label: CommandDeliveryWayNameEnum.MODBUS, value: CommandDeliveryWayEnum.MODBUS },
116 ] 121 ]
117 let options = [...values] 122 let options = [...values]
118 - if (deviceType === DeviceTypeEnum.SENSOR && transportType === TransportTypeEnum.TCP)  
119 - options = values.filter(item => item.value !== CommandDeliveryWayEnum.SERVICE) 123 + if (transportType === TransportTypeEnum.TCP) { // 只有TCP类型的才有MODBUS
  124 + if (codeType === CommandDeliveryWayEnum.CUSTOM) {
  125 + if (deviceType !== DeviceTypeEnum.SENSOR)
  126 + options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS)
120 127
121 - if (transportType !== TransportTypeEnum.TCP) 128 + else
  129 + options = values.filter(item => item.value === CommandDeliveryWayEnum.CUSTOM)
  130 + }
  131 + else {
  132 + if (deviceType === DeviceTypeEnum.SENSOR)
  133 + options = values.filter(item => item.value !== CommandDeliveryWayEnum.SERVICE)
  134 + }
  135 + }
  136 + else {
122 options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS) 137 options = values.filter(item => item.value !== CommandDeliveryWayEnum.MODBUS)
  138 + }
  139 +
  140 + if (isTemplate)// 是模板的话选择不到设备标识符类型所以就判断为放开自定义命令
  141 + options = values.filter(item => item.value === CommandDeliveryWayEnum.CUSTOM)
123 142
124 return { 143 return {
125 options, 144 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,12 @@ export const formSchemas = (componentKey?: string): FormSchema[] => { @@ -56,11 +56,12 @@ 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 + },
64 } 65 }
65 }, 66 },
66 }, 67 },
@@ -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
1 import { defineStore } from 'pinia' 1 import { defineStore } from 'pinia'
  2 +import { toRaw, unref } from 'vue'
2 import { store } from '..' 3 import { store } from '..'
3 import type { NodeDataType } from '@/api/node/model' 4 import type { NodeDataType } from '@/api/node/model'
4 import type { ProductAndDevice } from '@/api/content/model' 5 import type { ProductAndDevice } from '@/api/content/model'
5 6
  7 +interface DeviceList {
  8 + deviceId: string
  9 + name: string
  10 + codeType: string
  11 +}
  12 +
6 interface ContentDataStoreType { 13 interface ContentDataStoreType {
7 contentData: NodeDataType[] 14 contentData: NodeDataType[]
8 configurationId: Nullable<string> 15 configurationId: Nullable<string>
@@ -11,6 +18,7 @@ interface ContentDataStoreType { @@ -11,6 +18,7 @@ interface ContentDataStoreType {
11 isTemplate?: number | null | string 18 isTemplate?: number | null | string
12 configurationContentList?: any 19 configurationContentList?: any
13 configurationContentId: Nullable<string> 20 configurationContentId: Nullable<string>
  21 + diveceDetailMap: Record<string, DeviceList>
14 } 22 }
15 23
16 export const useContentDataStore = defineStore('app-content-data', { 24 export const useContentDataStore = defineStore('app-content-data', {
@@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', { @@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', {
22 productAndDevice: [], 30 productAndDevice: [],
23 configurationContentList: [], 31 configurationContentList: [],
24 configurationContentId: null, 32 configurationContentId: null,
  33 + diveceDetailMap: {},
25 }), 34 }),
26 actions: { 35 actions: {
27 36
@@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', { @@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', {
47 this.isTemplate = string 56 this.isTemplate = string
48 }, 57 },
49 58
50 - setProductAndDevice(string: ProductAndDevice[]) {  
51 - return this.productAndDevice = string 59 + setProductAndDevice(list: ProductAndDevice[]) {
  60 + this.productAndDevice = list
  61 + this.doBuildDeviceMap()
  62 + return list
  63 + },
  64 +
  65 + doBuildDeviceMap() {
  66 + const list = this.productAndDevice.map(item => toRaw(unref(item.deviceList))).flat(1)
  67 + this.diveceDetailMap = list.reduce((prev, next) => {
  68 + return { ...prev, [next?.deviceId]: next }
  69 + }, {} as Record<'string', ProductAndDevice>)
52 }, 70 },
53 }, 71 },
54 72