From 030c6b792140f9f62bdedda105a30af6885cbfa4 Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Thu, 4 May 2023 18:06:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C=E8=81=94=E7=BA=A7=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scene/Save/action/ListItem/CheckItem.vue | 63 +++++++++++++++++-- .../Scene/Save/action/ListItem/Item.vue | 12 ++-- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue b/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue index 2ea815b5..981c7909 100644 --- a/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue +++ b/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue @@ -11,6 +11,7 @@ import { query as deviceQuery } from '@/api/device/instance' import noticeConfig from '@/api/notice/config' import noticeTemplate from '@/api/notice/template' import { Form } from 'jetlinks-ui-components' +import { EventEmitter, EventSubscribeKeys } from '@/views/rule-engine/Scene/Save/util' const sceneStore = useSceneStore(); const { data: _data } = storeToRefs(sceneStore); @@ -31,6 +32,8 @@ const props = defineProps({ }, }); +const sub = ref() + const rules = [{ validator(_: any, v?: ActionsType) { console.log('validator',v) @@ -62,7 +65,6 @@ const checkDeviceDelete = async () => { return } if (item?.selector === 'fixed') { - console.log(item) const deviceList = item!.selectorValues?.map(item => item.value) || [] const deviceResp = await deviceQuery({ terms: [{ terms: [{ column: 'id', termType: 'in', value: deviceList.toString() }]}]}) if (deviceResp.success && (deviceResp.result as any)?.total < (item!.selectorValues?.length || 0)) { // 某一个设备被删除 @@ -71,6 +73,19 @@ const checkDeviceDelete = async () => { return } } + + if (item!.source === 'upper') { // 如果是按变量,校验上一个设备输出的产品id + if (props.name === 0) { + formTouchOff() + return + } else { + const prevItem = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].device + if (prevItem?.productId !== item?.productId) { + formTouchOff() + return + } + } + } } /** @@ -92,14 +107,52 @@ const checkNoticeDelete = async () => { } } -nextTick(() => { +const check = () => { const _executor = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.executor - if (_executor === 'device' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.device) { + if (_executor === 'device' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.device) { // 设备输出,并且有值 checkDeviceDelete() } else if (_executor === 'notify' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.notify) { - checkNoticeDelete + checkNoticeDelete() } -}) +} + +const checkPrevData = (data: any) => { + console.log(data) + const _executor = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.executor + if (_executor === 'device' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.device) { // 设备输出,并且有值 + // 校验内置参数 + // 按变量时,需校验产品id是否一致 + + } else if (_executor === 'notify' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.notify) { + // 校验内置参数 + } +} + +const subscribe = (newName: number, oldName: number) => { + const _key = EventSubscribeKeys({ + branch: props.branchesName, + branchGroup: props.thenName, + action: props.name - 1 + }) + + if (sub.value) { + const oldKey = EventSubscribeKeys({ + branch: props.branchesName, + branchGroup: props.thenName, + action: oldName - 1 + }) + + sub.value.unSubscribe(oldKey, checkPrevData) + } + + sub.value = EventEmitter.subscribe(_key, checkPrevData) +} + +watch(() => props.name, (newName, oldName) => { + // subscribe(newName, oldName || 0) +}, { immediate: true }) + +check() diff --git a/src/views/rule-engine/Scene/Save/action/ListItem/Item.vue b/src/views/rule-engine/Scene/Save/action/ListItem/Item.vue index 133e2256..f3464456 100644 --- a/src/views/rule-engine/Scene/Save/action/ListItem/Item.vue +++ b/src/views/rule-engine/Scene/Save/action/ListItem/Item.vue @@ -445,11 +445,11 @@ const emit = defineEmits(['delete', 'update']); const visible = ref(false); const triggerVisible = ref(false); const actionType = ref(''); -const eventEmitterKey = EventEmitterKeys({ +const eventEmitterKey = ref(EventEmitterKeys({ branch: props.branchesName, branchGroup: props.thenName, action: props.name -}) +})) const formItemContext = Form.useInjectFormItemContext() const termsOptions = computed(() => { if (!props.parallel) { @@ -464,7 +464,7 @@ const termsOptions = computed(() => { const onDelete = () => { const key = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].key - EventEmitter.emit(key!, { isDelete: true }) + EventEmitter.emit(key!, { isDelete: true }) // 发布消息 if (props.name !== 0 && !props.parallel) { // 清空上一个串行执行动作中的options.termsColumns和terms _data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].options!.termsColumns = [] _data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].options!.terms = [] @@ -524,7 +524,6 @@ const onType = (_type: string) => { */ const onSave = (data: ActionsType, options: any) => { const { key, terms } = _data.value.branches![props.branchesName].then?.[props.thenName].actions?.[props.name] - console.log({...props.options, ...options}) const columns = new Set([...(props.options?.termsColumns || []), ...(options.otherColumns.filter((item?: string) => item))]) @@ -535,14 +534,11 @@ const onSave = (data: ActionsType, options: any) => { terms } - console.log(actionItem) _data.value.branches![props.branchesName].then[props.thenName].actions.splice(props.name, 1, actionItem) visible.value = false; - if (props.parallel === false) { // 串行 - EventEmitter.emit(eventEmitterKey, data) - } + EventEmitter.emit(eventEmitterKey.value, data) // 发布消息 }; /**