uni-app 123转发功能实现

Posted 2019ab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uni-app 123转发功能实现相关的知识,希望对你有一定的参考价值。

/pages/chat/chat-list/chat-list.vue

<template>
	<view class="page">
		<!-- 导航栏 -->
		<free-nav-bar title="选择" showBack :showRight="true">
			<free-main-button :name="muliSelect ? '发送 ('+selectCount+')' : '多选'" slot="right" @click="handlenNav">
			</free-main-button>
		</free-nav-bar>
		<!-- 搜索框 -->
		<view class="p-3 bg-light position-fixed left-0 right-0" :style="'top:'+top+'px;'" style="z-index: 2;">
			<input type="text" value="" v-model="keyword" placeholder="搜索" class="bg-white rounded"
				placeholder-class="text-center" style="height: 80rpx;" />
		</view>
		<view style="height:140rpx;"></view>

		<free-list-item v-for="(item,index) in allList" :key="index" :title="item.name"
			:cover="item.avatar || '/static/images/userpic.png'" showRight :showRightIcon="false"
			@click="selectItem(item)">
			<view v-if="muliSelect" slot="right" class="border rounded-circle flex align-center"
				style="width: 40rpx;height: 40rpx;">
				<view v-if="item.checked" class="main-bg-color rounded-circle" style="width: 39rpx;height: 39rpx;">
				</view>
			</view>
		</free-list-item>

		<view style="height:100rpx;" class="flex align-center justify-center"
			v-if="keyword !== '' && searchList.length === 0">
			<text class="font text-light-muted">暂无搜索结果</text>
		</view>
		<free-confirm ref="confirm" title="发送给:">
			<scroll-view v-if="selectCount > 0" scroll-x="true" :show-scrollbar='false'>
				<view class="flex">
					<view class="mr-1" v-for="(item,index) in selectList" :key="index">
						<free-avatar :src="item.avatar" size="60"></free-avatar>
					</view>
				</view>
			</scroll-view>
			<view class="flex" v-else>
				<free-avatar :src="sendItem.avatar" size="60"></free-avatar>
				<text class="font text-muted ml-2">sendItem.name</text>
			</view>
			<view class="my-3 bg-light rounded p-2">
				<text class="font text-light-muted">message</text>
			</view>
			<input type="text" value="" class="border-bottom font-md" style="height: 60rpx;" placeholder="给朋友留言" />
		</free-confirm>
	</view>
</template>

<script>
	import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
	import freeMainButton from '@/components/free-ui/free-main-button.vue';
	import freeListItem from '@/components/free-ui/free-list-item.vue';
	import freeConfirm from '@/components/free-ui/free-confirm.vue';
	import freeAvatar from '@/components/free-ui/free-avatar.vue';
	import 
		mapState
	 from 'vuex';
	export default 
		components: 
			freeNavBar,
			freeMainButton,
			freeListItem,
			freeConfirm,
			freeAvatar
		,
		data() 
			return 
				keyword: '',
				muliSelect: false,
				top: 0,
				list: [],
				detail: ,
				sendItem: 
			
		,
		computed: 
			...mapState(
				chatList: state => state.user.chatList,
				chat: state => state.user.chat,
			),
			// 最终列表
			allList() 
				return this.keyword === '' ? this.list : this.searchList;
			,
			// 搜索结果列表
			searchList() 
				if (this.keyword === '') 
					return [];
				
				return this.list.filter(item => 
					return item.name.indexOf(this.keyword) !== -1;
				)
			,
			// 选中列表
			selectList() 
				return this.list.filter(item => item.checked)
			,
			// 选中数量
			selectCount() 
				return this.selectList.length;
			,
			message() 
				let obj = 
					image: '[图片]',
					video: '[视频]',
					audio: '[语音]',
					card: '[名片]',
					emoticon: '[表情]'
				;
				return this.detail.type === 'text' ? this.detail.data : obj[this.detail.type];
			
		,
		methods: 
			// 点击导航栏 (群发)
			handlenNav() 
				if (!this.muliSelect) 
					return this.muliSelect = true;
				
				// 发送
				if (this.selectCount === 0) 
					return uni.showToast(
						title: '请先选择',
						icon: 'none'
					);
				
				this.$refs.confirm.show((close) => 
					this.selectList.forEach(item => 
						this.send(item)
						if (this.content) 
							this.send(item, this.content, 'text')
						
					);
					close();
					uni.reLaunch(
						url: "../../tabbar/index/index"
					)
				);
			,
			// 选中、取消选中
			selectItem(item) 
				// 选中、取消选中
				if (this.muliSelect) 
					// 选中
					if (!item.checked && (this.selectCount === 9)) 
						// 限制选中数量
						return uni.showToast(
							title: '最多选中9个',
							icon: 'none'
						)
					
					
					// 取消选中
					return item.checked = !item.checked;
				
				// 发送
				this.sendItem = item;
				this.$refs.confirm.show((close) => 
					this.send(item);
					close();
					uni.reLaunch(
						url: "../../tabbar/index/index"
					)
				);
			,
			send(item) 
				let message = this.chat.formatSendData(
					to_id: item.id,
					to_name: item.name,
					to_avatar: item.avatar,
					data: this.detail.data,
					type: this.detail.type,
					chat_type:item.chat_type,
					options: this.detail.opitons
				);
				this.chat.send(message);
				uni.$emit('updateHistory',false);
				
			
		,
		onLoad(e) 
			let res = uni.getSystemInfoSync();
			this.top = res.statusBarHeight + uni.upx2px(90);
			this.list = this.chatList.map(item => 
				return 
					...item,
					checked: false
				
			)

			if (e.params) 
				this.detail = JSON.parse(decodeURIComponent(e.params))
			
		
	
