基于springboot+vue+mybatisplus的商品管理系统
  px8Y25gMnWbQ 2023年11月02日 51 0


新建项目

新建springboot项目,内建vue模块

基于springboot+vue+mybatisplus的商品管理系统_mysql

基于springboot+vue+mybatisplus的商品管理系统_spring_02

基于springboot+vue+mybatisplus的商品管理系统_vue.js_03

 

基于springboot+vue+mybatisplus的商品管理系统_java_04

 

基于springboot+vue+mybatisplus的商品管理系统_spring_05

mysql数据库

drop table if exists e_fruit;
create table e_fruit(
	id int not null auto_increment primary key comment 'id',
	fruit_name varchar(30) not null comment '水果名称',
	sale_count int not null comment '销售数量',
	icon varchar(500) default null comment '图标'
) comment '水果表';

insert into e_fruit(fruit_name,sale_count) values ('苹果',100);
insert into e_fruit(fruit_name,sale_count) values ('香蕉',200);
insert into e_fruit(fruit_name,sale_count) values ('橘子',40);

drop table if exists e_authority;
create table e_authority(
	authority_id int not null auto_increment primary key comment '权限id',
	authority_name varchar(50) not null comment '权限名称',
	controller varchar(500) not null comment '权限控制器'
) comment '权限表';
insert into e_authority(authority_name,controller) values ('商品管理','/productInfo/list,/productInfo/save,/productInfo/update,/productInfo/delete,/productCategory/categoryList');
insert into e_authority(authority_name,controller) values ('分类管理','/productCategory/delete,/productCategory/list,/productCategory/save,/productCategory/update');
insert into e_authority(authority_name,controller) values ('用户管理','/employee/list,/roleEmployee/updateRole,/role/roleList,/roleEmployee/getRoleByEmpId,/employee/delete,/employee/list,/employee/save,/employee/update');
insert into e_authority(authority_name,controller) values ('供应商管理','/supplier/list,/supplier/delete,/supplier/save,/supplier/update');
insert into e_authority(authority_name,controller) values ('权限管理','/roleAuthority/updateAuthority,/authority/authorityList,/roleAuthority/getAuthorityByRoleId,/role/delete,/role/list,/role/save,/role/update');

drop table if exists e_employee;
create table e_employee(
	emp_id int not null auto_increment primary key comment '用户id',
	emp_name varchar(50) not null comment '用户姓名',
	sex varchar(10) default null comment '性别',
	phone varchar(20) default null comment '电话',
	email varchar(50) default null comment '邮箱',
	address varchar(300) default null comment '地址',
	user_name varchar(50) not null comment '登录名',
	password varchar(30) not null comment '登录密码',
	status int not null comment '状态'
) comment '用户表';
insert into e_employee values(null,'徐老师','男','13012345678','xu@163.com','北京市前门大道','user1','1234',1);
insert into e_employee values(null,'李莎莎','女','18912345678','shasha@163.com','福清市龙门大道','user2','1234',1);

drop table if exists e_product_category;
create table e_product_category(
	category_id int not null auto_increment primary key comment '分类id',
	category_name varchar(50) not null comment '分类名称'
) comment '产品分类表';
insert into e_product_category values (null,'生鲜');
insert into e_product_category values (null,'手机');
insert into e_product_category values (null,'食品');
insert into e_product_category values (null,'水果');
insert into e_product_category values (null,'女装');
insert into e_product_category values (null,'百货');
insert into e_product_category values (null,'男装');
insert into e_product_category values (null,'图书');
insert into e_product_category values (null,'运动');

drop table if exists e_product_info;
create table e_product_info(
	product_id int not null auto_increment primary key comment '产品id',
	product_name varchar(50) not null comment '产品名称',
	product_price double not null comment '产品价格',
	product_stock int not null comment '产品库存',
	product_desc varchar(300) default null comment '产品描述',
	category_id int not null comment '分类id'
) comment '产品表';
insert into e_product_info values(null,'生鲜大虾',82.60,647,'鲜活冷冻',1);
insert into e_product_info values(null,'帝王蟹',105,204,'帝王蟹礼盒装',1);
insert into e_product_info values(null,'OPPO A52 8GB+128BG大屏手机',1349,645,'拍照游戏智能手机',1);
insert into e_product_info values(null,'方便面',5.10,71,'严选工厂',1);
insert into e_product_info values(null,'舟山海捕新鲜带鱼中段',72.80,929,'五斤特大装',1);
insert into e_product_info values(null,'八爪鱼',67.20,63,'新鲜海捕',1);

drop table if exists e_role;
create table e_role(
	role_id int not null auto_increment primary key comment '角色id',
	role_name varchar(50) not null comment '角色名称'
) comment '角色表';
insert into e_role values(null,'系统管理员');
insert into e_role values(null,'普通用户');

drop table if exists e_role_authority;
create table e_role_authority(
	ra_id int not null auto_increment primary key comment 'id',
	auth_id int not null comment '权限id',
	role_id int not null comment '角色id'
) comment '角色权限关系表';
insert into e_role_authority values(null,1,1);
insert into e_role_authority values(null,2,1);
insert into e_role_authority values(null,3,1);
insert into e_role_authority values(null,4,1);
insert into e_role_authority values(null,5,1);

drop table if exists e_role_employee;
create table e_role_employee(
	re_id int not null auto_increment primary key comment 'id',
	emp_id int not null comment '用户id',
	role_id int not null comment '角色id'
) comment '角色用户关系表';
insert into e_role_employee values(null,1,1);
insert into e_role_employee values(null,2,2);


drop table if exists e_supplier;
create table e_supplier(
	sup_id int not null auto_increment primary key comment '供应商id',
	sup_code varchar(10) not null comment '供应商编码',
	sup_name varchar(50) not null comment '供应商名称',
	address varchar(100) default null comment '地址',
	contact varchar(20) default null comment '联系人',
	email varchar(50) default null comment '邮箱',
	phone varchar(20) default null comment '电话',
	tax_id varchar(20) default null comment '发票号',
	bank_name varchar(50) default null comment '开户行',
	bank_chairman varchar(20) default null comment '户名',
	remark varchar(100) default null comment '备注'
) comment '供应商表';
insert into e_supplier values(null,'a001','斯巴达','河南省','李仲达','lzd@qq.com','13300000000','','','','');
insert into e_supplier values(null,'s001','北大方正','高新产业园','苏慧莹','bdfz@qq.com','15500000000','','','','');
insert into e_supplier values(null,'c001','百盛','科创三号','王五','bs@163.com','18800000000','','','','');

springboot

配置

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.15</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.shrimpking</groupId>
    <artifactId>springboot-vue-test08</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-vue-test08</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.30</version>
        </dependency>
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>spring-boot-starter-swagger</artifactId>
            <version>1.5.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

application.properties

server.port=8089

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=UTC
spring.datasource.username=root
spring.datasource.password=mysql123
#日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#配置别名
mybatis-plus.type-aliases-package=com.shrimpking.pojo

config

CorsConfig .java 

 解决跨域的

package com.shrimpking.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author user1
 * // 案例 一
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer
{
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //是否发送Cookie
                .allowCredentials(true)
                //放行哪些原始域
                .allowedOriginPatterns("*")
                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
                .allowedHeaders("*")
                .exposedHeaders("*");
    }
}

InterceptorConfig .java 

配置拦截器的

package com.shrimpking.config;

import com.shrimpking.interceptor.AdminInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/9/1 20:08
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer
{
    @Bean
    public AdminInterceptor adminInterceptor(){
        return new AdminInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        InterceptorRegistration registration = registry.addInterceptor(adminInterceptor());
        registration.addPathPatterns("/**");
        registration.excludePathPatterns("/**/doLogin");
    }
}

MybatisPlusConfig.java

配置分页的

package com.shrimpking.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.shrimpking.mapper")
public class MybatisPlusConfig
{
    /**
     * 配置分页插件的
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        MybatisPlusInterceptor interceptor
                = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

controller

AuthorityController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shrimpking.pojo.Authority;
import com.shrimpking.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/authority")
public class AuthorityController {

    @Autowired
    private AuthorityService authorityService;

    @GetMapping("/authorityList")
    public List<Authority> authorityList(){
        return this.authorityService.list();
    }


}

EmployeeController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shrimpking.pojo.Employee;
import com.shrimpking.pojo.RoleEmployee;
import com.shrimpking.pojo.Supplier;
import com.shrimpking.service.EmployeeService;
import com.shrimpking.service.RoleEmployeeService;
import com.shrimpking.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private RoleEmployeeService roleEmployeeService;

    //分页
    @GetMapping("/list/{page}/{pageSize}")
    public PageVO list(
            @PathVariable("page") Long page,
            @PathVariable("pageSize") Long pageSize){
        Page<Employee> employeePage = new Page<>(page, pageSize);
        Page<Employee> resultPage = this.employeeService.page(employeePage);
        PageVO<Employee> pageVO = new PageVO<>(
                resultPage.getRecords(),
                resultPage.getSize(),
                resultPage.getTotal()
        );
        return pageVO;
    }

    //保存
    @PostMapping("/save")
    public boolean save(@RequestBody Employee employee){
        return this.employeeService.save(employee);
    }

    //修改
    @PutMapping("/update")
    public boolean update(@RequestBody Employee employee){
        return this.employeeService.updateById(employee);
    }


    //删除
    @DeleteMapping("/delete/{id}")
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(@PathVariable("id") Integer id){
        //先删除用户与角色关系表的记录
        LambdaQueryWrapper<RoleEmployee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RoleEmployee::getEmpId,id);
        boolean remove1 = roleEmployeeService.remove(wrapper);
        //在删除用户表
        boolean remove2 = this.employeeService.removeById(id);
        if(remove1 && remove2) { return true;}
        return false;
    }
}

LoginController.java

package com.shrimpking.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shrimpking.pojo.Employee;
import com.shrimpking.service.EmployeeService;
import com.shrimpking.util.EmployeeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/9/1 12:27
 */
@RestController
@RequestMapping("/login")
public class LoginController
{
    @Autowired
    private EmployeeService employeeService;



