feat: 增加移动端检测功能并优化widget参数传递 & v0.9.69

This commit is contained in:
haorwen
2026-03-17 00:05:34 +08:00
committed by cnb
parent 11e5c982ed
commit 3310a0abdb
5 changed files with 18 additions and 8 deletions
+7 -2
View File
@@ -78,6 +78,8 @@
script.src = `${origin}${manifest.files["widget.js"]}`;
script.onload = () => {
// 脚本加载完成后,需要手动初始化 React 应用到 shadow DOM
// 检测父窗口是否为移动端
const isMobile = w.innerWidth < 768;
const params = new URLSearchParams({
id,
host: hostId,
@@ -97,7 +99,8 @@
closeWidth,
closeHeight,
openWidth,
openHeight
openHeight,
isMobile
});
// 将参数传递给 shadow DOM 内的应用
@@ -131,9 +134,11 @@
const wrapper = d.createElement("iframe");
wrapper.id = "VOCECHAT_WIDGET";
Object.assign(wrapper.style, baseStyles);
// 检测父窗口是否为移动端
const isMobile = w.innerWidth < 768;
wrapper.src = `${origin}/widget.html?id=${id}&host=${hostId}&autoReg=${autoReg}&token=${loginToken}&themeColor=${encodeURIComponent(
themeColor
)}&from=${encodeURIComponent(location.hostname)}&welcome=${encodeURIComponent(welcome)}&title=${encodeURIComponent(title)}&logo=${encodeURIComponent(logo)}&popupTitle=${encodeURIComponent(popupTitle)}&popupSubtitle=${encodeURIComponent(popupSubtitle)}&popupImage=${encodeURIComponent(popupImage)}&popupClosable=${popupClosable}&showPopup=${showPopup}`;
)}&from=${encodeURIComponent(location.hostname)}&welcome=${encodeURIComponent(welcome)}&title=${encodeURIComponent(title)}&logo=${encodeURIComponent(logo)}&popupTitle=${encodeURIComponent(popupTitle)}&popupSubtitle=${encodeURIComponent(popupSubtitle)}&popupImage=${encodeURIComponent(popupImage)}&popupClosable=${popupClosable}&showPopup=${showPopup}&isMobile=${isMobile}`;
wrapper.width = actualCloseWidth;
wrapper.height = actualCloseHeight;
wrapper.frameborder = 0;