输入搜索、分组展示选项、下拉选取,el-select 实现:即输入关键字检索,返回分组选项,选取跳转到相应内容页 —— VUE 项目-全局模糊检索

后端数据代码写于下一篇:输入搜索、分组展示选项、下拉选取,全局跳转页,el-select 实现 —— 后端数据处理代码,抛砖引玉展思路 

【效果图】:分组展示选项 =>【提供界面操作体验】

 【录制效果视频展示】: 

菜单栏-快速检索1

【流程】:

(1)读取目标数据,如果是多个,需要多次读取;
(2)对数据进行分组,放入特定分组数据结构;
(3)各分组,做相应设置;
(4)数据组装到 el-select 控件;
(5)点击选项,跳转到相应位置。

现将关键代码及结构附于下方:

1. 分组数据结构示例:

(1)标准结构示例:

groupSelectOptions2: [
				{
					id: 1,
					label: '超期',
					options: [
						{
							value: 'cqwbj',
							label: '超期未办结'
						},
						{
							value: 'ycq',
							label: '已超期'
						}
					]
				},
				{
					id: 2,
					label: '按天',
					options: [
						{
							value: 't1',
							label: '1天'
						},
						{
							value: 't2',
							label: '2天'
						},
						{
							value: 't3',
							label: '3天'
						}
					]
				},
				{
					id: 3,
					label: '按小时',
					options: [
						{
							value: 'h1',
							label: '1小时'
						},
						{
							value: 'h2',
							label: '2小时'
						}
					]
				}
			]

(2)项目数据结构示例:

主要的就 label 和 srcPath 这两个属性(其余省略):label,用于显示;srcPath,存储选取跳转的 url 地址。

[
    {
        label:'',
        options:[
            {srcPath: ''}
        ]
    },
]

2. 封装 el-select 成组件:

<template>
    <div style="height: 15px; justify-content: center; align-items: center;">
		<template>
			<el-select
				v-model="innerValue"
				filterable
				:remote="true"
				:likeQuery="false"
				@change="changeSelect"
				:clearable="clearable"
				:multiple="multiple"
				:remote-method="fetchOptions"
				size="small"
				popper-class="productGroupSelector"
				:placeholder="placeholder"
				
			>
			
				<el-option-group class="productGroupSelector-group" v-for="group in localOptions" :key="group.label" :label="group.label">
					
					<div style="" v-if="multiple">
						<div style="">
							<el-checkbox v-model="group.checked" @change="selectAll($event, group.id)" :indeterminate="group.isIndeterminate"></el-checkbox>
						</div>
						
						<div>
							<el-option
								class="productGroupSelector-option"
								v-for="item in group.options"
								:key="item.value"
								:label="item.label"
								:value="item"
							></el-option>
						</div>
					</div>

					<div v-else>
						<el-option
							class="productGroupSelector-option"
							v-for="(item,index) in group.options"
							:key="index"
							:label="item.label"
							:value="item"
						></el-option>
					</div>
					
				</el-option-group>
			</el-select>

		</template>
    </div>
</template>

3. javascript 和 css

<script>

