123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <template>
- <!-- 授权用户 -->
- <el-dialog title="选择用户" :visible.sync="visible" width="800px" top="5vh" append-to-body :close-on-click-modal="false">
- <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
- <el-form-item label="用户名称" prop="userName">
- <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @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>
- <el-table
- ref="table"
- :data="userList"
- border
- stripe
- header-row-class-name="headBackground"
- @row-click="clickRow"
- @selection-change="handleSelectionChange"
- >
- <el-table-column type="selection" width="55" />
- <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>
- <pagination
- v-show="total > 0"
- :total="total"
- align="right"
- :page.sync="queryParams.page"
- :limit.sync="queryParams.limit"
- @pagination="getList"
- />
- </el-row>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" size="mini" @click="handleSelectUser">确定</el-button>
- <el-button size="mini" @click="visible = false">取消</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import { getUserList, addUserToAuthRole } from '@/api/system/user'
- export default {
- props: {
- // 角色编号
- roleId: {
- type: [Number, String]
- }
- },
- data() {
- return {
- // 遮罩层
- visible: false,
- // 选中数组值
- userIds: [],
- // 总条数
- total: 0,
- // 未授权用户数据
- userList: [],
- // 用户状态
- userStatus: this.$store.getters.userStatus,
- // 用户类型
- userType: this.$store.getters.userType,
- // 查询参数
- queryParams: {
- page: 1,
- limit: 10,
- roleId: undefined,
- userName: undefined
- }
- }
- },
- created() {
- 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
- }
- })
- return result
- },
- /** 显示弹框 */
- show() {
- this.queryParams.roleId = this.roleId
- this.visible = true
- this.resetQuery()
- },
- /** 行点击事件 */
- clickRow(row) {
- this.$refs.table.toggleRowSelection(row)
- },
- /** 多选框选中数据 */
- handleSelectionChange(selection) {
- this.userIds = selection.map(item => item.userId)
- },
- /** 查询用户列表 */
- getList() {
- getUserList(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
- }
- })
- },
- /** 搜索按钮操作 */
- handleQuery() {
- this.queryParams.page = 1
- this.getList()
- },
- /** 重置按钮操作 */
- resetQuery() {
- if (this.$refs['queryForm']) {
- this.$refs['queryForm'].resetFields()
- }
- this.handleQuery()
- },
- /** 选择授权用户操作 */
- handleSelectUser() {
- const query = {
- roleId: Number(this.queryParams.roleId),
- userIdList: this.userIds
- }
- if (this.userIds.length === 0) {
- this.$message({
- message: '请选择要分配的用户',
- type: 'warning'
- })
- return
- } else {
- addUserToAuthRole(query).then(res => {
- if (res.code === 200) {
- this.$message({
- message: '分配用户成功',
- type: 'success'
- })
- this.visible = false
- this.$emit('updateUserList')
- }
- })
- }
- }
- }
- // watch: {
- // //弹出框表格数据刷新滚动条置顶
- // userList: {
- // handler () {
- // this.$nextTick(() => {
- // // 滚动到顶部
- // this.$refs.table.bodyWrapper.scrollTop = 0;
- // });
- // },
- // deep: true,
- // immediate: true,
- // }
- // }
- }
- </script>
- <style lang="scss" scoped>
- .el-dialog {
- height: 78vh;
- overflow: auto;
- }
- </style>
|