    @PostMapping("/doLogin")
    public Map doLogin(@RequestBody Employee employee){
        //声明条件查询
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper<>();
        //根据用户名查询
        System.out.println(employee);
        wrapper.eq(Employee::getUserName,employee.getUserName());
        Employee one = this.employeeService.getOne(wrapper);
        Map map = new HashMap();
        if(one == null){
            //用户名不存在
            map.put("code",-1);
            return map;
        }
        //判断密码
        if(!one.getPassword().equals(employee.getPassword())){
            //密码错误
            map.put("code",-2);
            return map;
        }

        //都相同
        map.put("code",0);
        map.put("employee",one);
        //当前登录用户
        EmployeeUtil.employee = one;
        return map;
    }
}

ProductCategoryController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shrimpking.mapper.ProductCategoryMapper;
import com.shrimpking.pojo.ProductCategory;
import com.shrimpking.pojo.ProductInfo;
import com.shrimpking.pojo.Supplier;
import com.shrimpking.service.ProductCategoryService;
import com.shrimpking.service.ProductInfoService;
import com.shrimpking.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 产品分类表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @Autowired
    private ProductInfoService productInfoService;

    //分页
    @GetMapping("/list/{page}/{pageSize}")
    public PageVO list(
            @PathVariable("page") Long page,
            @PathVariable("pageSize") Long pageSize){
        Page<ProductCategory> categoryPage = new Page<>(page, pageSize);
        Page<ProductCategory> resultPage = this.productCategoryService.page(categoryPage);
        PageVO<ProductCategory> pageVO = new PageVO<>(
                resultPage.getRecords(),
                resultPage.getSize(),
                resultPage.getTotal()
        );
        return pageVO;
    }

    //保存
    @PostMapping("/save")
    public boolean save(@RequestBody ProductCategory productCategory){
        return this.productCategoryService.save(productCategory);
    }

    //修改
    @PutMapping("/update")
    public boolean update(@RequestBody ProductCategory productCategory){
        return this.productCategoryService.updateById(productCategory);
    }


    //删除
    @DeleteMapping("/delete/{id}")
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(@PathVariable("id") Integer id){
        //删除从表
        LambdaQueryWrapper<ProductInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductInfo::getCategoryId,id);
        productInfoService.remove(wrapper);
        //删除主表
        return this.productCategoryService.removeById(id);
    }

    //下拉框列表
    @GetMapping("/categoryList")
    public List<ProductCategory> categoryList(){
        return this.productCategoryService.list();
    }
}

ProductInfoController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shrimpking.pojo.ProductCategory;
import com.shrimpking.pojo.ProductInfo;
import com.shrimpking.service.ProductCategoryService;
import com.shrimpking.service.ProductInfoService;
import com.shrimpking.vo.PageVO;
import com.shrimpking.vo.ProductInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@RestController
@RequestMapping("/productInfo")
public class ProductInfoController {

    @Autowired
    private ProductInfoService productInfoService;

    @Autowired
    private ProductCategoryService productCategoryService;

    //分页
    @GetMapping("/list/{page}/{pageSize}")
    public PageVO list(
            @PathVariable("page") Long page,
            @PathVariable("pageSize") Long pageSize){
        //分页,传入当前页,页数量
        Page<ProductInfo> productInfoPage = new Page<>(page, pageSize);
        //获得分页数据
        Page<ProductInfo> resultPage = this.productInfoService.page(productInfoPage);
        //声明一个页面vo
        List<ProductInfoVO> productInfoVOList = new ArrayList<>();
        //遍历
        for (ProductInfo productInfo : resultPage.getRecords())
        {

            ProductInfoVO productInfoVO = new ProductInfoVO();
            //拷贝属性
            BeanUtils.copyProperties(productInfo,productInfoVO);
            //根据分类id,查到分类名称
            ProductCategory category = productCategoryService.getById(productInfo.getCategoryId());
            //将分类名称放入页面vo对象中
            productInfoVO.setCategoryName(category.getCategoryName());
            //放入列表
            productInfoVOList.add(productInfoVO);
        }
        PageVO<ProductInfoVO> pageVO = new PageVO<>(
                productInfoVOList,
                resultPage.getSize(),
                resultPage.getTotal()
        );
        return pageVO;
    }

    //保存
    @PostMapping("/save")
    public boolean save(@RequestBody ProductInfo productInfo){
        return this.productInfoService.save(productInfo);
    }

    //修改
    @PutMapping("/update")
    public boolean update(@RequestBody ProductInfo productInfo){
        return this.productInfoService.updateById(productInfo);
    }


    //删除
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id){
        return this.productInfoService.removeById(id);
    }


}

RoleAuthorityController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shrimpking.pojo.RoleAuthority;
import com.shrimpking.service.RoleAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import sun.security.util.Length;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 角色权限关系表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/roleAuthority")
public class RoleAuthorityController {

    @Autowired
    private RoleAuthorityService roleAuthorityService;


    @PutMapping("/updateAuthority")
    public boolean updateAuthority(@RequestBody Integer[] ids){
        //最后一位,是roleid
        Integer roleId = ids[ids.length -1];
        LambdaQueryWrapper<RoleAuthority> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(RoleAuthority::getRoleId,roleId);
        this.roleAuthorityService.remove(queryWrapper1);

        for (int i = 0; i < ids.length - 1; i++)
        {
            RoleAuthority roleAuthority = new RoleAuthority();
            roleAuthority.setAuthId(ids[i]);
            roleAuthority.setRoleId(roleId);
            this.roleAuthorityService.save(roleAuthority);
        }
        return true;
    }

    @GetMapping("/getAuthorityByRoleId/{roleId}")
    public List<Integer> getAuthorityByRoleId(@PathVariable("roleId") Integer roleId){
        //声明查询条件
        LambdaQueryWrapper<RoleAuthority> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RoleAuthority::getRoleId,roleId);
        List<RoleAuthority> list = roleAuthorityService.list(queryWrapper);
        //只需要id列
        List<Integer> idsList = new ArrayList<>();
        for (RoleAuthority roleAuthority : list)
        {
            idsList.add(roleAuthority.getAuthId());
        }
        return idsList;
    }
}

RoleController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shrimpking.pojo.Employee;
import com.shrimpking.pojo.Role;
import com.shrimpking.pojo.RoleAuthority;
import com.shrimpking.pojo.RoleEmployee;
import com.shrimpking.service.RoleAuthorityService;
import com.shrimpking.service.RoleEmployeeService;
import com.shrimpking.service.RoleService;
import com.shrimpking.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private RoleAuthorityService roleAuthorityService;

    @Autowired
    private RoleEmployeeService roleEmployeeService;

    @GetMapping("/roleList")
    public List<Role> roleList(){
        return roleService.list();
    }

    //分页
    @GetMapping("/list/{page}/{pageSize}")
    public PageVO list(
            @PathVariable("page") Long page,
            @PathVariable("pageSize") Long pageSize){
        Page<Role> rolePage = new Page<>(page, pageSize);
        Page<Role> resultPage = this.roleService.page(rolePage);
        PageVO<Role> pageVO = new PageVO<>(
                resultPage.getRecords(),
                resultPage.getSize(),
                resultPage.getTotal()
        );
        return pageVO;
    }

    //保存
    @PostMapping("/save")
    public boolean save(@RequestBody Role role){
        return this.roleService.save(role);
    }

    //修改
    @PutMapping("/update")
    public boolean update(@RequestBody Role role){
        return this.roleService.updateById(role);
    }


    //删除
    @DeleteMapping("/delete/{id}")
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(@PathVariable("id") Integer id){
        //先删除角色与权限关系表的记录
        LambdaQueryWrapper<RoleAuthority> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RoleAuthority::getRoleId,id);
        boolean remove1 = roleAuthorityService.remove(wrapper);
        //再删除角色与用户的记录
        LambdaQueryWrapper<RoleEmployee> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RoleEmployee::getRoleId,id);
        boolean remove2 = roleEmployeeService.remove(queryWrapper);
        //在删除角色表
        boolean remove3 = this.roleService.removeById(id);
        if(remove1 && remove2 && remove3) { return true;}
        return false;
    }
}

RoleEmployeeController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shrimpking.pojo.Employee;
import com.shrimpking.pojo.RoleEmployee;
import com.shrimpking.service.RoleEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 角色用户关系表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/roleEmployee")
public class RoleEmployeeController {

    @Autowired
    private RoleEmployeeService roleEmployeeService;

    //读取角色
    @GetMapping("/getRoleByEmpId/{empId}")
    public RoleEmployee getRoleByEmpId(@PathVariable("empId") Integer empId){
        LambdaQueryWrapper<RoleEmployee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RoleEmployee::getEmpId,empId);
        RoleEmployee one = this.roleEmployeeService.getOne(wrapper);
        return one;
    }

    //配置角色
    @PutMapping("/updateRole")
    public boolean updateRole(@RequestBody RoleEmployee roleEmployee){
        LambdaQueryWrapper<RoleEmployee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RoleEmployee::getEmpId,roleEmployee.getEmpId());
        //先删除旧角色配置,再保存新角色
        this.roleEmployeeService.remove(wrapper);
        return roleEmployeeService.save(roleEmployee);
    }
}

SupplierController .java

