uniapp仿微信--聊天界面模板

该项目演示了如何使用uniapp构建一个仿微信的聊天界面。主要涉及chat.vue组件,包含dateTime.js的时间处理js文件和submit.vue、emoji.vue组件。前端技术栈包括vue.js、typescript和javascript。
摘要由CSDN通过智能技术生成

项目演示

在这里插入图片描述

前言

我是看B站的视频一个一个敲的,讲的还不错。可以去看看vue+node.js即时通讯聊天室APP开发前端篇

主界面

chat.vue

<template>
	<!-- 聊天界面展示https://www.bilibili.com/video/BV1hT4y1P75N?p=22  搭建1和2 -->
	<view class="content">

		<!-- 聊天内容 -->
		<scroll-view class="chat" scroll-y="true" scroll-with-animation="true" :scroll-into-view="scrollToView">
			<view class="chat-main" :style="{paddingBottom:inputh+'px'}">
				<view class="chat-ls" v-for="(item,index) in unshiftmsg" :key="index" :id="'msg'+ index">
					<view class="chat-time" v-if="item.createTime != ''">{
  {changeTime(item.createTime)}}</view>
					<view class="msg-m msg-left" v-if="item.sendName ==  friendName">
						<image class="user-img" src="../../../static/logo.png"></image>
						<view class="message" v-if="item.TextType == 0">
							<!-- 文字 -->
							<view class="msg-text">{
  {item.sendText}}</view>
						</view>
						<view class="message" v-if="item.TextType == 1" @tap="previewImg(item.sendText)">
							<!-- 图像 -->
							<image :src="item.sendText" class="msg-img" mode="widthFix"></image>
						</view>
						<view class="message" v-if="item.TextType == 2" @tap="playVoice(item.sendText.voice)">
							<!-- 音频 -->
							<view class="msg-text voice" :style="{width:item.sendText.time*4+'rpx'}">
								<image src="../../../static/icon/Hotline.png" class="voice-img"></image>
								{
  {item.sendText.time}}″
							</view>
						</view>
						<view class="message" v-if="item.TextType == 3" @tap="openLocation(item.sendText)">
							<!-- 位置 -->
							<view class="msg-map">
								<view class="map-name">{
  {item.sendText.name}}</view>
								<view class="map-address">{
  {item.sendText.address}}</view>
								<!-- 如果map不起作用,就可以直接用一张图片去替代 -->
								<map class="map" :longitude="item.sendText.longitude" :latitude="item.sendText.latitude"
									:markers="covers(item.sendText)"></map>
							</view>
						</view>
					</view>
					<view class="msg-m msg-right" v-if="item.sendName != friendName">
						<image class="user-img" src="../../../static/logo.png"></image>
						<view class="message" v-if="item.TextType == 0">
							<view class="msg-text">{
  {item.sendText}}</view>
						</view>
						<view class="message" v-if="item.TextType == 1" @tap="previewImg(item.sendText)">
							<image :src="item.sendText" class="msg-img" mode="widthFix"></image>
						</view>
						<view class="message" v-if="item.TextType == 2" @tap="playVoice(item.sendText.voice)">
							<!-- 音频 -->
							<view class="msg-text voice" :style="{width:item.sendText.time*4+'rpx'}">
								{
  {item.sendText.time}}″
								<image src="../../../static/icon/Hotline.png" class="voice-img"></image>
							</view>
						</view>
						<view class="message" v-if="item.TextType == 3" @tap="openLocation(item.sendText)">
							<!-- 位置 -->
							<view class="msg-map">
								<view class="map-name">{
  {item.sendText.name}}</view>
								<view class="map-address">{
  {item.sendText.address}}</view>
								<map class="map" :longitude="item.sendText.longitude" :latitude="item.sendText.latitude"
									:markers="covers(item.sendText)"></map>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<submit @inputs="inputs" @heights="heights"></submit>
	</view>
</template>

<script>
	import dateTime from '../../../common/dateTime.js';
	import submit from '../../../components/submit/submit.vue';

	
	//音频播放
	const innerAudioContext = uni.createInnerAudioContext();

	export default {
		data() {
			return {
				friendName: "xpq",
				msg: [{
						"sendName": "xpq",
						"receviceName": "゛时光い",
						"sendText": {
							"address": "湖南省岳阳市湘阴县新世纪大道",
							"latitude": 28.68925,
							"longitude": 112.90917,
							"name": "湘阴县政府(新世纪大道北)",
						},
						"createTime": "2022-01-06 12:40:12",
						"updateTime": null,
						"chatmState": 1,
						"TextType": 3
					}, {
						"sendName": "゛时光い",
						"receviceName": "xpq",
						"sendText": {
							"voice": "时光匆匆流过",
							"time": 2 //秒
						},
						"createTime": "2022-01-06 12:22:12",
						"updateTime": null,
						"chatmState": 1,
						"TextType": 2
					}, {
						"sendName": "xpq",
						"receviceName": "゛时光い",
						"sendText": {
							"voice": "谢谢你",
							"time": 60 //秒
						},
						"createTime": "2022-01-06 12:00:12",
						"updateTime": null,
						"chatmState": 1,
						&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值