|
@@ -1,136 +0,0 @@
|
1
|
|
-// chat.js
|
2
|
|
-import Toast from "../../utils/toast";
|
3
|
|
-
|
4
|
|
-let chatInput = require('../../modules/chat-input/chat-input');
|
5
|
|
-/**
|
6
|
|
- * 聊天输入组件展示页面
|
7
|
|
- */
|
8
|
|
-Page({
|
9
|
|
-
|
10
|
|
- /**
|
11
|
|
- * 页面的初始数据
|
12
|
|
- */
|
13
|
|
- data: {
|
14
|
|
- textMessage: '',
|
15
|
|
- chatItems: [],
|
16
|
|
- },
|
17
|
|
-
|
18
|
|
-
|
19
|
|
- /**
|
20
|
|
- * 生命周期函数--监听页面加载
|
21
|
|
- */
|
22
|
|
- onLoad(options) {
|
23
|
|
- this.initData();
|
24
|
|
- },
|
25
|
|
- initData() {
|
26
|
|
- let that = this;
|
27
|
|
- let systemInfo = wx.getSystemInfoSync();
|
28
|
|
- chatInput.init(this, {
|
29
|
|
- systemInfo: systemInfo,
|
30
|
|
- minVoiceTime: 1,
|
31
|
|
- maxVoiceTime: 60,
|
32
|
|
- startTimeDown: 56,
|
33
|
|
- format: 'mp3',//aac/mp3
|
34
|
|
- sendButtonBgColor: 'mediumseagreen',
|
35
|
|
- sendButtonTextColor: 'white',
|
36
|
|
- extraArr: [{
|
37
|
|
- picName: 'choose_picture',
|
38
|
|
- description: '照片'
|
39
|
|
- }, {
|
40
|
|
- picName: 'take_photos',
|
41
|
|
- description: '拍摄'
|
42
|
|
- }, {
|
43
|
|
- picName: 'close_chat',
|
44
|
|
- description: '自定义功能'
|
45
|
|
- }],
|
46
|
|
- // tabbarHeigth: 48
|
47
|
|
- });
|
48
|
|
-
|
49
|
|
- that.setData({
|
50
|
|
- pageHeight: systemInfo.windowHeight,
|
51
|
|
- });
|
52
|
|
- wx.setNavigationBarTitle({
|
53
|
|
- title: '好友1'
|
54
|
|
- });
|
55
|
|
- that.textButton();
|
56
|
|
- that.extraButton();
|
57
|
|
- that.voiceButton();
|
58
|
|
- },
|
59
|
|
- textButton() {
|
60
|
|
-
|
61
|
|
- chatInput.setTextMessageListener(function (e) {
|
62
|
|
- console.log(1222);
|
63
|
|
- let content = e.detail.value;
|
64
|
|
- console.log(content);
|
65
|
|
- });
|
66
|
|
- },
|
67
|
|
- voiceButton() {
|
68
|
|
-
|
69
|
|
- chatInput.recordVoiceListener(function (res, duration) {
|
70
|
|
- let tempFilePath = res.tempFilePath;
|
71
|
|
- let vDuration = duration;
|
72
|
|
- console.log(tempFilePath, vDuration);
|
73
|
|
- });
|
74
|
|
- chatInput.setVoiceRecordStatusListener(function (status) {
|
75
|
|
- switch (status) {
|
76
|
|
- case chatInput.VRStatus.START://开始录音
|
77
|
|
-
|
78
|
|
- break;
|
79
|
|
- case chatInput.VRStatus.SUCCESS://录音成功
|
80
|
|
-
|
81
|
|
- break;
|
82
|
|
- case chatInput.VRStatus.CANCEL://取消录音
|
83
|
|
-
|
84
|
|
- break;
|
85
|
|
- case chatInput.VRStatus.SHORT://录音时长太短
|
86
|
|
-
|
87
|
|
- break;
|
88
|
|
- case chatInput.VRStatus.UNAUTH://未授权录音功能
|
89
|
|
-
|
90
|
|
- break;
|
91
|
|
- case chatInput.VRStatus.FAIL://录音失败(已经授权了)
|
92
|
|
-
|
93
|
|
- break;
|
94
|
|
- }
|
95
|
|
- })
|
96
|
|
- },
|
97
|
|
- extraButton() {
|
98
|
|
- let that = this;
|
99
|
|
- chatInput.clickExtraListener(function (e) {
|
100
|
|
- console.log(e);
|
101
|
|
- let itemIndex = parseInt(e.currentTarget.dataset.index);
|
102
|
|
- if (itemIndex === 2) {
|
103
|
|
- that.myFun();
|
104
|
|
- return;
|
105
|
|
- }
|
106
|
|
- wx.chooseImage({
|
107
|
|
- count: 1, // 默认9
|
108
|
|
- sizeType: ['compressed'],
|
109
|
|
- sourceType: itemIndex === 0 ? ['album'] : ['camera'],
|
110
|
|
- success: function (res) {
|
111
|
|
- let tempFilePath = res.tempFilePaths[0];
|
112
|
|
- }
|
113
|
|
- });
|
114
|
|
- });
|
115
|
|
- chatInput.setExtraButtonClickListener(function (dismiss) {
|
116
|
|
- console.log('Extra弹窗是否消失', dismiss);
|
117
|
|
- })
|
118
|
|
- },
|
119
|
|
- myFun() {
|
120
|
|
- wx.showModal({
|
121
|
|
- title: '小贴士',
|
122
|
|
- content: '这是用于拓展的自定义功能!',
|
123
|
|
- confirmText: '确认',
|
124
|
|
- showCancel: true,
|
125
|
|
- success: function (res) {
|
126
|
|
- if (res.confirm) {
|
127
|
|
- Toast.show('success', '自定义功能')
|
128
|
|
- }
|
129
|
|
- }
|
130
|
|
- })
|
131
|
|
- },
|
132
|
|
-
|
133
|
|
- resetInputStatus() {
|
134
|
|
- chatInput.closeExtraView();
|
135
|
|
- },
|
136
|
|
-});
|