uniapp+uView搜索列表变颜色
首先看一下页面效果:

<template>
<view class="page">
<b-nav-bar title="公司多维图" class="title">
<template slot="left">
<view @click="goBack" class="iconfont icon-zuofanhui nBack ml15"></view>
</template>
</b-nav-bar>
<view class="companyIpt">
<u-search placeholder="请输入上市公司代码或简称" :show-action="false" searchIconColor="#999999" searchIconSize="24"
shape="round" bgColor="#F1F2F4" maxlength="10" placeholderColor="#C0C0C0" v-model="serchVal"
@change="searchCompany" ref="searchIpt"></u-search>
</view>
<view class="serchImg" v-if="showBottomImg"></view>
<view class="noDataBox" v-if="indexList.length == 0 && !showBottomImg">
<view class="noDataImg"></view>
<view class="noDataText">
暂无搜索记录~
</view>
</view>
<u-list @scrolltolower="scrolltolower" class="uList" v-if="indexList.length != 0 && !showBottomImg">
<u-list-item v-for="(item, index) in indexList" :key="index" class="uCellItem">
<u-cell v-html="item.cellText || `${item.title}(${item.code})`" class="uCellStyle" @click="toCompanyPage(item, index)"></u-cell>
</u-list-item>
</u-list>
</view>
</template>
<script>
import { // 接口文件
queryCompanyList
} from "@/api/company.js"
export default {
data() {
return {
wh: 0, // 当前设备可用的高度
scrollTop: 0,
token: '',
account: '',
serchVal: '', // 搜索框值
indexList: [], // 列表数据
cellText: '', // 搜索高亮显示的数据
timer: null, // 定时器
showBottomImg: true
}
},
onLoad(e) {
if (e.token) {
this.token = e.token
sessionStorage.setItem('token', e.token)
}
},
methods: {
goBack() {
this.nativeBack()
},
nativeBack() {
uni.getSystemInfo({
success(res) {
if (res.platform == 'ios') { //iOS返回APP
window.webkit.messageHandlers.backUp.postMessage('123');
} else { //安卓返回APP
if (window.ytyJsApi) {
window.ytyJsApi.backUp()
} else {
uni.showToast({
title: 'window.ytyJsApi.backUp() is null',
icon: "none"
});
}
}
}
})
},
// 验证输入框不能输入表情符
validParams() {
let iconRule = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig
if (iconRule.test(this.serchVal) == true) {
uni.$u.toast('不能输入表情符')
return false
}
return true
},
// 搜索
searchCompany() {
if (this.timer) {
clearTimeout(this.timer);
}
if (this.serchVal.trim() != '' && this.validParams()) {
this.timer = setTimeout(() => {
let params = {
company: this.serchVal.trim()
}
let _this = this
queryCompanyList(params).then(res => {
if (res.code == 0) {
this.indexList = []
this.showBottomImg = false
// 遍历所有对话文本内容
for (let i = 0; i < res.data.length; i++) {
this.cellText = `${res.data[i].title}(${res.data[i].code})`
let item = res.data || {}
// 当对话内容中有包含搜索框中的字符串时(不区分大小写)
var oRegExp = new RegExp('('+this.serchVal.trim()+')',"ig");
this.cellText = this.cellText.replace(oRegExp,`<font style='color:#3849B4;'>$1</font>`
)
//替换所有搜索找到的关键字 更换颜色
this.indexList.push({
cellText: this.cellText,
...item
})
}
} else {
uni.$u.toast(res.msg)
}
})
}, 500)
} else {
this.indexList = []
this.showBottomImg = true
}
},
// 查看公司详情页面跳转
toCompanyPage(item, index) {
let objValues = Object.values(item) // 获取对象值
objValues.forEach((res1, index1) => {
if (index1 == index) {
uni.navigateTo({
url: `/pages/look-company/companyDetail/companyDetail?title=${res1.title}&code=${res1.code}`
})
}
})
},
// 列表下滑
scrolltolower() {
this.loadmore()
},
// 列表加载更多
loadmore() {
for (let i = 0; i < 30; i++) {
this.indexList.push({
url: this.urls[uni.$u.random(0, this.urls.length - 1)]
})
}
}
},
}
</script>
<style lang="scss" scoped>
.page {
width: 100%;
background: #ffffff;
.title {
font-size: 32rpx;
text-align: center;
border-bottom: 1px solid #DCDEE3;
.nBack {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
}
.companyIpt {
width: 690rpx;
height: 66rpx;
line-height: 66rpx;
margin: 20rpx auto 20rpx;
}
.uList {
width: 690rpx;
margin: 0rpx auto;
color: #666666;
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
.uCellItem {
padding: 30rpx 24rpx;
border-bottom: 1px solid #DCDEE3;
}
.uCellStyle {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
color: #666666;
}
}
.noDataBox {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
.noDataImg {
width: 320rpx;
height: 268rpx;
background-image: url('./../../../static/images/noData.png');
background-size: 100% 100%;
}
.noDataText {
color: #666666;
font-size: 26rpx;
margin-top: 53rpx;
text-align: center;
}
}
.serchImg {
width: 586rpx;
height: 482rpx;
background-image: url('../../../static/images/serch.png');
background-size: 100% 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
}
/deep/ .u-image {
width: 320rpx;
height: 268rpx;
}
/deep/ .u-search__content__input--placeholder {
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 500;
}
/deep/ uni-view,
uni-scroll-view,
uni-swiper-item {
display: block;
}
</style>
uniapp+uView搜索列表变颜色的更多相关文章
- vue 搜索关键词 变颜色
<a class="text"> <span>{{item.name.slice(0,item.name.toLowerCase().indexOf(inp ...
- tcxtreelist 控制单元格变颜色,或者行变颜色
如果控制单元格变颜色,只需要把注释的放开就可以了, 也就是判断当前列,是否是你想让变颜色的列. 如果想整行变颜色, 则只需要注释下面的就可以了. procedure TfrmwpOrderSendin ...
- vue 音乐App QQ音乐搜索列表最新接口跨域设置
在 webpack.dev.config.js中 'use strict' const utils = require('./utils') const webpack = require('webp ...
- table鼠标滑过变颜色
table鼠标滑过变颜色 添加 table tr:hover{background-color: #eee;} 设置鼠标滑过行背景变色,重新刷新浏览器页面. 一般设置灰色,eee
- 【原创】webbluetoorh 在windows下无法显示搜索列表,在mac下正常的解决办法
google webbluetooth在windows下不能弹出设备搜索列表提示“Web Bluetooth API is not available”,因为webbluetooth是google新推 ...
- Thinkphp+Ajax带关键词搜索列表无刷新分页实例
Thinkphp+Ajax带关键词搜索列表无刷新分页实例,两个查询条件,分页和搜索关键字,懂的朋友还可以添加其他分页参数. 搜索#keyword和加载内容区域#ajax_lists <input ...
- Excel按照某一列的重复数据设置隔行变颜色效果
问题:如图所示,想按照A列中的重复数据设置隔重复行变颜色的效果,能否通过条件格式命令实现. 方法1:(最佳答案) 条件格式公式:=MOD(SUMPRODUCT(--($A$1:$A1<>$ ...
- html 如何使表格一列都变颜色的简单方法!!
html怎么让一列变颜色用到属性colgroup 重点我都加粗了!! <colgroup span="3" bgcolor="yellow">&l ...
- jquery : 菜单根据url变颜色
//菜单根据url变颜色$(document).ready(function(){ $('#nav li a').each(function(){ if($($(this))[0].href==Str ...
- Android基于RecyclerView实现高亮搜索列表
这篇应该是RecycleView的第四篇了,RecycleView真是新生代的宠儿能做这么多的事情. 转载请注明作者AndroidMsky及原文链接 http://blog.csdn.net/Andr ...
随机推荐
- SpringBoot启动流程与自动装配
是什么 Spring Boot基于Spring框架之上的一个微服务架构开发框架大大简化了Spring的开发.因为Spring Boot提供了大量的自动配置.而且它是基于Java配置方式的开发(全注解) ...
- P5731 蛇形方阵
P5731 [深基5.习6]蛇形方阵 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) //为什么用动态二维数组 --->To play to user's input, but ...
- DSL语言思想的应用
背景 DSL语言的认知 DSL思想的应用 DSL的拓展思考 目标 业务限定 简化逻辑 提高效率 实现 业务提取 业务共性抽离 语法生成 语法实施
- 在windows 7下构建 FTP 服务器
首先我们在C盘建立两个文件夹,用于发ftp的上传和下载 其次我们找到控制面板>程序>打开或关闭windows功能 进入后找到Internet 信息服务>FTP服务器>确定! 选 ...
- NetBeans的一些快捷键
Alt + Insert getter 覆盖toString方法 Shift+ F6 运行当前文件 F6 运行当前项目 Tab 完成代码片段 ctrl+\ 代码补全 Alt + Shift + F格式 ...
- linux 服务器 重命名
vim /etc/hosts 追加 10.10.134.68 RmcbTestDB3 RmcbTestDB3 # ip 名称 名称 127.0.0.1 localhost ...
- Redis之Redis缓存管理机制
Redis缓存管理机制 目录 Redis缓存管理机制 缓存过期 && 缓存淘汰 缓存穿透 && 布隆过滤器 缓存击穿 && 缓存雪崩 总结 彩蛋 从博客 ...
- localStorage/sessionStorage/cookie
html5本地存储主要有两种localStorage和sessionStorage 都是使用相同api,存入后都是字符串类型 localStorage和sessionStorage使用方 ...
- C++杂乱
基本内置类型 类型 关键字 布尔型 bool 字符型 char 整型 int 浮点型 float 双浮点型 double 无类型 void 宽字符型 wchar_t endl是换行符 cout < ...
- HTTP请求报文(请求行,请求头,请求体)
HTTP协议 1.简介 HTTP协议(Hyper Text Transfer Protocol,超文本传输协议),是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的 ...