vue3后台管理系统封装的普通搜索框组件

news2024/10/5 16:19:36

1.普通搜索框效果

 代码:SearchItem.vue

<template>
  <div class="searchBox" id="searchBox">
    <!-- <a-form ref="formRef" name="advanced_search" class="ant-advanced-search-form" :model="formState"
      @finish="handleSearch" :label-col="labelCol" :wrapper-col="wrapperCol"> -->
    <a-form
      ref="formRef"
      name="advanced_search"
      class="ant-advanced-search-form"
      autocomplete="off"
      layout="inline"
      :model="formState"
      @finish="handleSearch"
    >
      <!-- <a-row :gutter="24"> -->
      <template v-for="(item, index) in searchitemList" :key="index">
        <!-- <a-col v-show="expand || index < 7" :md="12" :lg="item.type === 'rangeDate' ? 9 : 4"
            :xl="item.type === 'rangeDate' ? 7 : 3"> -->

        <div v-if="item.type === 'selctone'" style="margin-right: 18px">
          <span>{{ item[`label${selctone}`] }}</span
          ><swap-outlined
            @click.stop="changeleselctone"
            style="color: #1e5bc8"
          />:
          <span>
            <!-- v-model:value="formState[item[`queryName${selctone}`]]" -->
            <a-select
              v-model:value="value"
              show-search
              :placeholder="item[`placeholder${selctone}`]"
              :allowClear="true"
              style="width: 143.33px; margin-left: 10px"
              :default-active-first-option="false"
              :show-arrow="false"
              :filter-option="false"
              :options="data"
              :getPopupContainer="(triggerNode) => triggerNode.parentNode"
              @search="handleSearchone"
              @change="handleSearchoneChange"
              @focus="hadlefocus"
              @popupScroll="lazyLoading"
            >
              <template #dropdownRender="{ menuNode: menu }">
                <v-nodes :vnodes="menu" />
                <div class="nomore" v-show="props.nomore">没有更多数据了~</div>
              </template>
              <!-- <template v-if="props.fetching" #notFoundContent>
                <a-spin size="small" />
              </template> -->
            </a-select>
          </span>
        </div>
        <a-form-item
          v-else
          :label="item.label"
          :name="item.queryName"
          :rules="item.rules"
        >
          <a-input
            v-if="item.type === 'input'"
            :allowClear="true"
            v-model:value="formState[item.queryName]"
            style="width: 143.33px"
            :placeholder="item.placeholder"
            @change="changeSearchKey"
          ></a-input>
          <a-select
            v-if="item.type == 'select'"
            v-bind="item.open"
            :allowClear="!item?.allowClear"
            v-model:value="formState[item.queryName]"
            style="width: 143.33px"
            :placeholder="item.placeholder"
            @change="changeSearchKey"
            @click="hadlefocusmodel(item.queryName)"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          >
            <a-select-option
              v-for="selectItem in item.selectList"
              :key="selectItem.value"
              :value="selectItem.value"
              >{{ selectItem.name }}</a-select-option
            >
          </a-select>
          <a-range-picker
            v-model:value="formState[item.queryName]"
            @change="changeSearchKey"
            style="width: 100%; min-width: 331px"
            v-if="item.type == 'rangeDate'"
            :picker="item.picker"
            :show-time="item.showTime"
            :format="item.format"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          ></a-range-picker>
          <a-time-range-picker
            v-model:value="formState[item.queryName]"
            @change="changeSearchKey"
            style="width: 100%; min-width: 331px"
            v-if="item.type == 'timerangeDate'"
            :format="item.format"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          />

          <a-date-picker
            v-model:value="formState[item.queryName]"
            @change="changeSearchKey"
            style="width: 143.33px"
            v-if="item.type == 'Date'"
            :picker="item.picker"
            :show-time="item.showTime"
            :format="item.format"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          ></a-date-picker>
          <a-tree-select
            v-model:value="formState[item.queryName]"
            show-search
            style="width: 143.33px"
            v-if="item.type === 'treeselect'"
            :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
            :field-names="{
              children: 'children',
              label: 'title',
              value: 'key',
            }"
            :placeholder="item.placeholder"
            allow-clear
            tree-default-expand-all
            :tree-data="item.treedata"
          >
          </a-tree-select>

          <vagueSelect
            v-if="item.type === 'vagule'"
            :noneedfocus="item?.noneedfocus"
            :apifun="item.apifun"
            :ref="(e) => setvagueRef(e, index)"
            @vaguehandleSearchoneChange="
              (param) => vaguehandleSearchoneChange(param, item.queryName)
            "
            :searchText="item.searchText ? item.searchText : item.queryName"
            :requestParam="item.requestParam ? item.requestParam : {}"
            :searchValue="searchValue"
            :searchKey="searchKey"
          />

          <scrollSelect
            v-if="item.type === 'Tselect'"
            @handleSelectValue="(param) => handleSelectValue(param, item.value)"
            :apifun="item.apifun"
            :requestParam="item.requestParam"
            :param="item.param"
            :data="item.selectList"
            :ref="(e) => (setTSelectRef[index] = e)"
            :disabled="item?.isdisabled"
          />
        </a-form-item>

        <!-- </a-col> -->
      </template>
      <!-- <a-col :span="5" v-if="searchitemList.length<4"> -->
      <!-- <a-col :md="12" :sm="24" :lg="searchitemList.length > 3 ? 6 : 4" class="searchtbnbox"> -->

      <a-form-item class="searchtbnbox">
        <a-button type="primary" html-type="submit" style="margin-bottom: 24px"
          >查询</a-button
        >
        <a-button
          style="margin: 0 8px"
          @click="
            () => {
              formRef.resetFields(), handleReset();
            }
          "
          >重置</a-button
        >
        <!-- <a-button style="margin: 0 8px" @click="handleReset">重置</a-button> -->
        <a
          style="font-size: 12px"
          @click="expand = !expand"
          v-if="searchitemList.length > 5"
        >
          <template v-if="expand">
            <UpOutlined />
          </template>
          <template v-else>
            <DownOutlined />
          </template>
          {{ expand ? "折叠" : "展开" }}
        </a>
      </a-form-item>

      <!-- </a-row> -->
      <!-- <a-row  v-if="searchitemList.length>=4">
        <a-col :span="24" style="text-align: right">
          <a-button type="primary" html-type="submit" style="margin-bottom: 24px;">查询</a-button>
          <a-button style="margin: 0 8px" @click="() => formRef.resetFields()">清除</a-button>
          <a style="font-size: 12px" @click="expand = !expand">
            <template v-if="expand">
              <UpOutlined />
            </template>
            <template v-else>
              <DownOutlined />
            </template>
            {{ expand ? "折叠" : "展开" }}
          </a>
        </a-col>

      </a-row> -->
    </a-form>
  </div>