package com.shrimpking.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shrimpking.pojo.Supplier;
import com.shrimpking.service.SupplierService;
import com.shrimpking.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    //分页
    @GetMapping("/list/{page}/{pageSize}")
    public PageVO list(
            @PathVariable("page") Long page,
            @PathVariable("pageSize") Long pageSize){
        Page<Supplier> supplierPage = new Page<>(page,pageSize);
        Page<Supplier> resultPage = this.supplierService.page(supplierPage);
        PageVO<Supplier> pageVO = new PageVO<>(
                resultPage.getRecords(),
                resultPage.getSize(),
                resultPage.getTotal()
        );
        return pageVO;
    }

    //保存
    @PostMapping("/save")
    public boolean save(@RequestBody Supplier supplier){
        return this.supplierService.save(supplier);
    }

    //修改
    @PutMapping("/update")
    public boolean update(@RequestBody Supplier supplier){
        return this.supplierService.updateById(supplier);
    }


    //删除
    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id){
        return this.supplierService.removeById(id);
    }
}

handler

UnifiedExceptionHandler.java

package com.shrimpking.handler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

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

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/9/1 21:40
 */
@RestControllerAdvice
public class UnifiedExceptionHandler
{
    @ExceptionHandler(value = RuntimeException.class)
    public Map handlerException(Exception e){
        Map map = new HashMap();
        map.put("code",-1);
        map.put("msg",e.getMessage());
        return map;
    }
}

Interceptor

AdminInterceptor .java

package com.shrimpking.interceptor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shrimpking.pojo.Authority;
import com.shrimpking.pojo.Employee;
import com.shrimpking.pojo.RoleAuthority;
import com.shrimpking.pojo.RoleEmployee;
import com.shrimpking.service.AuthorityService;
import com.shrimpking.service.RoleAuthorityService;
import com.shrimpking.service.RoleEmployeeService;
import com.shrimpking.util.EmployeeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/9/1 20:03
 */
public class AdminInterceptor implements HandlerInterceptor
{
    @Autowired
    private RoleEmployeeService roleEmployeeService;

    @Autowired
    private RoleAuthorityService roleAuthorityService;

    @Autowired
    private AuthorityService authorityService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
        //获取当前用户的权限
        //判断当前的请求是否包含在权限范围内,如果包含则放行
        String servletPath = request.getServletPath();
        Employee employee = EmployeeUtil.employee;
        //System.out.println(employee);
        //先获取角色,在根据角色获取权限
        LambdaQueryWrapper<RoleEmployee> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(RoleEmployee::getEmpId,employee.getEmpId());
        RoleEmployee roleEmployee = this.roleEmployeeService.getOne(queryWrapper1);
        //
        LambdaQueryWrapper<RoleAuthority> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(RoleAuthority::getRoleId,roleEmployee.getRoleId());
        List<RoleAuthority> roleAuthorityList = this.roleAuthorityService.list(queryWrapper2);

        for (RoleAuthority roleAuthority : roleAuthorityList)
        {
            //
            Authority authority = this.authorityService.getById(roleAuthority.getAuthId());
            String controller = authority.getController();
            if(!controller.contains(",")){
                //不含逗号
                if(servletPath.contains(controller)){
                    return true;
                }
            }else {
                //包含逗号
                String[] split = controller.split(",");
                for (String str : split)
                {
                    if(servletPath.contains(str)){
                        return true;
                    }
                }
            }
        }
        throw new RuntimeException("当前用户无访问权限!");
        //return true;
    }


}

mapper

AuthorityMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.Authority;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface AuthorityMapper extends BaseMapper<Authority> {

}

EmployeeMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.Employee;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface EmployeeMapper extends BaseMapper<Employee> {

}

ProductCategoryMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.ProductCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 产品分类表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface ProductCategoryMapper extends BaseMapper<ProductCategory> {

}

ProductInfoMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.ProductInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 产品表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface ProductInfoMapper extends BaseMapper<ProductInfo> {

}

RoleAuthorityMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.RoleAuthority;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 角色权限关系表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleAuthorityMapper extends BaseMapper<RoleAuthority> {

}

RoleEmployeeMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.RoleEmployee;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 角色用户关系表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleEmployeeMapper extends BaseMapper<RoleEmployee> {

}

RoleMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleMapper extends BaseMapper<Role> {

}

SupplierMapper .java

package com.shrimpking.mapper;

import com.shrimpking.pojo.Supplier;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 供应商表 Mapper 接口
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface SupplierMapper extends BaseMapper<Supplier> {

}

pojo

Authority .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 权限表
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_authority")
@ApiModel(value="Authority对象", description="权限表")
public class Authority implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "权限id")
    @TableId(value = "authority_id", type = IdType.AUTO)
    @JsonProperty("id")
    private Integer authorityId;

    @ApiModelProperty(value = "权限名称")
    @JsonProperty("label")
    private String authorityName;

    @ApiModelProperty(value = "权限控制器")
    private String controller;


}

Employee .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_employee")
@ApiModel(value="Employee对象", description="用户表")
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户id")
    @TableId(value = "emp_id", type = IdType.AUTO)
    private Integer empId;

    @ApiModelProperty(value = "用户姓名")
    private String empName;

    @ApiModelProperty(value = "性别")
    private String sex;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "地址")
    private String address;

    @ApiModelProperty(value = "登录名")
    private String userName;

    @ApiModelProperty(value = "登录密码")
    private String password;

    @ApiModelProperty(value = "状态")
    private Integer status;
}

ProductCategory .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 产品分类表
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_product_category")
@ApiModel(value="ProductCategory对象", description="产品分类表")
public class ProductCategory implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "分类id")
    @TableId(value = "category_id", type = IdType.AUTO)
    private Integer categoryId;

    @ApiModelProperty(value = "分类名称")
    private String categoryName;


}

ProductInfo .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 产品表
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_product_info")
@ApiModel(value="ProductInfo对象", description="产品表")
public class ProductInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "产品id")
    @TableId(value = "product_id", type = IdType.AUTO)
    private Integer productId;

    @ApiModelProperty(value = "产品名称")
    private String productName;

    @ApiModelProperty(value = "产品价格")
    private Double productPrice;

    @ApiModelProperty(value = "产品库存")
    private Integer productStock;

    @ApiModelProperty(value = "产品描述")
    private String productDesc;

    @ApiModelProperty(value = "分类id")
    private Integer categoryId;
}

Role .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 角色表
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_role")
@ApiModel(value="Role对象", description="角色表")
public class Role implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "角色id")
    @TableId(value = "role_id", type = IdType.AUTO)
    private Integer roleId;

    @ApiModelProperty(value = "角色名称")
    private String roleName;


}

RoleAuthority .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 角色权限关系表
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_role_authority")
@ApiModel(value="RoleAuthority对象", description="角色权限关系表")
public class RoleAuthority implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "ra_id", type = IdType.AUTO)
    private Integer raId;

    @ApiModelProperty(value = "权限id")
    private Integer authId;

    @ApiModelProperty(value = "角色id")
    private Integer roleId;


}

RoleEmployee .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 角色用户关系表
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_role_employee")
@ApiModel(value="RoleEmployee对象", description="角色用户关系表")
public class RoleEmployee implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "re_id", type = IdType.AUTO)
    private Integer reId;

    @ApiModelProperty(value = "用户id")
    private Integer empId;

    @ApiModelProperty(value = "角色id")
    private Integer roleId;


}

Supplier .java

package com.shrimpking.pojo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 供应商表
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("e_supplier")
@ApiModel(value="Supplier对象", description="供应商表")
public class Supplier implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "供应商id")
    @TableId(value = "sup_id", type = IdType.AUTO)
    private Integer supId;

    @ApiModelProperty(value = "供应商编码")
    private String supCode;

    @ApiModelProperty(value = "供应商名称")
    private String supName;

    @ApiModelProperty(value = "地址")
    private String address;

    @ApiModelProperty(value = "联系人")
    private String contact;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "发票号")
    private String taxId;

    @ApiModelProperty(value = "开户行")
    private String bankName;

    @ApiModelProperty(value = "户名")
    private String bankChairman;

    @ApiModelProperty(value = "备注")
    private String remark;


}

service

AuthorityService .java

package com.shrimpking.service;

import com.shrimpking.pojo.Authority;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 权限表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface AuthorityService extends IService<Authority> {

}

EmployeeService .java

vpackage com.shrimpking.service;

import com.shrimpking.pojo.Employee;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 用户表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface EmployeeService extends IService<Employee> {

}

ProductCategoryService .java

package com.shrimpking.service;

import com.shrimpking.pojo.ProductCategory;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 产品分类表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface ProductCategoryService extends IService<ProductCategory> {

}

ProductInfoService .java

package com.shrimpking.service;

import com.shrimpking.pojo.ProductInfo;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 产品表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface ProductInfoService extends IService<ProductInfo> {

}

RoleAuthorityService .java

package com.shrimpking.service;

import com.shrimpking.pojo.RoleAuthority;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 角色权限关系表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleAuthorityService extends IService<RoleAuthority> {

}

RoleEmployeeService .java

package com.shrimpking.service;

import com.shrimpking.pojo.RoleEmployee;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 角色用户关系表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleEmployeeService extends IService<RoleEmployee> {

}

RoleService .java

package com.shrimpking.service;

import com.shrimpking.pojo.Role;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 角色表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-09-01
 */
public interface RoleService extends IService<Role> {

}

SupplierService .java

package com.shrimpking.service;

import com.shrimpking.pojo.Supplier;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 供应商表 服务类
 * </p>
 *
 * @author shrimpking
 * @since 2023-08-31
 */
public interface SupplierService extends IService<Supplier> {

}

util

EmployeeUtil.java

package com.shrimpking.util;

import com.shrimpking.pojo.Employee;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/9/1 20:29
 */
public class EmployeeUtil
{
    public static Employee employee;
}

vo

PageVO.java

