Ver código fonte

Merge branch 'dev' of http://git.ycjcjy.com/SpaceOfCheng/admin into dev

许成详 6 anos atrás
pai
commit
eafb6b8c1f

+ 51
- 18
src/pages/system/systemSet/roleManager/index.vue Ver arquivo

3
     <div class="system-table-search">
3
     <div class="system-table-search">
4
       <div class="flex-h">
4
       <div class="flex-h">
5
         <div class="flex-item flex-h">
5
         <div class="flex-item flex-h">
6
-          <el-button size="mini" type="success" @click='editRole'>新增角色</el-button>
6
+          <el-button size="mini" type="success" @click='addRole'>新增角色</el-button>
7
         </div>
7
         </div>
8
         <tableSearch value='角色名称' @exportSearchKey="searchList"></tableSearch>
8
         <tableSearch value='角色名称' @exportSearchKey="searchList"></tableSearch>
9
       </div>
9
       </div>
35
     layout="prev, pager, next, jumper"
35
     layout="prev, pager, next, jumper"
36
     :total="roles.pagenum">
36
     :total="roles.pagenum">
37
     </el-pagination>
37
     </el-pagination>
38
-    <!-- <el-dialog title="请选择机构" :visible.sync="dialogTableVisible">
38
+    <el-dialog title="请选择菜单" :visible.sync="dialogTableVisible">
39
       <el-tree
39
       <el-tree
40
+        v-if="dialogTableVisible"
40
         class="flxe-h"
41
         class="flxe-h"
41
-        :data="treeData"
42
+        :data="menus"
42
         :default-expand-all="true"
43
         :default-expand-all="true"
43
         :expand-on-click-node="false"
44
         :expand-on-click-node="false"
45
+        :default-checked-keys="defaultChecked"
44
         ref="tree"
46
         ref="tree"
45
         show-checkbox
47
         show-checkbox
46
         @node-click="handleNodeClick"></el-tree>
48
         @node-click="handleNodeClick"></el-tree>
47
         <div class="flex-h" style="justify-content: flex-end;margin-top: 1rem">
49
         <div class="flex-h" style="justify-content: flex-end;margin-top: 1rem">
48
           <el-button type='success' @click="getCheckedNodes">确定</el-button>
50
           <el-button type='success' @click="getCheckedNodes">确定</el-button>
49
         </div>
51
         </div>
50
-    </el-dialog> -->
52
+    </el-dialog>
51
   </div>
53
   </div>
52
 </template>
54
 </template>
53
 
55
 
54
 <script>
56
 <script>
55
-import { createNamespacedHelpers } from 'vuex'
57
+import { createNamespacedHelpers, mapState } from 'vuex'
56
 import tableSearch from '@/components/tableSearch/index'
58
 import tableSearch from '@/components/tableSearch/index'
57
 
59
 
58
 const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
60
 const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
62
   data () {
64
   data () {
63
     return {
65
     return {
64
       currentPage: 0, // 当前页码
66
       currentPage: 0, // 当前页码
65
-      tableSearch: {
66
-        // 表格搜索条件
67
-        key: '111' // 搜索关键字
68
-      },
67
+      key: '',
68
+      selid: '',
69
       dialogTableVisible: false,
69
       dialogTableVisible: false,
70
     }
70
     }
71
   },
71
   },
72
   computed: {
72
   computed: {
73
     ...mapRoleState({
73
     ...mapRoleState({
74
       roles: x => x.roleList,
74
       roles: x => x.roleList,
75
+      selmenus: x => x.roleMenus,
76
+    }),
77
+    ...mapState({
78
+      menus: x => x.app.menus
75
     }),
79
     }),
80
+    defaultChecked: {
81
+      get () {
82
+        console.log(this.selmenus)
83
+        // const sels = (this.selmenus || []).map(x => x.MenuId)
84
+        return []
85
+      },
86
+    },
76
   },
87
   },
