条件节点的条件组检验

This commit is contained in:
ChenXinXin committed 2024-05-08 16:10:20 +08:00
1 parent 84ac519499
commit c0487eea1e
1 file changed
+50 -24
+50 -24
View File
@@ -1,5 +1,5 @@
<template id="edit-node"> <template id="edit-node">
<v-form v-model="isFormValid" ref="dataForm" lazy-validation> <v-form ref="dataForm" lazy-validation>
<v-row class="ma-0 pa-0"> <v-row class="ma-0 pa-0">
<v-col cols="12" class="ma-0 pa-0 mb-1"> <v-col cols="12" class="ma-0 pa-0 mb-1">
<span class="jh-input-label">GUID</span> <span class="jh-input-label">GUID</span>
@@ -156,13 +156,13 @@
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<!-- <v-row v-for="(index, item) in node.conditionList"> -->
<v-card elevation="0" outlined> <v-card elevation="0" outlined>
<v-form ref="conditionForm" lazy-validation>
<v-data-table <v-data-table
:headers="headers" :headers="headers"
:items="node.conditionList" :items="node.conditionList"
v-model="node.conditionList" v-model="node.conditionList"
:items-per-page="10" :items-per-page="15"
class="elevation-1" class="elevation-1"
> >
<template v-slot:item.action="{ item, index }"> <template v-slot:item.action="{ item, index }">
@@ -172,26 +172,28 @@
</template> </template>
<template v-slot:item.id="{ item }"> <template v-slot:item.id="{ item }">
<v-select :items="conditions" dense filled single-line item-text="name" item-value="id" class="jh-v-input" v-model="item.id" <v-select :items="conditions" dense filled single-line item-text="name" item-value="id" class="jh-v-input" v-model="item.id"
@change="changeConditionId($event, item)"></v-select> @change="changeConditionId($event, item)" :rules="validationRules.requireRules"></v-select>
</template> </template>
<template v-slot:item.express="{ item }"> <template v-slot:item.express="{ item, index }">
<v-select :items="constantObj.operators[item.type]" dense filled single-line class="jh-v-input" v-model="item.express" <v-select :items="constantObj.operators[item.type]" dense filled single-line class="jh-v-input" v-model="item.express"
@change="changeExpress($event, item)"></v-select> @change="changeExpress($event, item, index)" :rules="validationRules.requireRules"></v-select>
</template> </template>
<template v-slot:item.option-list="{ item }"> <template v-slot:item.option-list="{ item }">
<div v-if="item.type == 'number'"> <div v-if="item.type == 'number'">
<div v-if="item.express == 'between'" class="d-flex align-center"> <div v-if="item.express == 'between'" class="d-flex align-center">
<v-text-field class="jh-v-input" dense filled v-model="item.option.begin"></v-text-field> <v-text-field class="jh-v-input" type="number" dense filled v-model="item.option.begin" :rules="validationRules.requireRules"></v-text-field>
<span> 至 </span> <span> 至 </span>
<v-text-field class="jh-v-input" dense filled v-model="item.option.end"></v-text-field> <v-text-field class="jh-v-input" type="number" dense filled v-model="item.option.end" :rules="validationRules.requireRules"></v-text-field>
</div> </div>
<v-text-field v-else class="jh-v-input" dense filled v-model="item.option"></v-text-field> <v-text-field v-else class="jh-v-input" type="number" dense filled v-model="item.option" :rules="validationRules.requireRules"></v-text-field>
</div> </div>
<v-select v-else :items="getOptionList(item)" item-text="text" item-value="value" dense filled class="jh-v-input" v-model="item.option" multiple></v-select> <v-select v-else :items="getOptionList(item)" item-text="text" item-value="value" dense filled class="jh-v-input" v-model="item.option"
multiple :rules="validationRules.arrayRequireRules"></v-select>
</template> </template>
</v-data-table> </v-data-table>
</v-form>
</v-card> </v-card>
<v-btn class="add-btn" @click="doUiAction('addCondition')">添加条件</v-btn> <v-btn class="add-btn" @click="doUiAction('addCondition')" v-show="node.conditionList.length < this.conditions.length">添加条件</v-btn>
</v-card-text> </v-card-text>
<v-divider></v-divider> <v-divider></v-divider>
@@ -264,7 +266,14 @@
}, },
data() { data() {
return { return {
isFormValid: true, validationRules: {
requireRules: [
v => !!v || '必填',
],
arrayRequireRules: [
v => (v && !!v.length) || '必填',
],
},
node: { node: {
id: '' id: ''
}, },
@@ -342,7 +351,6 @@
}, },
'node.conditionList': { 'node.conditionList': {
handler: async function (val) { handler: async function (val) {
this.$forceUpdate()
this.$emit('reflesh-workflow') this.$emit('reflesh-workflow')
}, },
deep: true deep: true
@@ -362,6 +370,9 @@
}) })
] ]
}, },
selectedCondition(){
return this.node.conditionList?.map(item => item.id).filter(item => item)
},
conditions(){ conditions(){
var conditions = [ var conditions = [
{ {
@@ -373,7 +384,8 @@
text: '包含' text: '包含'
} }
], ],
optionList: this.user optionList: this.user,
disabled: this.selectedCondition.includes('single-applyPerson')
}, },
...this.workflowForm ...this.workflowForm
.filter(i => ['single', 'multiple', 'number'].includes(i.type)) .filter(i => ['single', 'multiple', 'number'].includes(i.type))
@@ -383,7 +395,8 @@
name: i.statement, name: i.statement,
type: i.type, type: i.type,
operator: this.constantObj.operators[i.type], operator: this.constantObj.operators[i.type],
optionList: i.optionList optionList: i.optionList,
disabled: this.selectedCondition.includes(i.id)
} }
}) })
] ]
@@ -407,6 +420,7 @@
await this.deleteCondition(uiActionData); await this.deleteCondition(uiActionData);
break; break;
case 'closeConditionGroupDialog': case 'closeConditionGroupDialog':
await this.conditionValidate();
await this.closeConditionGroupDialog(); await this.closeConditionGroupDialog();
break; break;
default: default:
@@ -423,11 +437,18 @@
}, },
addCondition(){ addCondition(){
if(this.node?.conditionList && this.node.conditionList.length > 0){ if(this.node?.conditionList && this.node.conditionList.length > 0){
this.$set(this.node, 'conditionList', [...this.node.conditionList, {}]) this.$set(this.node, 'conditionList', [...this.node.conditionList, {
id: null,
express: null,
option: null
}])
}else{ }else{
this.$set(this.node, 'conditionList', [{}]) this.$set(this.node, 'conditionList', [{
id: null,
express: null,
option: null
}])
} }
this.$forceUpdate()
}, },
deleteCondition(index){ deleteCondition(index){
this.node.conditionList.splice(index, 1) this.node.conditionList.splice(index, 1)
@@ -436,16 +457,21 @@
var conditionItem = this.conditions.find(c => c.id == id) var conditionItem = this.conditions.find(c => c.id == id)
item.type = conditionItem.type || null item.type = conditionItem.type || null
item.express = null item.express = null
// item.option = item.type == 'number'? { begin: null, end: null} : null
item.option = null item.option = null
}, },
changeExpress(express, item){ changeExpress(express, item, index){
if(item.type == 'number' && express == 'between'){ if (item.type === 'number' && express === 'between') {
this.$set(item, 'option', { begin: null, end: null}) this.node.conditionList[index].option = { begin: null, end: null };
} else { } else {
this.$set(item, 'option', null) this.node.conditionList[index].option = null;
} }
this.$forceUpdate() },
async conditionValidate(){
if (await this.$refs.conditionForm.validate()) {
return true;
}
await window.vtoast.fail("请完善信息!");
throw new Error("请完善信息!")
}, },
closeConditionGroupDialog(){ closeConditionGroupDialog(){
this.$forceUpdate() this.$forceUpdate()