|
@@ -0,0 +1,177 @@
|
|
1
|
+<template>
|
|
2
|
+ <div class="subPage">
|
|
3
|
+ <div class="system-table-search">
|
|
4
|
+ <div class="flex-h">
|
|
5
|
+ <div class="flex-item flex-h">
|
|
6
|
+ <el-button size="mini" type="success" @click='addRole'>新增角色</el-button>
|
|
7
|
+ </div>
|
|
8
|
+ <tableSearch value='角色名称' @exportSearchKey="searchList"></tableSearch>
|
|
9
|
+ </div>
|
|
10
|
+ <div class="moreFilter"></div>
|
|
11
|
+ </div>
|
|
12
|
+ <div class="system-table-box">
|
|
13
|
+ <el-table :data="roles.list" stripe style="width: 100%">
|
|
14
|
+ <el-table-column prop="RoleName" label="角色名">
|
|
15
|
+ </el-table-column>
|
|
16
|
+ <el-table-column label="创建时间" width="300">
|
|
17
|
+ <template slot-scope="scope">
|
|
18
|
+ <label>{{FormatDate(scope.row.CreateDate)}}</label>
|
|
19
|
+ </template>
|
|
20
|
+ </el-table-column>
|
|
21
|
+ <el-table-column fixed='right' label="操作" width="300">
|
|
22
|
+ <template slot-scope="scope">
|
|
23
|
+ <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
|
24
|
+ <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
|
|
25
|
+ <el-button size="mini" type="success" @click="handlePermission(scope.$index, scope.row)">分配权限</el-button>
|
|
26
|
+ </template>
|
|
27
|
+ </el-table-column>
|
|
28
|
+ </el-table>
|
|
29
|
+ </div>
|
|
30
|
+ <el-pagination
|
|
31
|
+ @size-change="handleSizeChange"
|
|
32
|
+ @current-change="handleCurrentChange"
|
|
33
|
+ :current-page.sync="currentPage"
|
|
34
|
+ :page-size="10"
|
|
35
|
+ layout="prev, pager, next, jumper"
|
|
36
|
+ :total="roles.pagenum">
|
|
37
|
+ </el-pagination>
|
|
38
|
+ <el-dialog title="请选择菜单" :visible.sync="dialogTableVisible">
|
|
39
|
+ <el-tree
|
|
40
|
+ v-if="dialogTableVisible"
|
|
41
|
+ class="flxe-h"
|
|
42
|
+ :data="menus"
|
|
43
|
+ node-key="id"
|
|
44
|
+ :default-expand-all="true"
|
|
45
|
+ :default-checked-keys="defaultChecked"
|
|
46
|
+ ref="tree"
|
|
47
|
+ show-checkbox
|
|
48
|
+ @node-click="handleNodeClick"></el-tree>
|
|
49
|
+ <div class="flex-h" style="justify-content: flex-end;margin-top: 1rem">
|
|
50
|
+ <el-button type='success' @click="getCheckedNodes">确定</el-button>
|
|
51
|
+ </div>
|
|
52
|
+ </el-dialog>
|
|
53
|
+ </div>
|
|
54
|
+</template>
|
|
55
|
+
|
|
56
|
+<script>
|
|
57
|
+import { createNamespacedHelpers, mapState } from 'vuex'
|
|
58
|
+import tableSearch from '@/components/tableSearch/index'
|
|
59
|
+
|
|
60
|
+const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
|
|
61
|
+
|
|
62
|
+export default {
|
|
63
|
+ name: '',
|
|
64
|
+ data () {
|
|
65
|
+ return {
|
|
66
|
+ currentPage: 0, // 当前页码
|
|
67
|
+ key: '',
|
|
68
|
+ selid: '',
|
|
69
|
+ dialogTableVisible: false,
|
|
70
|
+ }
|
|
71
|
+ },
|
|
72
|
+ computed: {
|
|
73
|
+ ...mapRoleState({
|
|
74
|
+ roles: x => x.roleList,
|
|
75
|
+ roleMenus: x => x.roleMenus,
|
|
76
|
+ }),
|
|
77
|
+ ...mapState({
|
|
78
|
+ menus: x => x.app.menus
|
|
79
|
+ }),
|
|
80
|
+ defaultChecked: {
|
|
81
|
+ get () {
|
|
82
|
+ const sels = (this.roleMenus || []).map(x => x.MenuId)
|
|
83
|
+ console.log(sels)
|
|
84
|
+ return sels
|
|
85
|
+ },
|
|
86
|
+ },
|
|
87
|
+ },
|
|
88
|
+ components: {
|
|
89
|
+ tableSearch
|
|
90
|
+ },
|
|
91
|
+ methods: {
|
|
92
|
+ ...mapRoleActions([
|
|
93
|
+ 'GetRolesList',
|
|
94
|
+ 'DelRole',
|
|
95
|
+ 'SaveRoleMenus',
|
|
96
|
+ 'GetRoleMenu',
|
|
97
|
+ ]),
|
|
98
|
+ FormatDate (date) {
|
|
99
|
+ console.log()
|
|
100
|
+ return this.toolClass.dateFormat(date)
|
|
101
|
+ },
|
|
102
|
+ handleSizeChange (val) {
|
|
103
|
+ console.log(`每页 ${val} 条`)
|
|
104
|
+ },
|
|
105
|
+ handleCurrentChange (val) {
|
|
106
|
+ console.log(`当前页: ${val}`)
|
|
107
|
+ },
|
|
108
|
+ handleEdit (index, row) {
|
|
109
|
+ // 编辑
|
|
110
|
+ this.$router.push({ name: 'editRole', query: { id: row.RoleId } })
|
|
111
|
+ },
|
|
112
|
+ handleDelete (index, row) {
|
|
113
|
+ // 删除
|
|
114
|
+ console.log(index, row)
|
|
115
|
+ this.$confirm('确认删除此角色?', '提示', {
|
|
116
|
+ confirmButtonText: '确定',
|
|
117
|
+ cancelButtonText: '取消',
|
|
118
|
+ type: 'warning'
|
|
119
|
+ })
|
|
120
|
+ .then(() => {
|
|
121
|
+ this.DelRole({id: row.RoleId, callback: this.delCallBack})
|
|
122
|
+ })
|
|
123
|
+ .catch(() => {
|
|
124
|
+ this.$message({
|
|
125
|
+ type: 'info',
|
|
126
|
+ message: '已取消删除'
|
|
127
|
+ })
|
|
128
|
+ })
|
|
129
|
+ },
|
|
130
|
+ delCallBack () {
|
|
131
|
+ this.$message({
|
|
132
|
+ type: 'success',
|
|
133
|
+ message: '删除成功!'
|
|
134
|
+ })
|
|
135
|
+ this.GetRolesList({name: this.key})
|
|
136
|
+ },
|
|
137
|
+ handlePermission (index, row) {
|
|
138
|
+ this.selid = row.RoleId
|
|
139
|
+ this.GetRoleMenu({id: this.selid})
|
|
140
|
+ this.dialogTableVisible = true
|
|
141
|
+ },
|
|
142
|
+ handleNodeClick (node) {
|
|
143
|
+ console.log(node)
|
|
144
|
+ },
|
|
145
|
+ searchList (key) {
|
|
146
|
+ this.key = key
|
|
147
|
+ this.GetRolesList({name: this.key})
|
|
148
|
+ },
|
|
149
|
+ addRole () {
|
|
150
|
+ this.$router.push({ name: 'editRole' })
|
|
151
|
+ },
|
|
152
|
+ getCheckedNodes () { // 获取选中的节点
|
|
153
|
+ const menuids = this.$refs.tree.getCheckedNodes().map(x => x.id).join(',')
|
|
154
|
+ console.log(menuids)
|
|
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
|
+ },
|
|
168
|
+ },
|
|
169
|
+ beforeMount () {
|
|
170
|
+ this.GetRolesList()
|
|
171
|
+ },
|
|
172
|
+}
|
|
173
|
+</script>
|
|
174
|
+
|
|
175
|
+<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
176
|
+<style lang="scss" scoped>
|
|
177
|
+</style>
|