4455 * @Date: 2021-02-03 15:48:37
66 * @LastEditors: gumingchen
7- * @LastEditTime: 2021-04-21 22:42:39
7+ * @LastEditTime: 2021-04-29 14:08:04
88-->
99<template >
1010 <el-dialog
@@ -52,7 +52,7 @@ import { Inject } from 'vue-property-decorator'
5252import { add , edit , info } from ' @/api/base/role'
5353import { selfSelect } from ' @/api/base/menu'
5454import { $parseData2Tree } from ' @/utils/index'
55- import { Set } from ' @/store/modules/common'
55+ import { Set as ISet } from ' @/store/modules/common'
5656import { El } from ' @/types/el'
5757import { IObject } from ' @/types'
5858import { Menu } from ' @/types/menu'
@@ -62,7 +62,7 @@ import { Role } from '@/types/role'
6262 emits: [' refresh' ]
6363})
6464export default class extends Vue {
65- @Inject (' set' ) readonly set! : Set
65+ @Inject (' set' ) readonly set! : ISet
6666 protected visible: boolean = false
6767 protected loading: boolean = false
6868
@@ -77,7 +77,7 @@ export default class extends Vue {
7777 const prop = {
7878 multiple: true ,
7979 emitPath: false ,
80- checkStrictly: true ,
80+ checkStrictly: false ,
8181 value: ' id' ,
8282 label: ` name_${ this .set .language } ` ,
8383 children: ' children'
@@ -96,6 +96,7 @@ export default class extends Vue {
9696
9797 async init(id ? : number ): Promise <void > {
9898 this .visible = true
99+ this .loading = true
99100 this .form .id = id
100101 const res = await selfSelect ()
101102 if (res ) {
@@ -109,12 +110,14 @@ export default class extends Vue {
109110 this .menus = $parseData2Tree (res .data , ' id' , ' parent_id' )
110111 }
111112 if (this .form .id ) {
112- info (this .form .id ).then (r => {
113- if (r ) {
114- this .form = r .data
115- }
116- })
113+ const r = await info (this .form .id )
114+ if (r ) {
115+ this .form = r .data
116+ }
117117 }
118+ this .$nextTick (() => {
119+ this .loading = false
120+ })
118121 }
119122
120123 /**
@@ -126,6 +129,17 @@ export default class extends Vue {
126129 submit(): void {
127130 this .$refs .formR .validate (async (valid : boolean ) => {
128131 if (valid ) {
132+ // 处理菜单权限ID
133+ const checkedNodes = this .$refs .cascaderR .getCheckedNodes (true ) as El .CascaderCheckedNode <number >[]
134+ let menuIds: number [] = []
135+ checkedNodes .forEach (item => {
136+ menuIds .push .apply (menuIds , item .pathValues )
137+ })
138+ menuIds = Array .from (new Set (menuIds )).filter (item => {
139+ return item !== 0
140+ })
141+ this .form .menu_ids = menuIds
142+
129143 const r = ! this .form .id ? await add (this .form ) : await edit (this .form )
130144 if (r ) {
131145 this .visible = false
0 commit comments