package com.shrimpking.vo;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/8/31 12:58
 */
@Data
@AllArgsConstructor
public class PageVO<T>
{
    private List<T> content;
    private Long pageSize;
    private Long total;
}

ProductInfoVO.java

package com.shrimpking.vo;

import lombok.Data;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/8/31 21:58
 */
@Data
public class ProductInfoVO
{

    private Integer productId;
    private String productName;
    private Double productPrice;
    private Integer productStock;
    private String productDesc;
    private Integer categoryId;
    private String categoryName;
}

mapper xml

AuthorityMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.AuthorityMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.Authority">
        <id column="authority_id" property="authorityId" />
        <result column="authority_name" property="authorityName" />
        <result column="controller" property="controller" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        authority_id, authority_name, controller
    </sql>

</mapper>

EmployeeMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.EmployeeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.Employee">
        <id column="emp_id" property="empId" />
        <result column="emp_name" property="empName" />
        <result column="sex" property="sex" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="address" property="address" />
        <result column="user_name" property="userName" />
        <result column="password" property="password" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        emp_id, emp_name, sex, phone, email, address, user_name, password
    </sql>

</mapper>

ProductCategoryMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.ProductCategoryMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.ProductCategory">
        <id column="category_id" property="categoryId" />
        <result column="category_name" property="categoryName" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        category_id, category_name
    </sql>

</mapper>

ProductInfoMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.ProductInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.ProductInfo">
        <id column="product_id" property="productId" />
        <result column="product_name" property="productName" />
        <result column="product_price" property="productPrice" />
        <result column="product_stock" property="productStock" />
        <result column="product_desc" property="productDesc" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        product_id, product_name, product_price, product_stock, product_desc
    </sql>

</mapper>

RoleAuthorityMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.RoleAuthorityMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.RoleAuthority">
        <id column="ra_id" property="raId" />
        <result column="auth_id" property="authId" />
        <result column="role_id" property="roleId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ra_id, auth_id, role_id
    </sql>

</mapper>

RoleEmployeeMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.RoleEmployeeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.RoleEmployee">
        <id column="re_id" property="reId" />
        <result column="emp_id" property="empId" />
        <result column="role_id" property="roleId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        re_id, emp_id, role_id
    </sql>

</mapper>

RoleMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.RoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.Role">
        <id column="role_id" property="roleId" />
        <result column="role_name" property="roleName" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        role_id, role_name
    </sql>

</mapper>

SupplierMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shrimpking.mapper.SupplierMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shrimpking.pojo.Supplier">
        <id column="sup_id" property="supId" />
        <result column="sup_code" property="supCode" />
        <result column="sup_name" property="supName" />
        <result column="address" property="address" />
        <result column="contact" property="contact" />
        <result column="email" property="email" />
        <result column="phone" property="phone" />
        <result column="tax_id" property="taxId" />
        <result column="bank_name" property="bankName" />
        <result column="bank_chairman" property="bankChairman" />
        <result column="remark" property="remark" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        sup_id, sup_code, sup_name, address, contact, email, phone, tax_id, bank_name, bank_chairman, remark
    </sql>

</mapper>

vue

配置

main.js

import Vue from 'vue'
import App from './App.vue'
import router from "@/router";
import store from "@/store";
import axios from "axios";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import * as echarts from 'echarts'

Vue.config.productionTip = false;
Vue.use(ElementUI,{size:'small'});
Vue.prototype.$echarts = echarts;
axios.defaults.baseURL='http://localhost:8089';
Vue.prototype.$http = axios;

new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app');

app.vue

<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>

export default {
  name: 'App',
  components: {
  }
}
</script>

<style>
 * {
   padding: 0;
   margin: 0;
 }


</style>

router

index.js

import Vue from 'vue'
import VueRouter from "vue-router";
import Home from "@/views/Home";
import SupplierManager from "@/views/SupplierManager";
import ProductManager from "@/views/ProductManager";
import CategoryManager from "@/views/CategoryManager";
import EmployeeManager from "@/views/EmployeeManager";
import RoleAuthorManager from "@/views/RoleAuthorManager";
import Login from "@/views/Login";

Vue.use(VueRouter);

export default new VueRouter({
    mode:'history',
   routes:[
       {
           path:'/',
           redirect:'/login'
       },
       {
           path:'/login',
           name:'Login',
           component: Login
       },
       {
           path:'/home',
           name:'Home',
           component: Home,
           redirect:'/productManage',
           meta:{
               name:'首页'
           },
           children:[
               {
                   path:'/productManage',
                   name:'ProductManage',
                   component: ProductManager,
                   meta:{
                       name:'商品管理'
                   }
               },
               {
                   path:'/categoryManage',
                   name:'CategoryManage',
                   component: CategoryManager,
                   meta:{
                       name:'分类管理'
                   }
               },
               {
                   path:'/employeeManager',
                   name:'EmployeeManager',
                   component: EmployeeManager,
                   meta:{
                       name:'用户管理'
                   }
               },
               {
                   path:'/supplierManager',
                   name:'SupplierManager',
                   component: SupplierManager,
                   meta:{
                       name:'供应商管理'
                   }
               },
               {
                   path:'/roleAuthorManager',
                   name:'RoleAuthorManager',
                   component: RoleAuthorManager,
                   meta:{
                       name:'权限管理'
                   }
               },

           ]
       }
   ]
});

store

index.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

export default new Vuex.Store({
    state:{

    }
});

views

CategoryManager.vue

<template>
    <div style="">
        <el-form label-width="100px" class="demo-ruleForm">
            <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加分类</el-button>
        </el-form>

        <el-dialog title="添加分类" :visible.sync="dialogFormVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="分类名称" prop="categoryName">
                    <el-input v-model="ruleForm.categoryName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">保存数据</el-button>
                    <el-button type="warning" @click="ResetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="编辑分类" :visible.sync="dialogFormVisible2" :before-close="handleClose">
            <el-form :model="ruleFormEdit" :rules="rules" ref="ruleFormEdit"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="分类ID">
                    <el-input v-model="ruleFormEdit.categoryId" readonly></el-input>
                </el-form-item>
                <el-form-item label="分类名称" prop="categoryName">
                    <el-input v-model="ruleFormEdit.categoryName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitFormEdit('ruleFormEdit')">更新数据</el-button>
                    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-table
                :data="tableData"
                border
                stripe
                style="width:95%; margin: 20px auto;overflow-x: auto;">
            <el-table-column
                    prop="categoryId"
                    label="分类ID">
            </el-table-column>
            <el-table-column
                    prop="categoryName"
                    label="分类名称">
            </el-table-column>
            <el-table-column label="操作" width="200px">
                <template slot-scope="scope">
                    <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination style="margin-left:30px;"
                       background
                       layout="prev,pager,next"
                       :pageSize="pageSize"
                       :total="total"
                       :current-page.sync="currentPage"
                       @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "CategoryManager",
        data(){
            return {
                tableData:[],
                pageSize:5,
                total: null,
                currentPage:1,
                dialogFormVisible2: false,
                ruleFormEdit:{
                    categoryId:'',
                    categoryName:''
                },
                dialogFormVisible: false,
                ruleForm:{
                    categoryName:'',
                },
                rules:{
                    categoryName: [{ required: true, message: '请输入分类名称', trigger: 'blur'}]
                }
            }
        },
        methods:{
            //保存对话框,关闭按钮
            handleClose(done) {
                this.$confirm('本次数据尚未保存,确定关闭吗?','提示')
                    .then(() => {
                        done();
                    })
                    .catch(() => {});
            },
            //重置
            ResetFrom(formName){
                this.$refs[formName].resetFields();
            },
            //编辑
            edit(row){
                //先赋值
                this.ruleFormEdit = row;
                this.dialogFormVisible2 = true;
            },
            //删除
            del(row){
                this.$confirm('确认要删除【' + row.categoryName +'】吗?','删除提示',{
                    confirmButtonText:'删除',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(() =>{
                    //提示框,确定
                    this.$http.delete('/productCategory/delete/'+ row.categoryId)
                        .then(resp => {
                            if(resp.data){
                                this.$message.success('删除成功!');
                            } else {
                                this.$message.error('删除失败!');
                            }
                            location.reload();
                        }).catch((msg) => {
                        this.$message.error(msg);
                    })
                }).catch(()=>{
                    this.$message.warning('已取消删除!');
                });
            },
            //分页控件,点击分页
            page(currentPage){
                this.$http.get('/productCategory/list/'+currentPage+'/' + this.pageSize)
                    .then(resp =>{
                        this.tableData = resp.data.content;
                        this.pageSize = resp.data.pageSize;
                        this.total = resp.data.total;
                    })
            },
            //保存数据
            submitForm(formName){
                //先验证
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.post('/productCategory/save',this.ruleForm)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('保存成功!');
                                    //等待1秒后,关闭窗体,回显数据
                                    setTimeout(() => {
                                        this.dialogFormVisible = false;
                                        location.reload();
                                    },800);
                                }
                            })
                            .catch((msg) =>{
                                this.$message.error(msg);
                            });
                    }
                })
            },
            //更新数据
            submitFormEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.put('/productCategory/update',this.ruleFormEdit)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('更新成功');
                                    setTimeout(()=>{
                                        this.dialogFormVisible2 = false;
                                        location.reload();
                                    },800);
                                }
                            })
                    }
                })
            },
            //初始化,加载数据
            loadData(){
                this.$http.get('/productCategory/list/1/' + this.pageSize).then(resp => {
                    if(resp.data.code === -1){
                        this.$alert(resp.data.msg,'提示',{
                            confirmButtonText:'确定'
                        });
                    }
                    this.tableData = resp.data.content;
                    this.pageSize = resp.data.pageSize;
                    this.total = resp.data.total;
                });
            }
        },
        created(){

            this.loadData();
        }
    }
