首頁 微信小程式 小程式開發 小程式元件:聊天會話元件的介紹(附程式碼)

小程式元件:聊天會話元件的介紹(附程式碼)

Aug 10, 2018 pm 03:40 PM

這篇文章帶給大家的內容是關於小程式元件:聊天會話元件的介紹(附程式碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。

場景

用於線上客服的聊天對話等

一、版面圈點

#1、三角箭頭

繪製一個26rpx*26rpx矩形,使它旋轉45度,然後隱去對半,形成氣泡上的直角三角形。

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

2、flex-flow改變流動方向

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

<view class="body" style="flex-flow: {{item.myself == 0 ? &#39;row&#39; : &#39;row-reverse&#39;}}">
登入後複製

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;
}
登入後複製

經過對比,方案2要優於方案1

JS圈點

一、touch事件實現上滑取消語音輸入

按下出現懸浮,上滑到超過一定位移出現取消提示,鬆手取消;上滑未超過,鬆手發送

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,取消发送
 this.setData({
 status: distance > 50 ? this.data.state.cancel : this.data.state.pressed
 });
 },
 touchEnd: function (e) {
 // 触摸结束
 var endY = e.changedTouches[0].clientY;
 var distance = this.data.startY - endY;
 // console.log(distance);
 // 距离超过50,取消发送
 this.setData({
 cancel: distance > 50 ? true : false,
 status: this.data.state.normal
 });
 // 不论如何,都结束录音
 this.stop();
 },
登入後複製

二、發送訊息完畢滾到頁尾

data: {
 toView: &#39;&#39;
}
reply: {
// ...
this.scrollToBottom()
},
scrollToBottom: function () {
 this.setData({
 toView: &#39;row_&#39; + (this.data.message_list.length - 1)
 });
 },
登入後複製
<!--每一行消息条-->
<view class="row" wx:for="{{message_list}}" wx:key="" id="row_{{index}}">
登入後複製

 相關推薦:

小程式與背景互動的實作(附程式碼)

小程式實作自動載入的完整程式碼

以上是小程式元件:聊天會話元件的介紹(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)