feat(应用管理): 优化规则编辑对话框和主页面的字段类型过滤功能

- 在 RuleEditDialog 组件中添加规则类型变更事件处理,更新字段类型列表- 在主页面中添加规则类型变更事件处理,更新字段类型列表
- 优化字段类型列表的过滤逻辑,根据选中的规则类型动态显示相关字段
-调整字段类型列表的数据结构,使用 id 作为 key 值
This commit is contained in:
陈昱达
2025-07-30 13:32:06 +08:00
parent 91104a469e
commit 1d6cc05717
2 changed files with 78 additions and 8 deletions

View File

@@ -18,12 +18,13 @@
v-model="ruleForm.ruleType"
placeholder="请选择规则类型"
style="width: 100%"
@change="handleRuleTypeChange"
>
<el-option
v-for="item in ruleTypeList"
:key="item.typeCode"
:label="item.typeName"
:value="item.typeCode"
:value="item.typeName"
>
</el-option>
</el-select>
@@ -37,7 +38,7 @@
style="width: 100%"
>
<el-option
v-for="item in fieldTypeList"
v-for="item in filteredFieldTypeList"
:key="item.fieldName"
:label="item.fieldComment"
:value="item.fieldName"
@@ -168,6 +169,7 @@ export default {
ruleStatus: 1,
runType: 'ai'
},
filteredFieldTypeList: [],
// 表单验证规则
rules: {
ruleType: [
@@ -248,6 +250,8 @@ export default {
handler(val) {
if (val && Object.keys(val).length > 0) {
this.ruleForm = Object.assign({}, val)
console.log(this.ruleForm)
} else {
this.ruleForm = {
id: '',
@@ -263,14 +267,65 @@ export default {
}
},
immediate: true
},
// 监听规则类型列表变化
ruleTypeList: {
handler() {
this.updateFieldTypeList()
},
immediate: true
},
// 监听规则类型选择变化
'ruleForm.ruleType': {
handler() {
this.updateFieldTypeList()
},
immediate: true,
deep: true
}
},
methods: {
// 更新字段类型列表
updateFieldTypeList() {
// 如果规则类型列表为空,设置字段类型列表为空数组
if (!this.ruleTypeList || this.ruleTypeList.length === 0) {
this.filteredFieldTypeList = []
return
}
// 如果未选择规则类型,返回所有字段类型
if (!this.ruleForm.ruleType) {
this.filteredFieldTypeList = this.fieldTypeList
return
}
const ruleType = this.ruleTypeList.find(
item => item.typeName === this.ruleForm.ruleType
)
if (ruleType) {
console.log(ruleType, 1)
this.filteredFieldTypeList = this.fieldTypeList.filter(item => {
console.log(item)
return item.ruleTypeId === ruleType.id
})
console.log(this.filteredFieldTypeList)
} else {
this.filteredFieldTypeList = []
}
},
// 关闭对话框
handleClose() {
this.$refs.ruleForm.resetFields()
this.$emit('update:visible', false)
},
// 处理规则类型变更事件,与主页面保持一致效果
handleRuleTypeChange(value) {
this.ruleForm.ruleField = ''
// 更新已由watch处理无需额外操作
this.updateFieldTypeList()
},
// 提交表单
handleSubmit() {
this.$refs.ruleForm.validate(valid => {

View File

@@ -24,6 +24,7 @@
size="medium"
clearable
placeholder="请选择规则类型"
@change="handleRuleTypeChange"
>
<el-option
v-for="item in ruleTypeList"
@@ -43,10 +44,10 @@
placeholder="请选择字段类型"
>
<el-option
v-for="item in fieldTypeList"
v-for="item in fieldTypeListCopy"
:label="item.fieldComment"
:value="item.fieldName"
:key="item.fieldName"
:key="item.id"
></el-option>
</el-select>
</el-form-item>
@@ -172,6 +173,7 @@ export default {
ruleTypeList: [],
// 字段类型选项列表
fieldTypeList: [],
fieldTypeListCopy: [],
// 风险类型选项列表
riskTypeList: [],
// 规则状态选项列表
@@ -240,7 +242,7 @@ export default {
isRedraw: true,
render: (h, params) => {
const buttons = []
// 所有状态都显示查看详情按钮
buttons.push(
h(
@@ -258,7 +260,7 @@ export default {
''
)
)
// 规则状态为"停用"(ruleStatus === 1)时显示编辑和删除按钮
if (params.row.ruleStatus === 1) {
buttons.push(
@@ -292,7 +294,7 @@ export default {
)
)
}
// 显示启用/停用按钮(根据当前状态显示不同图标)
buttons.push(
h(
@@ -312,7 +314,7 @@ export default {
''
)
)
return h('div', buttons)
}
}
@@ -329,6 +331,19 @@ export default {
this.getRiskTypeList()
},
methods: {
handleRuleTypeChange(value) {
let ruleType = this.ruleTypeList.filter(
item => item.typeCode === value
)[0]
if (ruleType) {
this.fieldTypeListCopy = this.fieldTypeList.filter(item => {
console.log(item)
return item.ruleTypeId === ruleType.id
})
} else {
this.fieldTypeListCopy = []
}
},
// 获取规则列表数据
getList() {
this.loading = true