role.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="mod-role">
  3. <div class="rect rect-form">
  4. <el-form size="mini" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  5. <el-form-item>
  6. <el-input v-model="dataForm.roleName" placeholder="角色名称" clearable></el-input>
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button
  10. icon="el-icon-search"
  11. @click="getDataList()">
  12. 查 询
  13. </el-button>
  14. </el-form-item>
  15. </el-form>
  16. </div>
  17. <div class="rect rect-table">
  18. <el-form size="mini" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  19. <el-form-item>
  20. <el-button
  21. icon="el-icon-plus"
  22. v-if="isAuth('sys:role:save')"
  23. type="primary"
  24. @click="addOrUpdateHandle()">新 增</el-button>
  25. <el-button
  26. icon="el-icon-delete"
  27. v-if="isAuth('sys:role:delete')"
  28. type="danger"
  29. @click="deleteHandle()"
  30. :disabled="dataListSelections.length <= 0">删 除</el-button>
  31. </el-form-item>
  32. </el-form>
  33. <el-table
  34. :data="dataList"
  35. border
  36. stripe
  37. size="mini"
  38. height="540"
  39. v-loading="dataListLoading"
  40. @selection-change="selectionChangeHandle"
  41. style="width: 100%;"
  42. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  43. :cell-style="{color: '#888',fontSize: '13px'}">
  44. <el-table-column
  45. type="selection"
  46. header-align="center"
  47. align="center"
  48. width="50">
  49. </el-table-column>
  50. <el-table-column
  51. prop="roleId"
  52. header-align="center"
  53. align="center"
  54. width="80"
  55. label="ID">
  56. </el-table-column>
  57. <el-table-column
  58. prop="roleName"
  59. header-align="center"
  60. align="center"
  61. label="角色名称">
  62. </el-table-column>
  63. <el-table-column
  64. prop="remark"
  65. header-align="center"
  66. align="center"
  67. label="备注">
  68. </el-table-column>
  69. <el-table-column
  70. prop="createTime"
  71. header-align="center"
  72. align="center"
  73. width="180"
  74. label="创建时间">
  75. </el-table-column>
  76. <el-table-column
  77. header-align="center"
  78. align="center"
  79. width="150"
  80. label="操作">
  81. <template slot-scope="scope">
  82. <el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
  83. <el-button v-if="isAuth('sys:role:delete')" type="text" size="small" @click="deleteHandle(scope.row)">删除</el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <el-pagination
  88. @size-change="sizeChangeHandle"
  89. @current-change="currentChangeHandle"
  90. :current-page="pageIndex"
  91. :page-sizes="[10, 20, 50, 100]"
  92. :page-size="pageSize"
  93. :total="totalPage"
  94. layout="total, sizes, prev, pager, next, jumper">
  95. </el-pagination>
  96. <!-- 弹窗, 新增 / 修改 -->
  97. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  98. </div>
  99. </div>
  100. </template>
  101. <script>
  102. import AddOrUpdate from './role-add-or-update'
  103. export default {
  104. data () {
  105. return {
  106. dataForm: {
  107. roleName: ''
  108. },
  109. dataList: [],
  110. pageIndex: 1,
  111. pageSize: 10,
  112. totalPage: 0,
  113. dataListLoading: false,
  114. dataListSelections: [],
  115. addOrUpdateVisible: false
  116. }
  117. },
  118. components: {
  119. AddOrUpdate
  120. },
  121. activated () {
  122. this.getDataList()
  123. },
  124. methods: {
  125. // 获取数据列表
  126. getDataList () {
  127. this.dataListLoading = true
  128. this.$http({
  129. url: this.$http.adornUrl('/sys/role/list'),
  130. method: 'get',
  131. params: this.$http.adornParams({
  132. 'page': this.pageIndex,
  133. 'limit': this.pageSize,
  134. 'roleName': this.dataForm.roleName
  135. })
  136. }).then(({data}) => {
  137. if (data && data.code === 0) {
  138. this.dataList = data.page.list
  139. this.totalPage = data.page.totalCount
  140. } else {
  141. this.dataList = []
  142. this.totalPage = 0
  143. this.$message.error(data.msg)
  144. }
  145. this.dataListLoading = false
  146. })
  147. },
  148. // 每页数
  149. sizeChangeHandle (val) {
  150. this.pageSize = val
  151. this.pageIndex = 1
  152. this.getDataList()
  153. },
  154. // 当前页
  155. currentChangeHandle (val) {
  156. this.pageIndex = val
  157. this.getDataList()
  158. },
  159. // 多选
  160. selectionChangeHandle (val) {
  161. this.dataListSelections = val
  162. },
  163. // 新增 / 修改
  164. addOrUpdateHandle (id) {
  165. this.addOrUpdateVisible = true
  166. this.$nextTick(() => {
  167. this.$refs.addOrUpdate.init(id)
  168. })
  169. },
  170. // 删除
  171. deleteHandle (role) {
  172. var ids = role? [role.roleId] : this.dataListSelections.map(item => item.roleId )
  173. var names = role? [role.roleName] : this.dataListSelections.map(item => item.roleName )
  174. this.$confirm(`确定${id ? '删除' : '批量删除'}名称${names.join(',')}]角色?`, '提示', {
  175. confirmButtonText: '确定',
  176. cancelButtonText: '取消',
  177. type: 'warning'
  178. }).then(() => {
  179. this.$http({
  180. url: this.$http.adornUrl('/sys/role/delete'),
  181. method: 'post',
  182. data: this.$http.adornData(ids, false)
  183. }).then(({data}) => {
  184. if (data && data.code === 0) {
  185. this.getDataList()
  186. this.$message({
  187. message: '操作成功',
  188. type: 'success',
  189. duration: 1500,
  190. // onClose: () => {
  191. // this.getDataList()
  192. // }
  193. })
  194. } else {
  195. this.$message.error(data.msg)
  196. }
  197. })
  198. }).catch(() => {})
  199. }
  200. }
  201. }
  202. </script>
  203. <style scoped>
  204. .rect {
  205. background-color: #fff;
  206. padding: 30px 15px;
  207. border-radius: 5px;
  208. border: 1px solid #e8e8e8;
  209. }
  210. .rect-form {
  211. padding-bottom: 10px;
  212. }
  213. .rect-table {
  214. margin-top: 20px;
  215. }
  216. .demo-table-expand {
  217. font-size: 0;
  218. margin-left: 40px;
  219. }
  220. .demo-table-expand label {
  221. width: 90px;
  222. color: #99a9bf;
  223. }
  224. .demo-table-expand .el-form-item {
  225. margin-right: 0;
  226. margin-bottom: 0;
  227. width: 80%;
  228. }
  229. .el-table .height {
  230. background: rgba(254, 254, 254, 0.5);
  231. }
  232. /deep/ .el-table--mini td, .el-table--mini th {
  233. padding: 3px 0 !important;
  234. height: 20px !important;
  235. }
  236. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  237. color: rgb(24,144,255);
  238. background-color: rgb(24,144,255);
  239. border-color: rgb(24,144,255);
  240. }
  241. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  242. background-color: rgb(24,144,255);
  243. border-color: rgb(24,144,255);
  244. }
  245. /deep/.el-table .el-checkbox__inner:hover {
  246. border-color: rgb(24,144,255);
  247. }
  248. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  249. border-color: rgb(24,144,255);
  250. }
  251. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  252. background-color: rgb(24,144,255);
  253. border-color: rgb(24,144,255);
  254. }
  255. </style>