vue搜索表格功能,根据input输入框和下拉框传递的参数进行搜索

简介: vue搜索表格功能,根据input输入框和下拉框传递的参数进行搜索

json数据

{"msg":"success","total":0,"code":1,"data":[{"id":5,"userOrganId":null,"userName":"super","sex":1,"realName":"133","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":1,"roleName":"管理员","organId":1,"organName":"test311","authority":1,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":34,"userOrganId":null,"userName":"lijunfei","sex":1,"realName":"qqq","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":41,"roleName":"wangxiaotih","organId":26,"organName":"A部门","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":35,"userOrganId":null,"userName":"john","sex":1,"realName":"小猪","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":2,"organName":"研发部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":36,"userOrganId":null,"userName":"test","sex":0,"realName":"测试人员","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":37,"userOrganId":null,"userName":"www","sex":0,"realName":"ww","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1},{"id":38,"userOrganId":null,"userName":"wwwwww","sex":0,"realName":"www","birthday":null,"password":"202cb962ac59075b964b07152d234b70","roleId":43,"roleName":"普通管理员","organId":27,"organName":"测试部","authority":0,"companyId":1,"phone":null,"organIds":null,"isPagination":false,"page":1,"rows":1}]}

渲染表格

功能需求

1:在input输入框输入终端编号的时候,会查询出一条符合输入终端编号的数据

大概是这样子的

2:在选择下拉框里面的值的时候

将选中的值,传给后端,后端在数据库里面进行查询

返回符合条件的值

大概是这样子的

test.vue

<template>
  <div class="tab-container">
    <div class="filter-container" style="margin-bottom: 20px">
      <el-input
        maxlength="40"
        placeholder="用户名"
        style="width: 200px"
        class="filter-item"
        v-model="searchContent"
        @keyup.enter.native="handleFilter"
      />
      <el-select
        placeholder="全部部门"
        clearable
        style="width: 150px; margin-right: 30px"
        class="filter-item"
        v-model="questionForm.organId"
        @change="changeHandler"
      >
        <el-option
          v-for="item in getOrganList"
          :key="item.id"
          :label="item.organName"
          :value="item.id"
        ></el-option>
      </el-select>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="searchContList"
        >搜索
      </el-button>
    </div>
    <el-table
      :data="pvData.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column
        prop="userName"
        label="用户名"
        width="180"
      ></el-table-column>
      <el-table-column prop="realName" label="姓名"></el-table-column>
      <el-table-column
        prop="sex"
        label="性别"
        :formatter="formatSex"
      ></el-table-column>
      <el-table-column prop="organName" label="所属部门"></el-table-column>
      <el-table-column
        prop="authority"
        label="权限"
        :formatter="formatauthority"
      ></el-table-column>
      <el-table-column prop="roleName" label="角色"></el-table-column>
    </el-table>
    <el-pagination
      style="margin: 12px 0px"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 40]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pvData.length"
    >
    </el-pagination>
  </div>
</template>
<script>
//调用接口
import { getQuerycheckList, getOrgan } from "@/api/permission/user";
export default {
  data() {
    return {
      // 分页
      currentPage: 1, //初始页
      pagesize: 5, //    每页的数据
      total: 0,
      searchContent: "",
      questionForm: {
        organName: "",
        organId: "",
      },
      pvData: [],
      getOrganList: [],
    };
  },
  watch: {},
  created() {
    //加载用户列表信息接口
    this.getQuerycheckList();
    //加载部门
    this.getOrgan();
  },
  methods: {
    //部门下拉框
    changeHandler(value) {
      const checkedItem = this.getOrganList.find((a) => a.id === value);
      this.questionForm.organName = checkedItem.organName;
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    },
    // 查询按钮
    searchContList() {
      this.getQuerycheckList();
    },
    //查询用户列表信息接口
    getQuerycheckList() {
      //取出来sessionStorage的值
      const userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
      const params = {
        userName: "",
        organId: "",
        userOrganId: userInfo.userOrganId,
        authority: userInfo.authority,
        page: 1,
        rows: 20,
        isPagination: false,
      };
      //搜索内容的参数
      if (this.searchContent) {
        params.userName = this.searchContent;
      }
      if (this.questionForm.organId) {
        params.organId = this.questionForm.organId;
      }
      this.dataLoading = true;
      getQuerycheckList(params).then((res) => {
        if (res.data !== null) {
          this.pvData = res.data;
        }
        this.dataLoading = false;
      });
    },
    //获取部门信息接口定义
    getOrgan() {
      const userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
      const params = {
        organId: userInfo.userOrganId,
        authority: userInfo.authority,
      };
      this.dataLoading = true;
      getOrgan(params).then((res) => {
        this.getOrganList = res.data.organs;
        this.dataLoading = false;
      });
    },
    //格式化性别
    formatSex(row, column) {
      return row.sex === 1 ? "男" : "女";
    },
    //格式化权限
    formatauthority(row, column) {
      return row.authority === 1 ? "所有部门权限" : "当前部门权限";
    },
  },
};
</script>
<style scoped>
.tab-container {
  margin: 30px;
}
</style>
相关文章
|
6天前
|
资源调度
Vue3导入表格功能
Vue3导入表格功能
|
6天前
|
JavaScript 前端开发 数据安全/隐私保护
vue element plus Input 输入框
vue element plus Input 输入框
65 0
|
6天前
|
JavaScript 前端开发
【vue】iview如何把input输入框和点击输入框之后的边框去掉
【vue】iview如何把input输入框和点击输入框之后的边框去掉
24 0
|
5天前
|
资源调度 JavaScript 前端开发
将Elementui里的Table表格做成响应式并且和Pagination分页组件封装在一起(Vue实战系列)
将Elementui里的Table表格做成响应式并且和Pagination分页组件封装在一起(Vue实战系列)
|
6天前
|
JavaScript
vue3表格编辑(数据回显)和删除功能实现
vue3表格编辑(数据回显)和删除功能实现
14 1
|
6天前
|
JavaScript
vue中watch监听路由传来的参数变化问题
vue中watch监听路由传来的参数变化问题
8 0
|
6天前
|
JavaScript
Ant design vue 样式调整(包含导航栏、a-table表格、分页)
Ant design vue 样式调整(包含导航栏、a-table表格、分页)
56 1
|
6天前
|
JavaScript 前端开发
【vue】设计一个表格,增删改查,分页,固定列,特殊字符校验
【vue】设计一个表格,增删改查,分页,固定列,特殊字符校验
16 0
【vue】设计一个表格,增删改查,分页,固定列,特殊字符校验
|
6天前
|
JavaScript
vue父组件获取子组件单多个输入框(input)的值
vue父组件获取子组件单多个输入框(input)的值
21 0
|
4天前
|
缓存 监控 JavaScript
探讨优化Vue应用性能和加载速度的策略
【5月更文挑战第17天】本文探讨了优化Vue应用性能和加载速度的策略:1) 精简代码和组件拆分以减少冗余;2) 使用计算属性和侦听器、懒加载、预加载和预获取优化路由;3) 数据懒加载和防抖节流处理高频事件;4) 图片压缩和选择合适格式,使用CDN加速资源加载;5) 利用浏览器缓存和组件缓存提高效率;6) 使用Vue Devtools和性能分析工具监控及调试。通过这些方法,可提升用户在复杂应用中的体验。
15 0

相关实验场景

更多