123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <template>
- <div class="app-container">
- <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
- <el-form-item label="用户名称" prop="userName">
- <el-input
- v-model="queryParams.userName"
- placeholder="请输入用户名称"
- clearable
- style="width: 240px"
- @keyup.enter.native="handleQuery"
- />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
- </el-form-item>
- </el-form>
- <el-row :gutter="10" class="mb8 czBtns">
- <el-col :span="1.5">
- <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openSelectUser">添加用户</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button
- type="danger"
- plain
- icon="el-icon-delete-solid"
- size="mini"
- :disabled="multiple"
- @click="cancelAuthUserAll"
- >批量取消授权</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="warning" plain icon="el-icon-back" size="mini" @click="handleClose">返回</el-button>
- </el-col>
- </el-row>
- <el-table
- ref="roleTable"
- v-loading="loading"
- :data="userList"
- border
- stripe
- header-row-class-name="headBackground"
- @selection-change="handleSelectionChange"
- >
- <el-table-column type="selection" width="55" align="center" />
- <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
- <el-table-column label="用户状态" prop="state" :show-overflow-tooltip="true">
- <template slot-scope="scope">
- <span>{{ convertUserStatus(scope.row.state) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="用户类型" prop="userType" :show-overflow-tooltip="true">
- <template slot-scope="scope">
- <span>{{ convertUserType(scope.row.userType) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="最后登录时间" prop="lastLoginTime" width="160" />
- <el-table-column label="创建时间" prop="createTime" width="160" />
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
- <template slot-scope="scope">
- <el-button size="mini" type="text" :disabled="!multiple" @click="cancelAuthUser(scope.row)"><i
- class="el-icon-circle-close celBtn"
- /><span>取消授权</span>
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="total > 0"
- :total="total"
- :page.sync="queryParams.page"
- :limit.sync="queryParams.limit"
- align="right"
- @pagination="getList"
- />
- <select-user ref="select" :role-id="queryParams.roleId" @updateUserList="getList()" />
- </div>
- </template>
- <script>
- import selectUser from './user-select'
- import { getUserListById, cancelRoleAuth, cancelAllRoleAuth } from '@/api/system/user'
- export default {
- name: 'UserAuth',
- components: { selectUser },
- data() {
- return {
- // 遮罩层
- loading: true,
- // 选中用户组
- userIds: [],
- // 非多个禁用
- multiple: true,
- // 总条数
- total: 0,
- // 用户表格数据
- userList: [],
- // 用户状态
- userStatus: this.$store.getters.userStatus,
- // 用户类型
- userType: this.$store.getters.userType,
- // 查询参数
- queryParams: {
- page: 1,
- limit: 10,
- roleId: undefined,
- userName: undefined
- }
- }
- },
- created() {
- const roleId = this.$route.params.userId
- if (roleId) {
- this.queryParams.roleId = roleId
- this.getList()
- }
- },
- methods: {
- /** 用户状态转换 */
- convertUserStatus(val) {
- let result = ''
- this.userStatus.forEach((e) => {
- if (e.value === val) {
- result = e.name
- }
- })
- return result
- },
- /** 用户类型转换 */
- convertUserType(val) {
- let result = ''
- // this.userType.forEach((e) => {
- // if (e.value === val) {
- // result = e.name
- // }
- // })
- val === 0 ? result = '客户端用户' : result = '管理用户'
- return result
- },
- /** 查询授权用户列表 */
- getList() {
- getUserListById(this.queryParams).then(res => {
- if (res.code === 200) {
- const data = res.data
- data.userList.forEach(item => {
- item.lastLoginTime ? item.lastLoginTime : item.lastLoginTime = '暂未登录'
- })
- this.userList = data.userList
- this.total = data.count
- this.loading = false
- }
- })
- },
- /** 返回按钮 */
- handleClose() {
- this.$router.push('/system/role')
- },
- /** 搜索按钮操作 */
- handleQuery(event) {
- this.$resetBtn(event)
- this.queryParams.page = 1
- this.getList()
- },
- /** 重置按钮操作 */
- resetQuery(event) {
- if (this.$refs['queryForm']) {
- this.$refs['queryForm'].resetFields()
- }
- this.handleQuery(event)
- },
- /** 多选框选中数据 */
- handleSelectionChange(selection) {
- this.userIds = selection.map(item => {
- return {
- userId: item.userId,
- roleId: this.queryParams.roleId
- }
- })
- this.multiple = !selection.length
- },
- /** 打开授权用户表弹窗 */
- openSelectUser() {
- this.$refs.select.show()
- },
- /** 取消授权按钮操作 */
- cancelAuthUser(row) {
- const query = {
- roleId: this.queryParams.roleId,
- userId: row.userId
- }
- this.$confirm('您确定要取消该用户的授权吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'btn_custom_cancel',
- type: 'warning'
- }).then(() => {
- cancelRoleAuth(query).then(res => {
- if (res.code === 200) {
- this.getList()
- this.$message({
- type: 'success',
- message: '取消授权成功'
- })
- }
- })
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '取消操作'
- })
- })
- },
- /** 批量取消授权按钮操作 */
- cancelAuthUserAll() {
- this.$confirm('您确定要取消授权吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'btn_custom_cancel',
- type: 'warning'
- }).then(() => {
- cancelAllRoleAuth(this.userIds).then(res => {
- if (res.code === 200) {
- this.getList()
- this.$message({
- type: 'success',
- message: '批量取消授权成功'
- })
- }
- })
- }).catch(() => {
- this.$refs.roleTable.clearSelection()
- this.$message({
- type: 'info',
- message: '取消操作'
- })
- })
- }
- }
- }
- </script>
|