import $ from 'jquery';
import {getRequest} from "@/api/api";
export default {
    name: 'LiloGroupSelect',
    model: {
        prop: 'value',
        event: 'change'
    },
    props: {
        value: {
            type: [String, Array],
            default: () => []
        },
        options: {
            type: Array,
            default: () => []
        },
        placeholder: {
            type: String,
            default: '请选择'
        },
        multiple: {
            type: Boolean,
            default: false
        },
        clearable: {
            type: Boolean,
            default: false
        },
        collapseTags: {
            type: Boolean,
            default: false
        },
        likeQuery: {
            type: Boolean,
            default: false
        },
        searchApi: {
            type: String,
            default: '' // 后端搜索API地址
        }
    },
    data() {
        return {
			innerValue: this.value,
			inputValue: ''  ,// 添加这一行来定义 inputValue
			selectedOption: '',
            // searchQuery: '',
			filteredOptions: [],
            loading: false,
            allOptions: [], // 存储所有后端返回的选项,用于筛选
			localOptions: [...this.options], // 新增属性,用于存储当前选项
			groupSelectOptions2: [
				{
					id: 1,
					label: '超期',
					options: [
						{
							value: 'cqwbj',
							label: '超期未办结'
						},
						{
							value: 'ycq',
							label: '已超期'
						}
					]
				},
				{
					id: 2,
					label: '按天',
					options: [
						{
							value: 't1',
							label: '1天'
						},
						{
							value: 't2',
							label: '2天'
						}
					]
				},
				{
					id: 3,
					label: '按小时',
					options: [
						{
							value: 'h1',
							label: '1小时'
						},
						{
							value: 'h2',
							label: '2小时'
						}
					]
				}
			],
			isDropdownVisible: false, // 控制下拉列表的显示状态(默认收起)隐藏
        };
    },
    mounted() {
        this.innerValue = this.value;
		this.allOptions = [...this.options, ...this.groupSelectOptions2]; // 初始化所有选项
		this.filteredOptions = [...this.options]; // 初始化过滤后的选项
    },
    watch: {
        value(newVal, odlVal) {
            this.innerValue = newVal;
			console.log("当前输入值或选择值:"+this.innerValue)
        },
        searchQuery(newVal) {
			console.log("监听查询输入:"+newVal)
			this.fetchOptions(newVal);
        }
    },
    methods: {
		// 模拟后端查询,直接返回 groupSelectOptions2
		fetchOptions(queryString) {
		  console.log("调用后端,请求数据....查询条件:【"+queryString+"】查询接口为:"+this.searchApi)
		  if (this.loading) return;
		  this.loading = true;
		  try {
			// 此处模拟为直接返回 groupSelectOptions2,实际应调用后端API
			this.allOptions = [...this.options, ...this.groupSelectOptions2]; // 合并原始选项和后端返回的选项(去重应在后端处理或此处额外处理)
			if(this.likeQuery) queryString = '%'+queryString+'%';
			this.getRequest(this.searchApi, {query: queryString}).then(resp =>{
				if (resp){
					this.localOptions = [...resp];
					// console.log("调用后端,返回结果:"+JSON.stringify(resp))
				}
			});
			// this.localOptions = [...this.groupSelectOptions2]; // 更新 localOptions 而不是 this.options
			// this.filteredOptions = this.filterOptionsByQuery(this.allOptions, queryString);
			console.log("调用后端,数据处理结束。。。")
		  } catch (error) {
			console.error('搜索失败:', error);
		  } finally {
			this.loading = false;
		  }
		},
		
		async query(queryString){
			if(this.likeQuery) queryString = '%'+queryString+'%';
			this.getRequest(this.searchApi, {query: queryString}).then(resp =>{
				if (resp){
					this.localOptions = [...resp];
				}
			});
		},
		
		filterOptionsByQuery(options, query) {
			return this.allOptions.reduce((acc, group) => {
				const filteredGroup = { ...group, options: group.options.filter(option => option.label.toLowerCase().includes(query.toLowerCase())) };
				// const filteredGroup = { ...group, options: group.options.filter(option => option.label.includes(query)) };
				if (filteredGroup.options.length > 0) {
					acc.push(filteredGroup);
				}
				return acc;
			}, []);
		},
		
		selectAll(val, id) {
            const selectOption = this.options.find(f => f.id === id);
            const arr = selectOption.options.map(m => m.value);
            if (val) {
                if((typeof this.innerValue !== 'object') || this.innerValue.constructor !== Array) {
                    this.innerValue = [];
                }
                arr.forEach(item => {
                    if (!this.innerValue.includes(item)) {
                        this.innerValue.push(item);
                    }
                });
            } else {
                this.innerValue.forEach((item, index) => {
                    if (arr.includes(item)) {
                        this.innerValue.splice(index, 1, '');
                    }
                });
            }
            this.innerValue = this.innerValue.filter(f => f !== '');
            if (selectOption.checked) {
                selectOption.isIndeterminate = false;
            }
            this.$emit('change', this.innerValue);
        },
		
        changeSelect(val) {
			console.log("选项变更值:"+val)
            if (this.multiple) {
                this.options.forEach(item => {
                    const arr = item.options.map(m => m.value);
                    item.isIndeterminate = arr.some(v => {
                        return val.some(s => s === v);
                    });
                    item.checked = arr.every(v => {
                        return val.some(s => s === v);
                    });
                    if (item.checked) {
                        item.isIndeterminate = false;
                    }
                });
                this.$emit('change', this.innerValue);
            } else {
                this.$emit('change', val);
            }
        },
		
    }
};
</script>