</script>

<style scoped>
    .demo-ruleForm{
        width: 400px;
        height: 50px;
        margin-top: 30px;
        margin-left: 50px;
    }

    .dialog-ruleForm{
        width: 90%;
        margin: 1px auto;
    }
</style>

EmployeeManager.vue

<template>
    <div style="">
        <el-form label-width="100px" class="demo-ruleForm">
            <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加用户</el-button>
        </el-form>

        <el-dialog title="添加用户" :visible.sync="dialogFormVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="姓名" prop="empName">
                    <el-input v-model="ruleForm.empName"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-radio v-model="ruleForm.sex" label="男">男</el-radio>
                    <el-radio v-model="ruleForm.sex" label="女">女</el-radio>
                </el-form-item>
                <el-form-item label="电话" prop="phone">
                    <el-input v-model="ruleForm.phone"></el-input>
                </el-form-item>
                <el-form-item label="电子邮件" prop="email">
                    <el-input v-model="ruleForm.email"></el-input>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                    <el-input v-model="ruleForm.address"></el-input>
                </el-form-item>
                <el-form-item label="账号" prop="userName">
                    <el-input v-model="ruleForm.userName"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="ruleForm.password" type="password"></el-input>
                </el-form-item>
                <el-form-item label="状态" prop="status">
                    <el-radio v-model="ruleForm.status" :label="1">启用</el-radio>
                    <el-radio v-model="ruleForm.status" :label="0">禁用</el-radio>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">保存数据</el-button>
                    <el-button type="warning" @click="ResetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="编辑用户" :visible.sync="dialogFormVisible2" :before-close="handleClose">
            <el-form :model="ruleFormEdit" :rules="rules" ref="ruleFormEdit"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="用户ID">
                    <el-input v-model="ruleFormEdit.empId" readonly></el-input>
                </el-form-item>
                <el-form-item label="姓名" prop="empName">
                    <el-input v-model="ruleFormEdit.empName"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-radio v-model="ruleFormEdit.sex" label="男">男</el-radio>
                    <el-radio v-model="ruleFormEdit.sex" label="女">女</el-radio>
                </el-form-item>
                <el-form-item label="电话" prop="phone">
                    <el-input v-model="ruleFormEdit.phone"></el-input>
                </el-form-item>
                <el-form-item label="电子邮件" prop="email">
                    <el-input v-model="ruleFormEdit.email"></el-input>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                    <el-input v-model="ruleFormEdit.address"></el-input>
                </el-form-item>
                <el-form-item label="账号" prop="userName">
                    <el-input v-model="ruleFormEdit.userName"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="ruleFormEdit.password" type="password"></el-input>
                </el-form-item>
                <el-form-item label="状态" prop="status">
                    <el-radio v-model="ruleFormEdit.status" :label="1">启用</el-radio>
                    <el-radio v-model="ruleFormEdit.status" :label="0">禁用</el-radio>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitFormEdit('ruleFormEdit')">更新数据</el-button>
                    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="配置角色" :visible.sync="dialogRoleVisible" :before-close="handleClose">
            <el-form :model="roleForm" :rules="rulesRole" ref="roleForm"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="角色" prop="roleId">
                    <el-select v-model="roleForm.roleId" placeholder="请选择">
                        <el-option
                                v-for="item in roleOptions"
                                :key="item.roleId"
                                :label="item.roleName"
                                :value="item.roleId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitRole('roleForm')">保存角色</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-table
                :data="tableData"
                border
                stripe
                style="width:95%; margin: 20px auto;overflow-x: auto;">
            <el-table-column
                    fixed
                    prop="empId"
                    label="用户ID">
            </el-table-column>
            <el-table-column
                    prop="empName"
                    label="姓名">
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别">
            </el-table-column>
            <el-table-column
                    prop="phone"
                    label="电话">
            </el-table-column>
            <el-table-column
                    prop="email"
                    label="电子邮件">
            </el-table-column>
            <el-table-column
                    prop="address"
                    label="地址">
            </el-table-column>
            <el-table-column
                    prop="userName"
                    label="账号">
            </el-table-column>
            <el-table-column
                    prop="password"
                    label="密码">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="状态">
                <template slot-scope="scope">
                    <span>{{ scope.row.status === 1 ? '启用':'禁用' }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="260px">
                <template slot-scope="scope">
                    <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)">删除</el-button>
                    <el-button type="warning" @click="handleRole(scope.row)">配置角色</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination style="margin-left:30px;"
                       background
                       layout="prev,pager,next"
                       :pageSize="pageSize"
                       :total="total"
                       :current-page.sync="currentPage"
                       @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "EmployeeManager",
        data(){
            return {

                dialogRoleVisible:false,
                roleForm:{
                    empId:'',
                    roleId:''
                },
                roleOptions:[],
                tableData:[],
                pageSize:5,
                total: null,
                currentPage:1,
                dialogFormVisible2: false,
                ruleFormEdit:{
                    empId:'',
                    empName:'',
                    sex:'',
                    phone:'',
                    email:'',
                    address:'',
                    userName:'',
                    password:'',
                    status: null
                },
                dialogFormVisible: false,
                ruleForm:{
                    empName:'某老师',
                    sex:'男',
                    phone:'18800000000',
                    email:'yy@163.com',
                    address:'北京市大兴区同业胡同',
                    userName:'user3',
                    password:'1234',
                    status: 1
                },
                rules:{
                    empName: [{ required: true, message: '请输入姓名', trigger: 'blur'}],
                    phone: [{ required: true, message: '请输入电话', trigger: 'blur'}],
                    email: [{ required: true, message: '请输入电子邮件', trigger: 'blur'}],
                    address: [{ required: true, message: '请输入地址', trigger: 'blur'}],
                    userName: [{ required: true, message: '请输入账号', trigger: 'blur'}],
                    password: [{ required: true, message: '请输入密码', trigger: 'blur'}]
                },
                rulesRole:{
                    roleId:[{ required: true, message:'请选择角色', trigger:'change'}]
                }
            }
        },
        methods:{
            submitRole(formName){
                this.$refs[formName].validate((valid) =>{
                    if(valid){
                        this.$http.put('/roleEmployee/updateRole',this.roleForm)
                            .then(resp => {
                                if(resp.data){
                                    this.$message.success('角色更新成功!');
                                    setTimeout(() =>{
                                        this.dialogRoleVisible = false;
                                        location.reload();
                                    },600);

                                }
                            })
                    }
                })
            },
            handleRole(row){
                //
                this.roleForm.empId = row.empId;
                this.dialogRoleVisible = true;
                this.$http.get('/role/roleList').then(resp => {
                    this.roleOptions = resp.data;
                });

                this.$http.get('/roleEmployee/getRoleByEmpId/' + row.empId)
                    .then( resp => {
                        this.roleForm.roleId = resp.data.roleId;
                    });

            },
            //保存对话框,关闭按钮
            handleClose(done) {
                this.$confirm('本次数据尚未保存,确定关闭吗?','提示')
                    .then(() => {
                        done();
                    })
                    .catch(() => {});
            },
            //重置
            ResetForm(formName){
                this.$refs[formName].resetFields();
            },
            //编辑
            edit(row){
                //先赋值
                this.ruleFormEdit = row;
                this.dialogFormVisible2 = true;
            },
            //删除
            del(row){
                //console.log(row)
                this.$confirm('确认要删除【' + row.empName +'】吗?','删除提示',{
                    confirmButtonText:'删除',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(() =>{
                    //提示框,确定
                    this.$http.delete('/employee/delete/'+ row.empId)
                        .then(resp => {
                            if(resp.data){
                                this.$message.success('删除成功!');
                            } else {
                                this.$message.error('删除失败!');
                            }
                            location.reload();
                        }).catch((msg) => {
                        this.$message.error(msg);
                    })
                }).catch(()=>{
                    this.$message.warning('已取消删除!');
                });
            },
            //分页控件,点击分页
            page(currentPage){
                this.$http.get('/employee/list/'+currentPage+'/' + this.pageSize)
                    .then(resp =>{
                        this.tableData = resp.data.content;
                        this.pageSize = resp.data.pageSize;
                        this.total = resp.data.total;
                    })
            },
            //保存数据
            submitForm(formName){
                //console.log(formName)
                //先验证
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.post('/employee/save',this.ruleForm)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('保存成功!');
                                    //等待1秒后,关闭窗体,回显数据
                                    setTimeout(() => {
                                        this.dialogFormVisible = false;
                                        location.reload();
                                    },800);
                                }
                            })
                            .catch((msg) =>{
                                this.$message.error(msg);
                            });
                    }
                })
            },
            //更新数据
            submitFormEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.put('/employee/update',this.ruleFormEdit)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('更新成功');
                                    setTimeout(()=>{
                                        this.dialogFormVisible2 = false;
                                        location.reload();
                                    },800);
                                }
                            })
                    }
                })
            },
            //初始化,加载数据
            loadData(){
                this.$http.get('/employee/list/1/' + this.pageSize).then(resp => {
                    if(resp.data.code === -1){
                        this.$alert(resp.data.msg,'提示',{
                            confirmButtonText:'确定'
                        });
                    }
                    this.tableData = resp.data.content;
                    this.pageSize = resp.data.pageSize;
                    this.total = resp.data.total;
                });
            }
        },
        created(){
            this.loadData();
        }
    }
</script>

<style scoped>
    .demo-ruleForm{
        width: 400px;
        height: 50px;
        margin-top: 30px;
        margin-left: 50px;
    }

    .dialog-ruleForm{
        width: 90%;
        margin: 1px auto;
    }
</style>

Home.vue