</script>

<style>

</style>

/pages/chat/chat/chat.vue

<template>
	<view>

		<!-- 导航栏 -->
		<free-nav-bar :title="detail.name" :noreadnum="totalNoreadnum" showBack>
			<free-icon-button slot="right" 
			:icon="'\\ue6fd'"
			@click="openChatSet"></free-icon-button>
		</free-nav-bar>
		
		<!-- 聊天内容区域 -->
		<scroll-view scroll-y class="bg-light position-fixed left-0 right-0 px-3" style="bottom: 105rpx;box-sizing: border-box;" :style="chatBodyBottom" :show-scrollbar="false" :scroll-into-view="scrollIntoView" :scroll-with-animation="true"
		@click="clickPage">
			
			<!-- 聊天信息列表组件 -->
			<view v-for="(item,index) in list" :key="index" 
			:id="'chatItem_'+index">
				<free-chat-item :item="item" :index="index" ref="chatItem"
				:pretime=" index > 0 ? list[index-1].create_time : 0"
				@long="long" @preview="previewImage" 
				:shownickname="currentChatItem.shownickname"
				></free-chat-item>
			</view>
			
		</scroll-view>
		
		<!-- #ifdef APP-PLUS-NVUE -->
		<div v-if="mode === 'action' || mode === 'emoticon'"
		class="position-fixed top-0 right-0 left-0"
		:style="'bottom:'+maskBottom+'px;'"
		@click="clickPage"></div>
		<!-- #endif -->
		
		<!-- 底部输入框 -->
		<view class="position-fixed left-0 right-0 border-top flex align-center" style="background-color: #F7F7F6;height: 105rpx;" 
		:style="'bottom:'+KeyboardHeight+'px;'">
			<free-icon-button v-if="mode === 'audio'"  @click="changeVoiceOrText"><text class="iconfont font-lg">&#xe607;</text></free-icon-button>
			<free-icon-button v-else @click="changeVoiceOrText"><text class="iconfont font-lg">&#xe606;</text></free-icon-button>
			<view class="flex-1">
				<view v-if="mode === 'audio'" class="rounded flex align-center justify-center" style="height: 80rpx;" :class="isRecording?'bg-hover-light':'bg-white'" @touchstart="voiceTouchStart" @touchend="voiceTouchEnd" @touchcancel="voiceTouchCancel" @touchmove="voiceTouchMove">
					<text class="font">isRecording ? '松开 结束':'按住 说话'</text>
				</view>
				
				<textarea v-else fixed class="bg-white rounded p-2 font-md" style="height: 50rpx;max-width: 450rpx;" :adjust-position="false" v-model="text" @focus="mode = 'text'"/>
			</view>
			<!-- 表情 -->
			<free-icon-button
			@click="openActionOrEmoticon('emoticon')"><text class="iconfont font-lg"
						>&#xe605;</text></free-icon-button>
			<template v-if="text.length === 0">
				<!-- 扩展菜单 -->
				<free-icon-button 
				@click="openActionOrEmoticon('action')"><text class="iconfont font-lg"
						>&#xe603;</text></free-icon-button>
			</template>
			<view v-else class="flex-shrink">
				<!-- 发送按钮 -->
				<free-main-button name="发送" 
				@click="send('text')"></free-main-button>
			</view>
			
		</view>
	
	<!-- 扩展菜单 -->
	<free-popup ref="action" bottom transformOrigin="center bottom" @hide="KeyboardHeight = 0" :mask="false">
		<view style="height: 580rpx;" class="border-top border-light-secondary bg-light">
			<swiper :indicator-dots="emoticonOrActionList.length > 1" style="height: 510rpx;">
				<swiper-item class="row" 
				v-for="(item,index) in emoticonOrActionList"
				:key="index">
					<view class="col-3 flex flex-column align-center justify-center" style="height: 255rpx;" v-for="(item2,index2) in item" :key="index2" @click="actionEvent(item2)">
						<image :src="item2.icon" mode="widthFix"
						style="width: 100rpx;height: 100rpx;"></image>
						<text class="font-sm text-muted mt-2"
						>item2.name</text>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</free-popup>
	
	
	<!-- 弹出层 -->
	<free-popup ref="extend" :bodyWidth="240" :bodyHeight="450" :tabbarHeight="105">
		<view class="flex flex-column" 
		style="width: 240rpx;"
		:style="getMenusStyle">
			<view class="flex-1 flex align-center" 
			hover-class="bg-light"
			v-for="(item,index) in menusList"
			:key="index"
			@click="clickEvent(item.event)">
				<text class="font-md pl-3">item.name</text>
			</view>
		</view>
	</free-popup>
	
	
	<!-- 录音提示 -->
	<view v-if="isRecording" class="position-fixed top-0 left-0 right-0 flex align-center justify-center" style="bottom: 105rpx;">
		<

以上是关于uni-app 123转发功能实现的主要内容,如果未能解决你的问题,请参考以下文章

uni-app 122转发功能实现

uni-app 124转发功能实现

uni-app 179转发名片功能

uni-app 实现拨打电话功能(android)

uni-app 实现拨打电话功能(android)

小程序各种功能代码片段整理---持续更新