Skip to content

Commit fb6dfed

Browse files
committed
fix(Permission Configuration): Permission rules support binding to system variables.
1 parent a55241e commit fb6dfed

File tree

6 files changed

+101
-8
lines changed

6 files changed

+101
-8
lines changed

frontend/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Details": "Details"
99
},
1010
"variables": {
11+
"normal_value": "Normal value",
1112
"​​cannot_be_empty": "Variable values ​​cannot be empty.",
1213
"1_to_100": "{name}, the numerical range is {min} to {max}.",
1314
"1_to_100_de": "{name}, the date range is {min} to {max}.",

frontend/src/i18n/ko-KR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Details": "세부"
99
},
1010
"variables": {
11+
"normal_value": "정상값",
1112
"​​cannot_be_empty": "변수 값은 비어 있을 수 없습니다.",
1213
"1_to_100": "{name}, 숫자 범위는 {min}부터 {max}까지입니다.",
1314
"1_to_100_de": "{name}, 날짜 범위는 {min}부터 {max}까지입니다.",

frontend/src/i18n/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Details": "详情"
99
},
1010
"variables": {
11+
"normal_value": "常规值",
1112
"​​cannot_be_empty": "变量值不能为空",
1213
"1_to_100": "{name}数值范围 {min}~{max}",
1314
"1_to_100_de": "{name}日期范围 {min}~{max}",

frontend/src/views/system/permission/auth-tree/AuthTree.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const add = (type: any, child: any, logic: any) => {
7171
term: '',
7272
filter_type: 'logic',
7373
name: '',
74+
value_type: 'normal',
75+
variable_id: undefined,
7476
}
7577
: { child: [], logic }
7678
)

