fix: 修复场景联动数据格式错误问题

This commit is contained in:
xieyonghong 2023-04-24 11:05:26 +08:00
parent a42c108b08
commit 0154fb7d7c
5 changed files with 39 additions and 57 deletions

View File

@ -32,20 +32,14 @@ export const defaultBranches = [
{
terms: [
{
terms: [
{
column: undefined,
value: {
source: 'fixed',
value: undefined
},
termType: undefined,
key: 'params_1',
type: 'and',
},
],
column: undefined,
value: {
source: 'fixed',
value: undefined
},
termType: undefined,
key: 'params_1',
type: 'and',
key: 'terms_1_terms_1',
},
],
type: 'and',

View File

@ -106,6 +106,7 @@ const showWhen = computed(() => {
})
const whenData = computed(() => {
console.log(props.data.when)
return props.data.when
})
@ -141,19 +142,13 @@ const addWhen = () => {
type: 'and',
terms: [
{
terms: [
{
column: undefined,
value: {
source: 'fixed',
value: undefined
},
termType: undefined,
key: `params_${randomString()}`,
type: 'and',
}
],
key: `terms_2_${randomString()}`,
column: undefined,
value: {
source: 'fixed',
value: undefined
},
termType: undefined,
key: `params_${randomString()}`,
type: 'and',
}
],

View File

@ -284,8 +284,8 @@ const columnSelect = (option: any) => {
handOptionByColumn(option)
emit('update:value', { ...paramsValue })
formItemContext.onFieldChange()
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.name][0] = option.name
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.name][1] = paramsValue.termType
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName][0] = option.name
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName][1] = paramsValue.termType
}
const termsTypeSelect = (e: { key: string, name: string }) => {
@ -310,11 +310,12 @@ const termsTypeSelect = (e: { key: string, name: string }) => {
}
emit('update:value', { ...paramsValue })
formItemContext.onFieldChange()
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.name][1] = e.name
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName][1] = e.name
}
const valueSelect = (v: any, label: string, labelObj: Record<number, any>, option: any) => {
console.log(paramsValue.value?.source)
if (paramsValue.value?.source === 'metric') {
paramsValue.metric = option?.id
}
@ -325,14 +326,15 @@ const valueSelect = (v: any, label: string, labelObj: Record<number, any>, optio
delete newValues.metric
}
console.log(newValues)
emit('update:value', { ...newValues })
formItemContext.onFieldChange()
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.name][2] = labelObj
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName][2] = labelObj
}
const typeSelect = (e: any) => {
emit('update:value', { ...paramsValue })
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.name][3] = e.label
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName][3] = e.label
}
const termAdd = () => {
@ -346,17 +348,17 @@ const termAdd = () => {
type: 'and',
key: `params_${new Date().getTime()}`
}
formModel.value.branches?.[props.branchName]?.when?.[props.whenName]?.terms?.[props.termsName]?.terms?.push(terms)
formModel.value.branches?.[props.branchName]?.when?.[props.whenName]?.terms?.push(terms)
formModel.value.options!.when[props.branchName].terms[props.whenName].terms[props.termsName].push(['', '', '', '并且'])
}
const onDelete = () => {
formModel.value.branches?.[props.branchName]?.when?.[props.whenName]?.terms?.[props.termsName]?.terms?.splice(props.name, 1)
formModel.value.options!.when[props.branchName].terms[props.whenName].terms.splice(props.name, 1)
formModel.value.branches?.[props.branchName]?.when?.[props.whenName]?.terms?.splice(props.termsName, 1)
formModel.value.options!.when[props.branchName].terms[props.whenName].terms.splice(props.termsName, 1)
}
nextTick(() => {
Object.assign(paramsValue, pick(props.value, ['column', 'options', 'termType', 'terms', 'type', 'value']))
Object.assign(paramsValue, pick(props.value, ['column', 'options', 'termType', 'terms', 'type', 'value', 'metric']))
})
</script>

View File

@ -15,17 +15,14 @@
</j-popconfirm>
<j-form-item
v-for='(item, index) in termsData'
:key='item.key'
:name='["branches", branchName, "when", whenName, "terms", props.name, "terms", index]'
:name='["branches", branchName, "when", whenName, "terms", props.name]'
:rules='rules'
>
<ParamsItem
v-model:value='formModel.branches[branchName].when[whenName].terms[props.name].terms[index]'
:isFirst='index === 0'
:isLast='index === termsData.length - 1'
:showDeleteBtn='termsData.length !== 1'
:name='index'
v-model:value='formModel.branches[branchName].when[whenName].terms[props.name]'
:isFirst='isFirst'
:isLast='isLast'
:showDeleteBtn='showDeleteBtn'
:termsName='name'
:whenName='whenName'
:branchName='branchName'

View File

@ -18,7 +18,7 @@
:branchName='branchName'
:whenName='props.name'
:name='index'
:showDeleteBtn='showDeleteBtn'
:showDeleteBtn='termsData.length > 1'
:isFirst='index === 0'
:isLast='index === termsData.length -1'
:data='item'
@ -93,19 +93,13 @@ const addWhen = () => {
type: 'and',
terms: [
{
terms: [
{
column: undefined,
value: {
source: 'manual',
value: undefined
},
termType: undefined,
key: `params_${randomString()}`,
type: 'and',
}
],
key: `terms_2_${randomString()}`,
column: undefined,
value: {
source: 'manual',
value: undefined
},
termType: undefined,
key: `params_${randomString()}`,
type: 'and',
}
],