update: 优化场景联动样式

This commit is contained in:
xieyonghong 2023-03-21 09:56:27 +08:00
parent 995eca23cb
commit a2a52aaf66
5 changed files with 59 additions and 19 deletions

View File

@ -1,13 +1,15 @@
<template> <template>
<j-form-item <div class='actions-branches-item'>
:rules="actionRules" <j-form-item
:name="['branches', 0, 'then']" :rules="actionRules"
> :name="['branches', 0, 'then']"
<Action >
:thenOptions="data.branches ? data?.branches[0].then : []" <Action
:name="0" :thenOptions="data.branches ? data?.branches[0].then : []"
/> :name="0"
</j-form-item> />
</j-form-item>
</div>
</template> </template>
<script lang="ts" setup name='SceneSaveManual'> <script lang="ts" setup name='SceneSaveManual'>
@ -21,7 +23,6 @@ const { data } = storeToRefs(sceneStore);
const actionRules = [{ const actionRules = [{
validator(_: any, v?: BranchesThen[]) { validator(_: any, v?: BranchesThen[]) {
console.log(_, v)
if (!v || (v && !v.length) || (v && v.length && !v[0].actions.length)) { if (!v || (v && !v.length) || (v && v.length && !v[0].actions.length)) {
return Promise.reject('至少配置一个执行动作'); return Promise.reject('至少配置一个执行动作');
} }

View File

@ -14,15 +14,17 @@
<Title :options='data.options.trigger' /> <Title :options='data.options.trigger' />
</AddButton> </AddButton>
</j-form-item> </j-form-item>
<j-form-item <div class='actions-branches-item' >
:rules="actionRules" <j-form-item
:name="['branches', 0, 'then']" :rules="actionRules"
> :name="['branches', 0, 'then']"
<Action >
<Action
:thenOptions="data.branches ? data?.branches[0].then : []" :thenOptions="data.branches ? data?.branches[0].then : []"
:name="0" :name="0"
/> />
</j-form-item> </j-form-item>
</div>
<AddModel <AddModel
v-if="visible" v-if="visible"
@cancel='visible = false' @cancel='visible = false'

View File

@ -32,6 +32,18 @@
</div> </div>
</template> </template>
</template> </template>
<div v-else class='actions-branches-item'>
<j-form-item
:name='["branches", 0, "then"]'
:rules='thenRules'
>
<Action
:name='0'
:openShakeLimit="true"
:thenOptions='data.branches[0]?.then'
/>
</j-form-item>
</div>
</div> </div>
</template> </template>
@ -40,10 +52,11 @@ import { storeToRefs } from 'pinia';
import { useSceneStore } from 'store/scene' import { useSceneStore } from 'store/scene'
import { cloneDeep } from 'lodash-es' import { cloneDeep } from 'lodash-es'
import { provide } from 'vue' import { provide } from 'vue'
import { ContextKey, handleParamsData } from './util' import { ContextKey, handleParamsData, thenRules } from './util'
import { getParseTerm } from '@/api/rule-engine/scene' import { getParseTerm } from '@/api/rule-engine/scene'
import type { FormModelType } from '@/views/rule-engine/Scene/typings' import type { FormModelType } from '@/views/rule-engine/Scene/typings'
import Branches from './Branches.vue' import Branches from './Branches.vue'
import Action from '../../action/index.vue'
const sceneStore = useSceneStore() const sceneStore = useSceneStore()
const { data } = storeToRefs(sceneStore) const { data } = storeToRefs(sceneStore)
@ -55,6 +68,11 @@ provide(ContextKey, columnOptions)
const change = (e: boolean) => { const change = (e: boolean) => {
open.value = e open.value = e
if (!e) {
data.value.branches!.length = 1
} else {
data.value.branches!.push(null as any)
}
} }
const queryColumn = (dataModel: FormModelType) => { const queryColumn = (dataModel: FormModelType) => {

View File

@ -106,6 +106,10 @@
} }
} }
} }
.actions-branches-item {
width: 100%;
}
} }
.terms-params { .terms-params {
@ -224,6 +228,9 @@
} }
} }
} }
.actions-branches-item {
width: 75%;
}
} }
} }

View File

@ -9,4 +9,16 @@ export const handleParamsData = (data: any[], key: string = 'column'): any[] =>
children: handleParamsData(item.children, key) children: handleParamsData(item.children, key)
} }
}) || [] }) || []
} }
export const thenRules = [{
validator(_: string, value: any) {
if (!value || (value && !value.length)) {
return Promise.reject('至少配置一个执行动作')
} else {
const isActions = value.some((item: any) => item.actions && item.actions.length)
return isActions ? Promise.resolve() : Promise.reject('至少配置一个执行动作');
}
return Promise.resolve();
}
}]