首页 > 其他分享 >角色管理

角色管理

时间:2023-07-14 17:25:18浏览次数:22  
标签:return pageSize 角色 管理 role Result import id

1. 复制

把user.vue的内容全部复制粘贴到role.vue

2. 修改

查询条件没有电话,给它删了
用户名改成角色名称

结果列表改为rolelist

观察数据库


只有三个字段

role.vue

点击查看代码
<template>
  <div>
    <!-- 搜索栏 -->
    <el-card id="search">
      <el-row>
        <el-col :span="18">
          <el-input placeholder="角色名" v-model="searchModel.roleName" clearable> </el-input>
          <el-button @click="getRoleList" type="primary" icon="el-icon-search" round>查询</el-button>
        </el-col>
        <el-col :span="6" align="right">
          <el-button @click="openEditUI(null)" type="primary" icon="el-icon-plus" circle></el-button>
        </el-col>
      </el-row>
    </el-card>

    <!-- 结果列表 -->
    <el-card>
 
        <el-table :data="roleList" stripe style="width: 100%">
          <el-table-column label="#" width="80">
            <template slot-scope="scope">
              {{(searchModel.pageNo-1) * searchModel.pageSize + scope.$index + 1}}
            </template>
          </el-table-column>
          <el-table-column prop="roleId" label="角色编号" width="180">
          </el-table-column>
          <el-table-column prop="roleName" label="角色名称" width="180">
          </el-table-column>
          <el-table-column prop="roleDesc" label="角色描述" >
          </el-table-column>
          <el-table-column   label="操作" width="180">
            <template slot-scope="scope">
              <el-button @click="openEditUI(scope.row.roleId)" type="primary" icon="el-icon-edit" circle size="mini"></el-button>
              <el-button @click="deleteRole(scope.row)" type="danger" icon="el-icon-delete" circle size="mini"></el-button>
            </template>
          </el-table-column>
        </el-table> 
 
    </el-card>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchModel.pageNo"
      :page-sizes="[5, 10, 20, 50]"
      :page-size="searchModel.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!-- 对话框 -->
    <el-dialog @close="clearForm" :title="title" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form :model="roleForm" ref="roleFormRef" :rules="rules">
        <el-form-item prop="roleName" label="角色名称" :label-width="formLabelWidth">
          <el-input v-model="roleForm.roleName" autocomplete="off"></el-input>
        </el-form-item>
        
        <el-form-item prop="roleDesc" label="角色描述" :label-width="formLabelWidth">
          <el-input v-model="roleForm.roleDesc" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveRole">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import roleApi from '@/api/roleManage'
