Commit 358bd6960c68f995c0da1ad9ab1d4ff235009341

Authored by ww
1 parent c78fb78e

perf: 优化事件在模版模式中无法选择产品

@@ -111,6 +111,7 @@ export interface NodeDataDataSourceJsonType { @@ -111,6 +111,7 @@ export interface NodeDataDataSourceJsonType {
111 export interface DeviceCommandListItemType { 111 export interface DeviceCommandListItemType {
112 deviceId: string 112 deviceId: string
113 way: CommandWayEnum 113 way: CommandWayEnum
  114 + deviceProfileId: string
114 command: string | Recordable 115 command: string | Recordable
115 } 116 }
116 117
@@ -142,12 +143,17 @@ export interface DoubleClickEventDataType { @@ -142,12 +143,17 @@ export interface DoubleClickEventDataType {
142 143
143 export interface SingleClickEventDataType extends DoubleClickEventDataType { } 144 export interface SingleClickEventDataType extends DoubleClickEventDataType { }
144 145
  146 +export interface OperationPasswordDataType {
  147 + checked: boolean
  148 + pawssword?: string
  149 +}
  150 +
145 export interface NodeDataEventJsonType { 151 export interface NodeDataEventJsonType {
146 [EventTypeEnum.DOUBLE]: DoubleClickEventDataType 152 [EventTypeEnum.DOUBLE]: DoubleClickEventDataType
147 [EventTypeEnum.SINGLE]: SingleClickEventDataType 153 [EventTypeEnum.SINGLE]: SingleClickEventDataType
148 [EventTypeEnum.DOWN]: MouseDownEventDataType 154 [EventTypeEnum.DOWN]: MouseDownEventDataType
149 [EventTypeEnum.UP]: MouseUpEventDataType 155 [EventTypeEnum.UP]: MouseUpEventDataType
150 - [EventTypeEnum.OPERATION_PASSWORD]: { password: string } | any 156 + [EventTypeEnum.OPERATION_PASSWORD]: OperationPasswordDataType
151 } 157 }
152 158
153 export interface RangeItemType { 159 export interface RangeItemType {
@@ -9,6 +9,7 @@ export enum TableColumnFieldEnum { @@ -9,6 +9,7 @@ export enum TableColumnFieldEnum {
9 DEVICE_ID = 'deviceId', 9 DEVICE_ID = 'deviceId',
10 WAY = 'way', 10 WAY = 'way',
11 COMMAND = 'command', 11 COMMAND = 'command',
  12 + DEVICE_PROFILE_ID = 'deviceProfileId',
12 } 13 }
13 14
14 export interface TableRecordItemType { 15 export interface TableRecordItemType {
@@ -18,6 +19,7 @@ export interface TableRecordItemType { @@ -18,6 +19,7 @@ export interface TableRecordItemType {
18 [TableColumnFieldEnum.COMMAND]?: Nullable<string | Recordable> 19 [TableColumnFieldEnum.COMMAND]?: Nullable<string | Recordable>
19 [ContentDataFieldsEnum.DEVICE_TYPE]?: Nullable<DeviceTypeEnum> 20 [ContentDataFieldsEnum.DEVICE_TYPE]?: Nullable<DeviceTypeEnum>
20 [ContentDataFieldsEnum.CODE_TYPE]?: Nullable<CodeTypeEnum> 21 [ContentDataFieldsEnum.CODE_TYPE]?: Nullable<CodeTypeEnum>
  22 + [ContentDataFieldsEnum.DEVICE_PROFILE_ID]: Nullable<string>
21 [ContentDataFieldsEnum.TRANSPORT_TYPE]?: Nullable<TransportTypeEnum> 23 [ContentDataFieldsEnum.TRANSPORT_TYPE]?: Nullable<TransportTypeEnum>
22 } 24 }
23 25
@@ -65,28 +67,38 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { @@ -65,28 +67,38 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
65 ] 67 ]
66 } 68 }
67 69
68 -export const tableColumns: BasicColumn[] = [  
69 - {  
70 - title: '设备',  
71 - width: 200,  
72 - key: TableColumnFieldEnum.DEVICE_ID,  
73 - dataIndex: TableColumnFieldEnum.DEVICE_ID,  
74 - },  
75 - {  
76 - title: '单向/双向',  
77 - width: 200,  
78 - key: TableColumnFieldEnum.WAY,  
79 - dataIndex: TableColumnFieldEnum.WAY,  
80 - },  
81 - {  
82 - title: '下发值',  
83 - key: TableColumnFieldEnum.COMMAND,  
84 - dataIndex: TableColumnFieldEnum.COMMAND,  
85 - editComponent: 'JSONEditor',  
86 - helpMessage: ['点击进行命令编辑'],  
87 - },  
88 - {  
89 - title: '操作',  
90 - key: 'action',  
91 - },  
92 -] 70 +export const getTableColumns = (isTemplateMode: boolean): BasicColumn[] => {
  71 + return [
  72 + {
  73 + title: '产品',
  74 + width: 200,
  75 + ifShow: isTemplateMode,
  76 + key: TableColumnFieldEnum.DEVICE_PROFILE_ID,
  77 + dataIndex: TableColumnFieldEnum.DEVICE_PROFILE_ID,
  78 + },
  79 + {
  80 + title: '设备',
  81 + width: 200,
  82 + ifShow: !isTemplateMode,
  83 + key: TableColumnFieldEnum.DEVICE_ID,
  84 + dataIndex: TableColumnFieldEnum.DEVICE_ID,
  85 + },
  86 + {
  87 + title: '单向/双向',
  88 + width: 200,
  89 + key: TableColumnFieldEnum.WAY,
  90 + dataIndex: TableColumnFieldEnum.WAY,
  91 + },
  92 + {
  93 + title: '下发值',
  94 + key: TableColumnFieldEnum.COMMAND,
  95 + dataIndex: TableColumnFieldEnum.COMMAND,
  96 + editComponent: 'JSONEditor',
  97 + helpMessage: ['点击进行命令编辑'],
  98 + },
  99 + {
  100 + title: '操作',
  101 + key: 'action',
  102 + },
  103 + ]
  104 +}
1 <script setup lang="ts"> 1 <script setup lang="ts">
2 import { Button, Empty, FormItem, RadioGroup, Select, Tooltip } from 'ant-design-vue' 2 import { Button, Empty, FormItem, RadioGroup, Select, Tooltip } from 'ant-design-vue'
3 -import { onMounted, ref, unref } from 'vue' 3 +import { onMounted, ref, toRaw, unref } from 'vue'
4 import type { DefaultOptionType, SelectValue } from 'ant-design-vue/es/select' 4 import type { DefaultOptionType, SelectValue } from 'ant-design-vue/es/select'
5 import type { ComponentExposeType } from '../../..' 5 import type { ComponentExposeType } from '../../..'
6 import type { TableRecordItemType } from './config' 6 import type { TableRecordItemType } from './config'
7 -import { TableColumnFieldEnum, getFormSchemas, tableColumns } from './config' 7 +import { TableColumnFieldEnum, getFormSchemas, getTableColumns } from './config'
8 import CommandEditor from './CommandEditor.vue' 8 import CommandEditor from './CommandEditor.vue'
9 import { FormLayoutEnum } from '@/components/Form/src/enum' 9 import { FormLayoutEnum } from '@/components/Form/src/enum'
10 import { BasicForm, useForm } from '@/components/Form' 10 import { BasicForm, useForm } from '@/components/Form'
@@ -18,6 +18,7 @@ import type { DeviceItemType } from '@/api/device/model' @@ -18,6 +18,7 @@ import type { DeviceItemType } from '@/api/device/model'
18 import { useContentDataStore } from '@/store/modules/contentData' 18 import { useContentDataStore } from '@/store/modules/contentData'
19 import { useJsonParse } from '@/hooks/business/useJSONParse' 19 import { useJsonParse } from '@/hooks/business/useJSONParse'
20 import type { DeviceCommandListItemType, MouseDownEventDataType } from '@/api/node/model' 20 import type { DeviceCommandListItemType, MouseDownEventDataType } from '@/api/node/model'
  21 +import type { ProductAndDevice } from '@/api/content/model'
21 22
22 const props = defineProps<{ event: EventTypeEnum }>() 23 const props = defineProps<{ event: EventTypeEnum }>()
23 24
@@ -37,8 +38,10 @@ const dataSource = ref<TableRecordItemType[]>([getInitTableRecord()]) @@ -37,8 +38,10 @@ const dataSource = ref<TableRecordItemType[]>([getInitTableRecord()])
37 38
38 const deviceList = ref<DeviceItemType[]>([]) 39 const deviceList = ref<DeviceItemType[]>([])
39 40
  41 +const productList = ref<ProductAndDevice[]>([])
  42 +
40 const [registerTable] = useTable({ 43 const [registerTable] = useTable({
41 - columns: tableColumns, 44 + columns: getTableColumns(!!unref(contentDataStore.getIsTemplate)),
42 showIndexColumn: false, 45 showIndexColumn: false,
43 pagination: false, 46 pagination: false,
44 canResize: true, 47 canResize: true,
@@ -53,6 +56,7 @@ function getInitTableRecord(): TableRecordItemType { @@ -53,6 +56,7 @@ function getInitTableRecord(): TableRecordItemType {
53 deviceId: null, 56 deviceId: null,
54 way: CommandWayEnum.ONE_WAY, 57 way: CommandWayEnum.ONE_WAY,
55 command: null, 58 command: null,
  59 + deviceProfileId: null,
56 } 60 }
57 } 61 }
58 62
@@ -65,6 +69,7 @@ const handleDeleteRow = (data: TableRecordItemType) => { @@ -65,6 +69,7 @@ const handleDeleteRow = (data: TableRecordItemType) => {
65 } 69 }
66 70
67 async function getDeviceList() { 71 async function getDeviceList() {
  72 + if (unref(contentDataStore.getIsTemplate)) return
68 const organizationId = window.useParseParams().organizationId 73 const organizationId = window.useParseParams().organizationId
69 if (!organizationId) return 74 if (!organizationId) return
70 const productIds = unref(contentDataStore.getProductIds) 75 const productIds = unref(contentDataStore.getProductIds)
@@ -76,9 +81,19 @@ async function getDeviceList() { @@ -76,9 +81,19 @@ async function getDeviceList() {
76 })) 81 }))
77 } 82 }
78 83
  84 +async function getDeviceProfileList() {
  85 + if (!unref(contentDataStore.getIsTemplate)) return
  86 + productList.value = toRaw(unref(contentDataStore.getProductAndDevice)) || []
  87 +}
  88 +
79 const handleSelectDevice = (_value: SelectValue, option: DefaultOptionType | DefaultOptionType[], record: TableRecordItemType) => { 89 const handleSelectDevice = (_value: SelectValue, option: DefaultOptionType | DefaultOptionType[], record: TableRecordItemType) => {
80 - const { codeType, transportType } = option as DeviceItemType  
81 - Object.assign(record, { codeType, transportType } as TableRecordItemType) 90 + const { transportType } = option as DeviceItemType
  91 + Object.assign(record, { transportType } as TableRecordItemType)
  92 +}
  93 +
  94 +const handleSelectProduct = (_value: SelectValue, option: DefaultOptionType | DefaultOptionType[], record: TableRecordItemType) => {
  95 + const { transportType } = option as ProductAndDevice
  96 + Object.assign(record, { transportType })
82 } 97 }
83 98
84 const handleOpenJSONEditorModal = (record: TableRecordItemType) => { 99 const handleOpenJSONEditorModal = (record: TableRecordItemType) => {
@@ -93,11 +108,12 @@ const handleEditComplete = (record: TableRecordItemType, command: string | Recor @@ -93,11 +108,12 @@ const handleEditComplete = (record: TableRecordItemType, command: string | Recor
93 108
94 const getFieldsValue = (): MouseDownEventDataType => { 109 const getFieldsValue = (): MouseDownEventDataType => {
95 const commandList = unref(dataSource).map((item) => { 110 const commandList = unref(dataSource).map((item) => {
96 - const { deviceId, command, way } = item 111 + const { deviceId, command, way, deviceProfileId } = item
97 return { 112 return {
98 deviceId, 113 deviceId,
99 way, 114 way,
100 command, 115 command,
  116 + deviceProfileId,
101 } as DeviceCommandListItemType 117 } as DeviceCommandListItemType
102 }) 118 })
103 119
@@ -108,7 +124,9 @@ const getFieldsValue = (): MouseDownEventDataType => { @@ -108,7 +124,9 @@ const getFieldsValue = (): MouseDownEventDataType => {
108 124
109 const setFieldsValue = (record: MouseDownEventDataType) => { 125 const setFieldsValue = (record: MouseDownEventDataType) => {
110 const { commandList = [] } = record || {} 126 const { commandList = [] } = record || {}
111 - dataSource.value = commandList ? commandList.map(item => ({ ...item, uuid: buildUUID() })) : [getInitTableRecord()] 127 + dataSource.value = commandList
  128 + ? commandList.map(item => ({ ...item, uuid: buildUUID() }))
  129 + : [getInitTableRecord()]
112 } 130 }
113 131
114 const validate = async () => { 132 const validate = async () => {
@@ -116,8 +134,8 @@ const validate = async () => { @@ -116,8 +134,8 @@ const validate = async () => {
116 await fromActionType.validate() 134 await fromActionType.validate()
117 let passFlag = true 135 let passFlag = true
118 for (const item of unref(dataSource)) { 136 for (const item of unref(dataSource)) {
119 - const { deviceId } = item  
120 - if (deviceId) continue 137 + const { deviceId, deviceProfileId } = item
  138 + if (deviceId || deviceProfileId) continue
121 passFlag = false 139 passFlag = false
122 } 140 }
123 return passFlag ? Promise.resolve(getFieldsValue()) : Promise.reject(new Error('请输入')) 141 return passFlag ? Promise.resolve(getFieldsValue()) : Promise.reject(new Error('请输入'))
@@ -130,6 +148,7 @@ const getValidateStatus = (value: string | number) => { @@ -130,6 +148,7 @@ const getValidateStatus = (value: string | number) => {
130 148
131 onMounted(() => { 149 onMounted(() => {
132 getDeviceList() 150 getDeviceList()
  151 + getDeviceProfileList()
133 }) 152 })
134 153
135 defineExpose<ComponentExposeType>({ 154 defineExpose<ComponentExposeType>({
@@ -142,11 +161,26 @@ defineExpose<ComponentExposeType>({ @@ -142,11 +161,26 @@ defineExpose<ComponentExposeType>({
142 <template> 161 <template>
143 <section> 162 <section>
144 <BasicForm @register="registerForm" /> 163 <BasicForm @register="registerForm" />
145 - <section class="w-full h-24"> 164 + <section class="w-full ">
146 <BasicTable @register="registerTable"> 165 <BasicTable @register="registerTable">
147 <template #bodyCell="{ column, record }"> 166 <template #bodyCell="{ column, record }">
  167 + <template v-if="column.key === TableColumnFieldEnum.DEVICE_PROFILE_ID">
  168 + <FormItem
  169 + name="record[TableColumnFieldEnum.DEVICE_PROFILE_ID]"
  170 + :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_PROFILE_ID])"
  171 + >
  172 + <Select
  173 + v-model:value="record[TableColumnFieldEnum.DEVICE_PROFILE_ID]" :options="productList" :field-names="{ label: 'name', value: 'profileId' }" placeholder="请选择产品"
  174 + class="w-full"
  175 + @change="(value, option) => handleSelectProduct(value, option, record as TableRecordItemType)"
  176 + />
  177 + </FormItem>
  178 + </template>
148 <template v-if="column.key === TableColumnFieldEnum.DEVICE_ID"> 179 <template v-if="column.key === TableColumnFieldEnum.DEVICE_ID">
149 - <FormItem name="record[TableColumnFieldEnum.DEVICE_ID]" :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_ID])"> 180 + <FormItem
  181 + name="record[TableColumnFieldEnum.DEVICE_ID]"
  182 + :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_ID])"
  183 + >
150 <Select 184 <Select
151 v-model:value="record[TableColumnFieldEnum.DEVICE_ID]" :options="deviceList" placeholder="请选择设备" 185 v-model:value="record[TableColumnFieldEnum.DEVICE_ID]" :options="deviceList" placeholder="请选择设备"
152 class="w-full" 186 class="w-full"
@@ -204,7 +238,9 @@ defineExpose<ComponentExposeType>({ @@ -204,7 +238,9 @@ defineExpose<ComponentExposeType>({
204 </template> 238 </template>
205 239
206 <style lang="less" scoped> 240 <style lang="less" scoped>
207 - :deep(.ant-table-cell>.css-dev-only-do-not-override-eq3tly){  
208 - margin:0 !important 241 +:deep(.ant-table-cell>) {
  242 + .ant-form-item {
  243 + margin: 0 !important
209 } 244 }
  245 +}
210 </style> 246 </style>
@@ -20,8 +20,10 @@ const onReceiveActMessage = (commandSource: CommandSource, message: Subscription @@ -20,8 +20,10 @@ const onReceiveActMessage = (commandSource: CommandSource, message: Subscription
20 const nodeUtils = new NodeUtils() 20 const nodeUtils = new NodeUtils()
21 const cell = nodeUtils.getCellById(node) 21 const cell = nodeUtils.getCellById(node)
22 if (!cell) return 22 if (!cell) return
23 - const { attr, rangeList, defaultImage } = data as VariableImageActDataType  
24 - const { latestValue } = useLatestMessageValue(message.data, attr) 23 + const { attr, enable, rangeList, defaultImage } = data as VariableImageActDataType
  24 + if (!enable) return
  25 +
  26 + const { latestValue } = useLatestMessageValue(message.data, attr!)
25 const { flag, record } = getMeetTheConditionsRange(rangeList, latestValue) 27 const { flag, record } = getMeetTheConditionsRange(rangeList, latestValue)
26 let imageSrc 28 let imageSrc
27 if (flag) { 29 if (flag) {
@@ -57,7 +57,8 @@ export class DataDynamicEffectHandler { @@ -57,7 +57,8 @@ export class DataDynamicEffectHandler {
57 const { node, data } = commandSource 57 const { node, data } = commandSource
58 const cell = this.nodeUtils.getCellById(node) 58 const cell = this.nodeUtils.getCellById(node)
59 if (!cell) return 59 if (!cell) return
60 - const { attr } = data as FlashActDataType 60 + const { attr, enable } = data as FlashActDataType
  61 + if (!enable) return
61 const { latestValue } = useLatestMessageValue(message.data, attr!) 62 const { latestValue } = useLatestMessageValue(message.data, attr!)
62 const { flag } = getMeetTheConditionsRange((data as FlashActDataType).rangeList, latestValue) 63 const { flag } = getMeetTheConditionsRange((data as FlashActDataType).rangeList, latestValue)
63 64
@@ -76,7 +77,8 @@ export class DataDynamicEffectHandler { @@ -76,7 +77,8 @@ export class DataDynamicEffectHandler {
76 const { node, data } = commandSource 77 const { node, data } = commandSource
77 const cell = this.nodeUtils.getCellById(node) 78 const cell = this.nodeUtils.getCellById(node)
78 if (!cell) return 79 if (!cell) return
79 - const { attr } = data as DisplayActDataType 80 + const { attr, enable } = data as DisplayActDataType
  81 + if (!enable) return
80 const { latestValue } = useLatestMessageValue(message.data, attr!) 82 const { latestValue } = useLatestMessageValue(message.data, attr!)
81 const { flag, record } = getMeetTheConditionsRange((data as DisplayActDataType).rangeList, latestValue) 83 const { flag, record } = getMeetTheConditionsRange((data as DisplayActDataType).rangeList, latestValue)
82 if (flag) { 84 if (flag) {
@@ -101,7 +103,8 @@ export class DataDynamicEffectHandler { @@ -101,7 +103,8 @@ export class DataDynamicEffectHandler {
101 const { node, data } = commandSource 103 const { node, data } = commandSource
102 const cell = this.nodeUtils.getCellById(node) 104 const cell = this.nodeUtils.getCellById(node)
103 if (!cell) return 105 if (!cell) return
104 - const { attr } = data as RotateActDataType 106 + const { attr, enable } = data as RotateActDataType
  107 + if (!enable) return
105 const { latestValue } = useLatestMessageValue(message.data, attr!) 108 const { latestValue } = useLatestMessageValue(message.data, attr!)
106 const { flag } = getMeetTheConditionsRange((data as RotateActDataType).rangeList, latestValue) 109 const { flag } = getMeetTheConditionsRange((data as RotateActDataType).rangeList, latestValue)
107 const nodeEl = this.nodeUtils.getNodesForCells<SVGAElement>([cell]) 110 const nodeEl = this.nodeUtils.getNodesForCells<SVGAElement>([cell])
@@ -124,7 +127,8 @@ export class DataDynamicEffectHandler { @@ -124,7 +127,8 @@ export class DataDynamicEffectHandler {
124 const { node, data } = commandSource 127 const { node, data } = commandSource
125 const cell = this.nodeUtils.getCellById(node) 128 const cell = this.nodeUtils.getCellById(node)
126 if (!cell) return 129 if (!cell) return
127 - const { attr } = data as DynamicActDataType 130 + const { attr, enable } = data as DynamicActDataType
  131 + if (!enable) return
128 const { latestValue } = useLatestMessageValue(message.data, attr!) 132 const { latestValue } = useLatestMessageValue(message.data, attr!)
129 const { flag, record } = getMeetTheConditionsRange((data as DynamicActDataType).rangeList, latestValue) 133 const { flag, record } = getMeetTheConditionsRange((data as DynamicActDataType).rangeList, latestValue)
130 const nodeEl = this.nodeUtils.getNodeForCell<SVGAElement>(cell) 134 const nodeEl = this.nodeUtils.getNodeForCell<SVGAElement>(cell)
@@ -2,8 +2,10 @@ import { isString } from 'lodash-es' @@ -2,8 +2,10 @@ import { isString } from 'lodash-es'
2 import type { PackageCategoryEnum } from '@/core/Library/enum' 2 import type { PackageCategoryEnum } from '@/core/Library/enum'
3 import type { DrawApp, MxCell } from '@/fitCore/types' 3 import type { DrawApp, MxCell } from '@/fitCore/types'
4 import type { BasicComponentEnum } from '@/core/Library/packages/Basic' 4 import type { BasicComponentEnum } from '@/core/Library/packages/Basic'
  5 +import type { ControlComponentEnum } from '@/core/Library/packages/Control'
  6 +import type { ChartComponentEnum } from '@/core/Library/packages/Chart'
5 7
6 -type ComponentKey = BasicComponentEnum 8 +type ComponentKey = BasicComponentEnum | ControlComponentEnum | ChartComponentEnum
7 9
8 export class NodeUtils { 10 export class NodeUtils {
9 App: DrawApp 11 App: DrawApp