mirror of
https://github.com/yudaocode/yudao-ui-admin-vue3.git
synced 2026-05-14 03:16:37 +00:00
【代码优化】IoT: 场景联动彻底修复索引重用问题
This commit is contained in:
@@ -72,6 +72,7 @@ interface TriggerCondition {
|
|||||||
|
|
||||||
// 触发器配置
|
// 触发器配置
|
||||||
interface TriggerConfig {
|
interface TriggerConfig {
|
||||||
|
key: any // 解决组件索引重用
|
||||||
type: number // 触发类型
|
type: number // 触发类型
|
||||||
productKey: string // 产品标识
|
productKey: string // 产品标识
|
||||||
deviceNames: string[] // 设备名称数组
|
deviceNames: string[] // 设备名称数组
|
||||||
@@ -98,6 +99,7 @@ interface ActionAlert {
|
|||||||
|
|
||||||
// 执行器配置
|
// 执行器配置
|
||||||
interface ActionConfig {
|
interface ActionConfig {
|
||||||
|
key: any // 解决组件索引重用
|
||||||
type: number // 执行类型
|
type: number // 执行类型
|
||||||
deviceControl?: ActionDeviceControl // 设备控制
|
deviceControl?: ActionDeviceControl // 设备控制
|
||||||
alert?: ActionAlert // 告警执行
|
alert?: ActionAlert // 告警执行
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<el-divider content-position="left">触发器配置</el-divider>
|
<el-divider content-position="left">触发器配置</el-divider>
|
||||||
<device-listener
|
<device-listener
|
||||||
v-for="(trigger, index) in formData.triggers"
|
v-for="(trigger, index) in formData.triggers"
|
||||||
:key="`trigger-${index}-${Date.now()}`"
|
:key="trigger.key"
|
||||||
:model-value="trigger"
|
:model-value="trigger"
|
||||||
@update:model-value="(val) => (formData.triggers[index] = val)"
|
@update:model-value="(val) => (formData.triggers[index] = val)"
|
||||||
class="mb-10px"
|
class="mb-10px"
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<el-divider content-position="left">执行器配置</el-divider>
|
<el-divider content-position="left">执行器配置</el-divider>
|
||||||
<action-executor
|
<action-executor
|
||||||
v-for="(action, index) in formData.actions"
|
v-for="(action, index) in formData.actions"
|
||||||
:key="`action-${index}-${Date.now()}`"
|
:key="action.key"
|
||||||
:model-value="action"
|
:model-value="action"
|
||||||
@update:model-value="(val) => (formData.actions[index] = val)"
|
@update:model-value="(val) => (formData.actions[index] = val)"
|
||||||
class="mb-10px"
|
class="mb-10px"
|
||||||
@@ -88,6 +88,7 @@ import {
|
|||||||
TriggerConfig
|
TriggerConfig
|
||||||
} from '@/api/iot/rule/scene/scene.types'
|
} from '@/api/iot/rule/scene/scene.types'
|
||||||
import ActionExecutor from './components/action/ActionExecutor.vue'
|
import ActionExecutor from './components/action/ActionExecutor.vue'
|
||||||
|
import { generateUUID } from '@/utils'
|
||||||
|
|
||||||
/** IoT 场景联动表单 */
|
/** IoT 场景联动表单 */
|
||||||
defineOptions({ name: 'IotRuleSceneForm' })
|
defineOptions({ name: 'IotRuleSceneForm' })
|
||||||
@@ -115,6 +116,7 @@ const formRef = ref() // 表单 Ref
|
|||||||
/** 添加触发器 */
|
/** 添加触发器 */
|
||||||
const addTrigger = () => {
|
const addTrigger = () => {
|
||||||
formData.value.triggers.push({
|
formData.value.triggers.push({
|
||||||
|
key: generateUUID(), // 解决组件索引重用
|
||||||
type: IotRuleSceneTriggerTypeEnum.DEVICE,
|
type: IotRuleSceneTriggerTypeEnum.DEVICE,
|
||||||
productKey: '',
|
productKey: '',
|
||||||
deviceNames: [],
|
deviceNames: [],
|
||||||
@@ -135,6 +137,7 @@ const removeTrigger = (index: number) => {
|
|||||||
/** 添加执行器 */
|
/** 添加执行器 */
|
||||||
const addAction = () => {
|
const addAction = () => {
|
||||||
formData.value.actions.push({
|
formData.value.actions.push({
|
||||||
|
key: generateUUID(), // 解决组件索引重用
|
||||||
type: IotRuleSceneActionTypeEnum.DEVICE_CONTROL
|
type: IotRuleSceneActionTypeEnum.DEVICE_CONTROL
|
||||||
} as ActionConfig)
|
} as ActionConfig)
|
||||||
}
|
}
|
||||||
@@ -153,7 +156,11 @@ const open = async (type: string, id?: number) => {
|
|||||||
if (id) {
|
if (id) {
|
||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
formData.value = await RuleSceneApi.getRuleScene(id)
|
const data = (await RuleSceneApi.getRuleScene(id)) as IotRuleScene
|
||||||
|
// 解决组件索引重用
|
||||||
|
data.triggers?.forEach((item) => (item.key = generateUUID()))
|
||||||
|
data.actions?.forEach((item) => (item.key = generateUUID()))
|
||||||
|
formData.value = data
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user