</template>
<script setup>
import { reactive, ref, unref, nextTick, onMounted, watch } from "vue";
import { DownOutlined, UpOutlined } from "@ant-design/icons-vue";
import vagueSelect from "./vagueSelect.vue";
import scrollSelect from "./scrollSelect.vue";
import jsonp from "fetch-jsonp";
import qs from "qs";
import { Form } from "ant-design-vue";
const props = defineProps({
  searchitemList: {
    type: Array,
    default: () => [],
  },
  searchValue: {
    type: String,
    default: "",
  },
  searchKey: {
    type: String,
    default: "",
  },

  searchitem: {
    type: Array,
    default: () => {
      return [
        {
          type: "", // 搜索条件类型 input,select,rangeDate,scrollSelect
          label: "", // 搜索条件名称
          val: null, // 值
          rules: [], // 校验规则
          selectList: [], // 下拉框选项
          placeholder: "", // 占位符提示
          queryName: "", // 字段名称
          allowClear: null, // 下拉框是否允许删除选项
          scrollFunc: () => {}, // 'scrollSelect'时,请求接口
          requestAllowClear: false, // 'scrollSelect'时,是否允许清除
          watchParams: true, // 'scrollSelect'时,是否请求的监听参数
          requestParams: {}, // 'scrollSelect'时,请求接口参数
          isAffect: true, // 'scrollSelect'时,选值时是否影响其他scrollSelect的选择
        },
      ];
    },
  },
  data: {
    type: Array,
    default: () => [],
  },
  apifun: {
    type: Function,
    default: () => {},
  },
  nomore: {
    type: Boolean,
    default: false,
  },
  fetching: {
    type: Boolean,
    default: false,
  },
});
const labelCol = {
  style: {
    width: "110px",
    // span: 10,
  },
};
const wrapperCol = {
  span: 16,
};
const expand = ref(false);
const formRef = ref();
let formState = reactive({});
const emits = defineEmits([
  "lazyLoading",
  "handleSearch",
  "handleChangeSearchKey",
  "handleSearchoneChange",
  "handleSearchone",
  "changeleselctone",
]);
//点击查询按钮
const handleSearch = (values) => {
  emits("handleSearch", values);
};

