fix: Support embedding multiple Applications

Closes #1659
This commit is contained in:
CaptainB 2024-12-18 10:46:11 +08:00 committed by 刘瑞斌
parent b2829963ab
commit bdea68c4e6

View File

@ -1,3 +1,4 @@
(function() {
const guideHtml=`
<div class="maxkb-mask">
<div class="maxkb-content"></div>
@ -131,8 +132,9 @@ const initChat=(root)=>{
function initMaxkb(){
const maxkb=document.createElement('div')
const root=document.createElement('div')
root.id="maxkb"
initMaxkbStyle(maxkb)
const maxkbId = 'maxkb-'+crypto.randomUUID().split('-')[0]
root.id=maxkbId
initMaxkbStyle(maxkb, maxkbId)
maxkb.appendChild(root)
document.body.appendChild(maxkb)
const maxkbMaskTip=localStorage.getItem('maxkbMaskTip')
@ -144,7 +146,7 @@ function initMaxkb(){
// 初始化全局样式
function initMaxkbStyle(root){
function initMaxkbStyle(root, maxkbId){
style=document.createElement('style')
style.type='text/css'
style.innerText= `
@ -306,6 +308,7 @@ function initMaxkbStyle(root){
height: 600px;
}
}`
.replaceAll('#maxkb ',`#${maxkbId} `)
root.appendChild(style)
}
@ -319,3 +322,4 @@ function embedChatbot() {
} else console.error('invalid parameter')
}
window.addEventListener('load',embedChatbot)
})();