index.vue 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. :default-expand-all="true"
  44. :expand-on-click-node="false"
  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. <script>
  56. import { createNamespacedHelpers, mapState } from 'vuex'
  57. import tableSearch from '@/components/tableSearch/index'
  58. const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
  59. export default {
  60. name: '',
  61. data () {
  62. return {
  63. currentPage: 0, // 当前页码
  64. key: '',
  65. selid: '',
  66. dialogTableVisible: false,
  67. }
  68. },
  69. computed: {
  70. ...mapRoleState({
  71. roles: x => x.roleList,
  72. selmenus: x => x.roleMenus,
  73. }),
  74. ...mapState({
  75. menus: x => x.app.menus
  76. }),
  77. defaultChecked: {
  78. get () {
  79. console.log(this.selmenus)
  80. // const sels = (this.selmenus || []).map(x => x.MenuId)
  81. return []
  82. },
  83. },
  84. },
  85. components: {
  86. tableSearch
  87. },
  88. methods: {
  89. ...mapRoleActions([
  90. 'GetRolesList',
  91. 'DelRole',
  92. 'SaveRoleMenus',
  93. 'GetRoleMenu',
  94. ]),
  95. FormatDate (date) {
  96. console.log()
  97. return this.toolClass.dateFormat(date)
  98. },
  99. handleSizeChange (val) {
  100. console.log(`每页 ${val} 条`)
  101. },
  102. handleCurrentChange (val) {
  103. console.log(`当前页: ${val}`)
  104. },
  105. handleEdit (index, row) {
  106. // 编辑
  107. this.$router.push({ name: 'editRole', query: { id: row.RoleId } })
  108. },
  109. handleDelete (index, row) {
  110. // 删除
  111. console.log(index, row)
  112. this.$confirm('确认删除此角色?', '提示', {
  113. confirmButtonText: '确定',
  114. cancelButtonText: '取消',
  115. type: 'warning'
  116. })
  117. .then(() => {
  118. this.DelRole({id: row.RoleId, callback: this.delCallBack})
  119. })
  120. .catch(() => {
  121. this.$message({
  122. type: 'info',
  123. message: '已取消删除'
  124. })
  125. })
  126. },
  127. delCallBack () {
  128. this.$message({
  129. type: 'success',
  130. message: '删除成功!'
  131. })
  132. this.GetRolesList({name: this.key})
  133. },
  134. handlePermission (index, row) {
  135. this.selid = row.RoleId
  136. this.GetRoleMenu(this.selid)
  137. this.dialogTableVisible = true
  138. console.log(index)
  139. },
  140. handleNodeClick (node) {
  141. console.log(node)
  142. },
  143. searchList (key) {
  144. this.key = key
  145. this.GetRolesList({name: this.key})
  146. },
  147. addRole () {
  148. this.$router.push({ name: 'editRole' })
  149. },
  150. getCheckedNodes () { // 获取选中的节点
  151. const menuids = this.$refs.tree.getCheckedNodes().map(x => x.id).join(',')
  152. this.SaveRoleMenus({
  153. id: this.selid,
  154. menuids: menuids,
  155. callback: this.hideDialog,
  156. })
  157. },
  158. hideDialog () {
  159. this.$message({
  160. type: 'success',
  161. message: '操作成功!'
  162. })
  163. this.dialogTableVisible = false
  164. },
  165. },
  166. beforeMount () {
  167. this.GetRolesList()
  168. },
  169. }
  170. </script>
  171. <!-- Add "scoped" attribute to limit CSS to this component only -->
  172. <style lang="scss" scoped>
  173. </style>