//查询条件元素改变
const changeSearchKey = (value) => {
  console.log(value, "22222222");
  emits("handleChangeSearchKey", value);
};

//2选1 模糊查询
const VNodes = (_, { attrs }) => {
  return attrs.vnodes;
};

const value = ref();
let selctone = ref(1);
const changeleselctone = () => {
  //点击切换图表
  if (selctone.value === 1) {
    selctone.value = 2;
  } else {
    selctone.value = 1;
  }
  value.value = undefined;
  emits("changeleselctone", selctone);
};
const hadlefocus = () => {
  emits("hadlefocus", unref(selctone));
};
const hadlefocusmodel = (hname) => {
  emits("hadlefocusmodel", hname);
};
const handleSearchone = (val) => {
  //模糊输入值
  emits("handleSearchone", unref(selctone), val);
};
const handleSearchoneChange = (val) => {
  //最终选择值
  value.value = val;
  emits("handleSearchoneChange", val);
};
const lazyLoading = (e) => {
  //滚动分页加载
  emits("lazyLoading", e);
};

//普通模糊查询
const vaguehandleSearchoneChange = (param, param2) => {
  formState[param2] = param;
};
//重置按钮,重置2选一数据,重置普通模糊的值
const boxVagueref = ref([]);
const setvagueRef = (el, i) => {
  if (el) {
    boxVagueref.value.push(el);
  }
};
const handleReset = () => {
  changeleselctone();
  boxVagueref.value.map((item) => {
    item?.initdata();
  });
};
const setFormState = (key, value) => {
  formState[key] = value;
};

const setTSelectRef = ref([]);
const handleSelectValue = async (param, param2) => {
  let str = param.key.toString();
  formState.value[param2] = str;
};
watch(
  () => props.searchitemList,
  () => {
    props.searchitemList.forEach((item) => {
      if (item.val) {
        formState[item.queryName] = item.val;
      }
    });
  },
  { deep: true, immediate: true }
);
defineExpose({
  setFormState,
});
</script>
<style lang="less" scoped>
.searchBox {
  background-color: white;
  padding: 18px;
  padding-bottom: 0;

  :deep(.ant-form-item-with-help .ant-form-item-explain) {
    min-height: 0;
  }

  :deep(.ant-form-item-explain-error) {
    line-height: 14px;
    height: 0;
  }
}

// .searchtbnbox {
//   margin-left: 18px;
// }
</style>

使用:

<SearchItem :searchitemList="SearchitemList" @handleSearch="handleSearchModal"></SearchItem>

const SearchitemList = [
    {
        type: "rangeDate",
        label: "时间",
        val: "",
        placeholder: "请选择时间",
        queryName: "DisplayName",
        showTime:true

    }
];