<style>
	.productGroupSelector {
		min-width: initial !important;
		width: 415px;
	}
</style>

<style lang="scss" scoped>
::v-deep {
	.el-select-group {
		width: 400px;
		display: flex;
		flex-wrap: wrap;
		justify-content: start;
		padding: 0px 10px;
	}

	.el-select-group__title {
		padding-left: 20px;
		font-size: 12px;
	}
}

.productGroupSelector-group {
	padding-top: 5px;
	display: flex;
	// align-items: center;
	// flex-wrap: wrap;
	// width: 400px;
	padding-bottom: 5px;
	flex-direction: column;
	margin: 0 5px;

	// &:not(:last-child) {
	// 	border-bottom: 1px solid rgba($color: #000000, $alpha: 0.1);
	// }

	&::after {
		display: none;
	}
}

.productGroupSelector-option {
	display: inline-flex;
	align-items: center;
	flex-wrap: wrap;
}

// .productGroupSelector {
// .el-scrollbar__view .el-select-dropdown__list {
//     display: flex;
//     flex-wrap: wrap;
//     justify-content: space-between;
//     align-items: baseline;
//     padding-top: 0;
//     overflow-x: hidden;
// }
// .el-select-dropdown__wrap .el-scrollbar__wrap {
//     max-height: 650px;
// }
// }
</style>

4. 引用 LiloGroupSelect 

<el-row :gutter="20" style="display: flex;  border-radius: 5px;" >
	<el-col style="margin-bottom: 7px;">
		<lilo-group-select @change="groupSelectChange" :multiple="false" :likeQuery="true" :searchApi="'/api/list/search'" clearable placeholder="请输入快速搜索" ></lilo-group-select>
	</el-col>
</el-row>


<script>
import LiloGroupSelect from "@/components/common/help/ElementUIGroupSelect";
export default {
	name: "***",
	components: {
		LiloGroupSelect
	},
	data(){
		return{}
    },
	methods: {
		groupSelectChange(option) {
			console.log("下拉选项选中:"+JSON.stringify(option));
			if(option==''|| option.srcPath=='')return;
			// this.$router.push(option.srcPath);
			this.$router.push(option.srcPath).catch(err => {
				if (err.name !== 'NavigationDuplicated') {
					// 处理其他可能的错误
					console.error(err);
				}
				// 对于 NavigationDuplicated 错误,可以选择不做任何处理
			});
		},
    }
}

 【效果图】:分组展示选项

参考资源:

1. Vue【原创】基于elementui的【分组多选下拉框group-select】  
2. el-select选择器组件封装 下拉菜单 elementui           
3. Vue Element 分组+多选+可搜索Select选择器实现示例        
4. 基于Vue和Element-UI自定义分组以及分组全选Select 选择器   

【项目实际效果】: 便捷简洁的企业官网

后端数据代码写于下一篇:输入搜索、分组展示选项、下拉选取,全局跳转页,el-select 实现 —— 后端数据处理代码,抛砖引玉展思路 

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【UCB CS 61B SP24】Lecture 11 - Inheritance 4: Iterators, Object Methods学习笔记

