【小程序】 键盘和表情同时存在时候,输入框上移问题

news/2024/7/20 3:58:02 标签: 小程序, javascript, 开发语言

键盘和表情

      • 效果图
      • 实现方法
      • 引入的js文件,文件名emoji.js,存放在untils路径下

效果图

在这里插入图片描述
在这里插入图片描述

  • 实现过程,监听键盘高度的同时,判断是否获取到焦点
  • 样式上,swiper实现左右按页滑动效果

实现方法

<template>
	<view class="content">
		<!-- 文本弹窗 -->
		<view class="keyboard" :style="{'padding-bottom':keybottonm+'rpx','bottom':Keydibu+'px'}">
			<textarea type="text" v-model="commentInput" placeholder="请输入消息..." placeholder-class="placestyle"  :show-confirm-bar="false" :adjust-position="false" @keyboardheightchange="keyboardheightchange" @focus="getfocus" @blur="getblur"></textarea>
			<image src="/static/face.png" mode="" class="faceImg" @tap="alertEmoji"></image>
			<view class="sendBtn" @click="sendComment">
				发送
			</view>
		</view>
		<!-- 表情弹窗 -->
		<view v-if="isShowEmoji">
			<swiper  class="emojiSelect">
				<swiper-item v-for="(item,index) in emojilist" :key="indx">
					<view class="emojiItem" >
						<view class="emojiSelectItem" v-for="(ite,IN) in item" @click="inputEmoji(index,IN)">
							{{ite}}
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>
javascript"><script>
	import emoji from "@/untils/emoji.js"
	export default {
		data() {
			return {
				keybottonm: 0,
				Keydibu:0,
				isShowEmoji: false,
				emojilist: [],
				focus:false,
				commentInput:"",
			}
		},
		onLoad() {
			this.getdevice()
			this.dealEmoji(35)//35控制一页显示多少个表情
		},
		methods: {
			// 自适应,判断ios还是安卓,ios底部要增大一下,避免遮挡
			getdevice() {
				let that = this
				let platform = uni.getSystemInfoSync().platform;
				if (platform == 'android') {
					that.keybottonm = 0
				} else {
					that.keybottonm = 24
				}
			},
			//表情处理
			dealEmoji(itemlength) { // 传过来每页展示个数
				let that = this;
				let alllength = parseInt(emoji.length / itemlength) + 1 //计算展示所有表情需要的总页数
				let itemIndex = 0
				for (let i = 0; i < alllength; i++) {
					that.emojilist[i] = []
					for (let j = 0; j < itemlength; j++) {
						itemIndex++
						if(emoji[itemIndex]!=null){
							that.emojilist[i].push(emoji[itemIndex])
						}
					}
				}
			},
			// 表情切换
			alertEmoji(){
				if(this.Keydibu>300){
					this.Keydibu=0
					return
				}
				this.isShowEmoji=!this.isShowEmoji
				if(this.isShowEmoji==true){
					this.Keydibu=240
				}else{
					this.Keydibu=0
				}
			},
			// 点击输入表情
			inputEmoji(index,IN) {
				this.commentInput += this.emojilist[index][IN];
			},
			//获取焦点
			getfocus(){
				this.focus=true
			},
			//失去焦点
			getblur(){
				this.focus=false
			},
			//键盘高度监听
			keyboardheightchange(e){
				console.log( e.detail.height)
				if(this.isShowEmoji==true&&this.focus){
					this.Keydibu=240
				}else{
					this.Keydibu = e.detail.height;
				}
			}
		}
	}
</script>
<style lang="less">
	.keyboard {
		position: fixed;
		bottom: 0;
		left: 0;
		padding: 14rpx 30rpx;
		box-sizing: border-box;
		width: 100%;
		display: flex;
		border-top: 2rpx solid #F5F5F5;
		align-items: center;
		z-index: 99;
		background-color: #fff;

		.placestyle {
			font-size: 26rpx;
		}

		textarea {
			padding: 10rpx 30rpx;
			box-sizing: border-box;
			padding-top: 20rpx;
			height: 72rpx;
			background: #f5f5f5;
			border-radius: 36rpx;
			flex: 1 !important;
			margin-right: 12rpx;
		}

		image {
			margin-right: 12rpx;
			width: 36rpx;
			height: 36rpx;
		}

		.sendBtn {
			width: 100rpx;
			height: 50rpx;
			font-size: 26rpx;
			color: #fff;
			border-radius: 8rpx;
			background-color: #007AFF;
			text-align: center;
			line-height: 50rpx;
		}
	}

	.emojiSelect {
		width: 100%;
		height: 460rpx;
		padding: 0 24rpx;
		box-sizing: border-box;
		background-color: #fff;
		position: fixed;
		z-index: 10000;
		bottom: 0;
		display: flex;
		flex-wrap: wrap;

		.emojiItem {
			display: flex;
			flex-wrap: wrap;

			.emojiSelectItem {
				width: 80rpx;
				height: 80rpx;
				margin: 0 8rpx 8rpx;
				display: flex;
				justify-content: center;
			}
		}
	}
