user.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="mod-user">
  3. <avue-crud ref="crud"
  4. :page="page"
  5. :data="dataList"
  6. :option="tableOption"
  7. @search-change="searchChange"
  8. @selection-change="selectionChange"
  9. @on-load="getDataList">
  10. <template slot="menuLeft">
  11. <el-button type="primary"
  12. icon="el-icon-plus"
  13. size="small"
  14. v-if="isAuth('sys:user:save')"
  15. @click.stop="addOrUpdateHandle()">新增</el-button>
  16. <el-button type="danger"
  17. @click="deleteHandle()"
  18. v-if="isAuth('sys:user:delete')"
  19. size="small"
  20. :disabled="dataListSelections.length <= 0">批量删除</el-button>
  21. </template>
  22. <template slot-scope="scope"
  23. slot="menu">
  24. <el-button type="primary"
  25. icon="el-icon-edit"
  26. size="small"
  27. v-if="isAuth('sys:user:update')"
  28. @click.stop="addOrUpdateHandle(scope.row.userId)">编辑</el-button>
  29. <el-button type="danger"
  30. icon="el-icon-delete"
  31. size="small"
  32. v-if="isAuth('sys:user:delete')"
  33. @click.stop="deleteHandle(scope.row.userId)">删除</el-button>
  34. </template>
  35. </avue-crud>
  36. <!-- 弹窗, 新增 / 修改 -->
  37. <add-or-update v-if="addOrUpdateVisible"
  38. ref="addOrUpdate"
  39. @refreshDataList="getDataList"></add-or-update>
  40. </div>
  41. </template>
  42. <script>
  43. import { tableOption } from '@/crud/sys/user'
  44. import AddOrUpdate from './user-add-or-update'
  45. export default {
  46. data () {
  47. return {
  48. dataList: [],
  49. dataListLoading: false,
  50. dataListSelections: [],
  51. addOrUpdateVisible: false,
  52. tableOption: tableOption,
  53. page: {
  54. total: 0, // 总页数
  55. currentPage: 1, // 当前页数
  56. pageSize: 10 // 每页显示多少条
  57. }
  58. }
  59. },
  60. components: {
  61. AddOrUpdate
  62. },
  63. methods: {
  64. // 获取数据列表
  65. getDataList (page, params, done) {
  66. this.dataListLoading = true
  67. this.$http({
  68. url: this.$http.adornUrl('/sys/user/page'),
  69. method: 'get',
  70. params: this.$http.adornParams(
  71. Object.assign(
  72. {
  73. current: page == null ? this.page.currentPage : page.currentPage,
  74. size: page == null ? this.page.pageSize : page.pageSize
  75. },
  76. params
  77. )
  78. )
  79. }).then(({ data }) => {
  80. this.dataList = data.records
  81. this.page.total = data.total
  82. this.dataListLoading = false
  83. if (done) {
  84. done()
  85. }
  86. })
  87. },
  88. // 条件查询
  89. searchChange (params, done) {
  90. this.getDataList(this.page, params, done)
  91. },
  92. // 多选变化
  93. selectionChange (val) {
  94. this.dataListSelections = val
  95. },
  96. // 新增 / 修改
  97. addOrUpdateHandle (id) {
  98. this.addOrUpdateVisible = true
  99. this.$nextTick(() => {
  100. this.$refs.addOrUpdate.init(id)
  101. })
  102. },
  103. // 删除
  104. deleteHandle (id) {
  105. var userIds = id ? [id] : this.dataListSelections.map(item => {
  106. return item.userId
  107. })
  108. this.$confirm(`确定对[id=${userIds.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  109. confirmButtonText: '确定',
  110. cancelButtonText: '取消',
  111. type: 'warning'
  112. }).then(() => {
  113. this.$http({
  114. url: this.$http.adornUrl('/sys/user'),
  115. method: 'delete',
  116. data: this.$http.adornData(userIds, false)
  117. }).then(({ data }) => {
  118. this.$message({
  119. message: '操作成功',
  120. type: 'success',
  121. duration: 1500,
  122. onClose: () => {
  123. this.getDataList()
  124. }
  125. })
  126. })
  127. }).catch(() => { })
  128. }
  129. }
  130. }
  131. </script>