update: 优化场景联动过滤条件中的columns
This commit is contained in:
parent
f8fb98df44
commit
a277fe1cb6
|
@ -94,8 +94,8 @@ export const useSceneStore = defineStore('scene', () => {
|
|||
const branchesLength = branches.length;
|
||||
if (
|
||||
triggerType === 'device' &&
|
||||
((branchesLength === 1 && !!branches[0]?.when?.length) || // 有一组数据并且when有值
|
||||
(branchesLength > 1 && !branches[branchesLength - 1]?.when?.length)) // 有多组否则数据,并且最后一组when有值
|
||||
((branchesLength === 1 && branches[0]?.when?.length) || // 有一组数据并且when有值
|
||||
(branchesLength > 1 && branches[branchesLength - 1]?.when?.length)) // 有多组否则数据,并且最后一组when有值
|
||||
) {
|
||||
branches.push(null);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ import ParamsDropdown, { DoubleParamsDropdown } from '../../components/ParamsDro
|
|||
import { inject } from 'vue'
|
||||
import { useSceneStore } from 'store/scene'
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { flattenDeep, set } from 'lodash-es'
|
||||
|
||||
const sceneStore = useSceneStore()
|
||||
const { data: formModel } = storeToRefs(sceneStore)
|
||||
|
@ -207,12 +208,32 @@ const mouseout = () => {
|
|||
}
|
||||
}
|
||||
|
||||
const columnSelect = () => {
|
||||
const handleOptionsColumnsValue = (termsColumns: any[], _options: any) => {
|
||||
formModel.value.branches![props.branchName].then[props.thenName].actions[props.name].options!.termsColumns = termsColumns
|
||||
const flatten = new Set(flattenDeep(termsColumns))
|
||||
let newColumns = [...flatten.values()]
|
||||
if (_options?.otherColumns) {
|
||||
newColumns = [..._options?.otherColumns, ...newColumns]
|
||||
}
|
||||
formModel.value.branches![props.branchName].then[props.thenName].actions[props.name].options!.columns = newColumns
|
||||
}
|
||||
|
||||
const columnSelect = (e: any) => {
|
||||
paramsValue.termType = 'eq'
|
||||
paramsValue.value = {
|
||||
source: tabsOptions.value[0].key,
|
||||
value: undefined
|
||||
}
|
||||
|
||||
const columns = e.metadata === true ? [e.column] : []
|
||||
const _options = formModel.value.branches![props.branchName].then[props.thenName].actions[props.actionName].options
|
||||
const termsColumns = _options?.termsColumns || []
|
||||
set(
|
||||
termsColumns,
|
||||
[props.termsName, props.name],
|
||||
columns
|
||||
)
|
||||
handleOptionsColumnsValue(termsColumns, _options)
|
||||
emit('update:value', { ...paramsValue })
|
||||
}
|
||||
|
||||
|
@ -245,6 +266,14 @@ const termAdd = () => {
|
|||
|
||||
const onDelete = () => {
|
||||
formModel.value.branches?.[props.branchName]?.then?.[props.thenName]?.actions?.[props.actionName].terms?.[props.termsName].terms?.splice(props.name, 1)
|
||||
const _options = formModel.value.branches![props.branchName].then[props.thenName].actions[props.name].options
|
||||
const termsColumns = _options?.termsColumns || []
|
||||
set(
|
||||
termsColumns,
|
||||
[props.termsName, props.name],
|
||||
[]
|
||||
)
|
||||
handleOptionsColumnsValue(termsColumns, _options)
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
|
|
|
@ -58,7 +58,7 @@ import { storeToRefs } from 'pinia'
|
|||
import { useSceneStore } from 'store/scene'
|
||||
import DropdownButton from '../../components/DropdownButton'
|
||||
import FilterItem from './FilterCondition.vue'
|
||||
import { isArray } from 'lodash-es'
|
||||
import { flattenDeep, isArray, set } from 'lodash-es'
|
||||
import { provide } from 'vue'
|
||||
import { randomString } from '@/utils/utils'
|
||||
import { useParams } from '@/views/rule-engine/Scene/Save/util'
|
||||
|
@ -66,8 +66,6 @@ import { useParams } from '@/views/rule-engine/Scene/Save/util'
|
|||
const sceneStore = useSceneStore()
|
||||
const { data: formModel } = storeToRefs(sceneStore)
|
||||
|
||||
|
||||
|
||||
const props = defineProps({
|
||||
isFirst: {
|
||||
type: Boolean,
|
||||
|
@ -103,9 +101,7 @@ const { columnOptions } = useParams({
|
|||
branch: props.branchName,
|
||||
branchGroup: props.thenName,
|
||||
action: props.actionName
|
||||
}, [
|
||||
formModel.value.branches![props.branchName].then[props.thenName].actions[props.actionName]
|
||||
])
|
||||
})
|
||||
|
||||
provide('filter-params', columnOptions)
|
||||
|
||||
|
@ -123,6 +119,16 @@ const mouseout = () => {
|
|||
showDelete.value = false
|
||||
}
|
||||
|
||||
const handleOptionsColumnsValue = (termsColumns: any[], _options: any) => {
|
||||
formModel.value.branches![props.branchName].then[props.thenName].actions[props.name].options!.termsColumns = termsColumns
|
||||
const flatten = new Set(flattenDeep(termsColumns))
|
||||
let newColumns = [...flatten.values()]
|
||||
if (_options?.otherColumns) {
|
||||
newColumns = [..._options?.otherColumns, ...newColumns]
|
||||
}
|
||||
formModel.value.branches![props.branchName].then[props.thenName].actions[props.name].options!.columns = newColumns
|
||||
}
|
||||
|
||||
const addTerms = () => {
|
||||
const item: any = {
|
||||
type: 'and',
|
||||
|
@ -154,6 +160,13 @@ const onDelete = () => {
|
|||
.then[props.thenName]
|
||||
.actions[props.actionName]
|
||||
.terms?.splice(props.name, 1)
|
||||
|
||||
const _options = formModel.value.branches![props.branchName].then[props.thenName].actions[props.actionName].options
|
||||
const termsColumns = _options?.termsColumns || []
|
||||
if (_options?.termsColumns) {
|
||||
termsColumns.splice(props.name, 1)
|
||||
handleOptionsColumnsValue(termsColumns, _options)
|
||||
}
|
||||
}
|
||||
|
||||
const rules = [
|
||||
|
|
|
@ -446,6 +446,11 @@ const termsOptions = computed(() => {
|
|||
});
|
||||
|
||||
const onDelete = () => {
|
||||
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 = []
|
||||
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].terms = []
|
||||
}
|
||||
emit('delete');
|
||||
};
|
||||
|
||||
|
@ -453,11 +458,16 @@ const onClose = () => {
|
|||
visible.value = false;
|
||||
};
|
||||
|
||||
const onSave = (data: ActionsType, options?: any) => {
|
||||
emit('update', data, options);
|
||||
// setTimeout(() => {
|
||||
// getParams();
|
||||
// }, 10);
|
||||
const onSave = (data: ActionsType, options: any) => {
|
||||
const { key, terms } = _data.value.branches![props.branchesName].then?.[props.thenName].actions?.[props.name]
|
||||
const actionItem: ActionsType = {
|
||||
...data,
|
||||
options,
|
||||
key,
|
||||
terms
|
||||
}
|
||||
_data.value.branches![props.branchesName].then[props.thenName].actions.splice(props.name, 1, actionItem)
|
||||
|
||||
visible.value = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
:isLast="index === actions.length - 1"
|
||||
:options="item.options"
|
||||
@delete="_delete(item.key || '')"
|
||||
@update="(data, options) => _update(data, options, item)"
|
||||
/>
|
||||
</template>
|
||||
<div class="actions-add-list" :class="{ 'border': props.actions.length }">
|
||||
|
@ -37,7 +36,6 @@ import { PropType } from 'vue';
|
|||
import { ActionsType, ParallelType } from '../../../typings';
|
||||
import Modal from '../Modal/index.vue';
|
||||
import Item from './Item.vue';
|
||||
import { pick } from 'lodash';
|
||||
import { useSceneStore } from '@/store/scene';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
|
@ -98,9 +96,7 @@ const _delete = (_key: string) => {
|
|||
emit('delete', _key)
|
||||
}
|
||||
|
||||
const _update = (data: ActionsType, options: any, item: any) => {
|
||||
const olData = pick(item, ['terms']);
|
||||
emit('add', {...olData, ...data, options})
|
||||
const _update = () => {
|
||||
visible.value = false
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -131,7 +131,8 @@ const onOk = () => {
|
|||
emit(
|
||||
'save',
|
||||
{
|
||||
...props.data,
|
||||
// ...props.data,
|
||||
key: props.data.key,
|
||||
executor: 'alarm',
|
||||
alarm: { mode: values.type },
|
||||
},
|
||||
|
|
|
@ -130,13 +130,14 @@ const onDelete = (_key: string, _parallel: boolean) => {
|
|||
const onAdd = (actionItem: any, _parallel: boolean) => {
|
||||
const thenName = props.thenOptions.findIndex(item => item.parallel === _parallel)
|
||||
if (thenName !== -1) { // 编辑
|
||||
const cacheAction = props.thenOptions[thenName].actions
|
||||
const indexOf = cacheAction?.findIndex(item => item.key === actionItem.key) || -1
|
||||
if (indexOf !== -1) {
|
||||
FormModel.value.branches?.[props.name].then?.[thenName].actions.splice(indexOf, 1, actionItem)
|
||||
} else {
|
||||
// const cacheAction = props.thenOptions[thenName].actions
|
||||
// const indexOf = cacheAction?.findIndex(item => item.key === actionItem.key) || -1
|
||||
// if (indexOf !== -1) {
|
||||
// FormModel.value.branches?.[props.name].then?.[thenName].actions.splice(indexOf, 1, actionItem)
|
||||
// } else {
|
||||
// FormModel.value.branches?.[props.name].then?.[thenName].actions.push(actionItem)
|
||||
// }
|
||||
FormModel.value.branches?.[props.name].then?.[thenName].actions.push(actionItem)
|
||||
}
|
||||
} else { // 新增
|
||||
const newThenItem = {
|
||||
parallel: _parallel,
|
||||
|
|
|
@ -27,7 +27,7 @@ export const getParams = (params: Params, sceneModel: FormModelType): Promise<an
|
|||
/**
|
||||
* @param params
|
||||
*/
|
||||
export const useParams = (params: Params, effect: any[] = []) => {
|
||||
export const useParams = (params: Params) => {
|
||||
const sceneStore = useSceneStore()
|
||||
const { data: formModel } = storeToRefs(sceneStore)
|
||||
const columnOptions = ref<any[]>([])
|
||||
|
@ -38,7 +38,7 @@ export const useParams = (params: Params, effect: any[] = []) => {
|
|||
}
|
||||
|
||||
watchEffect(() => {
|
||||
if (effect[0]) {
|
||||
if (formModel.value.branches![params.branch].then[params.branchGroup].actions[params.action]) {
|
||||
handleParams()
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue