list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
  5. 添加角色
  6. </el-button>
  7. </div>
  8. <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width:100%">
  9. <el-table-column label="序号" align="center" width="50">
  10. <template slot-scope="scope">{{ scope.$index + 1 }}</template>
  11. </el-table-column>
  12. <el-table-column label="角色名称" align="center">
  13. <template slot-scope="scope">{{ scope.row.roleName }}</template>
  14. </el-table-column>
  15. <el-table-column label="角色描述" width="100" align="center">
  16. <template slot-scope="scope">{{ scope.row.roleDesc }}</template>
  17. </el-table-column>
  18. <el-table-column label="创建时间" align="center">
  19. <template slot-scope="scope">{{ scope.row.createTime }}</template>
  20. </el-table-column>
  21. <el-table-column label="更新时间" align="center">
  22. <template slot-scope="scope">{{ scope.row.updateTime }}</template>
  23. </el-table-column>
  24. <el-table-column label="操作" width="250" align="center">
  25. <template slot-scope="scope">
  26. <el-button size="mini" type="primary" @click="handleShowNextLevel(scope.$index, scope.row)">分配
  27. </el-button>
  28. <el-button size="mini" type="primary" @click="handleUpdate(scope.$index, scope.row)">修改
  29. </el-button>
  30. <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
  31. </el-button>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
  36. </div>
  37. </template>
  38. <script>
  39. import { fetchList, deleteRole } from '@/api/role'
  40. import Pagination from '@/components/Pagination'
  41. export default {
  42. name: 'RoleList',
  43. components: { Pagination },
  44. filters: {
  45. levelFilter(value) {
  46. if (value === 0) {
  47. return '一级'
  48. } else if (value === 1) {
  49. return '二级'
  50. }
  51. },
  52. iconFilter(value) {
  53. if (!value) {
  54. return ''
  55. }
  56. if (value.substr(0, 7) === 'el-icon') {
  57. return '<i class="' + value + '" />'
  58. } else {
  59. return '<svg-icon :icon-class="' + value + '" />'
  60. }
  61. },
  62. disableNextLevel(value) {
  63. if (value === 0) {
  64. return false
  65. } else {
  66. return true
  67. }
  68. }
  69. },
  70. data() {
  71. return {
  72. tableKey: 0,
  73. list: [],
  74. total: 5,
  75. listLoading: true,
  76. listQuery: {
  77. pageNum: 1,
  78. pageSize: 10,
  79. parentId: 0
  80. }
  81. }
  82. },
  83. watch: {
  84. $route(route) {
  85. this.resetParentId()
  86. this.getList()
  87. }
  88. },
  89. created() {
  90. this.resetParentId()
  91. this.getList()
  92. },
  93. methods: {
  94. isElementIcon(value) {
  95. return value.substr(0, 7) === 'el-icon'
  96. },
  97. resetParentId() {
  98. this.listQuery.pageNum = 1
  99. if (this.$route.query.parentId != null) {
  100. this.parentId = this.$route.query.parentId
  101. } else {
  102. this.parentId = 0
  103. }
  104. },
  105. getList() {
  106. this.listLoading = true
  107. fetchList(this.listQuery).then(response => {
  108. this.listLoading = false
  109. console.log(response)
  110. this.list = response.data.results
  111. this.total = response.data.totalRecord
  112. // Just to simulate the time of the request
  113. setTimeout(() => {
  114. this.listLoading = false
  115. }, 1.5 * 1000)
  116. })
  117. },
  118. handleShowNextLevel(index, row) {
  119. this.$router.push({ path: '/sys/roles', query: { parentId: row.id } })
  120. },
  121. handleUpdate(index, row) {
  122. this.$router.push({ path: '/sys/roles/update', query: { id: row.id } })
  123. },
  124. handleCreate() {
  125. this.$router.push({ path: '/sys/roles/add' })
  126. },
  127. handleDelete(index, row) {
  128. this.$confirm('是否要删除该菜单', '提示', {
  129. confirmButtonText: '确定',
  130. cancelButtonText: '取消',
  131. type: 'warning'
  132. }).then(() => {
  133. deleteRole(row.id).then(response => {
  134. this.$message({
  135. message: '删除成功',
  136. type: 'success',
  137. duration: 1000
  138. })
  139. this.getList()
  140. })
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style scoped>
  147. </style>