我是靠谱客的博主 沉静摩托,这篇文章主要介绍小程序组件:聊天会话组件的介绍(附代码),现在分享给大家,希望可以做个参考。

本篇文章给大家带来的内容是关于小程序组件:聊天会话组件的介绍(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

场景

用于在线客服的聊天对话等

一、布局圈点

1、三角箭头

绘制一个26rpx*26rpx矩形,使它旋转45度,然后隐去对半,形成气泡上的直角三角形。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
<!-- 画三角箭头 --> <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'],实现对方发来的消息头像居左,自己发的消息头像居右。

复制代码
1
<view class="body" style="flex-flow: {{item.myself == 0 ? 'row' : 'row-reverse'}}">
登录后复制

3、按住说话悬浮层水平与垂直居中

方案1,js手工计算

复制代码
1
2
3
4
5
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

复制代码
1
2
3
4
5
6
7
8
9
10
/*悬浮提示框*/ .hud-container { position: fixed; width: 150px; height: 150px; left: 50%; top: 50%; margin-left: -75px; margin-top: -75px; }
登录后复制

经过对比,方案2要优于方案1

JS圈点

一、touch事件实现上滑取消语音输入

按下出现悬浮,上滑到超过一定位移出现取消提示,松手取消;上滑未超过,松手发送

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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(); },
登录后复制

二、发送消息完毕滚到页尾

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
data: { toView: '' } reply: { // ... this.scrollToBottom() }, scrollToBottom: function () { this.setData({ toView: 'row_' + (this.data.message_list.length - 1) }); },
登录后复制
复制代码
1
2
<!--每一行消息条--> <view class="row" wx:for="{{message_list}}" wx:key="" id="row_{{index}}">
登录后复制

相关推荐:

小程序与后台进行交互的实现(附代码)

小程序实现自动加载的完整代码

以上就是小程序组件:聊天会话组件的介绍(附代码)的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是沉静摩托最近收集整理的关于小程序组件:聊天会话组件的介绍(附代码)的全部内容,更多相关小程序组件:聊天会话组件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部