|
|
@@ -182,6 +182,8 @@
|
|
|
box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
|
|
|
touch-action: manipulation;
|
|
|
-webkit-tap-highlight-color: transparent;
|
|
|
+ position: relative;
|
|
|
+ z-index: 1;
|
|
|
}
|
|
|
|
|
|
.continue-btn__label {
|
|
|
@@ -203,15 +205,12 @@
|
|
|
min-height: 48px;
|
|
|
border-radius: 999px;
|
|
|
overflow: hidden;
|
|
|
+ z-index: 2;
|
|
|
}
|
|
|
|
|
|
body.is-wechat.wx-jssdk-ready #launch-btn {
|
|
|
display: block;
|
|
|
- }
|
|
|
-
|
|
|
- body.is-wechat.wx-jssdk-ready #btnContinue {
|
|
|
- visibility: hidden;
|
|
|
- pointer-events: none;
|
|
|
+ pointer-events: auto;
|
|
|
}
|
|
|
|
|
|
#openAppToast {
|
|
|
@@ -341,6 +340,67 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function stripPayloadQueryFromUrl() {
|
|
|
+ try {
|
|
|
+ if (!location.search || location.search.indexOf("payload=") < 0) return;
|
|
|
+ var u = new URL(location.href);
|
|
|
+ u.searchParams.delete("payload");
|
|
|
+ var next = u.pathname + (u.search || "") + (u.hash || "");
|
|
|
+ history.replaceState(null, document.title, next);
|
|
|
+ } catch (eStrip) {}
|
|
|
+ }
|
|
|
+
|
|
|
+ function parseContentToMessages(content) {
|
|
|
+ var text = String(content || "").trim();
|
|
|
+ if (!text) return [];
|
|
|
+ var messages = [];
|
|
|
+ var blocks = text.split(/\n\n+/);
|
|
|
+ for (var i = 0; i < blocks.length; i++) {
|
|
|
+ var block = String(blocks[i] || "").trim();
|
|
|
+ if (!block) continue;
|
|
|
+ var userMatch = block.match(/^我[::]\s*([\s\S]*)$/);
|
|
|
+ if (userMatch) {
|
|
|
+ var userText = String(userMatch[1] || "").trim();
|
|
|
+ if (userText) messages.push({ role: "user", content: userText });
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
|
|
|
+ if (aiMatch) {
|
|
|
+ var aiText = String(aiMatch[1] || "").trim();
|
|
|
+ if (aiText) messages.push({ role: "ai", content: aiText });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (messages.length) return messages;
|
|
|
+ var current = null;
|
|
|
+ var lines = text.split(/\n/);
|
|
|
+ for (var j = 0; j < lines.length; j++) {
|
|
|
+ var line = String(lines[j] || "");
|
|
|
+ var userLine = line.match(/^我[::]\s*(.*)$/);
|
|
|
+ var aiLine = line.match(/^UBAO[::]\s*(.*)$/i);
|
|
|
+ if (userLine) {
|
|
|
+ if (current) messages.push(current);
|
|
|
+ current = { role: "user", content: String(userLine[1] || "").trim() };
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (aiLine) {
|
|
|
+ if (current) messages.push(current);
|
|
|
+ current = { role: "ai", content: String(aiLine[1] || "").trim() };
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (current && line.trim()) {
|
|
|
+ current.content = (current.content ? current.content + "\n" : "") + line.trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (current && String(current.content || "").trim()) messages.push(current);
|
|
|
+ return messages;
|
|
|
+ }
|
|
|
+
|
|
|
+ function resolveShareMessages(data) {
|
|
|
+ var messages = Array.isArray(data && data.messages) ? data.messages : [];
|
|
|
+ if (messages.length) return messages;
|
|
|
+ return parseContentToMessages(data && data.content);
|
|
|
+ }
|
|
|
+
|
|
|
function getFirstUserQuestion(messages) {
|
|
|
var list = Array.isArray(messages) ? messages : [];
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
@@ -432,9 +492,15 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var messages = data.messages || [];
|
|
|
+ var messages = resolveShareMessages(data);
|
|
|
var firstQuestion =
|
|
|
- String(data.firstQuestion || "").trim() || getFirstUserQuestion(messages);
|
|
|
+ String(data.firstQuestion || "").trim() ||
|
|
|
+ getFirstUserQuestion(messages) ||
|
|
|
+ (function () {
|
|
|
+ var text = String(data.content || "").trim();
|
|
|
+ var m = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
|
|
|
+ return m ? String(m[1] || "").trim() : "";
|
|
|
+ })();
|
|
|
var pageTitle = formatDiscussionTitle(firstQuestion);
|
|
|
var dateText = formatDate(data.shareTime);
|
|
|
|
|
|
@@ -454,11 +520,6 @@
|
|
|
var convHtml = renderMessages(messages);
|
|
|
if (convHtml) {
|
|
|
bodyHtml += '<section class="conversation">' + convHtml + "</section>";
|
|
|
- } else if (data.content) {
|
|
|
- bodyHtml +=
|
|
|
- '<section class="fallback-card"><div class="ai-card__text">' +
|
|
|
- escHtml(data.content) +
|
|
|
- "</div></section>";
|
|
|
} else {
|
|
|
bodyHtml += '<div class="empty">暂无对话内容</div>';
|
|
|
}
|
|
|
@@ -551,8 +612,7 @@
|
|
|
}
|
|
|
|
|
|
function getWxConfigSignUrl() {
|
|
|
- if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
|
|
|
- return getWxSignPageUrlForApi();
|
|
|
+ return getWxHtmlUrlBase();
|
|
|
}
|
|
|
|
|
|
function getWxGetConfigApiUrl() {
|
|
|
@@ -753,6 +813,10 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ function hideWxLaunchOverlay() {
|
|
|
+ document.body.classList.remove("wx-jssdk-ready");
|
|
|
+ }
|
|
|
+
|
|
|
function refreshWxLaunchTagAttrs() {
|
|
|
var tag = document.getElementById("launch-btn");
|
|
|
if (!tag) return;
|
|
|
@@ -778,7 +842,18 @@
|
|
|
: detail && detail.errmsg
|
|
|
? String(detail.errmsg)
|
|
|
: "";
|
|
|
- console.warn("[wx-open-launch-app]", detail);
|
|
|
+ console.warn("[wx-open-launch-app]", detail, "extinfo=", tag.getAttribute("extinfo"));
|
|
|
+ hideWxLaunchOverlay();
|
|
|
+ if (/launch:fail_check/i.test(errMsg)) {
|
|
|
+ showAppOpenFailTip(
|
|
|
+ "请用微信分享卡片进入,或确认已安装最新版「U店在哪」"
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (/launch:fail/i.test(errMsg)) {
|
|
|
+ showAppOpenFailTip("未能打开 App,请确认已安装最新版「U店在哪」");
|
|
|
+ return;
|
|
|
+ }
|
|
|
showAppOpenFailTip(
|
|
|
errMsg
|
|
|
? "未能打开 App:" + errMsg
|
|
|
@@ -865,11 +940,9 @@
|
|
|
function showAppOpenFailTip(msg) {
|
|
|
var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
|
|
|
if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
|
|
|
- uni.showToast({ title: msg, icon: "none", duration: 2800 });
|
|
|
- } else if (isWeChatInAppBrowser()) {
|
|
|
- window.alert(tip);
|
|
|
+ uni.showToast({ title: tip, icon: "none", duration: 2800 });
|
|
|
} else {
|
|
|
- showFabToast(tip);
|
|
|
+ showFabToast(tip, 3200);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -944,7 +1017,14 @@
|
|
|
|
|
|
function tryOpenApp() {
|
|
|
if (isWeChatInAppBrowser()) {
|
|
|
+ if (weChatJssdkConfigured && !document.body.classList.contains("wx-jssdk-ready")) {
|
|
|
+ document.body.classList.add("wx-jssdk-ready");
|
|
|
+ refreshWxLaunchTagAttrs();
|
|
|
+ showFabToast("请再次点击底部按钮");
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!weChatJssdkConfigured) {
|
|
|
+ showFabToast("微信 SDK 初始化中,请稍候再点");
|
|
|
initWeChatOpenLaunchApp(true).then(function (ok) {
|
|
|
if (!ok) {
|
|
|
showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
|
|
|
@@ -960,10 +1040,22 @@
|
|
|
document.body.classList.add("is-wechat");
|
|
|
}
|
|
|
|
|
|
+ document.addEventListener("WeixinOpenTagsError", function (e) {
|
|
|
+ console.warn("[WeixinOpenTagsError]", e && e.detail);
|
|
|
+ hideWxLaunchOverlay();
|
|
|
+ showFabToast("微信开放标签加载失败,请稍候再试");
|
|
|
+ });
|
|
|
+
|
|
|
+ var sharePayload = parsePayload();
|
|
|
+ stripPayloadQueryFromUrl();
|
|
|
+
|
|
|
+ var launchTagBoot = document.getElementById("launch-btn");
|
|
|
+ if (launchTagBoot) launchTagBoot.setAttribute("appid", WECHAT_OPEN_APP_ID);
|
|
|
+
|
|
|
bindWeChatLaunchTagEvents();
|
|
|
- scheduleWeChatJssdkBootstrap();
|
|
|
document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
|
|
|
- render(parsePayload());
|
|
|
+ render(sharePayload);
|
|
|
+ scheduleWeChatJssdkBootstrap();
|
|
|
})();
|
|
|
</script>
|
|
|
</body>
|