const handleSearchModal = (params) => {
    CreationTimeStart.value = params.DisplayName[0]
    CreationTimeEnd.value = params.DisplayName[1]
    getModalData()
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/773502.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【笔记MD】

https://editor.csdn.net/md/?not_checkout1&articleId131798584 这里写自定义目录标题 https://editor.csdn.net/md/?not_checkout1&articleId131798584欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题&#xff0c;有助于目录的生成如何改变文本的样式插入…

基于PaddleOCR与OpenVINO™的结构化输出Pipeline

飞桨&#xff08;PaddlePaddle&#xff09;是百度自主研发的中国首个开源开放、功能丰富的产业级深度学习平台&#xff0c;以百度多年的深度学习技术研究和业务应用为基础。飞桨深度学习平台集核心框架、基础模型库、端到端开发套件、丰富的工具组件于一体&#xff0c;还包括了…

QGIS绘制一张地图——创建和编辑绘制线要素、由线要素生成面要素、面要素的编辑

前言 我们以描绘北京市市区案例来演示这部分功能。步骤大致如下: 1、按照市区分区的分界线来绘制线要素。 2、根据所绘线要素生成面要素。 3、对生成的面要素做整理编辑。待绘制底图如图所示: 一、创建和编辑绘制线要素 1.1 创建线要素 我们点击新建Shapefile要素按钮,…

ES6——Iterator 和 for...of 循环

Iterator:遍历器 是一接口&#xff0c;为不同的数据结构提供统一的访问机制&#xff0c;只要当前数据结构部署了iterator接口&#xff0c;当前数据结构就可以遍历。 作用&#xff1a;1、为不同的数据结构&#xff0c;提供统一的访问机制 2、使当前数据结构的成员依次被访问 3…

园区数字经济腾飞,先要长出“网络双翼”

没有人会否认&#xff0c;过去四十多年来&#xff0c;中国经济的腾飞&#xff0c;在全球发展史中写下了浓墨重彩的一笔。其中&#xff0c;产业园区有着不可替代的作用。有人说&#xff0c;园区的四十年&#xff0c;也是一部中国经济的演进史。 作为距离企业业务最近的网络层级&…

牛客网:华为机试刷题记录

牛客网&#xff1a;华为机试刷题记录 前言一、HJ15 求int型正整数在内存中存储时1的个数二、HJ10 字符个数统计三、HJ8 合并表记录四、HJ17 坐标移动五、HJ19 简单错误记录 前言 本文主要是想记录一下华为机试刷题过程中的总结 牛客网的华为机试链接&#xff1a;https://www.n…

通达信超级分时主图指标公式_通达信公式

{日引用} MA3:MA(C,3); MA5:MA(C,5); MA7:MA(C,7); MA10:MA(C,10); MA21:MA(C,21); {BBIYY} DKX:(MA(C,3)MA(C,6)MA(C,12)MA(C,24))/4; {LJFSYY} H1:REF(H,1); L1:REF(L,1); {大盘分时主图} SJ:IF(HOUR<12,(HOUR-9.5)*60MINUTE,(HOUR-11)*60MINUTE); F:DYNAINFO(3)…

J-Flash烧录工具如何添加新的芯片类型

0 Preface/Foreword 1 添加方法 1.1 修改JLinkDevices.xm <!-- --> <!-- CMS --> <!-- --> <Device> <ChipInfo Vendor"CMS32" Name"CMS32L051" Core"JLINK_CORE_CORTEX_…

2023年7月江苏/北京/深圳CDGA/CDGP数据治理认证招生

DAMA认证为数据管理专业人士提供职业目标晋升规划&#xff0c;彰显了职业发展里程碑及发展阶梯定义&#xff0c;帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力&#xff0c;促进开展工作实践应用及实际问题解决&#xff0c;形成企业所需的新数字经济下的核心职业…

Claude API接口调用配置方法和脚本

直接通过API调用Claude方法&#xff0c;这个已经应用到一键成片AI绘画软件中。对于GPT来说速度慢了一点但是还能接受和GPT35差不多&#xff0c;最重要的是不花钱。 先来看我在项目中的应用把。 创建Slack工作台 slack注册网址&#xff0c;请使用谷歌邮箱&#xff0c;点击登…

自洽性改善语言模型中的思维链推理7.13、7.14

自洽性改善语言模型中的思维链推理 摘要介绍对多样化路径的自洽实验实验设置主要结果当CoT影响效率时候&#xff0c;SC会有所帮助与现有方法进行比较附加研究 相关工作总结 原文&#xff1a; 摘要 本篇论文提出了一种新的编码策略——自洽性&#xff0c;来替换思维链中使用的…

Vue3中的透传Attributes / $attrs:简化组件开发的利器

前言 Vue3推出了一系列新功能和改进。使用下来后&#xff0c;其中一个很实用的新特性就是透传 Attributes&#xff08;透传属性&#xff09;。本文将介绍 Vue3中的透传 Attributes&#xff0c;并提结合代码示例来展示它在实际项目中的使用。 一、什么是透传 Attributes&#x…

多网点多设备的动环机房都怎样集中管理的呢?

多机房动力环境集中监控系统针对分布不同区域、设备数量较多、减少人工巡检费用支出而设计的在线集中监控的系统平台。可用于分布式的UPS电源、精密空调、空气质量检测传感器、精密配电等设备的网络集中监控&#xff0c;通过TCP/IP网络&#xff0c;可以实时的跨地域的监控多台都…

四、DML-2.数据操作-修改

原数据表&#xff1a; 一、案例一 修改id为1的数据&#xff0c;将name修改为itheima update employee set name itheima where id 1; 步骤一&#xff1a;输入update命令并执行&#xff1a; 步骤二&#xff1a;刷新查看employee表修改后数据&#xff1a; 二、案例二 修改id为…

Beyond Compare 代码比较工具

一、下载 官网下载地址&#xff1a; https://www.scootersoftware.com/download.php 选择 Windows 系统&#xff0c;简体中文版本&#xff0c;点击下载。 下载完成 二、安装 步骤1&#xff1a;双击安装包 步骤2&#xff1a;进入安装向导&#xff0c;点击下一步 步骤3&a…

【Git合并代码操作】B=>A

【Git合并代码操作步骤】B>A 前提&#xff1a;之前写了Git合并代码A>B&#xff0c;今天把B>A再写一下&#xff0c;顺风车》》》》》》》》 【git合并代码操作步骤】A&#xff1e;B_痴心阿文的博客-CSDN博客 拉B最新代码 > 然后git merge A &#xff0c;有冲突解决冲…

在SPringBoot生成验证码

1.引入依赖,这个依赖中包含了生成验证码的工具类 <!--引入hutool --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.3.9</version></dependency> 2.编写配置类 import cn.hu…

【软件测试】如何设计自动化测试脚本

企业中如何设计自动化测试脚本呢&#xff1f;今天我们就来为大家分享一些干货。 一、线性设计 线性脚本设计方式是以脚本的方式体现测试用例&#xff0c;是一种非结构化的编码方式&#xff0c;多数采用录制回放的方式&#xff0c;测试工程师通过录制回访的访问对被测系统进行…

为何零信任架构身份管理平台更可靠?

随着信息技术的不断进步&#xff0c;云计算、物联网以及移动设备的普及&#xff0c;信息泄露等安全问题愈发频繁。近期&#xff0c;一起某高校学生的信息泄露事件引发了大家的广泛讨论。该校学生利用其身份便利&#xff0c;非法获取了大量学生的姓名、学号、照片等隐私信息。 …

租赁小程序开发|租赁小程序定制|租赁系统源码定制功能

租赁小程序适合的产品开发范围广泛&#xff0c;可以涵盖各个行业和领域。下面将介绍租赁小程序适合的产品开发&#xff0c;并探讨其优势和应用场景。   一、租赁小程序适合的产品开发   物品租赁&#xff1a;租赁小程序可以用于各种物品的租赁&#xff0c;比如自行车、电动…