</style>

引入的js文件,文件名emoji.js,存放在untils路径下

javascript">export default [
    "😀", "😁", "😃", "😄", "😅", "😆", "😉", "😊", "😋", "😎", "😍",
    "😘", "😗", "😙", "😚", "☺", "😇", "😐", "😑", "😶", "😏", "😣", "😥", "😮", "😯", "😪",
    "😫", "😴", "😌", "😛", "😜", "😝", "😒", "😓", "😔", "😕", "😲", "😷", "😖", "😞", "😟",
    "😤", "😢", "😭", "😦", "😧", "😨", "😬", "😰", "😱", "😳", "😵", "😡", "😠",
    "👦", "👧", "👨", "👩", "👴", "👵", "👶", "👱", "👮", "👲", "👳", "👷", "👸", "💂", "🎅", "👰", "👼",
    "💆", "💇", "🙍", "🙎", "🙅", "🙆", "💁", "🙋", "🙇", "🙌", "🙏", "👤", "👥", "🚶", "🏃", "👯",
    "💃", "👫", "👬", "👭", "💏", "💑", "👪", "💪", "👈", "👉", "☝", "👆", "👇", "✌", "✋", "👌",
    "👍", "👎", "✊", "👊", "👋", "👏", "👐", "✍", "👣", "👀", "👂", "👃", "👅", "👄", "💋", "👓",
    "👔", "👙", "👛", "👜", "👝", "🎒", "💼", "👞", "👟", "👠", "👡", "👢", "👑",
    "👒", "🎩", "🎓", "💄", "💅", "💍", "🌂", "📶", "📳", "📴", "♻", "🏧","🚮", "🚰", "♿", "🚹", "🚺",
    "🚻", "🚼", "🚾", "⚠", "🚸", "⛔", "🚫", "🚳", "🚭", "🚯", "🚱", "🚷", "🔞", "💈",
    "🙈", "🐒", "🐶", "🐕", "🐩", "🐺", "🐱","🐈", "🐯", "🐅", "🐆", "🐴", "🐎", "🐮", "🐂",
    "🐃","🐄","🐷","🐖","🐗","🐽","🐏","🐑","🐐","🐪","🐫","🐘","🐭",
    "🐁","🐀","🐹","🐰","🐇","🐻","🐨","🐼","🐾","🐔","🐓","🐣","🐤","🐥",
    "🐦", "🐧", "🐸", "🐊","🐢", "🐍", "🐲", "🐉", "🐳", "🐋", "🐬", "🐟", "🐠", "🐡",
    "🐙", "🐚", "🐌", "🐛", "🐜", "🐝", "🐞", "🦋",  "💐", "🌸", "💮", "🌹", "🌺",
    "🌻", "🌼", "🌷", "🌱", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "🍀", "🍁", "🍂", "🍃",
    "🌍","🌎","🌏","🌐","🌑","🌒","🌓","🌔","🌕","🌖","🌗","🌘","🌙","🌚",
    "🌛","🌜","☀","🌝","🌞","⭐","🌟","🌠","☁","⛅","☔","⚡","❄","🔥","💧","🌊",
    "🏀", "🏈", "🏉", "🎾", "🎱", "🎳", "⛳", "🎣", "🎽", "🎿",
    "😈", "👿", "👹", "👺", "💀", "☠", "👻", "👽", "👾", "💣",
    "🌋", "🗻", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥", "🏦", "🏨",
    "⛲", "🌁", "🌃", "🌆", "🌇", "🌉", "🌌", "🎠", "🎡", "🎢", "🚂",
    "🚌", "🚍", "🚎", "🚏", "🚐", "🚑", "🚒", "🚓", "🚔", "🚕", "🚖", "🚗", "🚘",
    "💌", "💎", "🔪", "💈", "🚪", "🚽", "🚿", "🛁", "⌛", "⏳", "⌚", "⏰", "🎈", "🎉",
    "💤", "💢", "💬", "💭", "♨", "🌀", "🔔", "🔕", "✡", "✝", "🔯", "📛", "🔰", "🔱", "⭕", "✅",
    "☑", "✔", "✖", "❌", "❎", "➕", "➖", "➗", "➰", "➿", "〽", "✳", "✴", "❇", "‼", "⁉", "❓", "❔", "❕", "❗",
    "🕛", "🕧", "🕐", "🕜", "🕑", "🕝", "🕒", "🕞", "🕓", "🕟", "🕔", "🕠", "🕕", "🕡",
    "🕖", "🕢", "🕗", "🕣", "🕘", "🕤", "🕙", "🕥", "🕚", "🕦", "⏱", "⏲", "🕰",
    "💘", "❤", "💓", "💔", "💕", "💖", "💗", "💙", "💚", "💛", "💜", "💝", "💞", "💟❣",
    "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🍎", "🍏", "🍐", "🍑", "🍒", "🍓",
]

