File tree Expand file tree Collapse file tree 1 file changed +34
-10
lines changed Expand file tree Collapse file tree 1 file changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,27 @@ const componentProps = {
18
18
title : 'Ask AI'
19
19
}
20
20
21
- let currentLocale
22
21
let client
22
+ let currentLocale
23
+ let currentLayout = 'pc'
24
+
25
+ const mql = window . matchMedia ( '(max-width: 480px)' )
26
+ if ( mql . matches ) {
27
+ currentLayout = 'mobile'
28
+ }
29
+
30
+ mql . addEventListener ( 'change' , async ( { matches } ) => {
31
+ await loading
32
+
33
+ currentLayout = matches ? 'mobile' : 'pc'
34
+ console . log ( 'mql changed' , currentLayout )
35
+
36
+ if ( client ) {
37
+ client . destroy ( )
38
+ }
39
+
40
+ client = createClient ( currentLocale , currentLayout )
41
+ } )
23
42
24
43
export default ( { app } ) => {
25
44
app . router . afterEach ( async to => {
@@ -30,19 +49,24 @@ export default ({ app }) => {
30
49
return
31
50
}
32
51
52
+ currentLocale = locale
53
+
33
54
if ( client ) {
34
55
client . destroy ( )
35
56
}
36
57
37
- currentLocale = locale
58
+ client = createClient ( currentLocale , currentLayout )
59
+ } )
60
+ }
38
61
39
- const options = {
40
- config,
41
- componentProps : {
42
- ...componentProps ,
43
- lang : locale === 'zh-Hans' ? 'zh-CN' : 'en'
44
- }
62
+ function createClient ( locale , layout ) {
63
+ const options = {
64
+ config,
65
+ componentProps : {
66
+ ...componentProps ,
67
+ lang : locale === 'zh-Hans' ? 'zh-CN' : 'en' ,
68
+ layout
45
69
}
46
- client = new window . CozeWebSDK . WebChatClient ( options )
47
- } )
70
+ }
71
+ return new window . CozeWebSDK . WebChatClient ( options )
48
72
}
You can’t perform that action at this time.
0 commit comments