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

项目演示

在这里插入图片描述

前言

我是看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,
						"Text
  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在Uniapp中开发微信小程序的表单界面,你可以使用uni-form组件来创建表单,并使用uni-input组件来添加表单字段。 首先,你需要在页面中引入uni-form组件,然后在模板中使用uni-form标签来包裹表单内容。在uni-form标签中,你可以使用uni-input标签来创建输入框、uni-checkbox标签来创建复选框、uni-radio标签来创建单选框,等等。 下面是一个示例代码,展示了如何在Uniapp中创建一个简单的表单界面: ```html <template> <view> <uni-form> <uni-input type="text" v-model="name" placeholder="请输入姓名"></uni-input> <uni-input type="number" v-model.number="age" placeholder="请输入年龄"></uni-input> <uni-checkbox-group v-model="hobbies"> <uni-checkbox value="reading">阅读</uni-checkbox> <uni-checkbox value="music">音乐</uni-checkbox> <uni-checkbox value="sports">运动</uni-checkbox> </uni-checkbox-group> <uni-radio-group v-model="gender"> <uni-radio value="male">男</uni-radio> <uni-radio value="female">女</uni-radio> </uni-radio-group> <uni-button type="primary" @click="submitForm">提交</uni-button> </uni-form> </view> </template> <script> export default { data() { return { name: '', age: '', hobbies: [], gender: '' }; }, methods: { submitForm() { // 在这里进行表单验证和提交逻辑 // 可以使用this.name、this.age等来获取表单字段的值 } } }; </script> ``` 在上面的示例中,我们使用了v-model指令来绑定表单字段的值到data中的数据。当用户在输入框中输入内容时,data中的对应字段也会更新。使用@click事件监听提交按钮的点击事件,并在submitForm方法中进行表单验证和提交逻辑。 要进行表单验证,你可以在submitForm方法中使用条件判断来检查表单字段的值是否符合要求。例如,你可以检查姓名是否为空、年龄是否为数字等。 这只是一个简单的示例,你可以根据自己的需求进行更复杂的表单验证和提交逻辑。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值