电脑企微上传成功后关不掉当前页,分析看板线路筛选被挤窄、往下也滚不动。按销售实际操作补上关窗,并让看板整页可以滚动。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
本文件职责:给附件上传成功、选线路成功页一段共用脚本。
|
||||
手机端只调一次 WeixinJSBridge.closeWindow,关掉当前 H5 后留在询价对话里。
|
||||
再调 ww/wx/window.close 会把询价小助手整个退出,回到企业微信首页。
|
||||
电脑企微即使注入了 WeixinJSBridge,这一下也关不掉当前页,必须按电脑走 JS-SDK。
|
||||
电脑企微 5.x 内置页经常加载不了 JS-SDK,也不会打签名接口。
|
||||
这时 ww.closeWindow 不会执行。电脑改用 WeixinJSBridge.invoke,再补 window.close,只关当前页。
|
||||
失败、过期页不要挂这段。
|
||||
副作用:只产出 HTML 片段;关窗签名走浏览器短请求,不占智能体请求线程做慢活。
|
||||
"""
|
||||
@@ -24,8 +25,9 @@ def wecom_auto_close_script() -> str:
|
||||
成功页脚:加载企微 JS-SDK,register 后关掉当前 H5 窗口。
|
||||
|
||||
线程:浏览器端执行。签名接口与复制页共用,ticket 已缓存在 Redis。
|
||||
为何这样写:电脑企微也会带上 WeixinJSBridge,但关不掉当前页。
|
||||
若一发现桥就只走手机关闭,成功页会停在「正在返回企微」。手机仍只关一次。
|
||||
为何这样写:21:27 的上传日志里,成功页已经返回,但没有 jsapi 签名请求。
|
||||
电脑企微没跑起 ww.register,只调 ww.closeWindow 等于没关。
|
||||
电脑改为 invoke + window.close,不依赖签名先成功。手机仍只关一次。
|
||||
"""
|
||||
settings = get_settings()
|
||||
corp = escape((settings.wecom_corp_id or "").strip(), quote=True)
|
||||
@@ -51,7 +53,11 @@ def wecom_auto_close_script() -> str:
|
||||
var closed = false;
|
||||
|
||||
function isPhone() {{
|
||||
return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent || "");
|
||||
var ua = navigator.userAgent || "";
|
||||
if (/wxwork/i.test(ua) && /Windows|Macintosh/i.test(ua) && !/Android|iPhone|iPad|iPod/i.test(ua)) {{
|
||||
return false;
|
||||
}}
|
||||
return /Android|iPhone|iPad|iPod/i.test(ua);
|
||||
}}
|
||||
|
||||
function closeOnce(fn) {{
|
||||
@@ -65,13 +71,22 @@ def wecom_auto_close_script() -> str:
|
||||
closeOnce(function () {{ WeixinJSBridge.call("closeWindow"); }});
|
||||
}}
|
||||
|
||||
// 电脑企微即使有 WeixinJSBridge,也关不掉当前页。注册 JS-SDK 后再关一次。
|
||||
// 不要调 window.close:手机会把询价小助手整个退出。
|
||||
// 电脑企微:call 关不掉,JS-SDK 又经常没装上。invoke 关内置页,window.close 关独立窗口。
|
||||
function closeDesktop() {{
|
||||
closeOnce(function () {{
|
||||
if (window.ww && typeof ww.closeWindow === "function") ww.closeWindow();
|
||||
else if (window.wx && typeof wx.closeWindow === "function") wx.closeWindow();
|
||||
}});
|
||||
try {{
|
||||
if (typeof WeixinJSBridge !== "undefined" && typeof WeixinJSBridge.invoke === "function") {{
|
||||
WeixinJSBridge.invoke("closeWindow", {{}}, function () {{}});
|
||||
}}
|
||||
}} catch (e) {{}}
|
||||
try {{
|
||||
if (window.ww && typeof ww.closeWindow === "function") {{
|
||||
var ret = ww.closeWindow();
|
||||
if (ret && ret.catch) ret.catch(function () {{}});
|
||||
}} else if (window.wx && typeof wx.closeWindow === "function") {{
|
||||
wx.closeWindow();
|
||||
}}
|
||||
}} catch (e) {{}}
|
||||
try {{ window.close(); }} catch (e) {{}}
|
||||
}}
|
||||
|
||||
function boot() {{
|
||||
@@ -85,21 +100,15 @@ def wecom_auto_close_script() -> str:
|
||||
}}, false);
|
||||
return;
|
||||
}}
|
||||
var ready = Promise.resolve();
|
||||
if (window.ww && ww.register && corpId) {{
|
||||
ready = ww.register({{
|
||||
corpId: corpId,
|
||||
agentId: agentId,
|
||||
jsApiList: ["closeWindow"],
|
||||
getConfigSignature: sign("corp"),
|
||||
getAgentConfigSignature: sign("agent")
|
||||
}}).catch(function () {{ return null; }});
|
||||
}}
|
||||
var timed = Promise.race([
|
||||
ready,
|
||||
new Promise(function (resolve) {{ setTimeout(resolve, 2500); }})
|
||||
]);
|
||||
timed.then(function () {{
|
||||
setTimeout(closeDesktop, {delay});
|
||||
if (!(window.ww && ww.register && corpId)) return;
|
||||
ww.register({{
|
||||
corpId: corpId,
|
||||
agentId: agentId,
|
||||
jsApiList: ["closeWindow"],
|
||||
getConfigSignature: sign("corp"),
|
||||
getAgentConfigSignature: sign("agent")
|
||||
}}).then(function () {{
|
||||
setTimeout(closeDesktop, {delay});
|
||||
}}).catch(function () {{
|
||||
setTimeout(closeDesktop, {delay});
|
||||
|
||||
Reference in New Issue
Block a user