<template>
    <el-container class="home-container">
        <el-header>
            <div class="home-title">基于springboot+vue的超市商品管理系统</div>
            <div class="home-userinfo-contrainer">
                <el-avatar class="el-icon-user-solid"></el-avatar>
                <el-dropdown style="position: relative;top: -10px;left:10px;">
                    <span class="el-dropdown-link home-userinfo">
                        {{ admin.empName }} <i class="el-icon-arrow-down el-icon--right home-userinfo"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </el-header>

        <el-container>
            <el-aside width="200px" style="height: 92vh;">
                <el-menu router style="height:100%;" :default-openeds="openeds">
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-notebook-1"></i>
                            <span>物料管理</span>
                        </template>
                        <el-menu-item index="/productManage">
                            <div style="position: relative;left:10px;">
                                <i class="el-icon-goods"></i>
                                <span>商品管理</span>
                            </div>
                        </el-menu-item>
                        <el-menu-item index="/categoryManage">
                            <div style="position: relative;left:10px;">
                                <i class="el-icon-goods"></i>
                                <span>分类管理</span>
                            </div>
                        </el-menu-item>
                    </el-submenu>
                    <el-submenu index="2">
                        <template slot="title">
                            <i class="el-icon-notebook-1"></i>
                            <span>系统管理</span>
                        </template>
                        <el-menu-item index="/employeeManager">
                            <div style="position: relative;left:10px;">
                                <i class="el-icon-goods"></i>
                                <span>用户管理</span>
                            </div>
                        </el-menu-item>
                        <el-menu-item index="/roleAuthorManager">
                            <div style="position: relative;left:10px;">
                                <i class="el-icon-goods"></i>
                                <span>权限管理</span>
                            </div>
                        </el-menu-item>
                        <el-menu-item index="/supplierManager">
                            <div style="position: relative;left:10px;">
                                <i class="el-icon-goods"></i>
                                <span>供应商管理</span>
                            </div>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>

            <el-container>
                <el-main style="width: 100%;height: 500px;">
                    <el-breadcrumb separator-class="el-icon-arrow-right">
                        <el-breadcrumb-item :to="{path:'/home'}">首页</el-breadcrumb-item>
                        <el-breadcrumb-item v-text="this.$router.currentRoute.meta.name">首页</el-breadcrumb-item>
                    </el-breadcrumb>
                    <router-view></router-view>
                </el-main>
                <el-footer style="text-align: center;border-top:1px solid #cccccc;">
                        <span>虾米大王</span>
                </el-footer>
            </el-container>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "HomePage",
        data(){
            return {
                admin:null,
                //默认展开菜单
                openeds:['1','2']
            }
        },
        methods:{
            logout(){
                this.$confirm('确定要退出系统吗?','提示',{
                    confirmButtonText:'退出',
                    cancelButtonText:'取消',
                    type:"warning"
                }).then(() => {
                    localStorage.removeItem('access-admin');
                    this.$router.push('/login');
                }).catch(() => {
                    this.$message.warning('已取消退出!');
                })
            }
        },
        mounted(){
            let admin = JSON.parse(window.localStorage.getItem('access-admin'));
            if(admin != null){
                this.admin = admin;
            }else {
                this.$router.push('/login');
            }

        }
    }
</script>

<style scoped>
    .home-container{
        width: 100%;
        height: 100%;
    }

    .el-header{
        background-color: #8e90ff;
    }

    .home-title{
        line-height: 60px;
        font-size: 25px;
        color: #cbfffc;
        float: left;
    }

    .home-userinfo-contrainer{
        width: 200px;
        height: 60px;
        float: right;
        line-height: 60px;
        text-align: center;
    }

    .home-userinfo-contrainer .el-avatar{
        margin-top: 10px;
    }

    .home-userinfo{
        line-height: 60px;
        color: black;
    }
</style>

login.vue

<template>
    <div class="el-container">
        <el-form :model="ruleForm"
                status-icon
                :rules="rules"
                ref="ruleForm"
                label-position="left"
                label-width="80px"
                class="demo-ruleForm login-page">
            <h3 class="title">系统登录</h3>
            <el-form-item label="账号" prop="userName">
                <el-input type="text" v-model="ruleForm.userName" auto-complete="off" placeholder="账号"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
            </el-form-item>
            <el-form-item style="width: 100%;">
                <el-button type="primary" style="width: 70%;height:38px;font-size: 20px;" @click="handleLogin('ruleForm')" :loading="loading">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "LoginPage",
        data(){
            return {
                loading: false,
                fullscreenLoading: true,
                ruleForm:{
                    userName:'user1',
                    password:'1234'
                },
                rules:{
                    userName:[{ required: true, message:'请输入账号', trigger:'blur'}],
                    password: [{ required: true, message: '请输入密码', trigger: 'blur'}]
                }
            }
        },
        methods:{
            handleLogin(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        this.loading = true;
                        this.$http.post('/login/doLogin', this.ruleForm )
                            .then(resp => {
                                this.loading = false;
                                console.log(resp)
                                if(resp.data.code === -1){
                                    this.$message.warning('账号不存在');
                                }
                                if(resp.data.code === -2){
                                    this.$message.warning('密码错误');
                                }
                                if(resp.data.code === 0){
                                    localStorage.setItem('access-admin',JSON.stringify(resp.data.employee));
                                    this.$router.push('/home');
                                }
                            })
                    }else {
                        this.$message.error('登录错误,账号或密码有误!');
                        return false;
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .el-container{
        width: 500px;
        height: 300px;
        border: 1px solid green;
        border-radius: 20px;
        margin: 100px auto;
    }

    .login-page{
        width: 80%;
        margin: 30px auto;
    }

    .login-page .title{
        margin: 5px auto 20px auto;
        font-size: 30px;
        text-align: center;

    }
</style>

ProductManager.vue

<template>
    <div style="">
        <el-form label-width="100px" class="demo-ruleForm">
            <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加商品</el-button>
        </el-form>

        <el-dialog title="添加商品" :visible.sync="dialogFormVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="商品名称" prop="productName">
                    <el-input v-model="ruleForm.productName"></el-input>
                </el-form-item>
                <el-form-item label="价格" prop="productPrice">
                    <el-input v-model.number ="ruleForm.productPrice" type="number" step="0.1"></el-input>
                </el-form-item>
                <el-form-item label="库存" prop="productStock">
                    <el-input v-model.number="ruleForm.productStock"></el-input>
                </el-form-item>
                <el-form-item label="商品详情" prop="productDesc">
                    <el-input v-model="ruleForm.productDesc"></el-input>
                </el-form-item>
                <el-form-item label="分类" prop="categoryId">
                    <el-select v-model="ruleForm.categoryId" placeholder="请选择分类">
                        <el-option
                                v-for="item in categoryList"
                                :key="item.categoryId"
                                :label="item.categoryName"
                                :value="item.categoryId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">保存数据</el-button>
                    <el-button type="warning" @click="ResetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="编辑商品" :visible.sync="dialogFormVisible2" :before-close="handleClose">
            <el-form :model="ruleFormEdit" :rules="rules" ref="ruleFormEdit"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="商品ID">
                    <el-input v-model="ruleFormEdit.productId" readonly></el-input>
                </el-form-item>
                <el-form-item label="商品名称" prop="productName">
                    <el-input v-model="ruleFormEdit.productName"></el-input>
                </el-form-item>
                <el-form-item label="价格" prop="productPrice">
                    <el-input v-model.number ="ruleFormEdit.productPrice" type="number" step="0.1"></el-input>
                </el-form-item>
                <el-form-item label="库存" prop="productStock">
                    <el-input v-model.number ="ruleFormEdit.productStock"></el-input>
                </el-form-item>
                <el-form-item label="商品详情" prop="productDesc">
                    <el-input v-model="ruleFormEdit.productDesc"></el-input>
                </el-form-item>
                <el-form-item label="分类" prop="categoryId">
                    <el-select v-model="ruleFormEdit.categoryId" placeholder="请选择分类">
                        <el-option
                                v-for="item in categoryList"
                                :key="item.categoryId"
                                :label="item.categoryName"
                                :value="item.categoryId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitFormEdit('ruleFormEdit')">更新数据</el-button>
                    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-table
                :data="tableData"
                border
                stripe
                style="width:95%; margin: 20px auto;overflow-x: auto;">
            <el-table-column
                    fixed
                    prop="productId"
                    label="商品ID">
            </el-table-column>
            <el-table-column
                    prop="productName"
                    label="商品名称">
            </el-table-column>
            <el-table-column
                    prop="productPrice"
                    label="价格">
            </el-table-column>
            <el-table-column
                    prop="productStock"
                    label="库存">
            </el-table-column>
            <el-table-column
                    prop="productDesc"
                    label="商品详情">
            </el-table-column>
            <el-table-column
                    prop="categoryName"
                    label="分类">
            </el-table-column>
            <el-table-column label="操作" width="200px">
                <template slot-scope="scope">
                    <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination style="margin-left:30px;"
                       background
                       layout="prev,pager,next"
                       :pageSize="pageSize"
                       :total="total"
                       :current-page.sync="currentPage"
                       @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "ProductManager",
        data(){
            return {
                categoryList:[],
                tableData:[],
                pageSize:10,
                total: null,
                currentPage:1,
                dialogFormVisible2: false,
                ruleFormEdit:{
                    productId:'',
                    productName:'',
                    productPrice:'',
                    productStock:'',
                    productDesc:'',
                    categoryId:''
                },
                dialogFormVisible: false,
                ruleForm:{
                    productName:'巨无霸海鲜汉堡',
                    productPrice: 99,
                    productStock: 999,
                    productDesc:'必胜客',
                    categoryId:''
                },
                rules:{
                    productName: [{ required: true, message: '请输入商品名称', trigger: 'blur'}],
                    productPrice: [{ required: true, message: '请输入商品价格', trigger: 'blur'}],
                    productStock: [
                        { required: true, message: '请输入库存', trigger: 'blur'},
                        { type:'number', message: '库存必须是数字类型', trigger: 'blur'}
                    ],
                    productDesc: [{ required: true, message: '请输入商品详情', trigger: 'blur'}],
                    categoryId: [{ required: true, message: '请选择分类', trigger: 'blur'}]
                }
            }
        },
        methods:{
            //保存对话框,关闭按钮
            handleClose(done) {
                this.$confirm('本次数据尚未保存,确定关闭吗?','提示')
                    .then(() => {
                        done();
                    })
                    .catch(() => {});
            },
            //重置
            ResetForm(formName){
                this.$refs[formName].resetFields();
            },
            //编辑
            edit(row){
                console.log(row)
                //先赋值
                this.ruleFormEdit = row;
                this.dialogFormVisible2 = true;
            },
            //删除
            del(row){
                //console.log(row)
                this.$confirm('确认要删除【' + row.productName +'】吗?','删除提示',{
                    confirmButtonText:'删除',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(() =>{
                    //提示框,确定
                    this.$http.delete('/productInfo/delete/'+ row.productId)
                        .then(resp => {
                            if(resp.data){
                                this.$message.success('删除成功!');
                            } else {
                                this.$message.error('删除失败!');
                            }
                            location.reload();
                        }).catch((msg) => {
                        this.$message.error(msg);
                    })
                }).catch(()=>{
                    this.$message.warning('已取消删除!');
                });
            },
            //分页控件,点击分页
            page(currentPage){
                this.$http.get('/productInfo/list/'+currentPage+'/' + this.pageSize)
                    .then(resp =>{
                        this.tableData = resp.data.content;
                        this.pageSize = resp.data.pageSize;
                        this.total = resp.data.total;
                    })
            },
            //保存数据
            submitForm(formName){
                //console.log(formName)
                //先验证
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.post('/productInfo/save',this.ruleForm)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('保存成功!');
                                    //等待1秒后,关闭窗体,回显数据
                                    setTimeout(() => {
                                        this.dialogFormVisible = false;
                                        location.reload();
                                    },800);
                                }
                            })
                            .catch((msg) =>{
                                this.$message.error(msg);
                            });
                    }
                })
            },
            //更新数据
            submitFormEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.put('/productInfo/update',this.ruleFormEdit)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('更新成功');
                                    setTimeout(()=>{
                                        this.dialogFormVisible2 = false;
                                        location.reload();
                                    },800);
                                }
                            })
                    }
                })
            },
            //初始化,加载数据
            loadData(){
                this.$http.get('/productInfo/list/1/' + this.pageSize).then(resp => {
                    if(resp.data.code === -1){
                        this.$alert(resp.data.msg,'提示',{
                            confirmButtonText:'确定'
                        });
                    }
                    this.tableData = resp.data.content;
                    this.pageSize = resp.data.pageSize;
                    this.total = resp.data.total;
                });
            },
            getCategory(){
                this.$http.get('/productCategory/categoryList')
                    .then( resp =>{
                        this.categoryList = resp.data;
                    })
            }
        },
        created(){
            this.loadData();
            this.getCategory();
        }
    }
