Преглед изворни кода

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

许成详 пре 6 година
родитељ
комит
eafb6b8c1f
4 измењених фајлова са 97 додато и 22 уклоњено
  1. 51
    18
      src/pages/system/systemSet/roleManager/index.vue
  2. 6
    0
      src/store/app.js
  3. 32
    4
      src/store/system/role.js
  4. 8
    0
      src/util/api.js

+ 51
- 18
src/pages/system/systemSet/roleManager/index.vue Прегледај датотеку

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

+ 6
- 0
src/store/app.js Прегледај датотеку

@@ -20,6 +20,12 @@ function packChildren (data) {
20 20
   let cp = data.slice()
21 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 29
   data.forEach((it, inx) => {
24 30
     let found = false
25 31
     for (let i = 0; i < cp.length; i += 1) {

+ 32
- 4
src/store/system/role.js Прегледај датотеку

@@ -6,6 +6,7 @@ export default {
6 6
   state: {
7 7
     roleList: [],
8 8
     roleInfo: {},
9
+    roleMenus: [],
9 10
   },
10 11
   mutations: {
11 12
     updateList (state, payload) {
@@ -14,6 +15,9 @@ export default {
14 15
     updateInfo (state, payload) {
15 16
       state.roleInfo = payload || {}
16 17
     },
18
+    updateRoleMenus (state, payload) {
19
+      state.roleMenus = payload || {}
20
+    },
17 21
   },
18 22
   actions: {
19 23
     GetRolesList ({ commit }, payload) {
@@ -55,17 +59,41 @@ export default {
55 59
       }).then(res => {
56 60
       })
57 61
     },
58
-    DelRole ({ commit }, payload) {
62
+    DelRole ({ commit }, { id, callback }) {
59 63
       ajax(api.role.delete.url, {
60 64
         method: api.role.delete.method,
61
-        data: {
62
-          ...payload
65
+        urlData: {
66
+          id: id,
63 67
         }
64 68
       }).then(res => {
69
+        callback()
65 70
       })
66 71
     },
67 72
     SetRoleNull ({ commit }) {
68 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 Прегледај датотеку

@@ -348,6 +348,14 @@ const $api = {
348 348
       method: 'delete',
349 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 360
   dataStatistics: {
353 361
     getCustomerList: { // 获取会员列表