user-auth.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 czBtns">
  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-delete-solid"
  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-back" size="mini" @click="handleClose">返回</el-button>
  34. </el-col>
  35. </el-row>
  36. <el-table
  37. ref="roleTable"
  38. v-loading="loading"
  39. :data="userList"
  40. border
  41. stripe
  42. header-row-class-name="headBackground"
  43. @selection-change="handleSelectionChange"
  44. >
  45. <el-table-column type="selection" width="55" align="center" />
  46. <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  47. <el-table-column label="用户状态" prop="state" :show-overflow-tooltip="true">
  48. <template slot-scope="scope">
  49. <span>{{ convertUserStatus(scope.row.state) }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="用户类型" prop="userType" :show-overflow-tooltip="true">
  53. <template slot-scope="scope">
  54. <span>{{ convertUserType(scope.row.userType) }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="最后登录时间" prop="lastLoginTime" width="160" />
  58. <el-table-column label="创建时间" prop="createTime" width="160" />
  59. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  60. <template slot-scope="scope">
  61. <el-button size="mini" type="text" :disabled="!multiple" @click="cancelAuthUser(scope.row)"><i
  62. class="el-icon-circle-close celBtn"
  63. /><span>取消授权</span>
  64. </el-button>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <pagination
  69. v-show="total > 0"
  70. :total="total"
  71. :page.sync="queryParams.page"
  72. :limit.sync="queryParams.limit"
  73. align="right"
  74. @pagination="getList"
  75. />
  76. <select-user ref="select" :role-id="queryParams.roleId" @updateUserList="getList()" />
  77. </div>
  78. </template>
  79. <script>
  80. import selectUser from './user-select'
  81. import { getUserListById, cancelRoleAuth, cancelAllRoleAuth } from '@/api/system/user'
  82. export default {
  83. name: 'UserAuth',
  84. components: { selectUser },
  85. data() {
  86. return {
  87. // 遮罩层
  88. loading: true,
  89. // 选中用户组
  90. userIds: [],
  91. // 非多个禁用
  92. multiple: true,
  93. // 总条数
  94. total: 0,
  95. // 用户表格数据
  96. userList: [],
  97. // 用户状态
  98. userStatus: this.$store.getters.userStatus,
  99. // 用户类型
  100. userType: this.$store.getters.userType,
  101. // 查询参数
  102. queryParams: {
  103. page: 1,
  104. limit: 10,
  105. roleId: undefined,
  106. userName: undefined
  107. }
  108. }
  109. },
  110. created() {
  111. const roleId = this.$route.params.userId
  112. if (roleId) {
  113. this.queryParams.roleId = roleId
  114. this.getList()
  115. }
  116. },
  117. methods: {
  118. /** 用户状态转换 */
  119. convertUserStatus(val) {
  120. let result = ''
  121. this.userStatus.forEach((e) => {
  122. if (e.value === val) {
  123. result = e.name
  124. }
  125. })
  126. return result
  127. },
  128. /** 用户类型转换 */
  129. convertUserType(val) {
  130. let result = ''
  131. // this.userType.forEach((e) => {
  132. // if (e.value === val) {
  133. // result = e.name
  134. // }
  135. // })
  136. val === 0 ? result = '客户端用户' : result = '管理用户'
  137. return result
  138. },
  139. /** 查询授权用户列表 */
  140. getList() {
  141. getUserListById(this.queryParams).then(res => {
  142. if (res.code === 200) {
  143. const data = res.data
  144. data.userList.forEach(item => {
  145. item.lastLoginTime ? item.lastLoginTime : item.lastLoginTime = '暂未登录'
  146. })
  147. this.userList = data.userList
  148. this.total = data.count
  149. this.loading = false
  150. }
  151. })
  152. },
  153. /** 返回按钮 */
  154. handleClose() {
  155. this.$router.push('/system/role')
  156. },
  157. /** 搜索按钮操作 */
  158. handleQuery(event) {
  159. this.$resetBtn(event)
  160. this.queryParams.page = 1
  161. this.getList()
  162. },
  163. /** 重置按钮操作 */
  164. resetQuery(event) {
  165. if (this.$refs['queryForm']) {
  166. this.$refs['queryForm'].resetFields()
  167. }
  168. this.handleQuery(event)
  169. },
  170. /** 多选框选中数据 */
  171. handleSelectionChange(selection) {
  172. this.userIds = selection.map(item => {
  173. return {
  174. userId: item.userId,
  175. roleId: this.queryParams.roleId
  176. }
  177. })
  178. this.multiple = !selection.length
  179. },
  180. /** 打开授权用户表弹窗 */
  181. openSelectUser() {
  182. this.$refs.select.show()
  183. },
  184. /** 取消授权按钮操作 */
  185. cancelAuthUser(row) {
  186. const query = {
  187. roleId: this.queryParams.roleId,
  188. userId: row.userId
  189. }
  190. this.$confirm('您确定要取消该用户的授权吗?', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. cancelButtonClass: 'btn_custom_cancel',
  194. type: 'warning'
  195. }).then(() => {
  196. cancelRoleAuth(query).then(res => {
  197. if (res.code === 200) {
  198. this.getList()
  199. this.$message({
  200. type: 'success',
  201. message: '取消授权成功'
  202. })
  203. }
  204. })
  205. }).catch(() => {
  206. this.$message({
  207. type: 'info',
  208. message: '取消操作'
  209. })
  210. })
  211. },
  212. /** 批量取消授权按钮操作 */
  213. cancelAuthUserAll() {
  214. this.$confirm('您确定要取消授权吗?', '提示', {
  215. confirmButtonText: '确定',
  216. cancelButtonText: '取消',
  217. cancelButtonClass: 'btn_custom_cancel',
  218. type: 'warning'
  219. }).then(() => {
  220. cancelAllRoleAuth(this.userIds).then(res => {
  221. if (res.code === 200) {
  222. this.getList()
  223. this.$message({
  224. type: 'success',
  225. message: '批量取消授权成功'
  226. })
  227. }
  228. })
  229. }).catch(() => {
  230. this.$refs.roleTable.clearSelection()
  231. this.$message({
  232. type: 'info',
  233. message: '取消操作'
  234. })
  235. })
  236. }
  237. }
  238. }
  239. </script>