溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

小程序組件中聊天會話組件的示例分析

發(fā)布時間:2021-06-09 14:48:29 來源:億速云 閱讀:187 作者:小新 欄目:移動開發(fā)

這篇文章主要為大家展示了“小程序組件中聊天會話組件的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“小程序組件中聊天會話組件的示例分析”這篇文章吧。

場景

用于在線客服的聊天對話等

一、布局圈點

1、三角箭頭

繪制一個26rpx*26rpx矩形,使它旋轉(zhuǎn)45度,然后隱去對半,形成氣泡上的直角三角形。

<!-- 畫三角箭頭 -->
 <view class="triangle" style="{{item.myself == 1 ? 'right: 140rpx; background: #7ECB4B' : 'left: 140rpx;'}}"></view>
 
/* 三角箭頭 */
.body .triangle {
 background: white;
 width: 20rpx;
 height: 20rpx;
 margin-top: 26rpx;
 transform: rotate(45deg);
 position: absolute;
}

2、flex-flow改變流動方向

分別取值['row' | 'row-reverse'],實現(xiàn)對方發(fā)來的消息頭像居左,自己發(fā)的消息頭像居右。

<view class="body" style="flex-flow: {{item.myself == 0 ? 'row' : 'row-reverse'}}">

3、按住說話懸浮層水平與垂直居中

方案1,js手工計算

data: {
 hud_top: (wx.getSystemInfoSync().windowHeight - 150) / 2,
 hud_left: (wx.getSystemInfoSync().windowWidth - 150) / 2,
}
<view class="hud-container" wx:if="{{status != state.normal}}" style="top: {{hud_top}}px; left: {{hud_left}}px;">

方案2,純css

/*懸浮提示框*/
.hud-container {
 position: fixed;
 width: 150px;
 height: 150px;
 left: 50%;
 top: 50%;
 margin-left: -75px;
 margin-top: -75px;
}

經(jīng)過對比,方案2要優(yōu)于方案1

JS圈點

一、touch事件實現(xiàn)上滑取消語音輸入

按下出現(xiàn)懸浮,上滑到超過一定位移出現(xiàn)取消提示,松手取消;上滑未超過,松手發(fā)送

touchStart: function (e) {
 // 觸摸開始
 var startY = e.touches[0].clientY;
 // 記錄初始Y值
 this.setData({
 startY: startY,
 status: this.data.state.pressed
 });
 },
 touchMove: function (e) {
 // 觸摸移動
 var movedY = e.touches[0].clientY;
 var distance = this.data.startY - movedY;
 // console.log(distance);
 // 距離超過50,取消發(fā)送
 this.setData({
 status: distance > 50 ? this.data.state.cancel : this.data.state.pressed
 });
 },
 touchEnd: function (e) {
 // 觸摸結(jié)束
 var endY = e.changedTouches[0].clientY;
 var distance = this.data.startY - endY;
 // console.log(distance);
 // 距離超過50,取消發(fā)送
 this.setData({
 cancel: distance > 50 ? true : false,
 status: this.data.state.normal
 });
 // 不論如何,都結(jié)束錄音
 this.stop();
 },

二、發(fā)送消息完畢滾到頁尾

data: {
 toView: ''
}
reply: {
// ...
this.scrollToBottom()
},
scrollToBottom: function () {
 this.setData({
 toView: 'row_' + (this.data.message_list.length - 1)
 });
 },
<!--每一行消息條-->
<view class="row" wx:for="{{message_list}}" wx:key="" id="row_{{index}}">

以上是“小程序組件中聊天會話組件的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI