Taro+react仿微信app聊天室|taro仿微信界面|taro聊天/朋友圈

article/2025/9/22 6:10:40

基于Taro+react+redux+RN+taroPop等技术开发的跨端聊天App实例,支持编译到多端H5+小程序+RN端,界面仿制微信聊天界面,实现了消息发送、表情、图片预览、长按菜单、红包、朋友圈等功能。

Taro三端统一聊天应用:taro-chatroom (仿微信界面聊天App)

技术栈:

  • 编码/技术:Vscode / react+taro+react-redux+ReactNative
  • 字体图标:阿里iconfont字体图标库
  • 自定义顶部导航条 + 底部Tabbar
  • 弹窗组件:taroPop(taro封装自定义模态框)
  • 支持编译:H5端 + 小程序 + App端

为了展示更丰富的导航条功能,顶部导航栏和底部Tabbar均采用自定义模式,且测试兼容三端。

具体介绍可看看这篇:Taro+react自定义顶部导航 + tabbar菜单

另外项目中用到的弹窗效果也是基于taro自定义Modal实现,可参看:taro自定义对话框

入口页面App.jsx

项目中使用redux进行状态管理,具体用法和react里面一样。

yarn add redux redux-thunk @tarojs/redux
import Taro, { Component } from '@tarojs/taro'
import Index from './pages/index'// 引入状态管理redux
import { Provider } from '@tarojs/redux'
import { store } from './store'// 引入样式
import './app.scss'
import './styles/fonts/iconfont.css'
import './styles/reset.scss'class App extends Component {config = {pages: ['pages/auth/login/index','pages/auth/register/index','pages/index/index',...],window: {backgroundTextStyle: 'light',navigationBarBackgroundColor: '#fff',navigationBarTitleText: 'TaroChat',navigationBarTextStyle: 'black',navigationStyle: 'custom'}}// 在 App 类中的 render() 函数没有实际作用// 请勿修改此函数render () {return (<Provider store={store}><Index /></Provider>)}
}Taro.render(<App />, document.getElementById('app'))

登录/注册验证模块

taro中表单操作、redux状态管理及本地存储实现

