当前位置: 首页 > news >正文

传媒有限公司免费网站武安市精品网站开发

传媒有限公司免费网站,武安市精品网站开发,常州模板网站建设信息,长春电商网站建设价格低特性&#xff1a; 支持本地记录搜索关键词后台接口匹配搜索关键词支持自定义填充字段名支持user或address两种匹配列表布局样式 sgAutocomplete_v2 <template><div :class"$options.name" mouseover"inside true" mouseout"inside false…

特性:

  1. 支持本地记录搜索关键词
  2. 后台接口匹配搜索关键词
  3. 支持自定义填充字段名
  4. 支持user或address两种匹配列表布局样式

sgAutocomplete_v2 

<template><div :class="$options.name" @mouseover="inside = true" @mouseout="inside = false"><div class="search-layer"><el-inputclass="search-input"v-model.trim="inputSearchValue"maxlength="50":show-word-limit="false":placeholder="`你在找什么?快告诉我...`"clearable@keyup.native.enter="search"@focus="focusSearchInput"@clear="clearSearchInput"@input="inputingSearchInput"><el-button slot="append" icon="el-icon-search" @click="search"></el-button></el-input></div><div class="absolute-dropdownlist-layer" v-if="showAbsoluteDropdownlistLayer"><!-- 搜索建议 --><divclass="search-suggestion"v-if="historyKeywords.length > 0 && visible_search_suggestion"><!-- 搜索历史 --><div class="search-suggestion-item history"><div class="search-suggestion-item-head"><h1>最近搜索</h1><el-linkicon="el-icon-delete"type="danger":underline="false"@click.stop="clearAll">清除</el-link></div><ul class="historyKeywords"><li v-for="(a, i) in historyKeywords" :key="i"><el-tag:title="a"type="info"closable@click.stop="clickKeyword(a)"@close="closeTag(a)"><span class="text">{{ a }}</span></el-tag></li></ul></div></div><!-- 后台查询推荐匹配项 --><div class="matchList" v-if="matchList.length > 0"><ul><liv-for="(a, i) in matchList":key="i"@click.stop="clickMatchItem(a)":type="matchType"><template v-if="matchType == `user`"><div class="face"><img:src="a.src"v-if="a.src && !a.hideImg"@error="error($event, a, i)"/><el-avatarv-else:style="$g.convertData({ obj: `ROLE.PROFESSIONAL`, value: a.type }).style">{{a.username? a.username.slice(-1): a[matchKeyID] === "master"? "超": "未"}}</el-avatar></div><b class="username" v-html="a.username_HTML"> </b><span class="userid" v-html="a.userid_HTML"></span><spanclass="unit"v-html="`${a.unit_HTML ? `(${a.unit_HTML})` : ``}`"></span></template><template v-if="matchType == `address`"><b class="username" v-html="a.username_HTML"> </b><spanclass="address"v-html="`${a.address_HTML ? `[${a.address_HTML}]` : ``}`"></span></template></li></ul><div class="foot" v-if="showMoreBtn"><div class="more-btn" @click.stop="readmoreMatch" :loading="moreBtnLoading">{{ moreBtnLoading ? `加载中…` : `查看更多` }}</div></div></div></div></div>
</template>
<script>
export default {name: "sgAutocomplete_v2",components: {},data() {return {form: {},// ----------------------------------------inside: false, //鼠标是否在组件内showAbsoluteDropdownlistLayer: false, //显示absolute-dropdownlist-layerinputSearchValue: this.$route.query.keyword || "", //搜索关键词// 搜索建议----------------------------------------visible_search_suggestion: false, //显示搜索建议historyKeywords: [],// 搜索匹配----------------------------------------visible_search_match: false, //显示搜索匹配mainID: `ID`, //主键matchKeyID: `NAME`, //当点击匹配项,自动填充输入框的字段matchType: `user`, //默认匹配类型是user,枚举值:user、addressmatchList: [],keywordClassName: "match-autocomplete-keyword", //匹配高亮关键词样式showMoreBtn: false,moreBtnLoading: false,// ----------------------------------------};},props: ["value", "data"],computed: {},watch: {value: {handler(d) {this.inputSearchValue = d;},deep: true,immediate: true,},inputSearchValue(d) {this.$emit("input", d);},data: {handler(newValue, oldValue) {//console.log(`深度监听${this.$options.name}:`, newValue, oldValue);if (Object.keys(newValue || {}).length) {this.form = JSON.parse(JSON.stringify(newValue));this.form.matchType && (this.matchType = this.form.matchType);this.form.matchKeyID && (this.matchKeyID = this.form.matchKeyID);this.showMoreBtn = this.form.showMoreBtn;this.moreBtnLoading = this.form.moreBtnLoading;this.matchList = this.form.matchList || [];this.matchList = [...new Set(this.matchList.map((v) => v[this.matchKeyID])),].map((ID) => this.matchList.find((v) => v[this.matchKeyID] === ID)); //去重同样的ID数据this.setHighlightMatchList();this.$nextTick(() => {let matchListScrollDOM = this.$el.querySelector(`.matchList>ul`);matchListScrollDOM &&matchListScrollDOM.scrollTo({top: matchListScrollDOM.scrollHeight,behavior: "smooth",});});}},deep: true, //深度监听immediate: true, //立即执行},matchList: {handler(newValue, oldValue) {//console.log(`深度监听${this.$options.name}:`, newValue, oldValue);if (Object.keys(newValue || {}).length) {newValue.length > 0 && (this.visible_search_suggestion = false);}},deep: true, //深度监听immediate: true, //立即执行},},created() {this.initHistoryKeywords();},mounted() {this.__add();},destroyed() {this.__remove();},methods: {// 搜索输入框----------------------------------------search({ keyword = this.inputSearchValue } = {}) {this.visible_search_suggestion = false;this.saveHistoryKeywords();this.$emit(`search`, { keyword });},inputingSearchInput(keyword) {if (keyword === "") {this.visible_search_suggestion = true;}this.$emit(`change`, { keyword, isReset: true });},clearSearchInput(d) {this.visible_search_suggestion = true;},getmatchList({ matchList } = {}) {if (matchList.length > 0) {this.visible_search_suggestion = false;}},focusSearchInput(d) {this.showAbsoluteDropdownlistLayer = true;if (this.inputSearchValue.length === 0) {this.visible_search_suggestion = this.matchList.length === 0;} else {this.visible_search_suggestion = false;this.$emit(`change`, { keyword: this.inputSearchValue, isReset: true });}},saveHistoryKeywords(d) {let historyKeywords = (localStorage.historyKeywords || "").split("|");historyKeywords.unshift(this.inputSearchValue);historyKeywords = historyKeywords.filter(Boolean); //清空数组中的empty、undefined、nullhistoryKeywords = [...new Set(historyKeywords)];this.historyKeywords = historyKeywords;localStorage.historyKeywords = historyKeywords.join("|");},// 搜索建议----------------------------------------//初始化历史搜索记录initHistoryKeywords({ d } = {}) {this.historyKeywords = [...new Set((localStorage.historyKeywords || "").split("|").filter((v, i, ar) => v !== ``)),];},clickKeyword(d) {this.inputSearchValue = d;this.visible_search_suggestion = false;this.search();this.$nextTick(() => {this.focusSearchInput();});},closeTag(d) {this.historyKeywords = this.historyKeywords.filter((v, i, ar) => v !== d);localStorage.historyKeywords = this.historyKeywords.join("|");},clearAll(d) {this.visible_search_suggestion = false;this.historyKeywords = [];delete localStorage.historyKeywords;},// 搜索匹配----------------------------------------error($event, a, i) {this.$set(this.matchList[i], "hideImg", true);},clickMatchItem(a) {this.matchList = [];this.inputSearchValue = a[this.matchKeyID];this.search();},// 高亮匹配内容里面的关键词setHighlightMatchList() {let cls = this.keywordClassName;let keyword = this.inputSearchValue;this.matchList.forEach((d) => {Object.keys(d || {}).forEach((k) => {let originContent = this.$g.stripHTML(d[k]);d[`${k}_HTML`] = this.$g.highLightMatchString(originContent, keyword, cls);});});},readmoreMatch(d) {this.$emit(`readmoreMatch`, d);},// 全局监听----------------------------------------__add() {this.__remove();addEventListener("mousedown", this.__mousedown);},__remove() {removeEventListener("mousedown", this.__mousedown);},__mousedown(e) {this.inside || this.__hide(e); // 点击其他区域隐藏},__hide(e) {this.$emit("hide", e);this.showAbsoluteDropdownlistLayer = false;},__show(e) {this.$emit("show", e);this.showAbsoluteDropdownlistLayer = true;},},
};
</script>
<style lang="scss" scoped>
.sgAutocomplete_v2 {// 输入框搜索图层.search-layer {position: relative;z-index: 1;margin-bottom: 5px;.search-input {}}// 建议区域图层.absolute-dropdownlist-layer {z-index: 1;position: relative;width: 100%;$maxHeight: 400px; //下拉框最大高度// 搜索建议.search-suggestion {max-height: $maxHeight;position: absolute;top: 0;left: 0;box-shadow: 0 5px 20px 0 #00000022;background-color: white;border-radius: 4px;font-size: 14px;width: 100%;box-sizing: border-box;padding: 20px;.search-suggestion-item {margin-bottom: 20px;&:last-of-type {margin-bottom: 0;}.search-suggestion-item-head {display: flex;justify-content: space-between;align-items: center;margin-bottom: 20px;h1 {font-size: 14px;color: #2c343e;}}// 搜索历史.historyKeywords {display: flex;flex-wrap: wrap;margin-right: -10px;margin-bottom: -10px;max-height: calc(#{$maxHeight} - 80px);overflow-y: auto;li {margin-right: 10px;margin-bottom: 10px;>>> .el-tag {cursor: pointer;$tagMaxWidth: 200px;max-width: $tagMaxWidth;display: flex;align-items: center;&:hover,&:focus,&:active {border-color: #999;background-color: #00000009;span {color: black;}}.text {max-width: calc(#{$tagMaxWidth} - 20px);overflow: hidden;white-space: nowrap;text-overflow: ellipsis;display: inline-block;}.el-tag__close {flex-shrink: 0;}}}}}}// 搜索匹配.matchList {max-height: $maxHeight;position: absolute;top: 0;left: 0;box-shadow: 0 5px 20px 0 #00000022;background-color: white;border-radius: 8px;font-size: 14px;width: 100%;box-sizing: border-box;padding: 10px;ul {width: 100%;max-height: calc(#{$maxHeight} - 80px);overflow-y: auto;li {width: 100%;display: flex;align-items: center;box-sizing: border-box;padding: 10px;cursor: pointer;transition: 0.2s;border-radius: 8px;&[type="user"] {}&[type="address"] {}&:hover {filter: brightness(1.1);background-color: #00000009;}.face {margin-right: 10px;img,.el-avatar {width: 30px;height: 30px;display: flex;justify-content: center;align-items: center;object-position: center;object-fit: cover;border-radius: 88px;overflow: hidden;background-color: #00000009;}}.username {margin-right: 5px;color: black;}.userid {color: #999;margin-right: 10px;}.unit {color: #999;}.address {color: #999;}// 匹配高亮关键词样式>>> .match-autocomplete-keyword {color: #409eff;}}}.foot {box-sizing: border-box;display: flex;justify-content: center;align-items: center;.more-btn {padding: 10px;width: 100%;height: 100%;text-align: center;border-radius: 4px;cursor: pointer;transition: 0.2s;color: #409eff;&[loading] {pointer-events: none;}&:hover {background-color: #00000009;}}}}}
}
</style>

demo

<template><div :class="$options.name" style="display: flex; flex-wrap: nowrap"><sgAutocomplete_v2style="width: 500px":data="data_sgAutocomplete_v2"v-model="inputValue"@change="changeMatch"@readmoreMatch="readmoreMatch"@search="search"/><el-radio-groupv-model="data_sgAutocomplete_v2.matchType"size="small"style="margin-left: 10px; margin-top: 10px"><el-radiov-for="(radio, index) in radios":key="index":label="radio.value":disabled="radio.disabled">{{ radio.label }}</el-radio></el-radio-group></div>
</template>
<script>
import sgAutocomplete_v2 from "@/vue/components/admin/sgAutocomplete_v2";export default {name: "demoSgAutocomplete_v2",components: { sgAutocomplete_v2 },data() {return {radios: [{ value: `user`, label: "用户" },{ value: `address`, label: "地址" },],// ----------------------------------------inputValue: ``,data_sgAutocomplete_v2: {matchType: `user`, //默认匹配类型是user,枚举值:user、addressmatchKeyID: `NAME`, //当点击匹配项,自动填充输入框的字段matchList: [], //匹配项列表},// ----------------------------------------currentPage: 1,pageSize: 6,};},methods: {// 动态获取匹配项changeMatch({ keyword = this.inputValue, isReset } = {}) {if (!keyword) return (this.data_sgAutocomplete_v2.matchList = []);if (isReset) {this.data_sgAutocomplete_v2.matchList = [];this.currentPage = 1;}let data = {start: this.currentPage - 1, //当前页数(从0开始)limit: this.pageSize, //每页显示条目个数KEY: keyword, //匹配关键词};this.$f.biz_person_query({...data,l: {show: () => this.$set(this.data_sgAutocomplete_v2, "moreBtnLoading", true),close: () => this.$set(this.data_sgAutocomplete_v2, "moreBtnLoading", false),},cb: (d) => {//回调函数if (isReset) {this.data_sgAutocomplete_v2.matchList = []; //避免重复追加}let old_matchList = this.data_sgAutocomplete_v2.matchList;let matchList = old_matchList.concat(d.data || []);//转义适配字段matchList.forEach((v) => {v.type = v.TYPE;v.src = v.PHOTO_T ? this.$d.responseFile(v.PHOTO_T) : null; //头像路径v.username = v.NAME;v.userid = v.ACCOUNT;v.unit = v.UNIT_ID_TEXT;v.address = v.ADDRESS;});this.data_sgAutocomplete_v2.matchList = matchList;this.data_sgAutocomplete_v2.showMoreBtn = matchList.length < d.totalCount;},},this);},readmoreMatch(d) {this.currentPage++;this.changeMatch();},search(d) {// console.log(`搜索内容`, d, this.inputValue);},},
};
</script>

应用到了【全网最简短代码】去重对象数组中同一个ID的数据-CSDN博客【代码】【全网最简短代码】去重对象数组中同一个ID的数据。 https://blog.csdn.net/qq_37860634/article/details/146376768

http://www.dtcms.com/a/601466.html

相关文章:

  • 如何从多源业务表对商家进行综合评估?
  • DELMIA Role: RFE - Operations Experience Manager
  • 灭屏使用对讲,概率性出现无声
  • 问答系统网站模板天津建设工程交易信息网
  • GitHub 热榜项目 - 日榜(2025-11-12)
  • 继续访问这个网站字体安装wordpress
  • Java 进阶:反射机制深度解析
  • 如何开发高性能直播美颜sdk?人脸检测、美型算法与渲染优化详解
  • StreamAPI,取出list中的name属性,返回一个新list
  • SSM基于web的佳茗天香茶品销售平台的设计与实现z2m56(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • 请别人做网站需要注意什么问题公司做网站怎么做账
  • 茂名网站制作策划如何查看用wordpress建的站点
  • 【湿地数据集4】基于 TOPMODEL模型的1980–2020年全球湿地动态数据集 GWDD
  • C++重点知识梳理(下)
  • 苍穹外卖(第七天)
  • 新乡网站建设制作报价方案网站如何布局
  • 安全狗 网站打不开成都网络营销搜索推广
  • 预测汽车燃油效率——线性回归
  • 【自然语言处理】基于深度学习基的句子边界检测算法
  • 链接脚本(Linker Scripts)
  • 素材网站整站下载WordPress做图床
  • 企业网站相关案例网站建设域名怎么用
  • 太原专业做网站wordpress主体开发
  • 零基础新手小白快速了解掌握服务集群与自动化运维(十八)Ansible自动化模块--安装与入门
  • 【C++11】Lambda表达式+新的类功能
  • C语言编译工具 | 探讨常用C语言编译工具的选择与使用
  • SCT2A26——5.5V-100V Vin,4A峰值电流限制,高效率非同步降压DCDC转换器,兼容替代LM5012
  • 手机网站搜索框代码网上做网站怎么防止被骗
  • 滑动窗口(同向双指针)
  • C语言嵌入式编程实战指南(四):进阶技术和未来展望