77
   components: {
88
   components: {
78
     tableSearch
89
     tableSearch
80
   methods: {
91
   methods: {
81
     ...mapRoleActions([
92
     ...mapRoleActions([
82
       'GetRolesList',
93
       'GetRolesList',
94
+      'DelRole',
95
+      'SaveRoleMenus',
96
+      'GetRoleMenu',
83
     ]),
97
     ]),
84
     FormatDate (date) {
98
     FormatDate (date) {
85
       console.log()
99
       console.log()
98
     handleDelete (index, row) {
112
     handleDelete (index, row) {
99
       // 删除
113
       // 删除
100
       console.log(index, row)
114
       console.log(index, row)
101
-      this.$confirm('确认删除此用户?', '提示', {
115
+      this.$confirm('确认删除此角色?', '提示', {
102
         confirmButtonText: '确定',
116
         confirmButtonText: '确定',
103
         cancelButtonText: '取消',
117
         cancelButtonText: '取消',
104
         type: 'warning'
118
         type: 'warning'
105
       })
119
       })
106
         .then(() => {
120
         .then(() => {
107
-          this.$message({
108
-            type: 'success',
109
-            message: '删除成功!'
110
-          })
121
+          this.DelRole({id: row.RoleId, callback: this.delCallBack})
111
         })
122
         })
112
         .catch(() => {
123
         .catch(() => {
113
           this.$message({
124
           this.$message({
116
           })
127
           })
117
         })
128
         })
118
     },
129
     },
130
+    delCallBack () {
131
+      this.$message({
132
+        type: 'success',
133
+        message: '删除成功!'
134
+      })
135
+      this.GetRolesList({name: this.key})
136
+    },
119
     handlePermission (index, row) {
137
     handlePermission (index, row) {
138
+      this.selid = row.RoleId
139
+      this.GetRoleMenu(this.selid)
120
       this.dialogTableVisible = true
140
       this.dialogTableVisible = true
121
       console.log(index)
141
       console.log(index)
122
     },
142
     },
124
       console.log(node)
144
       console.log(node)
125
     },
145
     },
126
     searchList (key) {
146
     searchList (key) {
127
-      this.GetRolesList({name: key})
147
+      this.key = key
148
+      this.GetRolesList({name: this.key})
128
     },
149
     },
129
     addRole () {
150
     addRole () {
130
-      this.$router.push({ name: 'addRole' })
151
+      this.$router.push({ name: 'editRole' })
131
     },
152
     },
132
     getCheckedNodes () { // 获取选中的节点
153
     getCheckedNodes () { // 获取选中的节点
133
-      console.log(this.$refs.tree.getCheckedNodes())
134
-    }
154
+      const menuids = this.$refs.tree.getCheckedNodes().map(x => x.id).join(',')
155
+      this.SaveRoleMenus({
156
+        id: this.selid,
157
+        menuids: menuids,
158
+        callback: this.hideDialog,
159
+      })
160
+    },
161
+    hideDialog () {
162
+      this.$message({
163
+        type: 'success',
164
+        message: '操作成功!'
165
+      })
166
+      this.dialogTableVisible = false
167
+    },
135
   },
168
   },
136
   beforeMount () {
169
   beforeMount () {
137
     this.GetRolesList()
170
     this.GetRolesList()

+ 6
- 0
src/store/app.js Ver arquivo

20
   let cp = data.slice()
20
   let cp = data.slice()
21
   const res = []
21
   const res = []
22
 
22
 
23
+  cp.map(x => {
24
+    x.id = x.MenuId
25
+    x.label = x.MenuName
26
+    return x
27
+  })
28
+
23
   data.forEach((it, inx) => {
29
   data.forEach((it, inx) => {
24
     let found = false
30
     let found = false
25
     for (let i = 0; i < cp.length; i += 1) {
31
     for (let i = 0; i < cp.length; i += 1) {

+ 32
- 4
src/store/system/role.js Ver arquivo

6
   state: {
6
   state: {
7
     roleList: [],
7
     roleList: [],
8
     roleInfo: {},
8
     roleInfo: {},
9
+    roleMenus: [],
9
   },
10
   },
10
   mutations: {
11
   mutations: {
11
     updateList (state, payload) {
12
     updateList (state, payload) {
14
     updateInfo (state, payload) {
15
     updateInfo (state, payload) {
15
       state.roleInfo = payload || {}
16
       state.roleInfo = payload || {}
16
     },
17
     },
18
+    updateRoleMenus (state, payload) {
19
+      state.roleMenus = payload || {}
20
+    },
17
   },
21
   },
18
   actions: {
22
   actions: {
19
     GetRolesList ({ commit }, payload) {
23
     GetRolesList ({ commit }, payload) {
55
       }).then(res => {
59
       }).then(res => {
56
       })
60
       })
57
     },
61
     },
58
-    DelRole ({ commit }, payload) {
62
+    DelRole ({ commit }, { id, callback }) {
59
       ajax(api.role.delete.url, {
63
       ajax(api.role.delete.url, {
60
         method: api.role.delete.method,
64
         method: api.role.delete.method,
61
-        data: {
62
-          ...payload
65
+        urlData: {
66
+          id: id,
63
         }
67
         }
64
       }).then(res => {
68
       }).then(res => {
69
+        callback()
65
       })
70
       })
66
     },
71
     },
67
     SetRoleNull ({ commit }) {
72
     SetRoleNull ({ commit }) {
68
       commit('updateInfo', {})
73
       commit('updateInfo', {})
69
-    }
74
+    },
75
+    GetRoleMenu ({ commit }, payload) {
76
+      ajax(api.role.getmenus.url, {
77
+        method: api.role.getmenus.method,
78
+        urlData: {
79
+          id: payload.id,
80
+        },
81
+      }).then(res => {
82
+        commit('updateRoleMenus', res)
83
+      })
84
+    },
85
+    SaveRoleMenus ({ commit }, payload) {
86
+      ajax(api.role.savemenu.url, {
87
+        method: api.role.savemenu.method,
88
+        urlData: {
89
+          id: payload.id,
90
+        },
91
+        data: {
92
+          menuids: payload.menuids
93
+        }
94
+      }).then(res => {
95
+        payload.callback()
96
+      })
97
+    },
70
   }
98
   }
71
 }
99
 }

+ 8
- 0
src/util/api.js Ver arquivo

348
       method: 'delete',
348
       method: 'delete',
349
       url: `${baseUrl}${common}/role/:id`
349
       url: `${baseUrl}${common}/role/:id`
350
     },
350
     },
351
+    getmenus: {
352
+      method: 'get',
353
+      url: `${baseUrl}${common}/rolemenu/:id`
354
+    },
355
+    savemenu: {
356
+      method: 'put',
357
+      url: `${baseUrl}${common}/rolemenu/:id`
358
+    },
351
   },
359
   },
352
   dataStatistics: {
360
   dataStatistics: {
353
     getCustomerList: { // 获取会员列表
361
     getCustomerList: { // 获取会员列表