uniapp时间处理、键盘弹出处理

1. 时间处理

在安卓上使用2021-5-1 12:10:54这类字符串转时间
在字符串后添加.replace(/-/g,’/’)就可以解决了
这里是处理分解;今天、昨天、之前的

//用computed是可以在循环中进行运算
computed: {
			timestampFormat() {
				return function(time) {
				//可以直接截取,然后补零,比当前方法更有效率
					let newTime = new Date(formatDate(new Date(), 'yyyy-MM-dd')).getTime();
					let nowTime = new Date(time.replace(/-/g, '/')).getTime();
					let cutTime = (nowTime - newTime) / 3600 / 1000 + 8;
					if (typeof(time) != 'undefined') {
						console.log("11111111")
						if (-24 > cutTime) {
							return time.substr(0, 10)
						} else if (0 > cutTime&&cutTime >= -24) {
							console.log(time.substr(11, 5))
							return "昨天 " + time.substr(11, 5)
						} else if (cutTime >= 0) {
							return time.substr(11, 5)
						}
					}
					return "";
				}
			},
		},

时间处理,可使用formatDate(new date(),“yyyy-MM-dd hh:mm:ss”)

export function formatDate(date, fmt) {
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    }
    return fmt;
}
function padLeftZero(str) {
    return ('00' + str).substr(str.length);
}

2. 键盘弹出控制高度

在聊天界面,如果弹出键盘,则最上方的消息会被顶上去而看不见,这时候进行监听键盘高度,并将键盘的高度转换成padding-top,这样就可以实现消息不被顶上去

<template>
	
	<view class="input-box-flex-grow">
		<scroll-view class="content-box" :scroll-y="true" :scroll-top="scrollTop" :style="{'padding-top':inputBottom }">
			<view class="message" v-for="(item, index) in messageList" :key="index" :id="`msg-${item.hasBeenSentId}`">
				<view class="message-item " :class="item.isItMe ? 'right' : 'left'">
					<image class="img" :src="item.fromUserHeadImg" mode="" @tap="linkToBusinessCard(item.fromUserId)"></image>
					<view class="content">{{ item.content }}</view>
				</view>
			</view>
		</scroll-view>
		<input
			type="text"
			class="content"
			id="input"
			v-model="formData.content"
			@focus="focusTextarea"
			@blur="blurTextarea"
		/>
	</view>
</template>
<script>

export default {
data() {
		return {
			scrollTop: 1000,
			inputBottom:'',
		}
	}
	methods: {
		focusTextarea(e) {
		  this.inputBottom = e.detail.height +"px";
		  console.log( e.detail.height)
		  this.scrollTop += 1; //滚到底部
		},
		blurTextarea(e) {
		  this.inputBottom = "0px" ;
		  this.scrollTop += 1; //滚到底部
		},
	}
}
</script>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vace cc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值