fix(Permission Configuration): Permission rules support binding to system variables.

This commit is contained in:
dataeaseShu
2026-02-05 10:12:45 +08:00
committed by junjun
parent 439b253176
commit e930d68331
6 changed files with 101 additions and 8 deletions
+1
View File
@@ -8,6 +8,7 @@
"Details": "Details"
},
"variables": {
"normal_value": "Normal value",
"​​cannot_be_empty": "Variable values ​​cannot be empty.",
"1_to_100": "{name}, the numerical range is {min} to {max}.",
"1_to_100_de": "{name}, the date range is {min} to {max}.",
+1
View File
@@ -24,6 +24,7 @@
"return_to_view": "화면으로 돌아가기"
},
"variables": {
"normal_value": "정상값",
"​​cannot_be_empty": "변수 값은 비어 있을 수 없습니다.",
"1_to_100": "{name}, 숫자 범위는 {min}부터 {max}까지입니다.",
"1_to_100_de": "{name}, 날짜 범위는 {min}부터 {max}까지입니다.",
+1
View File
@@ -24,6 +24,7 @@
"return_to_view": "返回查看"
},
"variables": {
"normal_value": "常规值",
"​​cannot_be_empty": "变量值不能为空",
"1_to_100": "{name}数值范围 {min}~{max}",
"1_to_100_de": "{name}日期范围 {min}~{max}",
@@ -71,6 +71,8 @@ const add = (type: any, child: any, logic: any) => {
term: '',
filter_type: 'logic',
name: '',
value_type: 'normal',
variable_id: undefined,
}
: { child: [], logic }
)
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import icon_deleteTrash_outlined from '@/assets/svg/icon_delete.svg'
import { ref, inject, computed, onBeforeMount, toRefs, type Ref } from 'vue'
import { ref, inject, computed, onBeforeMount, toRefs, type Ref, shallowRef } from 'vue'
import { variablesApi } from '@/api/variables'
import { useI18n } from 'vue-i18n'
import { allOptions } from '../options'
export interface Item {
@@ -10,6 +11,8 @@ export interface Item {
enum_value: string
name: string
value: any
value_type: any
variable_id: any
}
export interface sysVariable {
@@ -32,6 +35,8 @@ const props = withDefaults(defineProps<Props>(), {
enum_value: '',
name: '',
value: null,
value_type: 'normal',
variable_id: undefined,
}),
})
@@ -41,7 +46,17 @@ const keywords = ref('')
const activeName = ref()
const checklist = ref<string[]>([])
const filterList = ref<any[]>([])
const variables = shallowRef<any[]>([])
const valueTypeList = [
{
value: 'normal',
label: t('variables.normal_value'),
},
{
value: 'variable',
label: t('variables.system_variables'),
},
]
const { item } = toRefs(props)
const filedList = inject('filedList') as Ref<any[]>
@@ -49,7 +64,7 @@ const filedList = inject('filedList') as Ref<any[]>
const computedWidth = computed(() => {
const { field_id } = item.value
return {
width: !field_id ? '270px' : '670px',
width: !field_id ? '270px' : '770px',
}
})
@@ -69,8 +84,15 @@ const dimensions = computed(() => {
onBeforeMount(() => {
initNameEnumName()
filterListInit()
getVariables()
})
const getVariables = () => {
variablesApi.listAll().then((res: any) => {
variables.value = res || []
})
}
const initNameEnumName = () => {
const { name, enum_value, field_id } = item.value
dimensions.value.forEach((ele) => {
@@ -103,6 +125,8 @@ const selectItem = ({ field_name, id }: any) => {
filter_type: 'logic',
value: '',
term: '',
variable_id: undefined,
value_type: 'normal',
})
filterListInit()
checklist.value = []
@@ -152,6 +176,20 @@ const emits = defineEmits(['update:item', 'del'])
>
</el-option>
</el-select>
<el-select
v-model="item.value_type"
style="width: 102px; margin-left: 8px"
:placeholder="$t('permission.conditional_filtering')"
@change="filterTypeChange"
>
<el-option
v-for="ele in valueTypeList"
:key="ele.value"
:label="ele.label"
:value="ele.value"
>
</el-option>
</el-select>
<el-select
v-if="['null', 'not_null', 'empty', 'not_empty'].includes(item.term)"
v-model="item.term"
@@ -167,7 +205,7 @@ const emits = defineEmits(['update:item', 'del'])
</el-option>
</el-select>
<el-input
v-else
v-else-if="item.value_type === 'normal'"
v-model="item.value"
style="max-width: 280px; margin-left: 8px"
:placeholder="$t('datasource.please_enter')"
@@ -190,6 +228,29 @@ const emits = defineEmits(['update:item', 'del'])
</el-select>
</template>
</el-input>
<template v-else>
<el-select
v-model="item.term"
style="width: 75px; margin-left: 8px"
:placeholder="t('datasource.Please_select')"
>
<el-option
v-for="ele in operators"
:key="ele.value"
:label="t(ele.label)"
:value="ele.value"
>
</el-option>
</el-select>
<el-select
v-model="item.variable_id"
style="max-width: 197px; margin-left: 8px"
:placeholder="t('datasource.Please_select')"
>
<el-option v-for="ele in variables" :key="ele.id" :label="ele.name" :value="ele.id">
</el-option>
</el-select>
</template>
</template>
<el-icon v-if="showDel" class="font16" @click="emits('del')">
<icon_deleteTrash_outlined />
@@ -39,7 +39,7 @@ const submit = () => {
errorMessage: errorMessage.value,
})
}
const errorDetected = ({ filter_type, field_id, term, value }: any) => {
const errorDetected = ({ filter_type, field_id, term, value, value_type, variable_id }: any) => {
if (!field_id) {
errorMessage.value = t('permission.cannot_be_empty_')
return
@@ -53,6 +53,16 @@ const errorDetected = ({ filter_type, field_id, term, value }: any) => {
errorMessage.value = t('permission.filter_value_can_null')
return
}
if (
value_type === 'variable' &&
!term.includes('null') &&
!term.includes('empty') &&
[null, undefined, ''].includes(variable_id)
) {
errorMessage.value = t('permission.filter_value_can_null')
return
}
}
}
const dfsInit = (arr: any[]) => {
@@ -64,7 +74,7 @@ const dfsInit = (arr: any[]) => {
const child = dfsInit(items)
elementList.push({ logic, child })
} else {
const { enum_value, field_id, filter_type, term, value, field } = ele
const { enum_value, field_id, filter_type, term, value, field, value_type, variable_id } = ele
const { name } = field || {}
elementList.push({
enum_value: enum_value.join(','),
@@ -73,6 +83,8 @@ const dfsInit = (arr: any[]) => {
term,
value,
name,
value_type,
variable_id,
})
}
})
@@ -90,13 +102,24 @@ const dfsSubmit = (arr: any[]) => {
field_id: '',
filter_type: '',
term: '',
value_type: 'normal',
variable_id: undefined,
type: 'tree',
value: '',
sub_tree: { logic, items: sub_tree },
})
} else {
const { enum_value, field_id, filter_type, term, value, name } = ele
errorDetected({ enum_value, field_id, filter_type, term, value, name })
const { enum_value, field_id, filter_type, term, value, name, value_type, variable_id } = ele
errorDetected({
enum_value,
field_id,
filter_type,
term,
value,
name,
value_type,
variable_id,
})
if (field_id) {
items.push({
enum_value: enum_value ? enum_value.split(',') : [],
@@ -104,6 +127,8 @@ const dfsSubmit = (arr: any[]) => {
filter_type,
term,
value,
value_type,
variable_id,
type: 'item',
sub_tree: null,
})
@@ -247,6 +272,8 @@ const addCondReal = (type: any, logic: any) => {
term: '',
filter_type: 'logic',
name: '',
value_type: 'normal',
variable_id: undefined,
}
: { child: [], logic }
)