user-auth.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="app-container">
  3. <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
  4. <el-form-item label="用户名称" prop="userName">
  5. <el-input
  6. v-model="queryParams.userName"
  7. placeholder="请输入用户名称"
  8. clearable
  9. style="width: 240px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openSelectUser">添加用户</el-button>
  21. </el-col>
  22. <el-col :span="1.5">
  23. <el-button
  24. type="danger"
  25. plain
  26. icon="el-icon-circle-close"
  27. size="mini"
  28. :disabled="multiple"
  29. @click="cancelAuthUserAll"
  30. >批量取消授权</el-button>
  31. </el-col>
  32. <el-col :span="1.5">
  33. <el-button type="warning" plain icon="el-icon-close" size="mini" @click="handleClose">关闭</el-button>
  34. </el-col>
  35. </el-row>
  36. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  37. <el-table-column type="selection" width="55" align="center" />
  38. <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  39. <el-table-column label="用户状态" prop="state" :show-overflow-tooltip="true">
  40. <template slot-scope="scope">
  41. <span>{{ convertUserStatus(scope.row.state) }}</span>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="用户类型" prop="userType" :show-overflow-tooltip="true">
  45. <template slot-scope="scope">
  46. <span>{{ convertUserType(scope.row.userType) }}</span>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="最后登录时间" prop="lastLoginTime" width="160" />
  50. <el-table-column label="创建时间" prop="createTime" width="160" />
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <el-button size="mini" type="text" icon="el-icon-circle-close" @click="cancelAuthUser(scope.row)">取消授权
  54. </el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination
  59. v-show="total > 0"
  60. :total="total"
  61. :page.sync="queryParams.page"
  62. :limit.sync="queryParams.limit"
  63. align="right"
  64. @pagination="getList"
  65. />
  66. <select-user ref="select" :role-id="queryParams.roleId" @updateUserList="getList()" />
  67. </div>
  68. </template>
  69. <script>
  70. import selectUser from './user-select'
  71. import { getUserListById, cancelRoleAuth, cancelAllRoleAuth } from '@/api/system/user'
  72. export default {
  73. name: 'UserAuth',
  74. components: { selectUser },
  75. data() {
  76. return {
  77. // 遮罩层
  78. loading: true,
  79. // 选中用户组
  80. userIds: [],
  81. // 非多个禁用
  82. multiple: true,
  83. // 总条数
  84. total: 0,
  85. // 用户表格数据
  86. userList: [],
  87. // 用户状态
  88. userStatus: this.$store.getters.userStatus,
  89. // 用户类型
  90. userType: this.$store.getters.userType,
  91. // 查询参数
  92. queryParams: {
  93. page: 1,
  94. limit: 10,
  95. roleId: undefined,
  96. userName: undefined
  97. }
  98. }
  99. },
  100. created() {
  101. const roleId = this.$route.params.userId
  102. if (roleId) {
  103. this.queryParams.roleId = roleId
  104. this.getList()
  105. }
  106. },
  107. methods: {
  108. /** 用户状态转换 */
  109. convertUserStatus(val) {
  110. let result = ''
  111. this.userStatus.forEach((e) => {
  112. if (e.value === val) {
  113. result = e.name
  114. }
  115. })
  116. return result
  117. },
  118. /** 用户类型转换 */
  119. convertUserType(val) {
  120. let result = ''
  121. // this.userType.forEach((e) => {
  122. // if (e.value === val) {
  123. // result = e.name
  124. // }
  125. // })
  126. val === 0 ? result = '客户端用户' : result = '管理用户'
  127. return result
  128. },
  129. /** 查询授权用户列表 */
  130. getList() {
  131. getUserListById(this.queryParams).then(res => {
  132. if (res.code === 200) {
  133. const data = res.data
  134. this.userList = data.userList
  135. this.total = data.count
  136. this.loading = false
  137. }
  138. })
  139. },
  140. /** 返回按钮 */
  141. handleClose() {
  142. this.$router.push('/system/role')
  143. },
  144. /** 搜索按钮操作 */
  145. handleQuery() {
  146. this.queryParams.page = 1
  147. this.getList()
  148. },
  149. /** 重置按钮操作 */
  150. resetQuery() {
  151. if (this.$refs['queryForm']) {
  152. this.$refs['queryForm'].resetFields()
  153. }
  154. this.handleQuery()
  155. },
  156. /** 多选框选中数据 */
  157. handleSelectionChange(selection) {
  158. this.userIds = selection.map(item => {
  159. return {
  160. userId: item.userId,
  161. roleId: this.queryParams.roleId
  162. }
  163. })
  164. this.multiple = !selection.length
  165. },
  166. /** 打开授权用户表弹窗 */
  167. openSelectUser() {
  168. this.$refs.select.show()
  169. },
  170. /** 取消授权按钮操作 */
  171. cancelAuthUser(row) {
  172. const query = {
  173. roleId: this.queryParams.roleId,
  174. userId: row.userId
  175. }
  176. this.$confirm('是否取消授权?', '提示', {
  177. confirmButtonText: '确定',
  178. cancelButtonText: '取消',
  179. cancelButtonClass: 'btn_custom_cancel',
  180. type: 'warning'
  181. }).then(() => {
  182. cancelRoleAuth(query).then(res => {
  183. if (res.code === 200) {
  184. this.getList()
  185. this.$message({
  186. type: 'success',
  187. message: res.data
  188. })
  189. }
  190. })
  191. }).catch(() => {
  192. this.$message({
  193. type: 'info',
  194. message: '取消操作'
  195. })
  196. })
  197. },
  198. /** 批量取消授权按钮操作 */
  199. cancelAuthUserAll() {
  200. this.$confirm('是否取消授权?', '提示', {
  201. confirmButtonText: '确定',
  202. cancelButtonText: '取消',
  203. cancelButtonClass: 'btn_custom_cancel',
  204. type: 'warning'
  205. }).then(() => {
  206. cancelAllRoleAuth(this.userIds).then(res => {
  207. if (res.code === 200) {
  208. this.getList()
  209. this.$message({
  210. type: 'success',
  211. message: '已取消授权'
  212. })
  213. }
  214. })
  215. }).catch(() => {
  216. this.$message({
  217. type: 'info',
  218. message: '取消操作'
  219. })
  220. })
  221. }
  222. }
  223. }
  224. </script>