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

news/2025/2/22 23:10:03

 详细前端代码写于上一篇:输入搜索、分组展示选项、下拉选取,el-select 实现:即输入关键字检索,返回分组选项,选取跳转到相应内容页 —— VUE项目-全局模糊检索

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

mybatis】:多数据表抓取数据


	<select id="findNews" resultType="com.bootdo.search.vo.SearchDetail">
		SELECT      n.cid           AS srcId,
		            pt.id           AS typeId,
		            pt.type_key     AS typeKey,
		            pt.page_type    AS pageType,
		            pt.page_name    AS srcTypeName,
		            n.title         AS srcName,
		            n.summary       AS alias,
		            pt.page_path    AS srcPath
        FROM a_news n
        LEFT JOIN a_product_type pt ON n.type_id = pt.id
        WHERE n.sys_id = #{sysId} AND n.is_enabled = 0 AND (n.title LIKE #{query} OR n.summary LIKE #{query} OR n.content LIKE #{query})
        LIMIT 20
	</select>

	<select id="findProducts" resultType="com.bootdo.search.vo.SearchDetail">
        SELECT      pt.id            AS srcId,
		            pt.page_type    AS pageType,
		            pt.page_name    AS srcTypeName,
                    pt.type_name     AS srcName,
                    pt.type_key     AS alias,
                    pt.page_path    AS srcPath
        FROM a_product_type pt
        WHERE  pt.sys_id = #{sysId} AND pt.is_deleted = 0 AND pt.type_name LIKE #{query}
        LIMIT 20
	</select>

    <select id="findItemInfos" resultType="com.bootdo.search.vo.SearchDetail">
		SELECT      n.cid           AS srcId,
		            pt.id           AS typeId,
		            pt.type_key     AS typeKey,
		            pt.page_type    AS pageType,
		            pt.page_name    AS srcTypeName,
		            pt.type_name    AS srcName,
		            pt.type_name    AS alias,
		            pt.page_path    AS srcPath
        FROM a_item_info n
        LEFT JOIN a_product_type pt ON n.type_id = pt.id
        WHERE n.sys_id = #{sysId} AND n.is_enabled = 0 AND n.content LIKE #{query}
        LIMIT 20
	</select>

java】:各数据源进一步整理、合并、分组

java">    public List<SearchVO> search(Map<String, Object> params){
        Map<String, SearchDetail> map = new HashMap<>();
        List<SearchDetail> products = searchDao.findProducts(params);
        List<SearchDetail> itemInfos = searchDao.findItemInfos(params);
        List<SearchDetail> news = searchDao.findNews(params);
        for(SearchDetail sd : products){
            String srcPath = sd.getSrcPath()+"?typeKey="+sd.getAlias();
            sd.setSrcPath(srcPath);
            map.put(srcPath, sd);
        }
        for(SearchDetail sd : itemInfos){
            this.changePath(map, sd);
        }
        for(SearchDetail sd : news){
            this.changePath(map, sd);
        }
        return groupSearchDetailsByTypeName(map.values());
    }

    private void changePath(Map<String, SearchDetail> map, SearchDetail sd){
        String srcPath = sd.getSrcPath();
        if(StringUtils.equals(srcPath, "/n")){
            srcPath = srcPath+"/nId?showDetailNewId="+sd.getSrcId()+"&menuSearch=true";
            sd.setSrcPath(srcPath);
        }
        if(StringUtils.equals(srcPath, "/p")){
            srcPath = srcPath+"/pId?showDetailNewId="+sd.getSrcId()+"&menuSearch=true&typeId="+sd.getTypeId()+"&typeKey="+sd.getTypeKey();
            sd.setSrcPath(srcPath);
        }
        map.put(srcPath, sd);
    }

    private List<SearchVO> groupSearchDetailsByTypeName(Collection<SearchDetail> sds) {
        // 使用 Collectors.groupingBy 按 srcTypeName(即 label)分组
        Map<Integer, List<SearchDetail>> groupedByTypeName = sds.stream()
                .collect(Collectors.groupingBy(SearchDetail::getPageType));

        // 将分组后的数据转换为 List<SearchVO>
        List<SearchVO> searchVOList = new ArrayList<>();
        for (Map.Entry<Integer, List<SearchDetail>> entry : groupedByTypeName.entrySet()) {
            SearchVO searchVO = new SearchVO();
            List<SearchDetail> value = entry.getValue();
            searchVO.setLabel(value.get(0).getSrcTypeName());
            searchVO.setOptions(value);
            searchVOList.add(searchVO);
        }
        return searchVOList;
    }