</script>

<style scoped>
    .demo-ruleForm{
        width: 400px;
        height: 50px;
        margin-top: 30px;
        margin-left: 50px;
    }

    .dialog-ruleForm{
        width: 90%;
        margin: 1px auto;
    }
</style>

RoleAuthorManager.vue

<template>
    <div style="">
        <el-form label-width="100px" class="demo-ruleForm">
            <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加角色</el-button>
        </el-form>

        <el-dialog title="添加角色" :visible.sync="dialogFormVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="角色名称" prop="roleName">
                    <el-input v-model="ruleForm.roleName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">保存数据</el-button>
                    <el-button type="warning" @click="ResetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="编辑角色" :visible.sync="dialogFormVisible2" :before-close="handleClose">
            <el-form :model="ruleFormEdit" :rules="rules" ref="ruleFormEdit"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="角色ID">
                    <el-input v-model="ruleFormEdit.roleId" readonly></el-input>
                </el-form-item>
                <el-form-item label="角色名称" prop="roleName">
                    <el-input v-model="ruleFormEdit.roleName"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitFormEdit('ruleFormEdit')">更新数据</el-button>
                    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="配置权限" :visible.sync="dialogRoleVisible" :before-close="handleClose">
            <el-tree
                :data="authData"
                show-checkbox
                default-expand-all
                node-key="id"
                ref="tree"
                highlight-current
                :default-checked-keys="selected">

            </el-tree>
            <el-button type="primary" @click="saveAuth">保存权限</el-button>
        </el-dialog>

        <el-table
                :data="tableData"
                border
                stripe
                style="width:95%; margin: 20px auto;overflow-x: auto;">
            <el-table-column
                    prop="roleId"
                    label="角色ID">
            </el-table-column>
            <el-table-column
                    prop="roleName"
                    label="角色名称">
            </el-table-column>
            <el-table-column label="操作" width="260px">
                <template slot-scope="scope">
                    <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)">删除</el-button>
                    <el-button type="warning" @click="handleAuth(scope.row)">配置权限</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination style="margin-left:30px;"
                       background
                       layout="prev,pager,next"
                       :pageSize="pageSize"
                       :total="total"
                       :current-page.sync="currentPage"
                       @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "RoleAuthorManager",
        data(){
            return {
                selected:[],
                authData:[],
                dialogRoleVisible:false,
                authForm:{
                    authId:'',
                    roleId:''
                },
                authOptions:[],
                tableData:[],
                pageSize:5,
                total: null,
                currentPage:1,
                dialogFormVisible2: false,
                ruleFormEdit:{
                    roleId:'',
                    roleName:''
                },
                dialogFormVisible: false,
                ruleForm:{
                    roleName:'一般用户',
                },
                rules:{
                    roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur'}]
                },
                rulesAuth:{
                    authId:[{ required: true, message:'请选择权限', trigger:'change'}]
                }
            }
        },
        methods:{
            saveAuth(){
                let selected = [];
                let array = this.$refs.tree.getCheckedNodes();
                for (let i=0;i<array.length;i++){
                    selected.push(array[i].id);
                }

                selected.push(this.authForm.roleId);
                this.$http.put('/roleAuthority/updateAuthority',selected)
                    .then(resp => {
                        if(resp.data){
                            this.$message.success('权限更新成功!');
                            this.dialogRoleVisible = false;
                        }
                    })
            },
            handleAuth(row){
                this.authForm.roleId = row.roleId;
                this.dialogRoleVisible = true;
                this.$http.get('/authority/authorityList').then(resp => {
                    //console.log(resp.data)
                    this.authData = resp.data;
                });

                this.$http.get('/roleAuthority/getAuthorityByRoleId/' + row.roleId)
                    .then( resp => {
                       this.selected = resp.data;
                    });

            },
            //保存对话框,关闭按钮
            handleClose(done) {
                this.$confirm('本次数据尚未保存,确定关闭吗?','提示')
                    .then(() => {
                        done();
                    })
                    .catch(() => {});
            },
            //重置
            ResetForm(formName){
                this.$refs[formName].resetFields();
            },
            //编辑
            edit(row){
                //先赋值
                this.ruleFormEdit = row;
                this.dialogFormVisible2 = true;
            },
            //删除
            del(row){
                //console.log(row)
                this.$confirm('确认要删除【' + row.roleName +'】吗?','删除提示',{
                    confirmButtonText:'删除',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(() =>{
                    //提示框,确定
                    this.$http.delete('/role/delete/'+ row.roleId)
                        .then(resp => {
                            if(resp.data){
                                this.$message.success('删除成功!');
                            } else {
                                this.$message.error('删除失败!');
                            }
                            location.reload();
                        }).catch((msg) => {
                        this.$message.error(msg);
                    })
                }).catch(()=>{
                    this.$message.warning('已取消删除!');
                });
            },
            //分页控件,点击分页
            page(currentPage){
                this.$http.get('/role/list/'+currentPage+'/' + this.pageSize)
                    .then(resp =>{
                        this.tableData = resp.data.content;
                        this.pageSize = resp.data.pageSize;
                        this.total = resp.data.total;
                    })
            },
            //保存数据
            submitForm(formName){
                //console.log(formName)
                //先验证
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.post('/role/save',this.ruleForm)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('保存成功!');
                                    //等待1秒后,关闭窗体,回显数据
                                    setTimeout(() => {
                                        this.dialogFormVisible = false;
                                        location.reload();
                                    },800);
                                }
                            })
                            .catch((msg) =>{
                                this.$message.error(msg);
                            });
                    }
                })
            },
            //更新数据
            submitFormEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.put('/role/update',this.ruleFormEdit)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('更新成功');
                                    setTimeout(()=>{
                                        this.dialogFormVisible2 = false;
                                        location.reload();
                                    },800);
                                }
                            })
                    }
                })
            },
            //初始化,加载数据
            loadData(){
                this.$http.get('/role/list/1/' + this.pageSize).then(resp => {
                    if(resp.data.code === -1){
                        this.$alert(resp.data.msg,'提示',{
                            confirmButtonText:'确定'
                        });
                    }
                    this.tableData = resp.data.content;
                    this.pageSize = resp.data.pageSize;
                    this.total = resp.data.total;
                });
            }
        },
        created(){
            this.loadData();
        }
    }
</script>

<style scoped>
    .demo-ruleForm{
        width: 400px;
        height: 50px;
        margin-top: 30px;
        margin-left: 50px;
    }

    .dialog-ruleForm{
        width: 90%;
        margin: 1px auto;
    }
</style>

SupplierManager.vue

