@@ -5,11 +5,12 @@ import icon_add_outlined from '@/assets/svg/icon_add_outlined.svg'
55import IconOpeEdit from ' @/assets/svg/icon_edit_outlined.svg'
66import IconOpeDelete from ' @/assets/svg/icon_delete.svg'
77import icon_close_outlined from ' @/assets/svg/operate/ope-close.svg'
8+ import EmptyBackground from ' @/views/dashboard/common/EmptyBackground.vue'
89import icon_down_outlined from ' @/assets/svg/icon_down_outlined.svg'
910import Card from ' ./Card.vue'
1011import SelectPermission from ' ./SelectPermission.vue'
1112import AuthTree from ' ./auth-tree/RowAuth.vue'
12- import { getList , savePermissions } from ' @/api/permissions'
13+ import { getList , savePermissions , delPermissions } from ' @/api/permissions'
1314import { datasourceApi } from ' @/api/datasource'
1415import { useI18n } from ' vue-i18n'
1516import { cloneDeep } from ' lodash-es'
@@ -116,6 +117,7 @@ const saveAuthTree = (val: any) => {
116117 currentPermission .permissions [key ],
117118 cloneDeep ({
118119 expression_tree ,
120+ tree: expression_tree ,
119121 table_id ,
120122 ds_id ,
121123 type ,
@@ -128,7 +130,17 @@ const saveAuthTree = (val: any) => {
128130 }
129131 } else {
130132 currentPermission .permissions .push (
131- cloneDeep ({ expression_tree , table_id , ds_id , type , name , ds_name , table_name })
133+ cloneDeep ({
134+ expression_tree ,
135+ tree: expression_tree ,
136+ table_id ,
137+ ds_id ,
138+ type ,
139+ name ,
140+ ds_name ,
141+ table_name ,
142+ id: + new Date (),
143+ })
132144 )
133145 }
134146 dialogFormVisible .value = false
@@ -142,7 +154,7 @@ const getDsList = (row: any) => {
142154 dsListOptions .value = res || []
143155 if (! row ?.ds_id ) return
144156 dsListOptions .value .forEach ((ele ) => {
145- if (ele .id === row .ds_id ) {
157+ if (+ ele .id === + row .ds_id ) {
146158 activeDs .value = ele
147159 }
148160 })
@@ -154,7 +166,7 @@ const getDsList = (row: any) => {
154166 })
155167
156168 if (row ) {
157- handleDsIdChange (row )
169+ handleDsIdChange ({ id: row . ds_id , name: row . ds_name } )
158170 handleEditeTable (row .table_id )
159171 }
160172}
@@ -170,7 +182,7 @@ const handleRowPermission = (row: any) => {
170182 table_id ,
171183 ds_name ,
172184 table_name ,
173- expression_tree: tree ,
185+ expression_tree: typeof tree === ' object ' ? tree : JSON . parse ( tree ) ,
174186 })
175187 }
176188 dialogFormVisible .value = true
@@ -206,7 +218,7 @@ const handleDsIdChange = (val: any) => {
206218 tableListOptions .value = res || []
207219 if (! columnForm .table_id ) return
208220 tableListOptions .value .forEach ((ele ) => {
209- if (ele .id === columnForm .table_id ) {
221+ if (+ ele .id === + columnForm .table_id ) {
210222 activeTable .value = ele
211223 }
212224 })
@@ -215,7 +227,7 @@ const handleDsIdChange = (val: any) => {
215227
216228const handleTableIdChange = (val : any ) => {
217229 columnForm .table_id = val .id
218- columnForm .table_name = val .name
230+ columnForm .table_name = val .table_name
219231 datasourceApi .fieldList (val .id ).then ((res : any ) => {
220232 fieldListOptions .value = res || []
221233 if (columnForm .type === ' row' ) return
@@ -242,6 +254,7 @@ const handleEditeTable = (val: any) => {
242254 })
243255 })
244256 .finally (() => {
257+ if (columnForm .type !== ' row' ) return
245258 authTreeRef .value .init (columnForm .expression_tree )
246259 })
247260}
@@ -250,10 +263,17 @@ const beforeClose = () => {
250263 activeStep .value = 0
251264 isCreate .value = false
252265}
266+
267+ const searchLoading = ref (false )
253268const handleSearch = () => {
254- getList ().then ((res : any ) => {
255- ruleList .value = res || []
256- })
269+ searchLoading .value = true
270+ getList ()
271+ .then ((res : any ) => {
272+ ruleList .value = res || []
273+ })
274+ .finally (() => {
275+ searchLoading .value = false
276+ })
257277}
258278handleSearch ()
259279const addHandler = () => {
@@ -280,13 +300,48 @@ const handleEditRule = (row: any) => {
280300 Object .assign (currentPermission , cloneDeep (row ))
281301 ruleConfigvVisible .value = true
282302}
303+
304+ const deleteRuleHandler = (row : any ) => {
305+ ElMessageBox .confirm (t (' permission.rule_rule_1' , { msg: row .name }), {
306+ confirmButtonType: ' danger' ,
307+ confirmButtonText: t (' dashboard.delete' ),
308+ cancelButtonText: t (' common.cancel' ),
309+ customClass: ' confirm-no_icon' ,
310+ autofocus: false ,
311+ }).then (() => {
312+ currentPermission .permissions = currentPermission .permissions .filter (
313+ (ele : any ) => ele .id !== row .id
314+ )
315+ })
316+ }
317+
283318const deleteHandler = (row : any ) => {
284- console .log (row )
319+ ElMessageBox .confirm (t (' permission.rule_group_1' , { msg: row .name }), {
320+ confirmButtonType: ' danger' ,
321+ confirmButtonText: t (' dashboard.delete' ),
322+ cancelButtonText: t (' common.cancel' ),
323+ customClass: ' confirm-no_icon' ,
324+ autofocus: false ,
325+ }).then (() => {
326+ delPermissions (row .id ).then (() => {
327+ ElMessage ({
328+ type: ' success' ,
329+ message: t (' dashboard.delete_success' ),
330+ })
331+ handleSearch ()
332+ })
333+ })
285334}
286335const setUser = (row : any ) => {
287336 editRule .value = 2
288337 setDrawerTitle ()
289- console .log (row )
338+ isCreate .value = false
339+ Object .assign (currentPermission , cloneDeep (row ))
340+ activeStep .value = 1
341+ ruleConfigvVisible .value = true
342+ nextTick (() => {
343+ selectPermissionRef .value .open (row .users )
344+ })
290345}
291346
292347const rules = {
@@ -317,6 +372,7 @@ const saveHandler = () => {
317372 currentPermission .permissions [key ],
318373 cloneDeep ({
319374 permissions ,
375+ permission_list: permissions ,
320376 table_id ,
321377 ds_id ,
322378 type ,
@@ -329,34 +385,48 @@ const saveHandler = () => {
329385 }
330386 } else {
331387 currentPermission .permissions .push (
332- cloneDeep ({ permissions , table_id , ds_id , type , name , ds_name , table_name })
388+ cloneDeep ({
389+ permissions ,
390+ permission_list: permissions ,
391+ table_id ,
392+ ds_id ,
393+ type ,
394+ name ,
395+ ds_name ,
396+ table_name ,
397+ id: + new Date (),
398+ })
333399 )
334400 }
335401 }
336402 dialogFormVisible .value = false
337403 }
338404 })
339405}
340- const preview = () => {}
406+ const preview = () => {
407+ currentPermission .user = selectPermissionRef .value .checkedWorkspace .map ((ele : any ) => ele .id )
408+ activeStep .value = 0
409+ }
341410const next = () => {
342- activeStep .value = 1
343- nextTick (() => {
344- selectPermissionRef .value .open ()
411+ termFormRef .value .validate ((res : any ) => {
412+ if (res ) {
413+ activeStep .value = 1
414+ nextTick (() => {
415+ selectPermissionRef .value .open (currentPermission .users )
416+ })
417+ }
345418 })
346419}
347420const savePermission = () => {
348- // termFormRef.value.validate((res: any) => {
349- // if (res) {
350-
351- // }
352- // })
353-
354421 const { id, name, permissions } = currentPermission
422+
355423 const permissionsObj = permissions .map ((ele : any ) => {
356424 return {
357425 ... cloneDeep (ele ),
358- permissions: JSON .stringify (ele .permissions || []),
359- expression_tree: JSON .stringify (ele .expression_tree || {}),
426+ permissions: ele .type !== ' row' ? JSON .stringify (ele .permissions || []) : JSON .stringify ([]),
427+ permission_list: [],
428+ expression_tree:
429+ ele .type === ' row' ? JSON .stringify (ele .expression_tree || {}) : JSON .stringify ({}),
360430 }
361431 })
362432 const obj = {
@@ -373,7 +443,7 @@ const savePermission = () => {
373443 type: ' success' ,
374444 message: t (' common.save_success' ),
375445 })
376- ruleConfigvVisible . value = false
446+ beforeClose ()
377447 handleSearch ()
378448 })
379449}
@@ -397,7 +467,7 @@ const columnRules = {
397467 </script >
398468
399469<template >
400- <div class =" permission" >
470+ <div v-loading = " searchLoading " class =" permission" >
401471 <div class =" tool-left" >
402472 <span class =" page-title" >{{ $t('workspace.permission_configuration') }}</span >
403473 <div >
@@ -443,6 +513,18 @@ const columnRules = {
443513 @set-user =" setUser(ele)"
444514 ></Card >
445515 </div >
516+ <template v-if =" ! keywords && ! ruleListWithSearch .length && ! searchLoading " >
517+ <EmptyBackground :description =" $t('permission.no_permission_rule')" img-type =" noneWhite" />
518+
519+ <div style =" text-align : center ; margin-top : -10px " >
520+ <el-button type =" primary" @click =" addHandler()" >
521+ <template #icon >
522+ <icon _add_outlined ></icon _add_outlined >
523+ </template >
524+ {{ $t('permission.add_rule_group') }}
525+ </el-button >
526+ </div >
527+ </template >
446528 <el-drawer
447529 v-model =" ruleConfigvVisible"
448530 :close-on-click-modal =" false"
@@ -454,7 +536,7 @@ const columnRules = {
454536 >
455537 <template #header =" { close } " >
456538 <span style =" white-space : nowrap " >{{ drawerTitle }}</span >
457- <div v-if =" ! editRule" class =" flex-center" style =" width : 100% " >
539+ <div v-if =" editRule !== 2 " class =" flex-center" style =" width : 100% " >
458540 <el-steps custom style =" max-width : 500px ; flex : 1 " :active =" activeStep" align-center >
459541 <el-step >
460542 <template #title > {{ $t('permission.set_permission_rule') }} </template >
@@ -572,7 +654,7 @@ const columnRules = {
572654 :content =" $t('dashboard.delete')"
573655 placement =" top"
574656 >
575- <el-icon class =" action-btn" size =" 16" @click =" deleteHandler (scope.row)" >
657+ <el-icon class =" action-btn" size =" 16" @click =" deleteRuleHandler (scope.row)" >
576658 <IconOpeDelete ></IconOpeDelete >
577659 </el-icon >
578660 </el-tooltip >
@@ -588,10 +670,10 @@ const columnRules = {
588670 </div >
589671 <template #footer >
590672 <el-button secondary @click =" beforeClose" > {{ $t('common.cancel') }} </el-button >
591- <el-button v-if =" activeStep === 1 && isCreate " secondary @click =" preview" >
673+ <el-button v-if =" activeStep === 1 && editRule !== 2 " secondary @click =" preview" >
592674 {{ t('ds.previous') }}
593675 </el-button >
594- <el-button v-if =" activeStep === 0 && isCreate " type =" primary" @click =" next" >
676+ <el-button v-if =" activeStep === 0 && editRule !== 2 " type =" primary" @click =" next" >
595677 {{ t('common.next') }}
596678 </el-button >
597679 <el-button v-if =" activeStep === 1" type =" primary" @click =" savePermission" >
@@ -703,6 +785,10 @@ const columnRules = {
703785
704786<style lang="less" scoped>
705787.permission {
788+ .ed-empty {
789+ padding-top : 200px ;
790+ padding-bottom : 0 ;
791+ }
706792 .tool-left {
707793 display : flex ;
708794 align-items : center ;
0 commit comments