1
- import { Component } from '../../src/_util/simply' ;
1
+ import { Component , getValueFromProps , triggerEventOnly } from '../../src/_util/simply' ;
2
2
import { BubbleProps } from './props' ;
3
3
4
4
Component (
5
5
BubbleProps ,
6
6
{
7
7
startTyping ( ) {
8
- if ( this . props . loading ) {
8
+ const [ loading , typing , content ] = getValueFromProps ( this , [
9
+ 'loading' ,
10
+ 'typing' ,
11
+ 'content' ,
12
+ ] ) ;
13
+ if ( loading ) {
9
14
return ;
10
15
}
11
- if ( this . props . content ) {
12
- const typingOptions = this . props . typing
13
- ? this . props . typing === true
16
+ if ( content ) {
17
+ const typingOptions = typing
18
+ ? typing === true
14
19
? { step : 1 , interval : 100 }
15
- : this . props . typing
20
+ : typing
16
21
: false ;
17
22
if ( typingOptions ) {
18
23
const { step = 1 , interval = 100 } = typingOptions ;
19
- const content = this . props . content ;
24
+ const bubbleText = content ;
20
25
// todo 待优化
21
26
const typingLoop = ( length : number , typedLength : number ) => {
22
- const typingText = content . slice ( 0 , typedLength ) ;
27
+ const typingText = bubbleText . slice ( 0 , typedLength ) ;
23
28
this . setData ( {
24
29
bubbleText : typingText ,
25
30
} ) ;
@@ -28,15 +33,15 @@ Component(
28
33
typingLoop ( length , typedLength + step ) ;
29
34
} , interval ) ;
30
35
} else {
31
- this . props . onTypingComplete ?. ( ) ;
36
+ triggerEventOnly ( this , 'typingComplete' )
32
37
}
33
38
} ;
34
- typingLoop ( content . length , step ) ;
39
+ typingLoop ( bubbleText . length , step ) ;
35
40
} else {
36
41
this . setData ( {
37
- bubbleText : this . props . content ,
42
+ bubbleText : content ,
38
43
} ) ;
39
- this . props . onTypingComplete ?. ( ) ;
44
+ triggerEventOnly ( this , 'typingComplete' )
40
45
}
41
46
}
42
47
} ,
@@ -58,8 +63,15 @@ Component(
58
63
}
59
64
} ,
60
65
} ,
66
+ /// #if ALIPAY
61
67
didMount ( ) {
62
68
this . startTyping ( ) ;
63
69
} ,
70
+ /// #endif
71
+ /// #if WECHAT
72
+ attached ( ) {
73
+ this . startTyping ( ) ;
74
+ } ,
75
+ /// #endif
64
76
}
65
77
) ;
0 commit comments