本文内容为集合&#xff08;Set&#xff09;的介绍与使用&#xff0c;并通过数组手动实现集合&#xff0c;接着介绍了迭代器&#xff0c;使用迭代器我们能够更方便地遍历集合中的元素。 1. Set 1.1 Set介绍与Java实现类的使用 集合&#xff08;Set&#xff09;是一种常见的数…

玩机日记 12 fnOS使用lucky反代https转发到外网提供服务

目录 1、安装lucky 2、更新lucky 3、上传ssl证书 4、设置安全入口&#xff0c;替换fnOS的应用url 5、添加https反代 这一篇主要是解决一下飞牛反代https的问题。可以先看玩机日记 12.5 在PVE Windows11上部署本地AI模型&#xff0c;使用群晖反代https转发到外网提供服务&a…

神经网络八股(3)

1.什么是梯度消失和梯度爆炸 梯度消失是指梯度在反向传播的过程中逐渐变小&#xff0c;最终趋近于零&#xff0c;这会导致靠前层的神经网络层权重参数更新缓慢&#xff0c;甚至不更新&#xff0c;学习不到有用的特征。 梯度爆炸是指梯度在方向传播过程中逐渐变大&#xff0c;…

【ARM】MDK如何生成指定大小的bin文件,并指定空区域的填充数据

1、 文档目标 解决MDK如何生成指定大小的bin文件&#xff0c;并指定空区域的填充数据 2、 问题场景 客户有这样的需求&#xff0c;客户本身的工程编译生成bin文件后&#xff0c;bin文件大小为200k。整体芯片的内存有512k。客户想要最终生成的bin文件可以达到512k的一个情况&a…

Linux-----进程间通信

一、按通信范围分类 同一主机进程通信 传统IPC方式&#xff1a; 管道&#xff08;无名管道、有名管道&#xff09;信号&#xff08;Signal&#xff09; System V IPC&#xff1a; 共享内存&#xff08;效率最高&#xff09;消息队列信号量 POSIX IPC&#xff08;较新标准&#…

Part 3 第十二章 单元测试 Unit Testing

概述 第十二章围绕单元测试展开&#xff0c;阐述了单元测试的实践与重要性&#xff0c;通过对比其他测试类型&#xff0c;突出其特点&#xff0c;还介绍了单元测试的最佳实践、避免的反模式以及与测试替身相关的内容&#xff0c;为编写高质量单元测试提供指导。 章节概要 1…

Windows10配置C++版本的Kafka,并进行发布和订阅测试

配置的环境为&#xff1a;Release x64下的环境 完整项目&#xff1a;https://gitee.com/jiajingong/kafka-publisher 1、首先下载相应的库文件&#xff08;.lib&#xff0c;.dll&#xff09; 参考链接&#xff1a; GitHub - eStreamSoftware/delphi-kafka GitHub - cloade…

Deepseek引爆AI热潮 防静电地板如何守护数据中心安全

近期&#xff0c;Deepseek的爆火将人工智能推向了新的高度&#xff0c;也引发了人们对AI背后基础设施的关注。作为AI运行的“大脑”&#xff0c;数据中心承载着海量数据的存储、处理和传输&#xff0c;其安全稳定运行至关重要。而在这背后&#xff0c;防静电地板扮演着不可或缺…

Spring框架基本使用(Maven详解)

前言&#xff1a; 当我们创建项目的时候&#xff0c;第一步少不了搭建环境的相关准备工作。 那么如果想让我们的项目做起来方便快捷&#xff0c;应该引入更多的管理工具&#xff0c;帮我们管理。 Maven的出现帮我们大大解决了管理的难题&#xff01;&#xff01; Maven&#xf…

QSplashScreen --软件启动前的交互

目录 QSplashScreen 类介绍 使用方式 项目中使用 THPrinterSplashScreen头文件 THPrinterSplashScreen实现代码 使用代码 使用效果 QSplashScreen 类介绍 QSplashScreen 是 Qt 中的一个类&#xff0c;用于显示启动画面。它通常在应用程序启动时显示&#xff0c;以向用户显…

【Vscode 使用】集合1