http://www.niftyadmin.cn/n/289893.html

相关文章

借助 Google Play 游戏电脑版 Com2uS 为用户打造多平台无缝体验

作者 / Google Play 游戏总监 Arjun Dayal 吸引潜在用户在 PC 端畅享游戏 《魔灵召唤&#xff1a;克罗尼柯战记》是韩国游戏开发商 Com2uS 于 2023 年 3 月面向全球发布的一款移动端大型多人在线角色扮演游戏。迄今为止&#xff0c;《魔灵召唤》在全球的下载量超过 1.8 亿&…

nestJS入门cli 创建项目以及集成swagger和mysql

nestJs 1. 简介 介绍 NestJS NestJS 是一个基于 TypeScript 的渐进式 Node.js 框架&#xff0c;它结合了 OOP、FP 和 FRP 的元素&#xff0c;以提供一种现代且可扩展的开发体验。NestJS 建立在 Express.js 之上&#xff0c;但是提供了更加抽象和模块化的方式来编写应用程序。…

mysql数据库高级操作

文章目录 一、克隆表1.方法一2.方法二 二、清空表&#xff0c;删除表内所有数据1.方法一2.方法二3.drop、truncate、delete对比 三、创建临时表四、用户管理五、忘记root密码的解决措施六、用户授权总结 一、克隆表 1.方法一 ​create table 新表名 like 复制的表名; ​ ​复…

【APSIM模型】高级应用及批量模拟

APSIM (Agricultural Production Systems sIMulator)模型是世界知名的作物生长模拟模型之一。APSIM模型有Classic和Next Generation两个系列模型&#xff0c;能模拟几十种农作物、牧草和树木的土壤-植物-大气过程&#xff0c;被广泛应用于精细农业、水肥管理、气候变化、粮食安…

Java时间类(八)-- Instant (时间戳类)(常用于Date与LocalDateTime的相互转化)

目录 1. Instant的概述: 2. Instant的常见方法: 3. Date --->Instant--->LocalDateTime 4. LocalDateTime --->Instant--->Date 1. Instant的概述

英文论文(sci)解读复现【NO.7】基于注意机制的改进YOLOv5s目标检测算法

此前出了目标检测算法改进专栏&#xff0c;但是对于应用于什么场景&#xff0c;需要什么改进方法对应与自己的应用场景有效果&#xff0c;并且多少改进点能发什么水平的文章&#xff0c;为解决大家的困惑&#xff0c;此系列文章旨在给大家解读发表高水平学术期刊中的 SCI论文&a…

Wikidata实操

1. Wikidata 简介 Wikidata 即维基数据&#xff0c;是维基百科的一个项目。个项目已经在维基百科德国分部开始进行&#xff0c;项目完成之后&#xff0c;将会交给维基百科基金会进行操作和维护。&#xff08;具体百度即可&#xff0c;不多赘述&#xff09; 官网&#xff1a;htt…

前端学习之使用JavaScript(2)

前情回顾&#xff1a;基本 存储类型 数组 Js的数组与其它语言的数组有很大的区别。跟其他语言中的数组一样&#xff0c;ECMAScript 数组也是一组有序的数据。但是&#xff0c;Js的一个数组中可以存储不同类型的数据。 // 数组字面量表示法 let array [1, 2, true];// 构造…