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 ...
随机推荐
- Vue案例——todolist
最近在学习vue,实现todolist案例,实现效果如下: 该案例分为四个部分:header为输入框,body为列表,item是列表中的条目,footer为最下方的统计. 实现步骤: ①创建项目 vu ...
- java创建对象时内存发生了什么
Student s = new Student();\ 把Student.class文件加载到内存 在栈内存给s变量开辟一个空间 在堆内存为学生对象申请一个空间 给成员变量进行默认初始化 给成员变量显 ...
- yolo v7使用triton部署
https://github.com/WongKinYiu/yolov7/tree/main/deploy/triton-inference-server
- div垂直居中的4种方式方式
一.使用单元格居中 <!DOCTYPE html> <html> <head> <title>测试</title> </head> ...
- ssh 登陆 Host key verification failed.
报错 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATION ...
- 论文笔记:To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem?
论文笔记:To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem? Conclusion 如果对象平均大小 ...
- 火爆全球的“饺子皮”3D手办原来是这样做的!关键时刻少不了远程控制软件!
2022年卡塔尔世界杯的吉祥物最近在全球火出圈了,并且喜提中国网友给予的爱称"饺子皮"."馄饨皮"(官方名字:拉伊卜,意为"技艺高超的球员" ...
- ORACLE 创建只读用户
create user cxuser01 identified by test123 default tablespace USERS temporary tablespace TEMP; --创建 ...
- IntelliJ IDEA 生成serialVersionUID
1.设置Settings-->Editor->Inspections 2.实现Serializble
- Apache 基本配置 代理 重定向 跨域 https ssl证书 在windows下常用命令
官网下载地址 https://httpd.apache.org/ => https://httpd.apache.org/docs/current/platform/windows.html#d ...