008-云E办_操作员管理

一、操作员管理

操作员就是登陆进来的用户。用户相关信息。
在这里插入图片描述

实现代码

SysAdmin.vue

<template>
    <div><!-- center 居中。向上举例10px -->
        <div style="display: flex;justify-content: center;margin-top: 10px">
            <el-input v-model="keywords" placeholder="通过用户名搜索用户..." prefix-icon="el-icon-search"
                      style="width: 400px;margin-right: 10px"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="doSearch">搜索</el-button>
        </div>
		
        <div class="admin-container"> <!-- 循环将所有的操作员进行打印-->
            <el-card class="admin-card" v-for="(admin,index) in admins" :key="index">
                <div slot="header" class="clearfix">
                    <span>{{admin.name}}</span>
                    <el-button style="float: right; padding: 3px 0;color: red" type="text"
                               icon="el-icon-delete" @click="deleteAdmin(admin)"></el-button>
                </div>
                <div>
                    <div class="img-container">
                        <img :src="admin.userFace" :alt="admin.name" :title="admin.name" class="userface-img">
                    </div>
                </div>
                <div class="userinfo-container">
                    <div>用户名:{{admin.name}}</div>
                    <div>手机号码:{{admin.phone}}</div>
                    <div>电话号码:{{admin.telephone}}</div>
                    <div>地址:{{admin.address}}</div>
                    <div>用户状态:
                        <el-switch
                                v-model="admin.enabled"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                @change="enabledChange(admin)"
                                active-text="启用"
                                inactive-text="禁用">
                        </el-switch>
                    </div>
                    <div>
                        用户角色:
                        <el-tag style="margin-right: 4px" type="success" v-for="(role,indexj) in admin.roles"
                                :key="indexj">{{role.nameZh}}
                        </el-tag>
                        <el-popover
                                placement="right"
                                title="角色列表"
                                width="200"
                                @show="showPop(admin)"
                                @hide="hidePop(admin)"
                                trigger="click">
                            <el-select v-model="selectedRoles" multiple placeholder="请选择">
                                <el-option
                                        v-for="(r,index) in allRoles"
                                        :key="index"
                                        :label="r.nameZh"
                                        :value="r.id">
                                </el-option>
                            </el-select>
                            <el-button slot="reference" type="text" icon="el-icon-more"></el-button>
                        </el-popover>
                    </div>
                    <div>
                        备注:{{admin.remark}}
                    </div>
                </div>
            </el-card>
        </div>
    </div>
</template>

<script>
    export default {
        name: "SysAdmin",
        data() {
            return {
                admins: [], //调用的数组
                keywords: '',
                allRoles: [],
                selectedRoles: []
            }
        },
        mounted() {/* 调用事件 */
            this.initAdmins();
        },
        methods: {
            hidePop(admin) {
                let roles = [];
                Object.assign(roles, admin.roles);
                let flag = false;
                if (roles.length != this.selectedRoles.length) {
                    flag = true;
                } else {
                    for (let i = 0; i < roles.length; i++) {
                        let role = roles[i];
                        for (let j = 0; j < this.selectedRoles.length; j++) {
                            let sr = this.selectedRoles[j];
                            if (role.id == sr) {
                                roles.splice(i, 1);
                                i--;
                                break;
                            }
                        }
                    }
                    if (roles.length != 0) {
                        flag = true;
                    }
                }
                if (flag) {
                    let url = '/system/admin/role?adminId=' + admin.id;
                    this.selectedRoles.forEach(sr => {
                        url += '&rids=' + sr;
                    });
                    this.putRequest(url).then(resp => {
                        if (resp) {
                            this.initAdmins();
                        }
                    })
                }
            },
            showPop(admin) {
                this.initAllRoles();
                let roles = admin.roles;
                this.selectedRoles = [];
                roles.forEach(r => {
                    this.selectedRoles.push(r.id);
                });
            },
            initAllRoles() {
                this.getRequest('/admin/roles').then(resp => {
                    if (resp) {
                        this.allRoles = resp;
                    }
                })
            },
            enabledChange(admin) {
                this.putRequest('/admin/update', admin).then(resp => {
                    if (resp) {
                        this.initAdmins();
                    }
                })
            },
            deleteAdmin(admin) {
                this.$confirm('此操作将永久删除该【' + admin.name + '】操作员, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.deleteRequest('/admin/delete' + admin.id).then(resp => {
                        if (resp) {
                            this.initAdmins();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            doSearch() {
                this.initAdmins();
            },
            initAdmins() {
                //this.getRequest('/admin/list?keywords=' + this.keywords).then(resp => {
				this.getRequest('/admin/list').then(resp => {
                    if (resp) {
                        this.admins = resp;
                    }
                })
            }
        }
    }
</script>
  


用户状态更新

SysAdmin.vue

<div class="userinfo-container">
      <div>用户名:{{admin.name}}</div>
      <div>手机号码:{{admin.phone}}</div>
      <div>电话号码:{{admin.telephone}}</div>
      <div>地址:{{admin.address}}</div>
      <div>用户状态:
          <el-switch
                  v-model="admin.enabled"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  @change="enabledChange(admin)"
                  active-text="启用"
                  inactive-text="禁用">
          </el-switch>
      </div>
      <div>
          用户角色:
          <el-tag style="margin-right: 4px" type="success" v-for="(role,indexj) in admin.roles"
                  :key="indexj">{{role.nameZh}}
          </el-tag>
          <el-popover
                  placement="right"
                  title="角色列表"
                  width="200"
                  @show="showPop(admin)"
                  @hide="hidePop(admin)"
                  trigger="click">
              <el-select v-model="selectedRoles" multiple placeholder="请选择">
                  <el-option
                          v-for="(r,index) in allRoles"
                          :key="index"
                          :label="r.nameZh"
                          :value="r.id">
                  </el-option>
              </el-select>
              <el-button slot="reference" type="text" icon="el-icon-more"></el-button>
          </el-popover>
      </div>
      <div>
          备注:{{admin.remark}}
      </div>
  </div>

删除

deleteAdmin(admin) {
                this.$confirm('此操作将永久删除该【' + admin.name + '】操作员, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.deleteRequest('/admin/delete' + admin.id).then(resp => {
                        if (resp) {
                            this.initAdmins();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

角色更新

在这里插入图片描述

<div class="admin-container"> <!-- 循环将所有的操作员进行打印-->
  <el-card class="admin-card" v-for="(admin,index) in admins" :key="index">
      <div slot="header" class="clearfix">
          <span>{{admin.name}}</span>
          <el-button style="float: right; padding: 3px 0;color: red" type="text"
                     icon="el-icon-delete" @click="deleteAdmin(admin)"></el-button>
      </div>
      <div>
          <div class="img-container">
              <img :src="admin.userFace" :alt="admin.name" :title="admin.name" class="userface-img">
          </div>
      </div>
                
 enabledChange(admin) {
     this.putRequest('/admin/update', admin).then(resp => {
         if (resp) {
             this.initAdmins();
         }
     })
 },

操作员搜索

<div style="display: flex;justify-content: center;margin-top: 10px">
    <el-input v-model="keywords" placeholder="通过用户名搜索用户..." prefix-icon="el-icon-search"
              style="width: 400px;margin-right: 10px"></el-input>
    <el-button type="primary" icon="el-icon-search" @click="doSearch">搜索</el-button>
</div>
 return {
 	 admins: [], //调用的数组
     keywords: '',
     allRoles: [],
     selectedRoles: []
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值