role.vue 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs='crumbs'></bread-crumb>
  5. <el-button type="primary" size="small" icon="el-icon-circle-plus" style="float:right;" @click="addRoleAction">新增</el-button>
  6. </div>
  7. <div class="app-container">
  8. <el-table :data="roles" v-loading="loading_roles" border :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}">
  9. <el-table-column label="角色名称" prop="name" min-width="20%" align="center"></el-table-column>
  10. <el-table-column label="角色描述" prop="intro" min-width="25%" align="center"></el-table-column>
  11. <el-table-column label="状态" min-width="15%" align="center">
  12. <template slot-scope="scope">
  13. <div v-if="scope.row.status == 1" style="color: #67C23A; font-size:20px;">
  14. <li class="el-icon-success"></li>
  15. </div>
  16. <div v-else style="color: #F56C6C; font-size:20px;">
  17. <li class="el-icon-error"></li>
  18. </div>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="操作" width="180" align="center">
  22. <template slot-scope="scope">
  23. <router-link :to='{ path:"/role/perview", query:{ id:scope.row.id }}'>
  24. <el-tooltip class="item" effect="dark" content="权限设置" placement="top">
  25. <el-button type="warning" icon="el-icon-setting" size="small"></el-button>
  26. </el-tooltip>
  27. </router-link>
  28. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  29. <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="modifyRoleAction(scope.row)"></el-button>
  30. </el-tooltip>
  31. <el-tooltip class="item" effect="dark" content="移除" placement="top">
  32. <el-button type="danger" size="small" icon="el-icon-delete" v-if="scope.row.status === 1" @click="disableRoleAction(scope.row)"></el-button>
  33. </el-tooltip>
  34. <el-tooltip class="item" effect="dark" content="恢复" placement="top">
  35. <el-button type="info" size="small" icon="el-icon-refresh" v-if="scope.row.status !== 1" @click="recoverRoleAction(scope.row)"></el-button>
  36. </el-tooltip>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <el-row style="margin-top: 15px;" v-if="role_total_count > 10">
  41. <el-col :span="24">
  42. <el-pagination :total="role_total_count" :current-page.sync="current_page" @current-change="pageChange" :page-size="10" layout="total, prev, pager, next, jumper"></el-pagination>
  43. </el-col>
  44. </el-row>
  45. <edit-role ref="edit_role" @did-add-role="didAddRole" @did-edit-role="didModifyRole"></edit-role>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import EditRole from './components/EditRole.vue'
  51. import { getRoles, setRoleStatus } from '@/api/role/role'
  52. import BreadCrumb from '@/scrm_pages/components/bread-crumb'
  53. export default {
  54. components: {
  55. EditRole,
  56. BreadCrumb
  57. },
  58. data: function() {
  59. return {
  60. crumbs: [
  61. { path: false, name: '权限管理' },
  62. { path: false, name: '角色管理' }
  63. ],
  64. loading_roles: true,
  65. roles: [],
  66. role_total_count: 0,
  67. current_page: 1
  68. }
  69. },
  70. created: function() {
  71. this.requestRoleWithPage(1)
  72. },
  73. methods: {
  74. requestRoleWithPage: function(page) {
  75. this.roles.splice(0, this.roles.length)
  76. this.loading_roles = true
  77. getRoles(page).then(rs => {
  78. this.loading_roles = false
  79. const resp = rs.data
  80. if (resp.state === 1) {
  81. this.roles.push(...resp.data.roles)
  82. this.role_total_count = resp.data.total_count
  83. } else {
  84. this.$message.error(resp.msg)
  85. }
  86. }).catch(err => {
  87. this.loading_roles = false
  88. this.$message.error(err)
  89. })
  90. },
  91. addRoleAction: function() {
  92. // 父组件调用子组件方法 https://segmentfault.com/a/1190000009525355
  93. this.$refs.edit_role.show()
  94. },
  95. modifyRoleAction: function(row) {
  96. this.$refs.edit_role.modify(row.id, row.name, row.intro)
  97. },
  98. disableRoleAction: function(row) {
  99. this.$msgbox({
  100. title: '提示',
  101. message: '是否确定要移除该角色',
  102. showCancelButton: true,
  103. confirmButtonText: '确定',
  104. cancelButtonText: '取消',
  105. type: 'warning',
  106. beforeClose: (action, instance, done) => {
  107. if (action === 'confirm') {
  108. instance.confirmButtonLoading = true
  109. instance.confirmButtonText = '移除中...'
  110. setRoleStatus(row.id, false).then(rs => {
  111. done()
  112. instance.confirmButtonLoading = false
  113. const resp = rs.data
  114. if (resp.state === 1) {
  115. row.status = 0
  116. } else {
  117. this.$message.error(resp.msg)
  118. }
  119. }).catch(err => {
  120. done()
  121. this.$message.error(err)
  122. instance.confirmButtonLoading = false
  123. })
  124. } else {
  125. done()
  126. }
  127. }
  128. })
  129. },
  130. recoverRoleAction: function(row) {
  131. const loading = this.$loading({
  132. lock: true,
  133. text: '正在恢复角色...',
  134. spinner: 'el-icon-loading',
  135. background: 'rgba(0, 0, 0, 0.7)'
  136. })
  137. setRoleStatus(row.id, true).then(rs => {
  138. loading.close()
  139. const resp = rs.data
  140. if (resp.state === 1) {
  141. row.status = 1
  142. } else {
  143. this.$message.error(resp.msg)
  144. }
  145. }).catch(err => {
  146. loading.close()
  147. this.$message.error(err)
  148. })
  149. },
  150. didAddRole: function(id, name, intro, status) {
  151. this.roles.push({ id: id, name: name, intro: intro, status: status })
  152. },
  153. didModifyRole: function(id, name, intro) {
  154. this.roles.forEach(role => {
  155. if (role.id === id) {
  156. role.name = name
  157. role.intro = intro
  158. return false
  159. }
  160. })
  161. },
  162. pageChange: function(nextPage) {
  163. this.requestRoleWithPage(nextPage)
  164. }
  165. }
  166. }
  167. </script>
  168. <style rel="stylesheet/scss" lang="scss" scoped>
  169. .el-button+.el-button{
  170. margin-left:0!important;
  171. }
  172. </style>