|
@@ -80,10 +80,11 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.user-bubble {
|
|
.user-bubble {
|
|
|
|
|
+ position: relative;
|
|
|
max-width: 78%;
|
|
max-width: 78%;
|
|
|
padding: 10px 12px;
|
|
padding: 10px 12px;
|
|
|
background: var(--orange);
|
|
background: var(--orange);
|
|
|
- border-radius: 6px;
|
|
|
|
|
|
|
+ border-radius: 6px 6px 2px 6px;
|
|
|
color: #fff;
|
|
color: #fff;
|
|
|
font-size: 15px;
|
|
font-size: 15px;
|
|
|
font-weight: 500;
|
|
font-weight: 500;
|
|
@@ -92,6 +93,18 @@
|
|
|
word-break: break-word;
|
|
word-break: break-word;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ .user-bubble::after {
|
|
|
|
|
+ content: "";
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ right: -5px;
|
|
|
|
|
+ bottom: 6px;
|
|
|
|
|
+ width: 0;
|
|
|
|
|
+ height: 0;
|
|
|
|
|
+ border-style: solid;
|
|
|
|
|
+ border-width: 5px 0 5px 6px;
|
|
|
|
|
+ border-color: transparent transparent transparent var(--orange);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
.ai-card {
|
|
.ai-card {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
padding: 14px 13px;
|
|
padding: 14px 13px;
|
|
@@ -113,6 +126,15 @@
|
|
|
padding: 14px 13px;
|
|
padding: 14px 13px;
|
|
|
background: #fff;
|
|
background: #fff;
|
|
|
border-radius: 8px;
|
|
border-radius: 8px;
|
|
|
|
|
+ box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .fallback-card .ai-card__text {
|
|
|
|
|
+ font-size: 14px;
|
|
|
|
|
+ line-height: 1.65;
|
|
|
|
|
+ white-space: pre-wrap;
|
|
|
|
|
+ word-break: break-word;
|
|
|
|
|
+ text-align: left;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.empty {
|
|
.empty {
|
|
@@ -173,21 +195,23 @@
|
|
|
|
|
|
|
|
#launch-btn {
|
|
#launch-btn {
|
|
|
display: none;
|
|
display: none;
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ left: 0;
|
|
|
|
|
+ top: 0;
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- height: 48px;
|
|
|
|
|
|
|
+ height: 100%;
|
|
|
min-height: 48px;
|
|
min-height: 48px;
|
|
|
border-radius: 999px;
|
|
border-radius: 999px;
|
|
|
overflow: hidden;
|
|
overflow: hidden;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /* 微信 SDK 就绪:仅显示开放标签(与 secondShareGoods 一致,须直接点开放标签) */
|
|
|
|
|
body.is-wechat.wx-jssdk-ready #launch-btn {
|
|
body.is-wechat.wx-jssdk-ready #launch-btn {
|
|
|
display: block;
|
|
display: block;
|
|
|
- pointer-events: auto;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
body.is-wechat.wx-jssdk-ready #btnContinue {
|
|
body.is-wechat.wx-jssdk-ready #btnContinue {
|
|
|
- display: none !important;
|
|
|
|
|
|
|
+ visibility: hidden;
|
|
|
|
|
+ pointer-events: none;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#openAppToast {
|
|
#openAppToast {
|
|
@@ -317,81 +341,6 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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 formatNavTitle(question) {
|
|
|
|
|
- var titled = formatDiscussionTitle(question);
|
|
|
|
|
- var maxLen = 14;
|
|
|
|
|
- var short = titled.length > maxLen ? titled.slice(0, maxLen) + "..." : titled;
|
|
|
|
|
- return short + "-U宝";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function parseContentToMessages(content) {
|
|
|
|
|
- var text = String(content || "").trim();
|
|
|
|
|
- if (!text) return [];
|
|
|
|
|
-
|
|
|
|
|
- function pushParsed(list, role, body) {
|
|
|
|
|
- var t = String(body || "").trim();
|
|
|
|
|
- if (t) list.push({ role: role, content: t });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- 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) {
|
|
|
|
|
- pushParsed(messages, "user", userMatch[1]);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
|
|
|
|
|
- if (aiMatch) {
|
|
|
|
|
- pushParsed(messages, "ai", aiMatch[1]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- 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) {
|
|
function getFirstUserQuestion(messages) {
|
|
|
var list = Array.isArray(messages) ? messages : [];
|
|
var list = Array.isArray(messages) ? messages : [];
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
for (var i = 0; i < list.length; i++) {
|
|
@@ -483,19 +432,13 @@
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var messages = resolveShareMessages(data);
|
|
|
|
|
|
|
+ var messages = data.messages || [];
|
|
|
var firstQuestion =
|
|
var firstQuestion =
|
|
|
- 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() : "";
|
|
|
|
|
- })();
|
|
|
|
|
|
|
+ String(data.firstQuestion || "").trim() || getFirstUserQuestion(messages);
|
|
|
var pageTitle = formatDiscussionTitle(firstQuestion);
|
|
var pageTitle = formatDiscussionTitle(firstQuestion);
|
|
|
var dateText = formatDate(data.shareTime);
|
|
var dateText = formatDate(data.shareTime);
|
|
|
|
|
|
|
|
- document.title = formatNavTitle(firstQuestion);
|
|
|
|
|
|
|
+ document.title = pageTitle;
|
|
|
|
|
|
|
|
var bodyHtml =
|
|
var bodyHtml =
|
|
|
'<section class="hero">' +
|
|
'<section class="hero">' +
|
|
@@ -511,6 +454,11 @@
|
|
|
var convHtml = renderMessages(messages);
|
|
var convHtml = renderMessages(messages);
|
|
|
if (convHtml) {
|
|
if (convHtml) {
|
|
|
bodyHtml += '<section class="conversation">' + convHtml + "</section>";
|
|
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 {
|
|
} else {
|
|
|
bodyHtml += '<div class="empty">暂无对话内容</div>';
|
|
bodyHtml += '<div class="empty">暂无对话内容</div>';
|
|
|
}
|
|
}
|
|
@@ -519,14 +467,24 @@
|
|
|
refreshWxLaunchTagAttrs();
|
|
refreshWxLaunchTagAttrs();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function buildAiConsultOpenParams() {
|
|
|
|
|
+ var params = new URLSearchParams();
|
|
|
|
|
+ params.set("pageType", "home");
|
|
|
|
|
+ params.set("fromShareAiConsult", "1");
|
|
|
|
|
+ return params;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function buildAppDeepLink() {
|
|
function buildAppDeepLink() {
|
|
|
- var path = String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
|
|
|
|
|
|
|
+ var path = APP_UNI_AI_PATH;
|
|
|
|
|
+ var qs = buildAiConsultOpenParams().toString();
|
|
|
var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
|
|
var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
|
|
|
- return root + "/" + path;
|
|
|
|
|
|
|
+ return root + "/" + path + (qs ? "?" + qs : "");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function buildWeChatLaunchExtinfo() {
|
|
function buildWeChatLaunchExtinfo() {
|
|
|
- return String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
|
|
|
|
|
|
|
+ var qs = buildAiConsultOpenParams().toString();
|
|
|
|
|
+ var uniPage = qs ? APP_UNI_AI_PATH + "?" + qs : APP_UNI_AI_PATH;
|
|
|
|
|
+ return uniPage.length <= 1024 ? uniPage : APP_UNI_AI_PATH + "?pageType=home&fromShareAiConsult=1";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function isWeChatInAppBrowser() {
|
|
function isWeChatInAppBrowser() {
|
|
@@ -593,7 +551,8 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getWxConfigSignUrl() {
|
|
function getWxConfigSignUrl() {
|
|
|
- return getWxHtmlUrlBase();
|
|
|
|
|
|
|
+ if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
|
|
|
|
|
+ return getWxSignPageUrlForApi();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getWxGetConfigApiUrl() {
|
|
function getWxGetConfigApiUrl() {
|
|
@@ -794,10 +753,6 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function hideWxLaunchOverlay() {
|
|
|
|
|
- document.body.classList.remove("wx-jssdk-ready");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function refreshWxLaunchTagAttrs() {
|
|
function refreshWxLaunchTagAttrs() {
|
|
|
var tag = document.getElementById("launch-btn");
|
|
var tag = document.getElementById("launch-btn");
|
|
|
if (!tag) return;
|
|
if (!tag) return;
|
|
@@ -823,19 +778,7 @@
|
|
|
: detail && detail.errmsg
|
|
: detail && detail.errmsg
|
|
|
? String(detail.errmsg)
|
|
? String(detail.errmsg)
|
|
|
: "";
|
|
: "";
|
|
|
- console.warn("[wx-open-launch-app]", detail, "extinfo=", tag.getAttribute("extinfo"));
|
|
|
|
|
- if (/launch:fail_check/i.test(errMsg)) {
|
|
|
|
|
- hideWxLaunchOverlay();
|
|
|
|
|
- showAppOpenFailTip(
|
|
|
|
|
- "请用微信分享卡片进入,或确认已安装最新版「U店在哪」"
|
|
|
|
|
- );
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (/launch:fail/i.test(errMsg)) {
|
|
|
|
|
- hideWxLaunchOverlay();
|
|
|
|
|
- showAppOpenFailTip("未能打开 App,请确认已安装最新版「U店在哪」");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ console.warn("[wx-open-launch-app]", detail);
|
|
|
showAppOpenFailTip(
|
|
showAppOpenFailTip(
|
|
|
errMsg
|
|
errMsg
|
|
|
? "未能打开 App:" + errMsg
|
|
? "未能打开 App:" + errMsg
|
|
@@ -922,9 +865,11 @@
|
|
|
function showAppOpenFailTip(msg) {
|
|
function showAppOpenFailTip(msg) {
|
|
|
var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
|
|
var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
|
|
|
if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
|
|
if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
|
|
|
- uni.showToast({ title: tip, icon: "none", duration: 2800 });
|
|
|
|
|
|
|
+ uni.showToast({ title: msg, icon: "none", duration: 2800 });
|
|
|
|
|
+ } else if (isWeChatInAppBrowser()) {
|
|
|
|
|
+ window.alert(tip);
|
|
|
} else {
|
|
} else {
|
|
|
- showFabToast(tip, 3200);
|
|
|
|
|
|
|
+ showFabToast(tip);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -999,14 +944,7 @@
|
|
|
|
|
|
|
|
function tryOpenApp() {
|
|
function tryOpenApp() {
|
|
|
if (isWeChatInAppBrowser()) {
|
|
if (isWeChatInAppBrowser()) {
|
|
|
- if (weChatJssdkConfigured && !document.body.classList.contains("wx-jssdk-ready")) {
|
|
|
|
|
- document.body.classList.add("wx-jssdk-ready");
|
|
|
|
|
- refreshWxLaunchTagAttrs();
|
|
|
|
|
- showFabToast("请再次点击底部按钮");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
if (!weChatJssdkConfigured) {
|
|
if (!weChatJssdkConfigured) {
|
|
|
- showFabToast("微信 SDK 初始化中,请稍候再点");
|
|
|
|
|
initWeChatOpenLaunchApp(true).then(function (ok) {
|
|
initWeChatOpenLaunchApp(true).then(function (ok) {
|
|
|
if (!ok) {
|
|
if (!ok) {
|
|
|
showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
|
|
showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
|
|
@@ -1022,22 +960,10 @@
|
|
|
document.body.classList.add("is-wechat");
|
|
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();
|
|
bindWeChatLaunchTagEvents();
|
|
|
- document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
|
|
|
|
|
- render(sharePayload);
|
|
|
|
|
scheduleWeChatJssdkBootstrap();
|
|
scheduleWeChatJssdkBootstrap();
|
|
|
|
|
+ document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
|
|
|
|
|
+ render(parsePayload());
|
|
|
})();
|
|
})();
|
|
|
</script>
|
|
</script>
|
|
|
</body>
|
|
</body>
|