export default {
  data(){
    
    return{
      formLabelWidth: '130px',
      roleForm: {},
      dialogFormVisible: false,
      title: '',
      searchModel: {
        pageNo: 1,
        pageSize: 10
      },
      roleList: [],
      total: 0,
      rules:{
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    deleteRole(role){
      this.$confirm(`您确定删除角色 ${role.roleName} ?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
      }).then(() => {
        roleApi.deleteRoleById(role.roleId).then(response => {
          this.$message({
            type: 'success',
            message: response.message
          });
          this.dialogFormVisible = false;
          this.getRoleList();
        });
        
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    },
    saveRole(){
      // 触发表单验证
      this.$refs.roleFormRef.validate((valid) => {
        if (valid) {
          // 提交保存请求
          roleApi.saveRole(this.roleForm).then(response => {
            // 成功提示
            this.$message({
              message: response.message,
              type: 'success'
            });
            // 关闭对话框
            this.dialogFormVisible = false;
            // 刷新表格数据
            this.getRoleList();
          });
          
        } else {
          console.log('error submit!!');
          return false;
        }
      });
      
    },
    clearForm(){
      this.roleForm = {};
      this.$refs.roleFormRef.clearValidate();
    },
    openEditUI(id){
      if(id == null){
        this.title = '新增角色';
      }else{
        this.title = '修改角色';
        roleApi.getRoleById(id).then(response => {
          this.roleForm = response.data;
        });
      }
      this.dialogFormVisible = true;
    },
    handleSizeChange(pageSize){
      this.searchModel.pageSize = pageSize;
      this.getRoleList();
    },
    handleCurrentChange(pageNo){
      this.searchModel.pageNo = pageNo;
      this.getRoleList();
    },
    getRoleList(){
      roleApi.getRoleList(this.searchModel).then(response => {
        this.roleList = response.data.rows;
        this.total = response.data.total;
      });
    }
  },
  created(){
    this.getRoleList();
  }
};
</script>

<style>
#search .el-input {
  width: 200px;
  margin-right: 10px;
}
.el-dialog .el-input{
  width: 85%;
}
</style>

userManage.js换成roleManage.js

点击查看代码
import request from '@/utils/request'

export default{
  // 分页查询角色列表
  getRoleList(searchModel){
    return request({
      url: '/role/list',
      method: 'get',
      params: {
        roleName: searchModel.roleName,
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize
      }
    });
  },
  // 新增
  addRole(role){
    return request({
      url: '/role',
      method: 'post',
      data: role
    });
  },
  // 修改
  updateRole(role){
    return request({
      url: '/role',
      method: 'put',
      data: role
    });
  },
  // 保存角色数据
  saveRole(role){
    if(role.roleId == null || role.roleId == undefined){
      return this.addRole(role);
    }
    return this.updateRole(role);
  },
  // 根据id查询
  getRoleById(id){
    return request({
      url: `/role/${id}`,
      method: 'get'
    });
  },
  // 根据id删除
  deleteRoleById(id){
    return request({
      url: `/role/${id}`,
      method: 'delete'
    });
  },

}

3. 观察页面

404,这是因为后端还没有修改
uploading-image-499758.png

4.后端

RoleController

点击查看代码
package com.example.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.vo.Result;
import com.example.sys.entity.Role;
import com.example.sys.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CanisRufus
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/list")
    public Result<Map<String,Object>> getUserList(@RequestParam(value = "roleName",required = false) String roleName,
                                                  @RequestParam(value = "pageNo") Long pageNo,
                                                  @RequestParam(value = "pageSize") Long pageSize){
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.hasLength(roleName),Role::getRoleName,roleName);
        wrapper.orderByDesc(Role::getRoleId);

        Page<Role> page = new Page<>(pageNo,pageSize);
        roleService.page(page, wrapper);

        Map<String,Object> data = new HashMap<>();
        data.put("total",page.getTotal());
        data.put("rows",page.getRecords());

        return Result.success(data);

    }

    @PostMapping
    public Result<?> addRole(@RequestBody Role role){
        roleService.save(role);
        return Result.success("新增角色成功");
    }

    @PutMapping
    public Result<?> updateRole(@RequestBody Role role){
        roleService.updateById(role);
        return Result.success("修改角色成功");
    }

    @GetMapping("/{id}")
    public Result<Role> getRoleById(@PathVariable("id") Integer id){
        Role role = roleService.getById(id);
        return Result.success(role);
    }

    @DeleteMapping("/{id}")
    public Result<Role> deleteRoleById(@PathVariable("id") Integer id){
        roleService.removeById(id);
        return Result.success("删除角色成功");
    }

}


运行后刷新页面

标签:return,pageSize,角色,管理,role,Result,import,id
From: https://www.cnblogs.com/dljx-springboot/p/17553805.html

相关文章

  • 【全流程管理解决方案】奥威BI金蝶云星空SaaS版:重新定义企业管控
    金蝶云星空是一套全面覆盖供应链、采购、生产、销售、财务等业务流程,实现了全链条的闭环管理的综合性管理软件。但在云时代,仅仅覆盖业务流程还不够,还需要有一套全流程管理解决方案,实现对全业务流程数据的深度挖掘,为运营决策提供支持。奥威BI金蝶云星空SaaS版,一套覆盖全流程业务管理......
  • flutter状态管理案例
     FLUTTER项目中管理不同组件、不同页面之间共享的数据关系。当需要共享的数据关系达到几十上百个的时候,我们就很难保持清晰的数据流动方向和顺序了,导致应用内各种数据传递嵌套和回调满天飞。在这个时候,我们迫切需要一个解决方案,来帮助我们理清楚这些共享数据的关系,于是状态管理......
  • 隐藏windows资源管理器中的收藏夹、库、家庭组
    打开windows7资源管理器(WindowsExplorer),左侧是一个导航窗格,包括:收藏夹,库,家庭组,计算机,网络。这些项目链接到文件夹,硬盘或者其他电脑系统。 但是,不是每一个Windows7用户都需要这些项目。没有直接选项可以隐藏它们,我们可以通过注册表编辑器来实现。 去掉家庭组,收藏夹或者库......
  • linux服务器安装环境和wdcp管理系统 V3最新版安装
    wdcp支持两种安装方式1源码编译此安装比较麻烦和耗时,一般是20分钟至一个小时不等,具体视机器配置情况而定2RPM包安装简单快速,下载快的话,几分钟就可以完成源码安装(ssh登录服务器,执行如下操作即可,需root用户身份安装)wgethttp://dl.wdlinux.cn:5180/lanmp_laster.tar.g......
  • 如何有效检测、识别和管理 Terraform 配置漂移?
    在理想的IaC世界中,我们所有的基础设施实现和更新都是通过将更新的代码推送到GitHub来编写和实现的,这将触发Jenkins或Circle-Ci中的CI/CD流水线,并且这些更改会反映在我们常用的公有云中。但现实并没有这么顺利,原因可能有很多,例如: 公司仍处于云自动化的初级阶段;不......
  • Python3+Django2实现后台管理系统入门
    Python3+Django2实现后台管理系统入门前言使用Django我们只需要做一些配置,就可以实现简单的后台管理系统,下面我们以新闻系统为例子来搭建后台。创建项目切换到工作空间,执行以下命令:django-admin.pystartprojectitstyle#进入itstyle文件夹cditstyle#创建newsApp......
  • 如何有效检测、识别和管理 Terraform 配置漂移?
    作者|KrishnaduttPanchagnula翻译|Seal软件链接|https://betterprogramming.pub/detecting-identifying-and-managing-terraform-state-drift-997366a74537 在理想的IaC世界中,我们所有的基础设施实现和更新都是通过将更新的代码推送到GitHub来编写和实现的,这将触发Jenki......
  • 使用Patroni管理LightDB高可用
    使用Patroni管理LightDB高可用测试环境CPU:海光x86OS:KylinAdvancedServerV10SP1LightDB:13.8-22.3Patroni:2.1.3etcd:3.5.4安装部署etcd集群需要3台机器。centos/RHEL等可以从epel获取etcd。麒麟ky10,ky10sp1没有etcd包,可以使用lightdb预编译的etcd-3.5.4。......
  • 从需求去理解 Linux dbus与基于dbus协议的无agent软件管理
    从需求去理解Linuxdbus与基于dbus协议的无agent软件管理 转载 WhatisIPCIPC[Inter-ProcessCommunication] 进程间通信,指至少两个进程或线程间传送数据或信号的一些技术或方法。在Linux/Unix中,提供了许多IPC。Unix七大IPC:Pipe:无名管道,最基本的IPC,单向通信,仅在......
  • 基于JAVA乳制品安全管理信息平台
    系统功能模块设计1.系统登录:系统登录是用户访问系统的路口,设计了系统登录界面,包括用户名、密码和验证码,然后对登录进来的用户判断身份信息,判断是管理员用户还是普通用户。2.系统用户管理:不管是超级管理员还是普通管理员都需要管理系统用户,包括普通管理员的添加、删除、修改、查询,修改......