当前位置: 首页 > 编程日记 > 正文

样式集(六)仿微信通讯录样式

效果图:

这里有引用到 自定义底部导航,自定义底部导航组件链接

<!--pages/chatList/chatList.wxml--><!-- <include src="/components/common/common" /> -->
<view class="top"><view class="pageTitle">通讯录</view><view class=" search_arr"><icon class="searchcion" catchtap="searchcion" size='16' type='search'></icon><input class="" bindinput="input_p" placeholder="请输入关键字" value="{{searchValue}}" /></view>
</view><view class="user_list" wx:if='{{list.length>0}}'><view wx:for='{{list}}' wx:key="index" class="item p_r" catchtap="nav_chat" data-item="{{item}}"><image class="head" catchtap="previewImage" data-img="{{item.shanghu?item.b_img:item.a_img}}" src="{{item.shanghu?item.b_img:item.a_img}}"></image><view class="num" wx:if='{{item.shanghu&&item.a_unreadMsgNum>0}}'>{{item.a_unreadMsgNum}}</view><view class="num" wx:if='{{!item.shanghu&&item.b_unreadMsgNum>0}}'>{{item.b_unreadMsgNum}}</view><view class="loc">{{item.shanghu?item.b_loc:item.a_loc}}</view><view class="userName"><view>{{item.shanghu?item.b_name:item.a_name}}</view><view class="chatTxt">{{item.msgList.length>0?item.msgList[item.msgList.length-1].txt:''}}<text class="date">{{item.date}}</text></view></view></view>
</view>
<view wx:if='{{list.length==0}}' class="no_msg">您还没有私聊好友</view><view class="tab_num" wx:if='{{tab_num>0}}'>{{tab_num}}</view>
<my_tab></my_tab>
const db = wx.cloud.database()
const _ = db.command;
var app =getApp();
var that = "";function compare(prop) {return function (obj1, obj2) {var val1 = obj1[prop];var val2 = obj2[prop];if (val1 < val2) {return -1;} else if (val1 > val2) {return 1;} else {return 0;}}
}
// 数组去重
function arrayUnique2(arr, name) {var hash = {};return arr.reduce(function (item, next) {hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);return item;}, []);
}
Page({data: {isEndOfList: false,is_guanfang: false,list: [],connectemoji: ['😊', '😅', '😲', '😭', '😂', '😄', '😩', '😞', '😵', '😒', '😍','😤', '😜', '😝', '😋', '😘', '😚', '😷', '😳', '😃', '😆', '😁', '😢', '😨','😠', '😣', '😌', '😖', '😔', '😰', '😱', '😪', '😏', '😓', '👍', '👎', '🔥', '🌹', '[發]', '❔', '🤝'],emoji_list: ['emoji1i1', 'emoji2i2', 'emoji3i3', 'emoji4i4', 'emoji5i5', 'emoji6i6', 'emoji7i7', 'emoji8i8', 'emoji9i9', 'emoji10i10', 'emoji11i11', 'emoji12i12', 'emoji13i13', 'emoji14i14', 'emoji15i15', 'emoji16i16', 'emoji17i17', 'emoji18i18', 'emoji19i19', 'emoji20i20', 'emoji21i21', 'emoji22i22', 'emoji23i23', 'emoji24i24', 'emoji25i25', 'emoji26i26', 'emoji27i27', 'emoji28i28', 'emoji29i29', 'emoji30i30', 'emoji31i31', 'emoji32i32', 'emoji33i33', 'emoji34i34', 'emoji35i35', 'emoji36i36', 'emoji37i37', 'emoji38i38', 'emoji39i39', 'emoji40i40', 'emoji41i41'],limit: 20 //每次拉取数量},previewImage: function (e) {console.log(e.currentTarget.dataset.img)wx.previewImage({current: e.currentTarget.dataset.img, // 当前显示图片的http链接 urls: [e.currentTarget.dataset.img] // 需要预览的图片http链接列表 })},onUnload: function (options) {getApp().page.onUnload(this);},getArr() {// console.log('=========')wx.cloud.callFunction({name: 'getFriends', // 对应云函数名data: {},success: res => {// console.log('-------',res)var list = res.result.data;list = arrayUnique2(list, '_id')// console.log('list2222222',list)var arr = list.sort(compare("newTime")).reverse()var tab_num = 0;arr.forEach(item => {// if(item.a_unreadMsgNum>0){//   tab_num= tab_num + item.a_unreadMsgNum// }if (item.b_unreadMsgNum > 0) {tab_num = tab_num + item.b_unreadMsgNum}})for (var i = 0; i < arr[0].msgList.length; i++) {for (let j = 0; j < that.data.connectemoji.length; j++) {try {arr[0].msgList[i].txt = arr[0].msgList[i].txt.replace(new RegExp(that.data.emoji_list[j], 'g'), that.data.connectemoji[j])} catch (ere) {}}}if (tab_num > that.data.tab_num) {getApp().paly()}this.setData({tab_num,list: arr,isEndOfList: true}, () => {setTimeout(() => {this.getArr()}, 3000);})}})},add_guanfang() {returnvar store = wx.getStorageSync('STORE')var my = wx.getStorageSync('USER_INFO')var date = new Date().getTime()let data = {a: "154",a_img: store.service,a_name: '家居博览会',a_loc: store.address || '石家庄',b: my.id,b_img: my.avatar_url,b_name: my.nickname,date,msgList: []}getApp().DB.collection('friends').add({data: data,success: function (res) {console.log('添加官方为好友--------', res, data)res.data.forEach(item => {if (item.a == wx.getStorageSync('mch_id')) {item.shanghu = true}})that.setData({list: [...that.data.list, ...res.data], //合并数据isEndOfList: true,is_guanfang: true})}})},getTAB: function () {console.log('监听')if (!wx.getStorageSync('USER_INFO')) return;var whereData = {}if (wx.getStorageSync('mch_id')) {whereData = [{a: wx.getStorageSync('mch_id') + ''},{b: wx.getStorageSync('USER_INFO').id}]} else {whereData = [{b: wx.getStorageSync('USER_INFO').id}]}getApp().DB.collection('friends').where(_.or(whereData)).watch({onChange: function (res) {// console.log('监听函数', res.docs)res.data = res.docs;if (!res.data || res.data.length == 0) {return}res.data.forEach(item => {if (item.a == wx.getStorageSync('mch_id')) {item.shanghu = true}})var list = res.data;// var list = [...that.data.list, ...res.data];list = arrayUnique2(list, '_id').reverse()var arr = list.sort(compare("newTime")).reverse()var tab_num = 0;arr.forEach(item => {if (item.shanghu && item.a_unreadMsgNum > 0) {tab_num = tab_num + item.a_unreadMsgNum}if (!item.shanghu && item.b_unreadMsgNum > 0) {tab_num = tab_num + item.b_unreadMsgNum}})for (var i = 0; i < arr[0].msgList.length; i++) {for (let j = 0; j < that.data.connectemoji.length; j++) {try {arr[0].msgList[i].txt = arr[0].msgList[i].txt.replace(new RegExp(that.data.emoji_list[j], 'g'), that.data.connectemoji[j])} catch (ere) {}}}// console.log('list11111111', list)if (tab_num > that.data.tab_num) {getApp().paly()}that.setData({tab_num,list: arr, //合并数据})},onError: function (err) {console.error('----------------error', err)}})},getData: function () {console.log('----------', wx.getStorageSync('mch_id'), wx.getStorageSync('USER_INFO').id)if (wx.getStorageSync('mch_id')) {console.log('----------222', wx.getStorageSync('mch_id'), wx.getStorageSync('USER_INFO').id)getApp().DB.collection('friends').where(_.or([{a: wx.getStorageSync('mch_id') + ''},{b: wx.getStorageSync('USER_INFO').id}])).get()// db.collection("friends")//   .where({_id: _.neq(1)})//   .skip(this.data.list.length)//   .limit(this.data.limit)//   .get().then(res => {console.log('我的好友', res.data)if (res.data.length == 0) {return}res.data.forEach(item => {if (item.a == wx.getStorageSync('mch_id')) {item.shanghu = true}})var list = [...this.data.list, ...res.data];list = arrayUnique2(list, '_id')var arr = list.sort(compare("newTime")).reverse()var tab_num = 0;arr.forEach(item => {//2.if包含数字,判断数据长度是否为11if (app.getNum(item.naa_nameme).length == 11) {//3.截取所有数字,并用*替换4,4var phNum = app.getNum(item.a_name);var phnumAfter = phNum.substr(0, 9) + "**";// phnumAfter = phNum.substr(0,3) + "****" + phNum.substr(7);//4.替换输出item.a_name = item.a_name.replace(phNum, phnumAfter);console.log('结果', item.a_name) //结果 为sd135****9471中}console.log('list2222222', item)if (item.shanghu && item.a_unreadMsgNum > 0) {tab_num = tab_num + item.a_unreadMsgNum}if (!item.shanghu && item.b_unreadMsgNum > 0) {tab_num = tab_num + item.b_unreadMsgNum}})for (var i = 0; i < arr[0].msgList.length; i++) {for (let j = 0; j < that.data.connectemoji.length; j++) {try {arr[0].msgList[i].txt = arr[0].msgList[i].txt.replace(new RegExp(that.data.emoji_list[j], 'g'), that.data.connectemoji[j])} catch (ere) {}}}if (tab_num > that.data.tab_num) {getApp().paly()}this.setData({tab_num,list: arr, //合并数据isEndOfList: res.data.length < this.data.limit ? true : false //判断是否结束})})} else {if (!wx.getStorageSync('USER_INFO')) {return}getApp().DB.collection('friends').where({b: wx.getStorageSync('USER_INFO').id}).get()// db.collection("friends")//   .where({_id: _.neq(1)})//   .skip(this.data.list.length)//   .limit(this.data.limit)//   .get().then(res => {console.log('我的好友', res.data)if (res.data.length == 0) {return}res.data.forEach(item => {if (item.a == wx.getStorageSync('mch_id')) {item.shanghu = true}})var list = [...this.data.list, ...res.data];list = arrayUnique2(list, '_id')this.setData({list: list, //合并数据isEndOfList: res.data.length < this.data.limit ? true : false //判断是否结束})})}},input_p(e) {console.log(e.detail.value)this.setData({inputVal: e.detail.value})},searchcion() {console.log('搜索', this.data.inputVal)if (this.data.inputVal) {var that = thisconst db = wx.cloud.database()const scol = db.collection("friends")scol.where({a_name: {$regex: '.*' + this.data.inputVal + '.*',$options: '1'}}).get({success: res => {console.log('匹配', res)if (res.data.length == 0) {wx.showModal({title: '提示',content: '抱歉,找不到该用户',showCancel: false,success: function (res) {}})return;} else {that.setData({list: res.data})}}})}},nav_chat(e) {var item = e.currentTarget.dataset.item;wx.setStorageSync('chat_item', item)wx.navigateTo({url: '../chat/chat',})},onShow() {wx.setStorageSync('myTab', 2)this.getTAB()},onLoad: function (options) {that = thisgetApp().page.onLoad(this, options);if (options.chat_id) {getApp().DB.collection('friends').doc(options.chat_id).get().then(res => {console.log('========', res.data)wx.setStorageSync('chat_item', res.data)wx.navigateTo({url: '/pages/chat/chat'})})return}if (wx.getStorageSync('USER_INFO') && wx.getStorageSync('USER_INFO').id == 162) {this.getArr()} else {this.getData()}},onReachBottom: function () {!this.data.isEndOfList && this.getData()}
})
/* pages/chatList/chatList.wxss */
page {background-color: #EDEDED;
}.top {position: fixed;top: 0;z-index: 2;width: 100%;background-color: #EDEDED;
}.pageTitle {padding-top: 60rpx;padding-left: 20rpx;height: 140rpx;color: black;font-size: 36rpx;background-color: #EDEDED;
}.searchcion {margin: 16rpx 10rpx 10rpx 10rpx;position: absolute;right: 15rpx;z-index: 992;width: 20px;height: 20px;text-align: center;
}.search_arr {border: 1px solid #d0d0d0;background-color: #EDEDED;border-radius: 50rpx;margin-left: 30rpx;position: fixed;width: 40%;top: 54rpx;left: 200rpx;
}.search_arr input {margin-left: 20rpx;height: 60rpx;border-radius: 5px;
}swiper {position: fixed;width: 100%;
}.swiper-item {width: 100%;height: 300rpx;
}.item {position: relative;margin-bottom: 20rpx;
}.head {width: 90rpx;height: 90rpx;border-radius: 10rpx;margin: 16rpx;
}.num {position: absolute;top: 4rpx;left: 100rpx;width: 40rpx;height: 40rpx;line-height: 40rpx;font-size: 26rpx;background-color: red;color: white;text-align: center;border-radius: 50%;
}.user_list {position: relative;top: 140rpx;padding: 20rpx 0 20rpx;background-color: white;padding-bottom: 100rpx;
}.chatTxt {font-size: 26rpx;color: #999;
}.date {margin-left: 40rpx;
}.userName {margin-left: 20rpx;border-bottom: 0.5rpx solid #f3f3f3;width: 62%;color: black;font-weight: normal;font-size: 32rpx;margin-top: 12rpx;padding-bottom: 10rpx;}.no_msg {position: absolute;top: 500rpx;text-align: center;width: 100%;}.loc {position: absolute;right: 40rpx;max-width: 200rpx;top: 40rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
}
{"navigationStyle": "custom","usingComponents": {"my_tab": "../Component/my_tab"}
}

相关文章:

WCF动态添加ServiceKnownType

WCF中传输自定义类型时&#xff0c;必须在服务接口类&#xff08;服务协定&#xff09;上加上ServiceKnownType(typeof(yourClass)), 在实际应用中比较麻烦&#xff0c;可以用动态的办法来实现动态添加。 服务接口类&#xff0c;加上一行 [ServiceKnownType("GetKnownType…

博客 rss 如何使用_如何使用RSS从您的GatsbyJS博客自动交叉发布

博客 rss 如何使用With the recent exodus from Medium many developers are now creating their own GatsbyJS Blogs and then cross-posting to Medium or publications like freecodecamp.org and dev.to.随着Medium最近的离职&#xff0c;许多开发人员现在正在创建自己的Ga…

大型技术网站的技术( 高并发、大数据、高可用、分布式....)(一)

面对高并发、大流量、高可用、海量数据、用户分布广泛、网络情况复杂这类网站系统我们如何应对&#xff1f;&#xff1f;&#xff1f; 第一阶段 一台服务器不行就上多台服务器 1.应用程序与数据服务分离 将应用程序、数据库、文件等资源放在一台服务器上&#xff0c;面对海量…

BestCoder Round #65 B C D || HDU 5591 5592 5593

B 题意&#xff1a;ZYB在远足中,和同学们玩了一个“数字炸弹”游戏&#xff1a;由主持人心里想一个在[1,N][1,N]中的数字XX&#xff0c;然后玩家们轮流猜一个数字&#xff0c;如果一个玩家恰好猜中XX则算负&#xff0c;否则主持人将告诉全场的人当前的数和XX比是偏大还是偏小&a…

数组去重,ES6数组去重 new Set()

普通数组去重 var b [...new Set([1,2, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果&#xff1a; 包含对象的数组去重 var o {a:1}var b [...new Set([o, o, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果&#xff1a; 包含对象的数组去重有一个坑 var b [...new Set([{…

使用angular的好处_在项目中使用Angular的最大好处

使用angular的好处by Irina Sidorenko伊琳娜西多连科(Irina Sidorenko) 在项目中使用Angular的最大好处 (The top benefits of using Angular for your project) 在项目实施中使用Angular的11个理由及其好处 (11 reasons to use Angular and its benefits for your project im…

python之路——模块和包

一、模块 1、什么是模块&#xff1f; 常见的场景&#xff1a;一个模块就是一个包含了Python定义和声明的文件&#xff0c;文件名就是模块名字加上.py的后缀。 但其实import加载的模块分为四个通用类别&#xff1a; 1、使用Python编写的代码&#xff08;.py文件&#xff09; 2、…

夺命雷公狗---linux NO:3 centos_mini版的安装和备份

废话不多说&#xff0c;和前面的其实是差不多的&#xff0c;如下图所示&#xff1a; 安装其实是和桌面版的差不多的&#xff0c;但是经典版的不能自定义分区&#xff08;如详细区&#xff0c;如home之类的&#xff09;。。。 因为我们使用的是命令行方式的所以直接选英文&#…

快速学习 async await 的使用, Demo 解析

async 和 await 字面都很好理解&#xff0c;分别是异步和等待。 来两个简单的 demo&#xff0c; demo1 tt2(){return new Promise(rps>{setTimeout(() > {rps(true)}, 1500);})},async tt1(){var a await this.tt2();console.log(a)},/*** 生命周期函数--监听页面加载*…

小型工作室创业项目_为什么新开发人员应该在小型创业公司工作

小型工作室创业项目In my first year of working in the industry (6 months as an intern, 6 months as a full-time employee), I worked at startups that were less than 10 people large. I was one of the only 2 or 3 developers, and usually one of the first. Throug…

head first python菜鸟学习笔记(第六章)

1. Python提供字典&#xff0c;允许有效组织数据&#xff0c;将数据与名关联&#xff0c;从而实现快速查找&#xff0c;而不是以数字关联。 字典是内置数据结构&#xff0c;允许将数据与键而不是数字关联。这样可以使内存中的数据与实际数据的结构保持一致。&#xff1f;&#…

小程序聊天室开发,发送文字,表情,图片,音频,视频,即时通讯,快速部署,可定制开发

效果图&#xff1a; 微信小程序聊天功能模块&#xff0c;现在已经支持发送图片&#xff0c;文字&#xff0c;音频&#xff0c;视频&#xff0c;表情&#xff0c;在线即时聊天啦。 需要做的可以联系我微信。13977284413 上代码&#xff1a; <view class"bo">…

常用浏览器插件

modify headers &#xff1a;firefox的IP伪造插件 httpRequester&#xff1a;firefox的模拟http请求插件JSON-handle&#xff1a;chrome格式化json插件firebug&#xff1a;firefox查看http请求工具firepath&#xff1a;firefox中获取元素路径转载于:https://www.cnblogs.com/xx…

编码中统一更该变量的快捷键_更多项目想法,以提高您的编码技能

编码中统一更该变量的快捷键Two weeks ago I published an article containing 15 project ideas that you can build to level up your coding skills, and people were very excited about that resource.两周前&#xff0c;我发表了一篇文章&#xff0c;其中包含15个项目构想…

My97DatePicker日历控件日报、每周和每月的选择

My97DatePicker日历控件日报、每周和每月的选择 1、设计源代码 <% page language"java" import"java.util.*" pageEncoding"UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><h…

DotNet Core Console 程序使用NLog

参考&#xff1a;https://github.com/NLog/NLog/wiki/Tutorial 步骤&#xff1a; 1. 使用Nuget安装NLog.Extensions.Logging Install-Package NLog.Extensions.Logging 2.编写代码&#xff08;到这步运行代码&#xff0c;不报错&#xff0c;但是也不会有log输出&#xff0c;因为…

小程序判断用户在线状态

在页面的两个生命周期组件里面 onShow() {console.log(-----上线线)let info wx.getStorageSync(chat_item)DB.collection(friends).where({_id: info._id}).get().then(res > {console.log(-----, res)if (res.data[0].a wx.getStorageSync(userInfo)._openid) {console.…

react.js做小程序_如何使用React.js构建现代的聊天应用程序

react.js做小程序In this tutorial, I will guide you to build your own group chat application using React, React Router, and CometChat Pro. Yes, rather than roll out our own server, we will instead use CometChat Pro to handle the real-time sending and receiv…

RAP Mock.js语法规范

Mock.js 的语法规范包括两部分&#xff1a; 数据模板定义规范&#xff08;Data Template Definition&#xff0c;DTD&#xff09;数据占位符定义规范&#xff08;Data Placeholder Definition&#xff0c;DPD&#xff09;1.数据模板定义规范 DTD 数据模板中的每个属性由 3 部分…

NSDictionary、NSMutableDictionary基本使用

郝萌主倾心贡献&#xff0c;尊重作者的劳动成果。请勿转载。假设文章对您有所帮助&#xff0c;欢迎给作者捐赠&#xff0c;支持郝萌主&#xff0c;捐赠数额任意&#xff0c;重在心意^_^ 我要捐赠: 点击捐赠Cocos2d-X源代码下载&#xff1a;点我传送游戏官方下载&#xff1a;htt…

h5轮播图及效果图

效果图&#xff1a; 代码&#xff1a; <!doctype html> <html><head><meta charset"utf-8"><title>jQuery响应式卡片轮播切换代码</title><link rel"stylesheet" type"text/css" href"css/style.c…

性能测试回归测试_自动网站性能回归测试

性能测试回归测试by Adam Henson亚当汉森(Adam Henson) 如何使用Foo自动执行网站性能回归测试 (How to automate website performance regression testing with Foo) 使用部署后步骤自动执行连续交付工作流程中的性能回归测试 (Using a post deploy step to automate performa…

【html】【13】特效篇--下拉导航

html代码&#xff1a; 1 <!DOCTYPE html>2 <html>3 <head>4 <meta http-equiv"Content-Type" content"text/html; charsetUTF-8">5 <title>Bootstrap导航条鼠标悬停下拉菜单</title>6 <li…

小程序获取用户所在城市完整代码

小程序目录结构 插入提示: 1. 申请开发者密钥&#xff08;key&#xff09;&#xff1a; 申请密钥 2. 下载微信小程序JavaScriptSDK&#xff0c;下载地址 下载完成后放入utils文件夹下引用即可 3. 安全域名设置&#xff0c;在“设置” -> “开发设置”中设置req…

prolog_如何通过观看权力的游戏学习Prolog

prologby Rachel Wiles瑞秋威尔斯(Rachel Wiles) 如何通过观看权力的游戏学习Prolog (How to learn Prolog by watching Game of Thrones) 他们死了吗&#xff1f; 他们还活着吗&#xff1f; 她是他的姨妈吗&#xff1f; 不用把精力浪费在2011年&#xff0c;而可以使用Prolog节…

身份证号码对应地区-官方措辞:行政区划代码

身份证前6位代表着该身份证的籍贯在哪里&#xff0c;而官方的措辞则为&#xff1a;行政区划代码 如何找到最新的行政区划代码了&#xff1f; 通过&#xff1a;http://blog.sina.com.cn/s/blog_5a76dae20100tqv5.html 此人的博客得知&#xff0c;行政区划代码是国家统计局统计的…

Jquery_操作cookies

首先引入jquery.cookie.js jquery.cookie.js下地址&#xff1a;http://plugins.jquery.com/cookie/ 操作文档&#xff1a; https://github.com/carhartl/jquery-cookie#readme 创建cookies&#xff1a; $.cookie(name, value); 设置有效期&#xff1a; 设置七天过期 $.cookie(n…

rem转rpx工具

对样式进行格式化&#xff0c;然后根据 “rem” 进行拆分&#xff0c;这样就会拆分成一个数组 [str1,str2,str3...,str6], 除了最后一个元素&#xff0c;前边的元素都会以 “rem” 样式的数值结尾&#xff0c; 然后在对数组中的元素字符串进行再次根据 “&#xff1a;” 进行…

colab中的变量怎么读取_Fizyr Retinanet在Colab中进行目标检测

colab中的变量怎么读取by RomRoc由RomRoc 带有Fizyr Retinanet的Google Colab中的对象检测 (Object Detection in Google Colab with Fizyr Retinanet) Let’s continue our journey to explore the best machine learning frameworks in computer vision.让我们继续我们的旅程…

c++重载(以运算符重载为主)

重载&#xff08;OverLoading&#xff09;是面向对象程序设计多态性的一种体现。所谓重载&#xff0c;是指“同一标识符”在同一作用域的不同场合具有不同的语义&#xff0c;这个标识符可以是函数名或运算符。也就是说&#xff0c;重载可以使多个函数使用同一个函数名&#xff…