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 6 profileId: string
7 7 transportType?: string
8 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 18 export interface ConfigurationContentType {
... ...
... ... @@ -91,6 +91,7 @@ export interface DeviceInfoType {
91 91 export interface NodeDataDataSourceJsonType {
92 92 deviceId: string
93 93 deviceProfileId: string
  94 + deviceProfileTemplateId?: string
94 95 attr: string
95 96 attrInfo: ThingsModelItemType
96 97
... ...
... ... @@ -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,17 @@ 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   - const { deviceProfileId, deviceInfo } = dataSourceJson || {}
  40 + const { deviceProfileId, deviceInfo, deviceId } = dataSourceJson || {}
38 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 46 return [
42 47 {
43 48 field: 'eventName',
... ... @@ -115,11 +120,25 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
115 120 { label: CommandDeliveryWayNameEnum.MODBUS, value: CommandDeliveryWayEnum.MODBUS },
116 121 ]
117 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 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 143 return {
125 144 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,12 @@ 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 + },
64 65 }
65 66 },
66 67 },
... ...
... ... @@ -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
... ...
1 1 import { defineStore } from 'pinia'
  2 +import { toRaw, unref } from 'vue'
2 3 import { store } from '..'
3 4 import type { NodeDataType } from '@/api/node/model'
4 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 13 interface ContentDataStoreType {
7 14 contentData: NodeDataType[]
8 15 configurationId: Nullable<string>
... ... @@ -11,6 +18,7 @@ interface ContentDataStoreType {
11 18 isTemplate?: number | null | string
12 19 configurationContentList?: any
13 20 configurationContentId: Nullable<string>
  21 + diveceDetailMap: Record<string, DeviceList>
14 22 }
15 23
16 24 export const useContentDataStore = defineStore('app-content-data', {
... ... @@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', {
22 30 productAndDevice: [],
23 31 configurationContentList: [],
24 32 configurationContentId: null,
  33 + diveceDetailMap: {},
25 34 }),
26 35 actions: {
27 36
... ... @@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', {
47 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
... ...