vue、js

<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>


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 错误,可以选择不做任何处理
	});
},

详细前端代码写于上一篇:输入搜索、分组展示选项、下拉选取,el-select 实现:即输入关键字检索,返回分组选项,选取跳转到相应内容页 —— VUE项目-全局模糊检索


http://www.niftyadmin.cn/n/5862831.html

相关文章

在工作中PostgreSQL常用的SQL命令

1. 查看所有数据库 \l 或 SELECT datname FROM pg_database; 2. 查看当前数据库中的所有表 \dt 或 SELECT table_name FROM information_schema.tables WHERE table_schema public; 3. 查看所有表空间 \db 或 SELECT spcname FROM pg_tablespace; 4. 查看所有用户&…

Lua C API :lua_insert 函数详解

lua_insert 是用于操作 Lua 栈的函数&#xff0c;其作用是将栈顶的元素移动到指定的位置。它允许我们调整栈中元素的顺序&#xff0c;非常适用于需要对栈中数据顺序进行操作的场景。 1. 函数简介 lua_insert 是 Lua C API 提供的一个栈操作函数&#xff0c;它将栈顶的元素插入…

使用useVModel简化 Vue 组件中 v-model 的实现

使用useVModel简化 Vue 组件中 v-model 的实现 基本原理&#xff1a; // VueUse的useVModel简化实现 function useVModel(props, propName, emit) {return computed({get: () > props[propName],set: (value) > emit(update:${propName}, value)}) }使用useVModel简化 …

C语言03

21-5.2 一维数组 22-5.3 数组访问越界与数组的传递 调用自定义的print函数时&#xff0c;只会打印前两个数值&#xff0c;因为传递的大小是指针为八个字节&#xff0c;不会传递原数组&#xff0c;并且自定义的数组大小不用定义&#xff0c;因为不会传递过去&#xff0c;面试官…

数据结构:哈希表(二)

目录 一、哈希表 1、概念 二、哈希冲突 1、概念 2、冲突避免 &#xff08;1&#xff09;哈希函数设计 &#xff08;2&#xff09;负载因子调节 3、冲突解决 &#xff08;1&#xff09;闭散列 1、线性探测 2、二次探测 &#xff08;2&#xff09;开散列 4、哈希桶实…

《ArkTS详解:鸿蒙生态中的高效开发语言》

文章目录 一、ArkTS的起源与背景二、ArkTS的核心特性三、ArkTS与其他编程语言的对比四、ArkTS的开发环境与工具五、ArkTS的实际应用案例六、ArkTS的未来发展与展望 一、ArkTS的起源与背景 ArkTS是华为公司为鸿蒙生态系统量身打造的一种高效开发语言&#xff0c;其起源可以追溯…

聊一聊提升测试用例覆盖率需要从哪几方面入手?

目录 一、需求覆盖&#xff1a;确保无遗漏 二、代码覆盖&#xff1a;工具辅助优化 三、路径覆盖&#xff1a;逻辑深度遍历 四、边界值覆盖&#xff1a;防御性测试设计 五、异常场景覆盖&#xff1a;模拟真实故障 六、兼容性覆盖&#xff1a;全环境验证 七、性能覆盖&…

C语言(22)

字符函数和字符串函数 7.strcpy/strcat/strcmp与strncpy/strncat/strncmp区别 前者是长度不受限制的字符串函数&#xff0c;后者是长度受限制的字符串函数 8.strncpy的使用 char * strncpy ( char * destination , const char * source , size_t num ) ; //拷贝num个字符从…