Vue2使用cube-ui?實(shí)現(xiàn)搜索過濾、高亮功能
介紹
cube-ui 是基于 Vue.js 實(shí)現(xiàn)的精致移動(dòng)端組件庫。
特性
- 質(zhì)量可靠由滴滴內(nèi)部組件庫精簡提煉而來,經(jīng)歷了業(yè)務(wù)一年多的考驗(yàn),并且每個(gè)組件都有充分單元測試,為后續(xù)集成提供保障。
- 體驗(yàn)極致以迅速響應(yīng)、動(dòng)畫流暢、接近原生為目標(biāo),在交互體驗(yàn)方面追求極致。
- 標(biāo)準(zhǔn)規(guī)范遵循統(tǒng)一的設(shè)計(jì)交互標(biāo)準(zhǔn),高度還原設(shè)計(jì)效果;接口標(biāo)準(zhǔn)化,統(tǒng)一規(guī)范使用方式,開發(fā)更加簡單高效。
- 擴(kuò)展性強(qiáng)支持按需引入和后編譯,輕量靈活;擴(kuò)展性強(qiáng),可以方便地基于現(xiàn)有組件實(shí)現(xiàn)二次開發(fā)。
前言
蠻久沒更新 cube-ui 的功能實(shí)現(xiàn)了,公司要為售后部門做一個(gè)方便查看公司產(chǎn)品的一個(gè)項(xiàng)目,遇這需求,雖然常見但自己沒做過,在此做個(gè)例子當(dāng)做記錄。
一、需求
流程:

實(shí)現(xiàn)效果:


功能實(shí)現(xiàn)
html
<template>
<div class = "device-list-main">
<div class ="header">
<div class="header_title">
<cube-select v-model="selectValue" :options="selectOptions" ></cube-select>
</div>
<div class="header_input">
<cube-input v-model="searchValue" placeholder="請輸入搜索值"
:maxlength=30
@input='showUpdatePropsPicker'></cube-input>
<div class="header_input_btn">
<img :src="searchImgUrl" />
</div>
</div>
</div>
</div>
</template>js
<script>
import searchImgUrl from '@/../static/img/search.png'
export default {
name: 'DeviceSwitchList',
data () {
return {
searchImgUrl: searchImgUrl,
selectOptions: ['設(shè)備IMEI', '醫(yī)院名稱'],
selectValue: '',
searchValue: '',
titleName: '設(shè)備設(shè)置',
data: [{ text: 'R1210699001', value: 'R1210699001' }, { text: 'N1220203010', value: 'N1220203010' },
{ text: 'N1220203001', value: 'N1220203001' }, { text: 'N1220203002', value: 'N1220203002' },
{ text: 'R1220101005', value: 'R1220101005' }]
}
},
methods: {
showUpdatePropsPicker () {
var searchValueList = this.searchFilter(this.searchValue)
if (!this.updatePropsPicker) {
// 創(chuàng)建一個(gè)選擇器
this.updatePropsPicker = this.$createPicker({
title: 'IMEI選擇器',
data: [searchValueList],
onSelect: this.selectHandle,
onCancel: this.cancelHandle
})
}
// 展示
this.updatePropsPicker.show()
// 定時(shí)刷新
setTimeout(() => {
this.updatePropsPicker.$updateProps({
data: [searchValueList]
})
}, 100)
},
// 確認(rèn)后
selectHandle (selectedVal, selectedIndex, selectedText) {
if (selectedVal !== '') {
this.searchValue = selectedVal[0].value
}
},
// 取消后
cancelHandle () {
},
// 篩選(重點(diǎn))
searchFilter (searchValue) {
var searchValueList = []
if (searchValue !== '' || searchValue !== null) {
if (this.data !== [] || this.data.length > 0) {
for (let index = 0; index < this.data.length; index++) {
if (this.data[index].value.search(searchValue) !== -1) {
var highlight = `<span style="color: #fe7d2d;">${searchValue}</span>`
searchValueList.push({text: this.data[index].value.replace(searchValue, highlight), value: this.data[index]})
}
}
}
}
return searchValueList
}
}
}
</script>css
<style scoped>
.device-list-main {
height: 100%;
}
/* 頭部樣式 */
.header {
width: 100%;
background: #fff;
padding: 0;
display: flex;
}
.header_title {
width: 30%;
float: left;
}
.cube-select {
padding: 0;
line-height: 2rem;
margin: 0.3rem;
font-size: small;
}
.cube-input {
float: left;
padding: 0;
font-size: small;
line-height: 0rem;
margin-top: 0.3rem;
width: 82%;
height: 2rem;
}
.cube-input::after {
border-radius: 1rem 0 0 1rem;
}
.header_input {
float: left;
width: 70%;
}
.header_input_btn {
float: left;
background-color: #eee;
width: 15%;
border-radius: 0 0.5rem 0.5rem 0;
margin-top: 0.3rem;
height: 2rem;
}
.header_input_btn img {
margin: 0.5rem;
height: 50%;
}
/* 設(shè)置搜索字體高亮 */
.highlight {
color: #fe7d2d;
}
.cube-popup-mask {
display: none;
overflow: hidden;
opacity: 0.4;
pointer-events: auto;
}
</style>
總結(jié)
這只是簡單的一種,還有很多種方法,這是在考慮數(shù)據(jù)量不大的情況下使用,如果數(shù)據(jù)量非常大,可以采用 Spring Boot集成elasticsearch 的方式。有幸做過在這也不好解釋。
到此這篇關(guān)于Vue2使用cube-ui 實(shí)現(xiàn)搜索過濾、高亮功能的文章就介紹到這了,更多相關(guān)vue搜索過濾高亮內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解Vue的常用指令v-if, v-for, v-show,v-else, v-bind, v-on
Vue.js的指令是以v-開頭的,它們作用于HTML元素,指令提供了一些特殊的特性。這篇文章主要介紹了Vue的常用指令v-if, v-for, v-show,v-else, v-bind, v-on 的相關(guān)知識(shí),需要的朋友可以參考下2018-10-10
vue element后臺(tái)鑒權(quán)流程分析
這篇文章主要介紹了vue element后臺(tái)鑒權(quán)流程分析,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
vue多級復(fù)雜列表展開/折疊及全選/分組全選實(shí)現(xiàn)
這篇文章主要介紹了vue多級復(fù)雜列表展開/折疊及全選/分組全選實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11
vue中defineProperty和Proxy的區(qū)別詳解
這篇文章主要介紹了vue中defineProperty和Proxy的區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11

