fix: 完善执行动作联级查询

This commit is contained in:
xieyonghong 2023-05-04 18:06:46 +08:00
parent 0fca64771a
commit 030c6b7921
2 changed files with 62 additions and 13 deletions

View File

@ -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>

View File

@ -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.termsColumnsterms if (props.name !== 0 && !props.parallel) { // options.termsColumnsterms
_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)
}
}; };
/** /**