<template>
    <div style="">
        <el-form label-width="100px" class="demo-ruleForm">
            <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加供应商</el-button>
        </el-form>

        <el-dialog title="添加供应商" :visible.sync="dialogFormVisible" :before-close="handleClose">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm"
                    label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="供应商编码" prop="supCode">
                    <el-input v-model="ruleForm.supCode"></el-input>
                </el-form-item>
                <el-form-item label="供应商名称" prop="supName">
                    <el-input v-model="ruleForm.supName"></el-input>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                    <el-input v-model="ruleForm.address"></el-input>
                </el-form-item>
                <el-form-item label="联系人" prop="contact">
                    <el-input v-model="ruleForm.contact"></el-input>
                </el-form-item>
                <el-form-item label="电子邮件" prop="email">
                    <el-input v-model="ruleForm.email"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="ruleForm.phone"></el-input>
                </el-form-item>
                <el-form-item label="发票号" prop="taxId">
                    <el-input v-model="ruleForm.taxId"></el-input>
                </el-form-item>
                <el-form-item label="开户行" prop="bankName">
                    <el-input v-model="ruleForm.bankName"></el-input>
                </el-form-item>
                <el-form-item label="户名" prop="bankChairman">
                    <el-input v-model="ruleForm.bankChairman"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input v-model="ruleForm.remark"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">保存数据</el-button>
                    <el-button type="warning" @click="ResetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog title="编辑供应商" :visible.sync="dialogFormVisible2" :before-close="handleClose">
            <el-form :model="ruleFormEdit" :rules="rules" ref="ruleFormEdit"
                     label-width="100px" label-position="left" class="dialog-ruleForm">
                <el-form-item label="供应商ID">
                    <el-input v-model="ruleFormEdit.supId" readonly></el-input>
                </el-form-item>
                <el-form-item label="供应商编码" prop="supCode">
                    <el-input v-model="ruleFormEdit.supCode"></el-input>
                </el-form-item>
                <el-form-item label="供应商名称" prop="supName">
                    <el-input v-model="ruleFormEdit.supName"></el-input>
                </el-form-item>
                <el-form-item label="地址" prop="address">
                    <el-input v-model="ruleFormEdit.address"></el-input>
                </el-form-item>
                <el-form-item label="联系人" prop="contact">
                    <el-input v-model="ruleFormEdit.contact"></el-input>
                </el-form-item>
                <el-form-item label="电子邮件" prop="email">
                    <el-input v-model="ruleFormEdit.email"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="ruleFormEdit.phone"></el-input>
                </el-form-item>
                <el-form-item label="发票号" prop="taxId">
                    <el-input v-model="ruleFormEdit.taxId"></el-input>
                </el-form-item>
                <el-form-item label="开户行" prop="bankName">
                    <el-input v-model="ruleFormEdit.bankName"></el-input>
                </el-form-item>
                <el-form-item label="户名" prop="bankChairman">
                    <el-input v-model="ruleFormEdit.bankChairman"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input v-model="ruleFormEdit.remark"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitFormEdit('ruleFormEdit')">更新数据</el-button>
                    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-table
            :data="tableData"
            border
            stripe
            style="width:95%; margin: 20px auto;overflow-x: auto;">
            <el-table-column
                    fixed
                prop="supId"
                label="供应商ID">
            </el-table-column>
            <el-table-column
                    prop="supCode"
                    label="供应商编码">
            </el-table-column>
            <el-table-column
                    prop="supName"
                    label="供应商名称">
            </el-table-column>
            <el-table-column
                    prop="address"
                    label="地址">
            </el-table-column>
            <el-table-column
                    prop="contact"
                    label="联系人">
            </el-table-column>
            <el-table-column
                    prop="email"
                    label="电子邮件">
            </el-table-column>
            <el-table-column
                    prop="phone"
                    label="联系电话">
            </el-table-column>
            <el-table-column
                    prop="taxId"
                    label="发票号">
            </el-table-column>
            <el-table-column
                    prop="bankName"
                    label="开户行">
            </el-table-column>
            <el-table-column
                    prop="bankChairman"
                    label="户名">
            </el-table-column>
            <el-table-column
                    prop="remark"
                    label="备注">
            </el-table-column>
            <el-table-column label="操作" width="200px">
                <template slot-scope="scope">
                    <el-button type="primary" @click="edit(scope.row)">编辑</el-button>
                    <el-button type="danger" @click="del(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination style="margin-left:30px;"
                background
                layout="prev,pager,next"
                :pageSize="pageSize"
                :total="total"
                :current-page.sync="currentPage"
                @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "SupplierManager",
        data(){
            return {
                tableData:[],
                pageSize:5,
                total: null,
                currentPage:1,
                dialogFormVisible2: false,
                ruleFormEdit:{
                    supId:'',
                    supCode:'',
                    supName:'',
                    address:'',
                    contact:'',
                    email:'',
                    phone:'',
                    taxId:'',
                    bankName:'',
                    bankChairman:'',
                    remark:''
                },
                dialogFormVisible: false,
                ruleForm:{
                    supCode:'001',
                    supName:'某某供应商',
                    address:'广州市白云区',
                    contact:'张三',
                    email:'zx@qq.com',
                    phone:'188',
                    taxId:'FP-889191',
                    bankName:'中国大众银行',
                    bankChairman:'萨丁',
                    remark:'备注'
                },
                rules:{
                    supCode: [{ required: true, message: '请输入供应商编码', trigger: 'blur'}],
                    supName: [{ required: true, message: '请输入供应商名称', trigger: 'blur'}],
                    address: [{ required: true, message: '请输入地址', trigger: 'blur'}],
                    contact: [{ required: true, message: '请输入联系人', trigger: 'blur'}],
                    email: [{ required: true, message: '请输入电子邮件', trigger: 'blur'}],
                    phone: [{ required: true, message: '请输入联系电话', trigger: 'blur'}],
                    taxId: [{ required: true, message: '请输入发票号', trigger: 'blur'}],
                    bankName: [{ required: true, message: '请输入开户行', trigger: 'blur'}],
                    bankChairman: [{ required: true, message: '请输入户名', trigger: 'blur'}]
                }
            }
        },
        methods:{
            //保存对话框,关闭按钮
            handleClose(done) {
                this.$confirm('本次数据尚未保存,确定关闭吗?','提示')
                    .then(() => {
                        done();
                    })
                    .catch(() => {});
            },
            //重置
            ResetForm(formName){
                this.$refs[formName].resetFields();
            },
            //编辑
            edit(row){
                //console.log(row)
                //先赋值
                this.ruleFormEdit = row;
                this.dialogFormVisible2 = true;
            },
            //删除
            del(row){
                //console.log(row)
                this.$confirm('确认要删除【' + row.supName +'】吗?','删除提示',{
                    confirmButtonText:'删除',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(() =>{
                    //提示框,确定
                    this.$http.delete('/supplier/delete/'+ row.supId)
                        .then(resp => {
                            if(resp.data){
                                this.$message.success('删除成功!');
                            } else {
                                this.$message.error('删除失败!');
                            }
                            location.reload();
                        }).catch((msg) => {
                            this.$message.error(msg);
                    })
                }).catch(()=>{
                    this.$message.warning('已取消删除!');
                });
            },
            //分页控件,点击分页
            page(currentPage){
                this.$http.get('/supplier/list/'+currentPage+'/' + this.pageSize)
                    .then(resp =>{
                        this.tableData = resp.data.content;
                        this.pageSize = resp.data.pageSize;
                        this.total = resp.data.total;
                    })
            },
            //保存数据
            submitForm(formName){
                //console.log(formName)
                //先验证
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.post('/supplier/save',this.ruleForm)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('保存成功!');
                                    //等待1秒后,关闭窗体,回显数据
                                    setTimeout(() => {
                                        this.dialogFormVisible = false;
                                        location.reload();
                                    },800);
                                }
                            })
                            .catch((msg) =>{
                                this.$message.error(msg);
                        });
                    }
                })
            },
            //更新数据
            submitFormEdit(formName){
                this.$refs[formName].validate((valid) => {
                    if(valid){
                        //验证通过
                        this.$http.put('/supplier/update',this.ruleFormEdit)
                            .then( resp => {
                                if(resp.data){
                                    this.$message.success('更新成功');
                                    setTimeout(()=>{
                                        this.dialogFormVisible2 = false;
                                        location.reload();
                                    },800);
                                }
                            })
                    }
                })
            },
            //初始化,加载数据
            loadData(){
                this.$http.get('/supplier/list/1/' + this.pageSize).then(resp => {
                    if(resp.data.code === -1){
                        this.$alert(resp.data.msg,'提示',{
                            confirmButtonText:'确定'
                        });
                    }
                    this.tableData = resp.data.content;
                    this.pageSize = resp.data.pageSize;
                    this.total = resp.data.total;
                });
            }
        },
        created(){
            this.loadData();
        }
    }
</script>

<style scoped>
    .demo-ruleForm{
        width: 400px;
        height: 50px;
        margin-top: 30px;
        margin-left: 50px;
    }

    .dialog-ruleForm{
        width: 90%;
        margin: 1px auto;
    }
</style>

测试

登录

基于springboot+vue+mybatisplus的商品管理系统_java_06

首页

基于springboot+vue+mybatisplus的商品管理系统_spring boot_07

商品管理

基于springboot+vue+mybatisplus的商品管理系统_java_08

 分类管理

基于springboot+vue+mybatisplus的商品管理系统_vue.js_09

用户管理

基于springboot+vue+mybatisplus的商品管理系统_mysql_10

 权限管理

基于springboot+vue+mybatisplus的商品管理系统_java_11

供应商管理

基于springboot+vue+mybatisplus的商品管理系统_spring_12

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
px8Y25gMnWbQ