Skip to content

Commit fea2d2b

Browse files
committed
feat: improve docbot layout
1 parent 5cb481a commit fea2d2b

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

plugins/coze.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,27 @@ const componentProps = {
1818
title: 'Ask AI'
1919
}
2020

21-
let currentLocale
2221
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+
})
2342

2443
export default ({ app }) => {
2544
app.router.afterEach(async to => {
@@ -30,19 +49,24 @@ export default ({ app }) => {
3049
return
3150
}
3251

52+
currentLocale = locale
53+
3354
if (client) {
3455
client.destroy()
3556
}
3657

37-
currentLocale = locale
58+
client = createClient(currentLocale, currentLayout)
59+
})
60+
}
3861

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
4569
}
46-
client = new window.CozeWebSDK.WebChatClient(options)
47-
})
70+
}
71+
return new window.CozeWebSDK.WebChatClient(options)
4872
}

0 commit comments

Comments
 (0)