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>
相关文章
|
12月前
|
存储 JavaScript 前端开发
基于 ant-design-vue 和 Vue 3 封装的功能强大的表格组件
VTable 是一个基于 ant-design-vue 和 Vue 3 的多功能表格组件,支持列自定义、排序、本地化存储、行选择等功能。它继承了 Ant-Design-Vue Table 的所有特性并加以扩展,提供开箱即用的高性能体验。示例包括基础表格、可选择表格和自定义列渲染等。
1013 6
|
JSON 自然语言处理 前端开发
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
675 72
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
|
JavaScript 前端开发
【Vue.js】监听器功能(EventListener)的实际应用【合集】
而此次问题的核心就在于,Vue实例化的时机过早,在其所依赖的DOM结构尚未完整构建完成时就已启动挂载流程,从而导致无法找到对应的DOM元素,最终致使计算器功能出现异常,输出框错误地显示“{{current}}”,并且按钮的交互功能也完全丧失响应。为了让代码结构更为清晰,便于后续的维护与管理工作,我打算把HTML文件中标签内的JavaScript代码迁移到外部的JS文件里,随后在HTML文件中对其进行引用。
240 8
|
存储 JavaScript 前端开发
介绍一下Vue的核心功能
介绍一下Vue的核心功能
537 17
|
JavaScript 前端开发 API
|
资源调度 JavaScript UED
如何使用Vue.js实现单页应用的路由功能
【10月更文挑战第1天】如何使用Vue.js实现单页应用的路由功能
|
7天前
|
人工智能 数据可视化 安全
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
本文详解如何用阿里云Lighthouse一键部署OpenClaw,结合飞书CLI等工具,让AI真正“动手”——自动群发、生成科研日报、整理知识库。核心理念:未来软件应为AI而生,CLI即AI的“手脚”,实现高效、安全、可控的智能自动化。
34445 17
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
|
18天前
|
人工智能 JSON 机器人
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
本文带你零成本玩转OpenClaw:学生认证白嫖6个月阿里云服务器,手把手配置飞书机器人、接入免费/高性价比AI模型(NVIDIA/通义),并打造微信公众号“全自动分身”——实时抓热榜、AI选题拆解、一键发布草稿,5分钟完成热点→文章全流程!
45269 142
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
|
8天前
|
人工智能 JSON 监控
Claude Code 源码泄露:一份价值亿元的 AI 工程公开课
我以为顶级 AI 产品的护城河是模型。读完这 51.2 万行泄露的源码,我发现自己错了。
4801 20

热门文章

最新文章