fix: 完善执行动作联级查询
This commit is contained in:
parent
0fca64771a
commit
030c6b7921
|
@ -11,6 +11,7 @@ import { query as deviceQuery } from '@/api/device/instance'
|
||||||
import noticeConfig from '@/api/notice/config'
|
import noticeConfig from '@/api/notice/config'
|
||||||
import noticeTemplate from '@/api/notice/template'
|
import noticeTemplate from '@/api/notice/template'
|
||||||
import { Form } from 'jetlinks-ui-components'
|
import { Form } from 'jetlinks-ui-components'
|
||||||
|
import { EventEmitter, EventSubscribeKeys } from '@/views/rule-engine/Scene/Save/util'
|
||||||
const sceneStore = useSceneStore();
|
const sceneStore = useSceneStore();
|
||||||
const { data: _data } = storeToRefs(sceneStore);
|
const { data: _data } = storeToRefs(sceneStore);
|
||||||
|
|
||||||
|
@ -31,6 +32,8 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sub = ref()
|
||||||
|
|
||||||
const rules = [{
|
const rules = [{
|
||||||
validator(_: any, v?: ActionsType) {
|
validator(_: any, v?: ActionsType) {
|
||||||
console.log('validator',v)
|
console.log('validator',v)
|
||||||
|
@ -62,7 +65,6 @@ const checkDeviceDelete = async () => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (item?.selector === 'fixed') {
|
if (item?.selector === 'fixed') {
|
||||||
console.log(item)
|
|
||||||
const deviceList = item!.selectorValues?.map(item => item.value) || []
|
const deviceList = item!.selectorValues?.map(item => item.value) || []
|
||||||
const deviceResp = await deviceQuery({ terms: [{ terms: [{ column: 'id', termType: 'in', value: deviceList.toString() }]}]})
|
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)) { // 某一个设备被删除
|
if (deviceResp.success && (deviceResp.result as any)?.total < (item!.selectorValues?.length || 0)) { // 某一个设备被删除
|
||||||
|
@ -71,6 +73,19 @@ const checkDeviceDelete = async () => {
|
||||||
return
|
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
|
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()
|
checkDeviceDelete()
|
||||||
} else if (_executor === 'notify' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.notify) {
|
} 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()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -445,11 +445,11 @@ const emit = defineEmits(['delete', 'update']);
|
||||||
const visible = ref<boolean>(false);
|
const visible = ref<boolean>(false);
|
||||||
const triggerVisible = ref<boolean>(false);
|
const triggerVisible = ref<boolean>(false);
|
||||||
const actionType = ref('');
|
const actionType = ref('');
|
||||||
const eventEmitterKey = EventEmitterKeys({
|
const eventEmitterKey = ref(EventEmitterKeys({
|
||||||
branch: props.branchesName,
|
branch: props.branchesName,
|
||||||
branchGroup: props.thenName,
|
branchGroup: props.thenName,
|
||||||
action: props.name
|
action: props.name
|
||||||
})
|
}))
|
||||||
const formItemContext = Form.useInjectFormItemContext()
|
const formItemContext = Form.useInjectFormItemContext()
|
||||||
const termsOptions = computed(() => {
|
const termsOptions = computed(() => {
|
||||||
if (!props.parallel) {
|
if (!props.parallel) {
|
||||||
|
@ -464,7 +464,7 @@ const termsOptions = computed(() => {
|
||||||
|
|
||||||
const onDelete = () => {
|
const onDelete = () => {
|
||||||
const key = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].key
|
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
|
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!.termsColumns = []
|
||||||
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].options!.terms = []
|
_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 onSave = (data: ActionsType, options: any) => {
|
||||||
const { key, terms } = _data.value.branches![props.branchesName].then?.[props.thenName].actions?.[props.name]
|
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))])
|
const columns = new Set([...(props.options?.termsColumns || []), ...(options.otherColumns.filter((item?: string) => item))])
|
||||||
|
|
||||||
|
@ -535,14 +534,11 @@ const onSave = (data: ActionsType, options: any) => {
|
||||||
terms
|
terms
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(actionItem)
|
|
||||||
_data.value.branches![props.branchesName].then[props.thenName].actions.splice(props.name, 1, actionItem)
|
_data.value.branches![props.branchesName].then[props.thenName].actions.splice(props.name, 1, actionItem)
|
||||||
|
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
|
|
||||||
if (props.parallel === false) { // 串行
|
EventEmitter.emit(eventEmitterKey.value, data) // 发布消息
|
||||||
EventEmitter.emit(eventEmitterKey, data)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue