当前位置: 首页 > article >正文

第77讲用户管理功能实现

用户管理功能实现
前端:
views/user/index.vue

<template>
  <el-card>
    <el-row :gutter="20" class="header">
      <el-col :span="7">
        <el-input placeholder="请输入用户昵称..." clearable v-model="queryForm.query"></el-input>
      </el-col>
      <el-button type="button" :icon="Search" @click="initUserList">搜索</el-button>
    </el-row>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="#ID" width="80" />
      <el-table-column prop="nickName" label="用户昵称" width="200" />
      <el-table-column prop="avatarUrl" label="头像" width="200">
        <template v-slot="scope">
          <img :src="scope.row.avatarUrl" width="50" height="50"/>
        </template>
      </el-table-column>
      <el-table-column prop="openid" label="openID" />
      <el-table-column prop="registerDate" label="注册日期" width="200"/>
      <el-table-column prop="lastLoginDate" label="最后登录日期" width="200"/>
    </el-table>
    <el-pagination
        v-model:currentPage="queryForm.pageNum"
        v-model:page-size="queryForm.pageSize"
        :page-sizes="[10, 20, 30, 40,50]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
  </el-card>
</template>

<script setup>
  import {Search} from '@element-plus/icons-vue'
  import { ref } from 'vue'
  import axios from "@/util/axios";

  const queryForm=ref({
    query:'',
    pageNum:1,
    pageSize:10
  })

  const total=ref(0)


  const tableData =ref([])

  const initUserList=async()=>{
    const res=await axios.post("admin/user/list",queryForm.value);
    tableData.value=res.data.userList;
    total.value=res.data.total;
  }

  initUserList();

  const handleSizeChange = (pageSize) => {
    queryForm.value.pageNum=1;
    queryForm.value.pageSize=pageSize;
    initUserList();
  }
  const handleCurrentChange = (pageNum) => {
    queryForm.value.pageNum=pageNum;
    initUserList();
  }



</script>

<style lang="scss" scoped>

.header{
  padding-bottom: 16px;
  box-sizing: border-box;
}

.el-pagination{
  padding-top: 15px;
  box-sizing: border-box;
}


</style>

后端:

@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    private IWxUserInfoService wxUserInfoService;

    /**
     * 根据条件分页查询用户信息
     * @param pageBean
     * @return
     */
    @RequestMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        System.out.println(pageBean);
        String query=pageBean.getQuery().trim();
        Page<WxUserInfo> page=new Page<>(pageBean.getPageNum(),pageBean.getPageSize());
        Page<WxUserInfo> pageResult = wxUserInfoService.page(page, new QueryWrapper<WxUserInfo>().like(StringUtil.isNotEmpty(query),"nickName", query));
        Map<String,Object> map=new HashMap<>();
        map.put("userList",pageResult.getRecords());
        map.put("total",pageResult.getTotal());
        return R.ok(map);
    }

}

管理员请求鉴权

在这里插入图片描述

package com.java1234.interceptor;

import com.java1234.util.JwtUtils;
import com.java1234.util.StringUtil;
import io.jsonwebtoken.Claims;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-04-06 9:14
 */
public class SysInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String path=request.getRequestURI();
        System.out.println("path="+path);
        if(handler instanceof HandlerMethod){
            // 判断token是否为空
            String token=request.getHeader("token");
            System.out.println("token="+token);
            if(StringUtil.isEmpty(token)){
                System.out.println("token为空!");
                throw new RuntimeException("签名验证不存在!");
            }else{
                // 如果token不为空
                Claims claims = JwtUtils.validateJWT(token).getClaims();
                if(claims==null){
                    System.out.println("鉴权失败");
                    throw new RuntimeException("鉴权失败!");
                }else{
                    System.out.println("鉴权成功");
                    return true;
                }
            }
        }else{
            return true;
        }
    }
}

PageBean

package com.java1234.entity;

/**
 * 分页Model类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company Java知识分享网
 * @create 2020-02-16 上午 11:05
 */
public class PageBean {


    private int pageNum; // 第几页
    private int pageSize; // 每页记录数
    private int start;  // 起始页
    private String query; // 查询参数

    public PageBean() {
    }

    public PageBean(int pageNum, int pageSize, String query) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.query = query;
    }

    public PageBean(int pageNum, int pageSize) {
        super();
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStart() {
        return (pageNum-1)*pageSize;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }
}

AdminUserController

package com.java1234.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java1234.entity.PageBean;
import com.java1234.entity.R;
import com.java1234.entity.WxUserInfo;
import com.java1234.service.IWxUserInfoService;
import com.java1234.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 后台管理-用户Controller控制器
 */
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    private IWxUserInfoService wxUserInfoService;

    /**
     * 根据条件分页查询用户信息
     * @param pageBean
     * @return
     */
    @RequestMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        System.out.println(pageBean);
        String query=pageBean.getQuery().trim();
        Page<WxUserInfo> page=new Page<>(pageBean.getPageNum(),pageBean.getPageSize());
        Page<WxUserInfo> pageResult=wxUserInfoService.page(page,new QueryWrapper<WxUserInfo>().like(StringUtil.isNotEmpty(query),"nickName",query));
        Map<String,Object> map=new HashMap<>();
        map.put("userList",pageResult.getRecords());
        map.put("total",pageResult.getTotal());
        return R.ok(map);
    }
}

router .js

path: ‘/user’,

import { createRouter, createWebHashHistory } from 'vue-router'


const routes = [
    {
        path: '/',
        name: '首页',
        component: () => import('../views/layout'),
        redirect:'/home',
        children:[
            {
                path: '/home',
                name: '首页',
                component: () => import('../views/home/index')
            },
            {
                path: '/bigType',
                name: '商品大类',
                component: () => import('../views/bigType/index')
            },
            {
                path: '/user',
                name: '用户管理',
                component: () => import('../views/user/index')
            }
        ]
    },
    {
        path: '/login',
        name: 'login',

        component: () => import('../views/login')
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

export default router

在这里插入图片描述


http://www.kler.cn/a/234567.html

相关文章:

  • Vue3.js - 一文看懂Vuex
  • 1.两数之和-力扣(LeetCode)
  • 字节跳动Android面试题汇总及参考答案(80+面试题,持续更新)
  • 21. Drag-Drop拖放操作(二) - 文件、表格和树的拖放实现
  • 项目集章程program charter
  • MySQL Workbench导入数据比mysql命令行慢
  • 指针的基本含义及其用法
  • limit深度分页和优化思路
  • Docker 基本介绍
  • 正则可视化工具:学习和编写正则表达式的利器
  • excel统计分析——成组设计和配对设计
  • 微软 CMU - Tag-LLM:将通用大语言模型改用于专业领域
  • 医院挂号预约|医院挂号预约小程序|基于微信小程序的医院挂号预约系统设计与实现(源码+数据库+文档)
  • disql备份还原
  • 【开源】JAVA+Vue.js实现衣物搭配系统
  • 华为 huawei 交换机 接口 MAC 地址学习限制接入用户数量 配置示例
  • 车载测试Vector工具——常见问题汇总
  • 【C++】多态语法概念
  • springboot174基于springboot的疾病防控综合系统的设计与实现
  • Springboot 2.5.x如何集成Nacos 2.x的配置管理功能?
  • C语言之预处理详解
  • svg基础(八)滤镜-feTurbulence(湍流)
  • Elasticsearch:混合搜索是 GenAI 应用的未来
  • 服务器解析漏洞及任意文件下载
  • 【实验1】分布式模式的CentOS 6上安装Hadoop(1个master节点,2个slave节点)
  • ChatGPT 4:新特性与优势