frontend/src/views/system/permission/auth-tree/FilterFiled.vue

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" setup>
22
import icon_deleteTrash_outlined from '@/assets/svg/icon_delete.svg'
3-
import { ref, inject, computed, onBeforeMount, toRefs, type Ref } from 'vue'
3+
import { ref, inject, computed, onBeforeMount, toRefs, type Ref, shallowRef } from 'vue'
4+
import { variablesApi } from '@/api/variables'
45
import { useI18n } from 'vue-i18n'
56
import { allOptions } from '../options'
67
export interface Item {
@@ -10,6 +11,8 @@ export interface Item {
1011
enum_value: string
1112
name: string
1213
value: any
14+
value_type: any
15+
variable_id: any
1316
}
1417
1518
export interface sysVariable {
@@ -32,6 +35,8 @@ const props = withDefaults(defineProps<Props>(), {
3235
enum_value: '',
3336
name: '',
3437
value: null,
38+
value_type: 'normal',
39+
variable_id: undefined,
3540
}),
3641
})
3742
@@ -41,15 +46,25 @@ const keywords = ref('')
4146
const activeName = ref()
4247
const checklist = ref<string[]>([])
4348
const filterList = ref<any[]>([])
44-
49+
const variables = shallowRef<any[]>([])
50+
const valueTypeList = [
51+
{
52+
value: 'normal',
53+
label: t('variables.normal_value'),
54+
},
55+
{
56+
value: 'variable',
57+
label: t('variables.system_variables'),
58+
},
59+
]
4560
const { item } = toRefs(props)
4661
4762
const filedList = inject('filedList') as Ref<any[]>
4863
4964
const computedWidth = computed(() => {
5065
const { field_id } = item.value
5166
return {
52-
width: !field_id ? '270px' : '670px',
67+
width: !field_id ? '270px' : '770px',
5368
}
5469
})
5570
@@ -69,8 +84,15 @@ const dimensions = computed(() => {
6984
onBeforeMount(() => {
7085
initNameEnumName()
7186
filterListInit()
87+
getVariables()
7288
})
7389
90+
const getVariables = () => {
91+
variablesApi.listAll().then((res: any) => {
92+
variables.value = res || []
93+
})
94+
}
95+
7496
const initNameEnumName = () => {
7597
const { name, enum_value, field_id } = item.value
7698
dimensions.value.forEach((ele) => {
@@ -103,6 +125,8 @@ const selectItem = ({ field_name, id }: any) => {
103125
filter_type: 'logic',
104126
value: '',
105127
term: '',
128+
variable_id: undefined,
129+
value_type: 'normal',
106130
})
107131
filterListInit()
108132
checklist.value = []
@@ -152,6 +176,20 @@ const emits = defineEmits(['update:item', 'del'])
152176
>
153177
</el-option>
154178
</el-select>
179+
<el-select
180+
v-model="item.value_type"
181+
style="width: 102px; margin-left: 8px"
182+
:placeholder="$t('permission.conditional_filtering')"
183+
@change="filterTypeChange"
184+
>
185+
<el-option
186+
v-for="ele in valueTypeList"
187+
:key="ele.value"
188+
:label="ele.label"
189+
:value="ele.value"
190+
>
191+
</el-option>
192+
</el-select>
155193
<el-select
156194
v-if="['null', 'not_null', 'empty', 'not_empty'].includes(item.term)"
157195
v-model="item.term"
@@ -167,7 +205,7 @@ const emits = defineEmits(['update:item', 'del'])
167205
</el-option>
168206
</el-select>
169207
<el-input
170-
v-else
208+
v-else-if="item.value_type === 'normal'"
171209
v-model="item.value"
172210
style="max-width: 280px; margin-left: 8px"
173211
:placeholder="$t('datasource.please_enter')"
@@ -190,6 +228,29 @@ const emits = defineEmits(['update:item', 'del'])
190228
</el-select>
191229
</template>
192230
</el-input>
231+
<template v-else>
232+
<el-select
233+
v-model="item.term"
234+
style="width: 75px; margin-left: 8px"
235+
:placeholder="t('datasource.Please_select')"
236+
>
237+
<el-option
238+
v-for="ele in operators"
239+
:key="ele.value"
240+
:label="t(ele.label)"
241+
:value="ele.value"
242+
>
243+
</el-option>
244+
</el-select>
245+
<el-select
246+
v-model="item.variable_id"
247+
style="max-width: 197px; margin-left: 8px"
248+
:placeholder="t('datasource.Please_select')"
249+
>
250+
<el-option v-for="ele in variables" :key="ele.id" :label="ele.name" :value="ele.id">
251+
</el-option>
252+
</el-select>
253+
</template>
193254
</template>
194255
<el-icon v-if="showDel" class="font16" @click="emits('del')">
195256
<icon_deleteTrash_outlined />

frontend/src/views/system/permission/auth-tree/RowAuth.vue

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const submit = () => {
3939
errorMessage: errorMessage.value,
4040
})
4141
}
42-
const errorDetected = ({ filter_type, field_id, term, value }: any) => {
42+
const errorDetected = ({ filter_type, field_id, term, value, value_type, variable_id }: any) => {
4343
if (!field_id) {
4444
errorMessage.value = t('permission.cannot_be_empty_')
4545
return
@@ -53,6 +53,16 @@ const errorDetected = ({ filter_type, field_id, term, value }: any) => {
5353
errorMessage.value = t('permission.filter_value_can_null')
5454
return
5555
}
56+
57+
if (
58+
value_type === 'variable' &&
59+
!term.includes('null') &&
60+
!term.includes('empty') &&
61+
[null, undefined, ''].includes(variable_id)
62+
) {
63+
errorMessage.value = t('permission.filter_value_can_null')
64+
return
65+
}
5666
}
5767
}
5868
const dfsInit = (arr: any[]) => {
@@ -64,7 +74,7 @@ const dfsInit = (arr: any[]) => {
6474
const child = dfsInit(items)
6575
elementList.push({ logic, child })
6676
} else {
67-
const { enum_value, field_id, filter_type, term, value, field } = ele
77+
const { enum_value, field_id, filter_type, term, value, field, value_type, variable_id } = ele
6878
const { name } = field || {}
6979
elementList.push({
7080
enum_value: enum_value.join(','),
@@ -73,6 +83,8 @@ const dfsInit = (arr: any[]) => {
7383
term,
7484
value,
7585
name,
86+
value_type,
87+
variable_id,
7688
})
7789
}
7890
})
@@ -90,20 +102,33 @@ const dfsSubmit = (arr: any[]) => {
90102
field_id: '',
91103
filter_type: '',
92104
term: '',
105+
value_type: 'normal',
106+
variable_id: undefined,
93107
type: 'tree',
94108
value: '',
95109
sub_tree: { logic, items: sub_tree },
96110
})
97111
} else {
98-
const { enum_value, field_id, filter_type, term, value, name } = ele
99-
errorDetected({ enum_value, field_id, filter_type, term, value, name })
112+
const { enum_value, field_id, filter_type, term, value, name, value_type, variable_id } = ele
113+
errorDetected({
114+
enum_value,
115+
field_id,
116+
filter_type,
117+
term,
118+
value,
119+
name,
120+
value_type,
121+
variable_id,
122+
})
100123
if (field_id) {
101124
items.push({
102125
enum_value: enum_value ? enum_value.split(',') : [],
103126
field_id,
104127
filter_type,
105128
term,
106129
value,
130+
value_type,
131+
variable_id,
107132
type: 'item',
108133
sub_tree: null,
109134
})
@@ -247,6 +272,8 @@ const addCondReal = (type: any, logic: any) => {
247272
term: '',
248273
filter_type: 'logic',
249274
name: '',
275+
value_type: 'normal',
276+
variable_id: undefined,
250277
}
251278
: { child: [], logic }
252279
)

0 commit comments

Comments
 (0)