<View className="taro__container flexDC bg-eef1f5"><Navigation background='#eef1f5' fixed /><ScrollView className="taro__scrollview flex1" scrollY><View className="auth-lgreg">{/* logo */}<View className="auth-lgreg__slogan"><View className="auth-lgreg__slogan-logo"><Image className="auth-lgreg__slogan-logo__img" src={require('../../../assets/taro.png')} mode="aspectFit" /></View><Text className="auth-lgreg__slogan-text">欢迎来到Taro-Chatroom</Text></View>{/* 表单 */}<View className="auth-lgreg__forms"><View className="auth-lgreg__forms-wrap"><View className="auth-lgreg__forms-item"><Input className="auth-lgreg__forms-iptxt flex1" placeholder="请输入手机号/昵称" onInput={this.handleInput.bind(this, 'tel')} /></View><View className="auth-lgreg__forms-item"><Input className="auth-lgreg__forms-iptxt flex1" placeholder="请输入密码" password onInput={this.handleInput.bind(this, 'pwd')} /></View></View><View className="auth-lgreg__forms-action"><TouchView onClick={this.handleSubmit}><Text className="auth-lgreg__forms-action__btn">登录</Text></TouchView></View><View className="auth-lgreg__forms-link"><Text className="auth-lgreg__forms-link__nav">忘记密码</Text><Text className="auth-lgreg__forms-link__nav" onClick={this.GoToRegister}>注册账号</Text></View></View></View></ScrollView><TaroPop ref="taroPop" />
</View>
/*** @tpl 登录模块*/import Taro from '@tarojs/taro'
import { View, Text, ScrollView, Image, Input, Button } from '@tarojs/components'import './index.scss'import { connect } from '@tarojs/redux'
import * as actions from '../../../store/action'...class Login extends Taro.Component {config = {navigationBarTitleText: '登录'}constructor(props) {super(props)this.state = {tel: '',pwd: '',}}componentWillMount() {// 判断是否登录storage.get('hasLogin').then(res => {if(res && res.hasLogin) {Taro.navigateTo({url: '/pages/index/index'})}})}// 提交表单handleSubmit = () => {let taroPop = this.refs.taroPoplet { tel, pwd } = this.stateif(!tel) {taroPop.show({content: '手机号不能为空', time: 2})}else if(!util.checkTel(tel)) {taroPop.show({content: '手机号格式有误', time: 2})}else if(!pwd) {taroPop.show({content: '密码不能为空', time: 2})}else {// ...接口数据...storage.set('hasLogin', { hasLogin: true })storage.set('user', { username: tel })storage.set('token', { token: util.setToken() })taroPop.show({skin: 'toast',content: '登录成功',icon: 'success',time: 2})...}}render () {...}
}const mapStateToProps = (state) => {return {...state.auth}
}export default connect(mapStateToProps, {...actions
})(Login)

项目开发中,尤其需要注意RN端样式问题,对于一些兼容处理,不希望编译到RN端,则可通过如下实现

/*postcss-pxtransform rn eject enable*//*postcss-pxtransform rn eject disable*/
/*** RN 不支持针对某一边设置 style,即 border-bottom-style 会报错* 那么 border-bottom: 1px 就需要写成如下形式: border: 0 style color; border-bottom-width: 1px;*/
@mixin border($dir, $width, $style, $color) {border: 0 $style $color;@each $d in $dir {#{border-#{$d}-width}: $width;}
}/*** NOTE RN 无法通过 text-overflow 实现省略号,这些代码不会编译到 RN 中*/
@mixin ellipsis {/*postcss-pxtransform rn eject enable*/overflow: hidden; white-space: nowrap; text-overflow: ellipsis;/*postcss-pxtransform rn eject disable*/
}/*** NOTE 实现多行文本省略,RN 用 Text 标签的 numberOfLines={2},H5/小程序用 -webkit-line-clamp*/
@mixin clamp($line) {/*postcss-pxtransform rn eject enable*/display: -webkit-box;overflow: hidden;-webkit-line-clamp:$line;/* autoprefixer: ignore next */-webkit-box-orient: vertical;/*postcss-pxtransform rn eject disable*/
}/*** 对于不能打包到 RN 的样式,可以用 postcss 方式引入*/@mixin eject($attr, $value) {/*postcss-pxtransform rn eject enable*/#{$attr}: $value;/*postcss-pxtransform rn eject disable*/
}

聊天时发送消息滚动到最底部,则需要进行兼容处理,因为ReactNative端不支持createSelectorQuery

componentDidMount() {if(process.env.TARO_ENV === 'rn') {this.scrollMsgBottomRN()}else {this.scrollMsgBottom()}
}
// 滚动至聊天底部
scrollMsgBottom = () => {let query = Taro.createSelectorQuery()query.select('#scrollview').boundingClientRect()query.select('#msglistview').boundingClientRect()query.exec((res) => {// console.log(res)if(res[1].height > res[0].height) {this.setState({ scrollTop: res[1].height - res[0].height })}})
}
scrollMsgBottomRN = (t) => {let that = thisthis._timer = setTimeout(() => {that.refs.ScrollViewRN.scrollToEnd({animated: false})}, t ? 16 : 0)
}

另外聊天表情使用emoj表情符,这个实现比较简单,就不介绍了。

...// 点击聊天消息区域
msgPanelClicked = () => {if(!this.state.showFootToolbar) returnthis.setState({ showFootToolbar: false })
}// 表情、选择区切换
swtEmojChooseView = (index) => {this.setState({ showFootToolbar: true, showFootViewIndex: index })
}// 底部表情tab切换
swtEmojTab = (index) => {let lists = this.state.emotionJsonfor(var i = 0, len = lists.length; i < len; i++) {lists[i].selected = false}lists[index].selected = truethis.setState({ emotionJson: lists })
}/* >>> 【编辑器/表情处理模块】------------------------------------- */
bindEditorInput = (e) => {this.setState({editorText: e.detail.value,editorLastCursor: e.detail.cursor})
}
bindEditorFocus = (e) => {this.setState({ editorLastCursor: e.detail.cursor })
}
bindEditorBlur = (e) => {this.setState({ editorLastCursor: e.detail.cursor })
}handleEmotionTaped = (emoj) => {if(emoj == 'del') return// 在光标处插入表情let { editorText, editorLastCursor } = this.statelet lastCursor = editorLastCursor ? editorLastCursor : editorText.lengthlet startStr = editorText.substr(0, lastCursor)let endStr = editorText.substr(lastCursor)this.setState({editorText: startStr + `${emoj} ` + endStr})
}...

好了,到这里taro开发聊天app的分享介绍就差不多了,希望能有些帮助!!

最后附上两个基于vue开发的实例项目

vue网页端聊天:https://blog.csdn.net/yanxinyun1990/article/details/89735778

vue+uniapp仿抖音小视频:https://blog.csdn.net/yanxinyun1990/article/details/103012086

 


http://chatgpt.dhexx.cn/article/WwRvuTgq.shtml

相关文章

android机器人聊天软件,虚拟男友聊天机器人

虚拟男友聊天机器人是一款能为大家提供专业的虚拟聊天软件&#xff0c;在这里大家可以设定一个符合自己心意的男友&#xff0c;让你们之间的对话是充满了甜蜜&#xff0c;并且还可以自己设定回复方式&#xff0c;对话也是十分的轻松愉悦&#xff0c;快来下载虚拟男友聊天机器人…

uniapp开发即时通讯聊天app,纯nvue仿微信,前后端开源

github地址&#xff1a;GitHub - guipie/GpChat: uniapp开发的纯nvue的即时聊天通讯App。 gitee&#xff1a;https://gitee.com/chenwei_zq/GpChat uniapp开发的纯nvue的即时聊天通讯App。 后台采用.net6,一套解决方案&#xff0c;分布式部署。 App采用uniapp的纯nvue&#x…

使用dialogflow和firebase构建whatsapp聊天机器人的指南

ChatBots are conversational agents, programs capable of conducting a conversation with an Internet user. In this tutorial I’ll walk you through an implementation of WhatsApp chatbot using Twilio platform. ChatBots是对话代理&#xff0c;是能够与Internet用户…

【uni-app】uni-app实现聊天页面功能(小程序)——布局篇

文章目录 前言划分区域问题内容溢出关于调试聊天框 代码实现 前言 在工作中使用uni-app参与开发一个小程序&#xff0c;其中要写一个简单的聊天页面&#xff0c;虽然功能不多&#xff08;只有一个发送文字的功能&#xff09;&#xff0c;但是其中的细节比较多&#xff0c;也踩…

如何搜索WhatsApp聊天消息

Trying to find a specific message in your huge WhatsApp chat log? There are two ways to search, so you can find what you’re looking for quickly. 试图在庞大的WhatsApp聊天日志中查找特定消息&#xff1f; 有两种搜索方式&#xff0c;因此您可以快速找到要查找的内…

【uni-app】uni-app实现聊天页面功能——功能篇(下)

目录 前言一、聊天框随键盘抬起思路代码实现 二、聊天消息列表随着聊天框的增高而滚动到最底部思路 三、问题完整代码实现总结 前言 前面我有写关于如何进行聊天页面布局和实现聊天消息滚动到最底部的文章。 【uni-app】uni-app实现聊天页面功能——功能篇&#xff08;上&…

如何将 WhatsApp 聊天添加到您的网站

WhatsApp是全球最受欢迎的消息传递应用程序。平台上有超过 2 亿活跃用户与朋友、家人和企业进行交流。对于企业而言&#xff0c;WhatsApp 是与客户进行个人、可访问和非正式对话的理想渠道。 要将 WhatsApp 作为渠道引入您的客户旅程&#xff0c;第一步是将 WhatsApp 聊天按钮…

uni-app 即时聊天

项目介绍 前段时间在B站看到了有一个UP主在讲uni-app即时聊天的项目&#xff08;逸刻时光&#xff09;&#xff0c;在看了这个视频之后&#xff0c;感觉还是挺有兴趣的&#xff0c;所以在看他的讲解视频之后&#xff0c;就自己动手写了这个即时聊天项目&#xff0c;在样式方面…

uniapp+nvue实现仿微信App聊天应用 —— 成功实现好友聊天+语音视频通话功能

基于uniapp nvue实现的uniapp仿微信App聊天应用 txim 实例项目&#xff0c;实现了以下功能。 1: 聊天会话管理 2: 好友列表 3: 文字、语音、视频、表情、位置等聊天消息收发 4: 一对一语音视频在线通话 技术实现 开发环境&#xff1a;HbuilderX nodejs技术框架&#xff…

WhatsApp聊天记录迁移新手机,备份如何找回和删除?

当外贸人更换手机时&#xff0c;面临的第一大问题就是WhatsApp数据迁移的问题。 因为WhatsApp的聊天记录、联系人、图片、视频等&#xff0c;都是与客户息息相关的数据&#xff0c;对外贸人来讲都非常重要&#xff0c;所以一定要确保在换手机过程中不丢失WhatsApp的任何资料。…

[uni-app]聊天App实例

项目简介 基于uni-appvuevuexuniPopswiper等技术开发的仿微信聊天室uniapp-chatroom项目&#xff0c;类似vue及小程序api语法使开发更加方便&#xff0c;实现了发送图文消息、表情(gif动图)&#xff0c;图片预览、地图位置、红包、仿微信朋友圈等功能 效果图 在H5 / 小程序 …

开发社交聊天APP需要注意什么?如何快速开发聊天功能

随着互联网的发展&#xff0c;人们的沟通方式也在悄悄发生变化&#xff0c;由原来的面对面沟通&#xff0c;发展为网上沟通。让大家日常生活的通讯越来越方便了&#xff0c;各种APP层出不穷。那么&#xff0c;想开发一款社交聊天并进行运营&#xff0c;需要注意哪些方面&#x…

比较好用的聊天交友软件?最受年轻人欢迎的APP在这

现在都有哪些比较火,比较好用的聊天交友软件?移动社交是一件越来越普遍的事情&#xff0c;人们可以通过互联网&#xff0c;在社交软件上认识众多的一样的有趣人群&#xff0c;在国内都有哪些**的交友app哪个好??在中国在中国最受年轻人欢迎的APP又有哪些呢? 微信 微信可以…

程序员的时钟/原生抖音罗盘时钟代码分享/ 罗盘文字时钟软件非常火 /文字时钟

原生抖音罗盘时钟代码分享 罗盘文字时钟软件非常火 文字时钟 本站给大家分享这款就是通过原生j来s实现的文字时钟源码&#xff0c;有喜欢的朋友可以下载哦&#xff0c;无需安装&#xff0c;上传访问即可使用 简单实现&#xff1a;https://sucaiip.com/time-302.html

Android实现模拟时钟(简单+漂亮)--时针、分针、秒针

前言 前不久在网上看见Android实现的模拟时钟&#xff0c;感觉十分有意思&#xff0c;这里是地址&#xff1a; http://www.eoeandroid.com/forum.php?modviewthread&tid58324可惜的是这种方式没有 秒表。笔者突然对其有了兴趣&#xff0c;也想去实现以下自己的模拟时钟。折…

网页电子时钟

如图就是一个简易的网页电子时钟&#xff0c;利用Javascript和 html和 css就可以制作 <div class"wrapper"><div class"time-box"><div class"hour"></div><div class"sec"></div></div>&…

时钟啊时钟

效果图 JS /*** color --color 父级定义颜色 css直接使用变量*/ import { useState, useEffect } from react; import styles from ./style.less const index () > {const [time, setTime] useState({hours: 00,minutes: 00,seconds: 00})useEffect(() >{countDown() …

模拟钟表的手机软件_手机时钟软件推荐

下载 生活服务|47.3MB 更新时间&#xff1a;2019-04-04 12:04:18 评分&#xff1a;7 概要&#xff1a;抖音文字云时钟app是一款异常火爆的数字时钟软件&#xff0c;该软件在抖音上已经被众多小伙伴种草了&#xff0c;它拥有非常炫酷的背景&#xff0c;设置安装起来也非常简便&a…

抖音文字时钟壁纸html,抖音文字时钟

抖音文字时钟是一款为最近非常火的珍惜时间打造的钟表&#xff0c;有记录时间的功能也有很强大的警示作用&#xff0c;告诉我们时间的重要性&#xff0c;它有很多的模式可以调节使用&#xff0c;展现出自己喜欢的需要的时钟模式来&#xff0c;有需要的用户们就来这里下载吧。 温…

实现时钟特效

需求&#xff1a; 显示年、月、日、星期和二十四进制的时钟特效&#xff01; 代码&#xff1a; <!DOCTYPE html> <html> <head lang"en"><meta charset"UTF-8"><title>时钟特效</title><style> body{backgrou…