5
5
<f7-messagebar
6
6
:placeholder =" placeholder"
7
7
ref =" messagebar"
8
- :attachmentsVisible =" attachmentsVisible"
9
- :sheetVisible =" sheetVisible"
8
+ :attachments-visible =" attachmentsVisible"
9
+ :sheet-visible =" sheetVisible"
10
+ :value =" messageText"
11
+ @input =" messageText = $event.target.value"
10
12
>
11
13
<f7-link
12
- icon-if-ios =" f7:camera_fill"
13
- icon-if-md =" f7:camera_alt"
14
+ icon-ios =" f7:camera_fill"
15
+ icon-aurora =" f7:camera_fill"
16
+ icon-md =" material:camera_alt"
14
17
slot =" inner-start"
15
- @click =" sheetToggle "
18
+ @click =" sheetVisible = !sheetVisible "
16
19
></f7-link >
17
20
<f7-link
18
- icon-if-ios =" f7:arrow_up_fill"
19
- icon-if-md =" material:send"
21
+ icon-ios =" f7:arrow_up_round_fill"
22
+ icon-aurora =" f7:arrow_up_round_fill"
23
+ icon-md =" material:send"
20
24
slot =" inner-end"
21
25
@click =" sendMessage"
22
26
></f7-link >
45
49
v-for =" (message, index) in messagesData"
46
50
:key =" index"
47
51
:type =" message.type"
48
- :text =" message.text"
49
52
:image =" message.image"
50
53
:name =" message.name"
51
54
:avatar =" message.avatar"
52
55
:first =" isFirstMessage(message, index)"
53
56
:last =" isLastMessage(message, index)"
54
57
:tail =" isTailMessage(message, index)"
58
+ >
59
+ <span slot =" text" v-if =" message.text" v-html =" message.text" ></span >
60
+ </f7-message >
61
+ <f7-message v-if =" typingMessage"
62
+ type =" received"
63
+ :typing =" true"
64
+ :first =" true"
65
+ :last =" true"
66
+ :tail =" true"
67
+ :header =" `${typingMessage.name} is typing`"
68
+ :avatar =" typingMessage.avatar"
55
69
></f7-message >
56
70
</f7-messages >
57
71
</f7-page >
58
72
</template >
59
73
<script >
74
+ import { f7Navbar , f7Page , f7Messages , f7MessagesTitle , f7Message , f7Messagebar , f7Link , f7MessagebarAttachments , f7MessagebarAttachment , f7MessagebarSheet , f7MessagebarSheetImage } from ' framework7-vue' ;
75
+
60
76
export default {
77
+ components: {
78
+ f7Navbar,
79
+ f7Page,
80
+ f7Messages,
81
+ f7MessagesTitle,
82
+ f7Message,
83
+ f7Messagebar,
84
+ f7MessagebarAttachments,
85
+ f7MessagebarAttachment,
86
+ f7MessagebarSheet,
87
+ f7MessagebarSheetImage,
88
+ f7Link,
89
+ },
61
90
data () {
62
91
return {
63
92
attachments: [],
64
93
sheetVisible: false ,
94
+ typingMessage: null ,
95
+ messageText: ' ' ,
65
96
messagesData: [
66
97
{
67
98
type: ' sent' ,
75
106
name: ' Kate' ,
76
107
type: ' received' ,
77
108
text: ' Hi, I am good!' ,
78
- avatar: ' http ://lorempixel.com/100/100/ people/9 ' ,
109
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-9.jpg ' ,
79
110
},
80
111
{
81
112
name: ' Blue Ninja' ,
82
113
type: ' received' ,
83
114
text: ' Hi there, I am also fine, thanks! And how are you?' ,
84
- avatar: ' http ://lorempixel.com/100/100/ people/7 ' ,
115
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-7.jpg ' ,
85
116
},
86
117
{
87
118
type: ' sent' ,
93
124
},
94
125
{
95
126
type: ' sent' ,
96
- image: ' http ://lorempixel.com/200/260/ cats/4/ ' ,
127
+ image: ' https ://cdn.framework7.io/placeholder/ cats-200x260-4.jpg ' ,
97
128
98
129
},
99
130
{
100
131
name: ' Kate' ,
101
132
type: ' received' ,
102
133
text: ' Nice!' ,
103
- avatar: ' http ://lorempixel.com/100/100/ people/9 ' ,
134
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-9.jpg ' ,
104
135
},
105
136
{
106
137
name: ' Kate' ,
107
138
type: ' received' ,
108
139
text: ' Like it very much!' ,
109
- avatar: ' http ://lorempixel.com/100/100/ people/9 ' ,
140
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-9.jpg ' ,
110
141
},
111
142
{
112
143
name: ' Blue Ninja' ,
113
144
type: ' received' ,
114
145
text: ' Awesome!' ,
115
- avatar: ' http ://lorempixel.com/100/100/ people/7 ' ,
146
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-7.jpg ' ,
116
147
},
117
148
],
118
149
images: [
119
- ' http ://lorempixel.com/300/300/ cats/1/ ' ,
120
- ' http ://lorempixel.com/200/300/ cats/2/ ' ,
121
- ' http ://lorempixel.com/400/300/ cats/3/ ' ,
122
- ' http ://lorempixel.com/300/150/ cats/4/ ' ,
123
- ' http ://lorempixel.com/150/300/ cats/5/ ' ,
124
- ' http ://lorempixel.com/300/300/ cats/6/ ' ,
125
- ' http ://lorempixel.com/300/300/ cats/7/ ' ,
126
- ' http ://lorempixel.com/200/300/ cats/8/ ' ,
127
- ' http ://lorempixel.com/400/300/ cats/9/ ' ,
128
- ' http ://lorempixel.com/300/150/ cats/10/ ' ,
150
+ ' https ://cdn.framework7.io/placeholder/ cats-300x300-1.jpg ' ,
151
+ ' https ://cdn.framework7.io/placeholder/ cats-200x300-2.jpg ' ,
152
+ ' https ://cdn.framework7.io/placeholder/ cats-400x300-3.jpg ' ,
153
+ ' https ://cdn.framework7.io/placeholder/ cats-300x150-4.jpg ' ,
154
+ ' https ://cdn.framework7.io/placeholder/ cats-150x300-5.jpg ' ,
155
+ ' https ://cdn.framework7.io/placeholder/ cats-300x300-6.jpg ' ,
156
+ ' https ://cdn.framework7.io/placeholder/ cats-300x300-7.jpg ' ,
157
+ ' https ://cdn.framework7.io/placeholder/ cats-200x300-8.jpg ' ,
158
+ ' https ://cdn.framework7.io/placeholder/ cats-400x300-9.jpg ' ,
159
+ ' https ://cdn.framework7.io/placeholder/ cats-300x150-10.jpg ' ,
129
160
],
130
161
people: [
131
162
{
132
163
name: ' Kate Johnson' ,
133
- avatar: ' http ://lorempixel.com/100/100/ people/9 ' ,
164
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-9.jpg ' ,
134
165
},
135
166
{
136
167
name: ' Blue Ninja' ,
137
- avatar: ' http ://lorempixel.com/100/100/ people/7 ' ,
168
+ avatar: ' https ://cdn.framework7.io/placeholder/ people-100x100-7.jpg ' ,
138
169
},
139
170
],
140
171
answers: [
154
185
responseInProgress: false ,
155
186
};
156
187
},
157
- // Resize page when attachments or sheet become visible
158
- watch: {
159
- attachmentsVisible () {
160
- const self = this ;
161
- self .$nextTick (() => {
162
- self .messagebar .resizePage ();
163
- });
164
- },
165
- sheetVisible () {
166
- const self = this ;
167
- self .$nextTick (() => {
168
- self .messagebar .resizePage ();
169
- });
170
- },
171
- },
172
188
computed: {
173
189
attachmentsVisible () {
174
190
const self = this ;
179
195
return self .attachments .length > 0 ? ' Add comment or Send' : ' Message' ;
180
196
},
181
197
},
198
+ mounted () {
199
+ const self = this ;
200
+ self .$f7ready (() => {
201
+ self .messagebar = self .$refs .messagebar .f7Messagebar ;
202
+ self .messages = self .$refs .messages .f7Messages ;
203
+ });
204
+ },
182
205
methods: {
183
206
isFirstMessage (message , index ) {
184
207
const self = this ;
201
224
if (! nextMessage || nextMessage .type !== message .type || nextMessage .name !== message .name ) return true ;
202
225
return false ;
203
226
},
204
- sheetToggle () {
205
- const self = this ;
206
- self .sheetVisible = ! self .sheetVisible ;
207
- },
208
227
deleteAttachment (image ) {
209
228
const self = this ;
210
229
const index = self .attachments .indexOf (image);
224
243
},
225
244
sendMessage () {
226
245
const self = this ;
227
- const text = self .messagebar . getValue () .replace (/ \n / g , ' <br>' ).trim ();
246
+ const text = self .messageText .replace (/ \n / g , ' <br>' ).trim ();
228
247
const messagesToSend = [];
229
248
self .attachments .forEach ((attachment ) => {
230
249
messagesToSend .push ({
231
250
image: attachment,
232
251
});
233
252
});
234
- if (text .trim (). length ) {
253
+ if (text .length ) {
235
254
messagesToSend .push ({
236
255
text,
237
256
});
238
257
}
258
+ if (messagesToSend .length === 0 ) {
259
+ return ;
260
+ }
261
+
239
262
// Reset attachments
240
263
self .attachments = [];
241
264
// Hide sheet
242
265
self .sheetVisible = false ;
243
266
// Clear area
244
- self .messagebar . clear () ;
267
+ self .messageText = ' ' ;
245
268
// Focus area
246
269
if (text .length ) self .messagebar .focus ();
247
270
// Send message
253
276
setTimeout (() => {
254
277
const answer = self .answers [Math .floor (Math .random () * self .answers .length )];
255
278
const person = self .people [Math .floor (Math .random () * self .people .length )];
256
- self .messages . showTyping ( {
257
- header : ` ${ person .name } is typing ` ,
279
+ self .typingMessage = {
280
+ name : person .name ,
258
281
avatar: person .avatar ,
259
- }) ;
282
+ };
260
283
setTimeout (() => {
261
284
self .messagesData .push ({
262
285
text: answer,
263
286
type: ' received' ,
264
287
name: person .name ,
265
288
avatar: person .avatar ,
266
289
});
267
- self .messages . hideTyping () ;
290
+ self .typingMessage = null ;
268
291
self .responseInProgress = false ;
269
292
}, 4000 );
270
293
}, 1000 );
271
- }
294
+ },
272
295
},
273
- mounted () {
274
- this .$f7ready ((f7 ) => {
275
- const self = this ;
276
- self .messagebar = self .$refs .messagebar .f7Messagebar ;
277
- self .messages = self .$refs .messages .f7Messages ;
278
- })
279
- }
280
296
};
281
297
</script >
0 commit comments