一、使用make工具管理工程 windows下&#xff0c;下载mingw64&#xff0c;配置好mingw64\bin 为 Win10系统全局变量后。 在mingw64/bin目录下找到mingw32-make.exe工具。复制一份改名为&#xff1a;make.exe&#xff0c;没错&#xff0c;就是那么简单&#xff0c;mingw64自带m…

PHP-create_function

[题目信息]&#xff1a; 题目名称题目难度PHP-create_function2 [题目考点]&#xff1a; create_function ( string args , string args , string code )[Flag格式]: SangFor{wWx5dEGHHhDUwmST4bpXwfjSzq43I6cz}[环境部署]&#xff1a; docker-compose.yml文件或者docker …

golang内存泄漏

golang也用了好几年了&#xff0c;趁着有空 整理归纳下&#xff0c;以后忘了好看下 一般认为 Go 10次内存泄漏&#xff0c;8次goroutine泄漏&#xff0c;1次是真正内存泄漏&#xff0c;还有1次是cgo导致的内存泄漏 1:环境 go1.20 win10 2:goroutine泄漏 单个Goroutine占用内存&…

Python Seaborn库使用指南:从入门到精通

1. 引言 Seaborn 是基于 Matplotlib 的高级数据可视化库,专为统计图表设计。它提供了更简洁的 API 和更美观的默认样式,能够轻松生成复杂的统计图表。Seaborn 在数据分析、机器学习和科学计算领域中被广泛使用。 本文将详细介绍 Seaborn 的基本概念、常用功能以及高级用法,…

修改与 Git 相关的邮箱

要修改与 Git 相关的邮箱信息&#xff0c;需要区分以下两种情况&#xff1a; 1. 修改 Git 提交时使用的邮箱&#xff08;影响提交记录&#xff09; Git 提交记录中的邮箱由本地 Git 配置的 user.email 决定&#xff0c;与 SSH 密钥无关。修改方法如下&#xff1a; 全局修改&a…

用PyTorch从零构建 DeepSeek R1:模型架构和分步训练详解

DeepSeek R1 的完整训练流程核心在于&#xff0c;在其基础模型 DeepSeek V3 之上&#xff0c;运用了多种强化学习策略。 本文将从一个可本地运行的基础模型起步&#xff0c;并参照其技术报告&#xff0c;完全从零开始构建 DeepSeek R1&#xff0c;理论结合实践&#xff0c;逐步…

基于SpringBoot的“流浪动物救助系统”的设计与实现(源码+数据库+文档+PPT)

基于SpringBoot的“流浪动物救助系统”的设计与实现&#xff08;源码数据库文档PPT) 开发语言&#xff1a;Java 数据库&#xff1a;MySQL 技术&#xff1a;SpringBoot 工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系统展示 系统功能结构图 局部E-R图 系统首页界面 系统…

从零开始玩转TensorFlow:小明的机器学习故事 5

图像识别的挑战 1 故事引入&#xff1a;小明的“图像识别”大赛 小明从学校里听说了一个有趣的比赛&#xff1a;“美食图像识别”。参赛者需要训练计算机&#xff0c;看一张食物照片&#xff08;例如披萨、苹果、汉堡等&#xff09;&#xff0c;就能猜出这是什么食物。听起来…

学习笔记--电磁兼容性EMC

一、基本概念 电磁兼容性&#xff08;Electromagnetic Compatibility&#xff0c;EMC&#xff09;是电子电气设备在特定电磁环境中正常工作的能力&#xff0c;同时不会对其他设备产生不可接受的电磁干扰。其核心目标是确保设备在共享的电磁环境中既能抵抗干扰&#xff0c;又能避…

unity学习51:所有UI的父物体:canvas画布

目录 1 下载资源 1.1 在window / Asset store下下载一套免费的UI资源 1.2 下载&#xff0c;导入import 1.3 导入后在 project / Asset下面可以看到 2 画布canvas&#xff0c;UI的父物体 2.1 创建canvas 2.1.1 画布的下面是 event system是UI相关的事件系统 2.2 canvas…