shareAiConsult.html 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <meta name="format-detection" content="telephone=no">
  7. <title>与U宝对话</title>
  8. <meta property="og:title" content="和U宝的对话">
  9. <meta property="og:description" content="点击查看对话内容">
  10. <meta property="og:site_name" content="U店在哪">
  11. <meta name="application-name" content="U店在哪">
  12. <link rel="icon" type="image/png" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
  13. <link rel="apple-touch-icon" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
  14. <style>
  15. :root {
  16. --bg: #f4f6fb;
  17. --text: #151515;
  18. --muted: #aaaaaa;
  19. --orange: #f47d1f;
  20. --safe-bottom: env(safe-area-inset-bottom, 0px);
  21. }
  22. * {
  23. margin: 0;
  24. padding: 0;
  25. box-sizing: border-box;
  26. }
  27. html {
  28. height: 100%;
  29. -webkit-tap-highlight-color: transparent;
  30. overflow: hidden;
  31. }
  32. body {
  33. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  34. background: var(--bg);
  35. color: var(--text);
  36. height: 100vh;
  37. display: flex;
  38. flex-direction: column;
  39. overflow: hidden;
  40. }
  41. #main {
  42. flex: 1;
  43. min-height: 0;
  44. overflow-x: hidden;
  45. overflow-y: auto;
  46. -webkit-overflow-scrolling: touch;
  47. padding-bottom: calc(100px + var(--safe-bottom));
  48. }
  49. .hero {
  50. padding: 16px 15px 0;
  51. }
  52. .hero__title {
  53. font-size: 20px;
  54. font-weight: 700;
  55. line-height: 1.4;
  56. word-break: break-word;
  57. }
  58. .hero__meta {
  59. margin-top: 8px;
  60. font-size: 12px;
  61. color: var(--muted);
  62. line-height: 1.4;
  63. }
  64. .hero__divider {
  65. margin-top: 14px;
  66. height: 1px;
  67. background: rgba(170, 170, 170, 0.25);
  68. }
  69. .conversation {
  70. padding: 14px 15px 8px;
  71. }
  72. .scroll-spacer {
  73. height: calc(72px + var(--safe-bottom));
  74. flex-shrink: 0;
  75. }
  76. .conversation .row:last-child {
  77. margin-bottom: 0;
  78. }
  79. .row {
  80. display: flex;
  81. margin-bottom: 12px;
  82. }
  83. .row--user {
  84. justify-content: flex-end;
  85. }
  86. .row--ai {
  87. justify-content: flex-start;
  88. }
  89. .user-bubble {
  90. position: relative;
  91. max-width: 78%;
  92. padding: 10px 14px;
  93. background: var(--orange);
  94. border-radius: 8px 8px 2px 8px;
  95. color: #fff;
  96. font-size: 15px;
  97. font-weight: 500;
  98. line-height: 1.5;
  99. white-space: pre-wrap;
  100. word-break: break-word;
  101. }
  102. .user-bubble::after {
  103. content: "";
  104. position: absolute;
  105. right: -6px;
  106. bottom: 8px;
  107. width: 0;
  108. height: 0;
  109. border-style: solid;
  110. border-width: 6px 0 6px 7px;
  111. border-color: transparent transparent transparent var(--orange);
  112. }
  113. .ai-card {
  114. width: 100%;
  115. padding: 14px 13px;
  116. background: #fff;
  117. border-radius: 12px;
  118. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
  119. }
  120. .ai-card__text {
  121. font-size: 14px;
  122. line-height: 1.65;
  123. white-space: pre-wrap;
  124. word-break: break-word;
  125. text-align: left;
  126. }
  127. .ai-card::after {
  128. content: "本回答由AI生成,内容仅供参考,请仔细甄别";
  129. display: block;
  130. margin-top: 8px;
  131. font-size: 12px;
  132. line-height: 1.5;
  133. color: #999999;
  134. text-align: left;
  135. font-style: italic;
  136. }
  137. .ai-card__image {
  138. display: block;
  139. max-width: 100%;
  140. height: auto;
  141. margin: 8px 0;
  142. border-radius: 6px;
  143. cursor: pointer;
  144. }
  145. .user-bubble__image {
  146. display: block;
  147. max-width: 180px;
  148. border-radius: 4px;
  149. }
  150. .user-bubble--images {
  151. padding: 8px 10px;
  152. }
  153. .user-bubble__images {
  154. display: flex;
  155. flex-wrap: nowrap;
  156. gap: 8px;
  157. overflow-x: auto;
  158. overflow-y: hidden;
  159. -webkit-overflow-scrolling: touch;
  160. scrollbar-width: none;
  161. -ms-overflow-style: none;
  162. }
  163. .user-bubble__images::-webkit-scrollbar {
  164. display: none;
  165. }
  166. .user-bubble__images .user-bubble__image {
  167. flex: 0 0 auto;
  168. width: 72px;
  169. height: 72px;
  170. max-width: none;
  171. object-fit: cover;
  172. border-radius: 8px;
  173. cursor: pointer;
  174. }
  175. .image-preview {
  176. display: none;
  177. position: fixed;
  178. inset: 0;
  179. z-index: 10004;
  180. align-items: center;
  181. justify-content: center;
  182. padding: 16px;
  183. background: rgba(0, 0, 0, 0.92);
  184. }
  185. .image-preview.is-open {
  186. display: flex;
  187. }
  188. .image-preview__img {
  189. max-width: 100%;
  190. max-height: 100%;
  191. object-fit: contain;
  192. -webkit-user-drag: none;
  193. user-select: none;
  194. pointer-events: none;
  195. }
  196. .image-preview__close {
  197. position: absolute;
  198. top: calc(12px + env(safe-area-inset-top, 0px));
  199. right: 12px;
  200. z-index: 1;
  201. width: 36px;
  202. height: 36px;
  203. border: none;
  204. border-radius: 50%;
  205. background: rgba(255, 255, 255, 0.18);
  206. color: #fff;
  207. font-size: 24px;
  208. line-height: 1;
  209. cursor: pointer;
  210. }
  211. .fallback-card {
  212. margin: 14px 15px 0;
  213. padding: 14px 13px;
  214. background: #fff;
  215. border-radius: 8px;
  216. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
  217. }
  218. .fallback-card .ai-card__text {
  219. font-size: 14px;
  220. line-height: 1.65;
  221. white-space: pre-wrap;
  222. word-break: break-word;
  223. text-align: left;
  224. }
  225. .empty {
  226. padding: 48px 20px;
  227. text-align: center;
  228. color: var(--muted);
  229. font-size: 14px;
  230. }
  231. .fab-wrap {
  232. position: fixed;
  233. left: 0;
  234. right: 0;
  235. bottom: 0;
  236. z-index: 200;
  237. padding: 12px 24px calc(12px + var(--safe-bottom));
  238. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  239. pointer-events: none;
  240. }
  241. .fab-dock__slot {
  242. width: 100%;
  243. max-width: 280px;
  244. height: 48px;
  245. margin: 0 auto;
  246. pointer-events: auto;
  247. }
  248. #openApp.fab {
  249. padding: 0 10px;
  250. -webkit-font-smoothing: antialiased;
  251. text-rendering: optimizeLegibility;
  252. }
  253. .fab__brand-clip {
  254. display: block;
  255. flex-shrink: 0;
  256. line-height: 0;
  257. }
  258. .fab__brand-img {
  259. display: block;
  260. height: 20px;
  261. width: auto;
  262. max-width: 90%;
  263. pointer-events: none;
  264. -webkit-user-drag: none;
  265. }
  266. .fab__label {
  267. font-size: 15px;
  268. line-height: 1;
  269. letter-spacing: 0.04em;
  270. white-space: nowrap;
  271. }
  272. #launch-btn {
  273. display: none;
  274. width: 100%;
  275. height: 48px;
  276. min-height: 48px;
  277. border-radius: 999px;
  278. overflow: hidden;
  279. opacity: 1;
  280. }
  281. body.is-wechat.wx-jssdk-ready #launch-btn {
  282. display: block;
  283. }
  284. body.is-wechat.wx-jssdk-ready #openApp {
  285. display: none !important;
  286. }
  287. .fab-wrap .fab {
  288. pointer-events: auto;
  289. }
  290. #openApp {
  291. touch-action: manipulation;
  292. }
  293. .fab {
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. gap: 4px;
  298. width: 100%;
  299. max-width: 280px;
  300. margin: 0 auto;
  301. height: 48px;
  302. border: none;
  303. border-radius: 999px;
  304. background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
  305. color: #fff;
  306. font-size: 16px;
  307. font-weight: 600;
  308. box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
  309. cursor: pointer;
  310. }
  311. .home-indicator {
  312. height: 5px;
  313. background: #000;
  314. border-radius: 3px;
  315. width: 134px;
  316. margin: 8px auto 4px;
  317. opacity: 0.2;
  318. }
  319. #openAppToast {
  320. display: none;
  321. position: fixed;
  322. left: 16px;
  323. right: 16px;
  324. bottom: calc(72px + var(--safe-bottom));
  325. z-index: 10001;
  326. padding: 10px 14px;
  327. font-size: 13px;
  328. line-height: 1.45;
  329. color: #fff;
  330. text-align: center;
  331. background: rgba(0, 0, 0, 0.78);
  332. border-radius: 8px;
  333. pointer-events: none;
  334. word-break: break-all;
  335. }
  336. .api-debug-btn {
  337. position: fixed;
  338. top: calc(12px + env(safe-area-inset-top, 0px));
  339. right: 12px;
  340. z-index: 10002;
  341. padding: 6px 10px;
  342. border: none;
  343. border-radius: 6px;
  344. background: rgba(0, 0, 0, 0.55);
  345. color: #fff;
  346. font-size: 12px;
  347. line-height: 1;
  348. cursor: pointer;
  349. }
  350. .api-debug-mask {
  351. display: none;
  352. position: fixed;
  353. inset: 0;
  354. z-index: 10003;
  355. background: rgba(0, 0, 0, 0.45);
  356. }
  357. .api-debug-mask.is-open {
  358. display: block;
  359. }
  360. .api-debug-modal {
  361. position: absolute;
  362. left: 12px;
  363. right: 12px;
  364. top: 50%;
  365. max-height: 80vh;
  366. transform: translateY(-50%);
  367. display: flex;
  368. flex-direction: column;
  369. background: #fff;
  370. border-radius: 12px;
  371. overflow: hidden;
  372. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  373. }
  374. .api-debug-modal__header {
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. padding: 14px 16px;
  379. border-bottom: 1px solid #eee;
  380. flex-shrink: 0;
  381. }
  382. .api-debug-modal__title {
  383. font-size: 16px;
  384. font-weight: 600;
  385. }
  386. .api-debug-modal__close {
  387. padding: 4px 8px;
  388. border: none;
  389. background: transparent;
  390. color: #666;
  391. font-size: 14px;
  392. cursor: pointer;
  393. }
  394. .api-debug-modal__body {
  395. flex: 1;
  396. min-height: 0;
  397. overflow-y: auto;
  398. -webkit-overflow-scrolling: touch;
  399. padding: 12px 16px 16px;
  400. }
  401. .api-debug-section {
  402. margin-bottom: 14px;
  403. }
  404. .api-debug-section:last-child {
  405. margin-bottom: 0;
  406. }
  407. .api-debug-section__label {
  408. margin-bottom: 6px;
  409. font-size: 13px;
  410. font-weight: 600;
  411. color: #333;
  412. }
  413. .api-debug-section__pre {
  414. margin: 0;
  415. padding: 10px 12px;
  416. background: #f5f6f8;
  417. border-radius: 8px;
  418. font-size: 12px;
  419. line-height: 1.5;
  420. white-space: pre-wrap;
  421. word-break: break-all;
  422. color: #222;
  423. font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  424. }
  425. </style>
  426. </head>
  427. <body>
  428. <main id="main">
  429. <div class="empty">对话内容加载中…</div>
  430. </main>
  431. <div id="openAppToast" role="status" aria-live="polite"></div>
  432. <!-- <button type="button" class="api-debug-btn" id="apiDebugBtn" aria-label="查看接口信息">接口</button> -->
  433. <div class="api-debug-mask" id="apiDebugMask" aria-hidden="true">
  434. <div class="api-debug-modal" role="dialog" aria-labelledby="apiDebugTitle">
  435. <div class="api-debug-modal__header">
  436. <span class="api-debug-modal__title" id="apiDebugTitle">聊天记录接口</span>
  437. <button type="button" class="api-debug-modal__close" id="apiDebugClose">关闭</button>
  438. </div>
  439. <div class="api-debug-modal__body" id="apiDebugBody"></div>
  440. </div>
  441. </div>
  442. <div class="image-preview" id="imagePreview" aria-hidden="true">
  443. <button type="button" class="image-preview__close" id="imagePreviewClose" aria-label="关闭预览">×</button>
  444. <img class="image-preview__img" id="imagePreviewImg" src="" alt="图片预览" />
  445. </div>
  446. <div class="fab-wrap">
  447. <div class="fab-dock__slot">
  448. <!-- 与 secondShareGoods 相同顺序:openApp 在下,launch-btn 在上,避免挡住点击 -->
  449. <button type="button" class="fab" id="openApp" aria-label="和U宝继续聊">
  450. <span class="fab__brand-clip" aria-hidden="true">
  451. <img class="fab__brand-img" src="images/uCharts.png" alt="和U宝继续聊" decoding="async">
  452. </span>
  453. </button>
  454. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  455. <script type="text/wxtag-template">
  456. <style>
  457. .wx-open-app-btn {
  458. display: flex;
  459. align-items: center;
  460. justify-content: center;
  461. width: 100%;
  462. height: 48px;
  463. margin: 0;
  464. padding: 0 10px;
  465. border: none;
  466. border-radius: 999px;
  467. background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
  468. box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
  469. cursor: pointer;
  470. overflow: hidden;
  471. -webkit-tap-highlight-color: transparent;
  472. box-sizing: border-box;
  473. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  474. -webkit-font-smoothing: antialiased;
  475. }
  476. .wx-open-app-btn .fab__brand-clip {
  477. display: block;
  478. flex-shrink: 0;
  479. line-height: 0;
  480. }
  481. .wx-open-app-btn .fab__brand-img {
  482. display: block;
  483. height: 20px;
  484. width: auto;
  485. max-width: 90%;
  486. pointer-events: none;
  487. -webkit-user-drag: none;
  488. }
  489. </style>
  490. <button class="wx-open-app-btn" aria-label="和U宝继续聊">
  491. <span class="fab__brand-clip" aria-hidden="true">
  492. <img class="fab__brand-img" src="https://prod.ailien.shop/h5/HBuilderProjects/images/uCharts.png" alt="和U宝继续聊" decoding="async">
  493. </span>
  494. </button>
  495. </script>
  496. </wx-open-launch-app>
  497. </div>
  498. <div class="home-indicator" aria-hidden="true"></div>
  499. </div>
  500. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  501. <script>
  502. (function () {
  503. "use strict";
  504. var API_BASE = "https://prod.ailien.shop/alienStore";
  505. var WECHAT_MP_APP_ID = "wx412792c77f47babd";
  506. var WECHAT_OPEN_APP_ID = "wxf5f1efe3a9f5012e";
  507. var WECHAT_GET_WX_CONFIG_PATH = "/wx/getWxConfig";
  508. var H5_PAGE_BASE_FALLBACK = "https://prod.ailien.shop/h5/HBuilderProjects/";
  509. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + "shareAiConsult.html";
  510. var WECHAT_JS_SAFE_HOSTS = ["uat.ailien.shop", "prod.ailien.shop"];
  511. var APP_ANDROID_PACKAGE = "com.alien.Udianzaizhe";
  512. var APP_DOWNLOAD_URL = "https://a.app.qq.com/o/simple.jsp?pkgname=com.alien.Udianzaina";
  513. var APP_IOS_DOWNLOAD_URL = "https://apps.apple.com/cn/app/u店在哪/id6752243565";
  514. var APP_IOS_URL_SCHEME = "shopro://";
  515. var APP_UNI_AI_PATH = "pages/aiSearchResult/index";
  516. var AI_LEGAL_CONVERSATION_API =
  517. "https://prod.ailien.shop/ai/life-manager/api/v1/legal-consultation/history/conversation";
  518. var AI_UBAO_CONVERSATION_API =
  519. "https://prod.ailien.shop/ai/life-manager/api/v1/ubao-conversation/history/conversation";
  520. var sharePayloadCache = null;
  521. var conversationApiDebugInfo = null;
  522. var weChatJssdkConfigured = false;
  523. var wxConfigSignRetriedBaseUrl = false;
  524. var wxInitLastError = "";
  525. var wxJssdkInitPromise = null;
  526. function escHtml(s) {
  527. return String(s || "")
  528. .replace(/&/g, "&amp;")
  529. .replace(/</g, "&lt;")
  530. .replace(/>/g, "&gt;")
  531. .replace(/"/g, "&quot;");
  532. }
  533. var IMAGE_EXT = "(?:jpe?g|png|gif|webp|bmp|avif)";
  534. var IMAGE_URL_PATTERN =
  535. "https?:\\/\\/[^\\s))\\]]+\\." + IMAGE_EXT + "(?:\\?[^\\s))\\]]*)?";
  536. function isInsideImageUrlSyntax(full, offset) {
  537. if (offset >= 2 && full.slice(offset - 2, offset) === "](") return true;
  538. if (offset >= 1 && full[offset - 1] === "(") return true;
  539. if (offset >= 6 && full.slice(offset - 6, offset) === "{{IMG|") return true;
  540. return false;
  541. }
  542. /** AI 回复常见:店名(https://...jpg) — 转为可渲染的图片占位 */
  543. function embedInlineImageUrls(text) {
  544. if (text == null) return "";
  545. var t = String(text);
  546. t = t.replace(
  547. new RegExp("([^\\n((]+?)\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  548. function (_, label, url) {
  549. var name = String(label).trim();
  550. if (!name) return "\n\n{{IMG|" + url + "|}}\n\n";
  551. var alt = name.length > 24 ? "图片" : name.replace(/[\[\]]/g, "");
  552. return name + "\n\n{{IMG|" + url + "|" + alt + "}}\n\n";
  553. }
  554. );
  555. t = t.replace(
  556. new RegExp("\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  557. function (_, url) {
  558. return "\n\n{{IMG|" + url + "|}}\n\n";
  559. }
  560. );
  561. t = t.replace(new RegExp(IMAGE_URL_PATTERN, "gi"), function (url, offset, full) {
  562. if (isInsideImageUrlSyntax(full, offset)) return url;
  563. return "\n\n{{IMG|" + url + "|}}\n\n";
  564. });
  565. return t.replace(/\n{3,}/g, "\n\n");
  566. }
  567. function formatTextBlockHtml(text) {
  568. return escHtml(text).replace(/\n/g, "<br>");
  569. }
  570. function buildAiImageTag(url, alt) {
  571. var safeUrl = escHtml(url);
  572. var safeAlt = escHtml(alt || "图片");
  573. return (
  574. '<img class="ai-card__image" src="' +
  575. safeUrl +
  576. '" alt="' +
  577. safeAlt +
  578. '" loading="lazy" decoding="async" />'
  579. );
  580. }
  581. function renderAiContentHtml(text) {
  582. var t = embedInlineImageUrls(text);
  583. var html = "";
  584. var tokenRe = /\{\{IMG\|([^|]+)\|([^}]*)\}\}/g;
  585. var lastIndex = 0;
  586. var match;
  587. while ((match = tokenRe.exec(t)) !== null) {
  588. if (match.index > lastIndex) {
  589. html += formatTextBlockHtml(t.slice(lastIndex, match.index));
  590. }
  591. html += buildAiImageTag(match[1], match[2]);
  592. lastIndex = tokenRe.lastIndex;
  593. }
  594. if (lastIndex < t.length) {
  595. html += formatTextBlockHtml(t.slice(lastIndex));
  596. }
  597. return html;
  598. }
  599. function q(name) {
  600. try {
  601. var v = new URLSearchParams(location.search || "").get(name);
  602. return v == null ? "" : String(v);
  603. } catch (e) {
  604. return "";
  605. }
  606. }
  607. function getQueryParam(name) {
  608. var m = new RegExp("[?&]" + name + "=([^&]*)").exec(window.location.search);
  609. if (!m) return "";
  610. try {
  611. return decodeURIComponent(m[1].replace(/\+/g, " "));
  612. } catch (e) {
  613. return "";
  614. }
  615. }
  616. function parsePayload() {
  617. var raw = getQueryParam("payload");
  618. if (!raw) return null;
  619. try {
  620. return JSON.parse(raw);
  621. } catch (e) {
  622. return null;
  623. }
  624. }
  625. function getConversationQueryParams() {
  626. var sessionId = String(q("session_id") || q("sessionId") || "").trim();
  627. var userId = String(q("user_id") || q("userId") || "").trim();
  628. var type = String(q("type") || "").trim();
  629. if (!sessionId || !userId) return null;
  630. return { sessionId: sessionId, userId: userId, type: type };
  631. }
  632. function parseMessageIdsFromQuery() {
  633. var raw = String(q("message_ids") || q("messageIds") || "").trim();
  634. if (!raw) return null;
  635. return raw
  636. .split(",")
  637. .map(function (s) {
  638. return String(s || "").trim();
  639. })
  640. .filter(Boolean);
  641. }
  642. function getMessageImageUrls(msg) {
  643. if (!msg) return [];
  644. if (Array.isArray(msg.imageUrls) && msg.imageUrls.length) {
  645. return msg.imageUrls
  646. .map(function (u) {
  647. return String(u || "").trim();
  648. })
  649. .filter(Boolean);
  650. }
  651. if (msg.imageUrl) return [String(msg.imageUrl)];
  652. return [];
  653. }
  654. function buildUserBubbleImagesHtml(imageUrls) {
  655. if (!Array.isArray(imageUrls) || !imageUrls.length) return "";
  656. var imgs = "";
  657. for (var j = 0; j < imageUrls.length; j++) {
  658. imgs +=
  659. '<img class="user-bubble__image" src="' +
  660. escHtml(imageUrls[j]) +
  661. '" alt="图片" loading="lazy" decoding="async" />';
  662. }
  663. return '<div class="user-bubble__images">' + imgs + "</div>";
  664. }
  665. function normalizeHistoryRowImageUrls(item) {
  666. var raw = item.image_urls || item.imageUrls || item.images;
  667. if (Array.isArray(raw)) {
  668. return raw
  669. .map(function (u) {
  670. return String(u || "").trim();
  671. })
  672. .filter(Boolean);
  673. }
  674. if (typeof raw === "string" && raw.trim()) {
  675. return raw
  676. .split(",")
  677. .map(function (s) {
  678. return s.trim();
  679. })
  680. .filter(Boolean);
  681. }
  682. return [];
  683. }
  684. function filterConversationMessagesByIds(messages, idList) {
  685. if (!Array.isArray(idList) || !idList.length) return messages;
  686. var idSet = {};
  687. for (var i = 0; i < idList.length; i++) {
  688. idSet[String(idList[i])] = true;
  689. }
  690. return (Array.isArray(messages) ? messages : []).filter(function (msg) {
  691. if (!msg || msg.id == null || msg.id === "") return false;
  692. return !!idSet[String(msg.id)];
  693. });
  694. }
  695. function getConversationApiBase(type) {
  696. return String(type || "").trim() === "1"
  697. ? AI_UBAO_CONVERSATION_API
  698. : AI_LEGAL_CONVERSATION_API;
  699. }
  700. function buildConversationApiUrl(sessionId, userId, type) {
  701. var params = new URLSearchParams();
  702. params.set("session_id", sessionId);
  703. params.set("user_id", userId);
  704. return getConversationApiBase(type) + "?" + params.toString();
  705. }
  706. function normalizeConversationRole(raw) {
  707. var role = String(raw || "").trim().toLowerCase();
  708. if (
  709. role === "user" ||
  710. role === "human" ||
  711. role === "customer" ||
  712. role === "question" ||
  713. role === "1" ||
  714. role === "我"
  715. ) {
  716. return "user";
  717. }
  718. if (
  719. role === "ai" ||
  720. role === "assistant" ||
  721. role === "bot" ||
  722. role === "ubao" ||
  723. role === "answer" ||
  724. role === "2" ||
  725. role === "system"
  726. ) {
  727. return "ai";
  728. }
  729. return "";
  730. }
  731. function normalizeConversationApiPayload(res) {
  732. if (!res || typeof res !== "object") return null;
  733. if (res.code != null) {
  734. var code = Number(res.code);
  735. if (code !== 200 && code !== 0 && res.success !== true) {
  736. throw new Error(res.msg || res.message || "对话接口返回 code " + code);
  737. }
  738. }
  739. var root = res.data != null && typeof res.data === "object" ? res.data : res;
  740. var rawList =
  741. (Array.isArray(root) && root) ||
  742. (Array.isArray(root.messages) && root.messages) ||
  743. (Array.isArray(root.messageList) && root.messageList) ||
  744. (Array.isArray(root.conversation) && root.conversation) ||
  745. (Array.isArray(root.conversations) && root.conversations) ||
  746. (Array.isArray(root.records) && root.records) ||
  747. (Array.isArray(root.list) && root.list) ||
  748. null;
  749. if (!rawList) return null;
  750. var messages = [];
  751. for (var i = 0; i < rawList.length; i++) {
  752. var item = rawList[i];
  753. if (!item || typeof item !== "object") continue;
  754. var msgId = item.id != null ? item.id : item.message_id;
  755. var role = normalizeConversationRole(
  756. item.role || item.sender || item.messageRole || item.type || item.messageType || item.senderType
  757. );
  758. var content = String(
  759. item.content != null
  760. ? item.content
  761. : item.message != null
  762. ? item.message
  763. : item.text != null
  764. ? item.text
  765. : ""
  766. ).trim();
  767. if (!role && item.question) {
  768. role = "user";
  769. content = String(item.question).trim();
  770. } else if (!role && item.answer) {
  771. role = "ai";
  772. content = String(item.answer).trim();
  773. } else if (!role && item.userMessage) {
  774. role = "user";
  775. content = String(item.userMessage).trim();
  776. } else if (!role && (item.aiMessage || item.assistantMessage)) {
  777. role = "ai";
  778. content = String(item.aiMessage || item.assistantMessage).trim();
  779. }
  780. var imageUrls = normalizeHistoryRowImageUrls(item);
  781. if (imageUrls.length) {
  782. messages.push({
  783. id: msgId,
  784. role: role || "user",
  785. isImage: true,
  786. imageUrls: imageUrls,
  787. imageUrl: imageUrls[0],
  788. content: content,
  789. });
  790. continue;
  791. }
  792. if (!content) continue;
  793. var imageUrl = item.imageUrl || item.image || item.imgUrl || item.url;
  794. if (imageUrl && /^(https?:)?\/\//i.test(String(imageUrl))) {
  795. messages.push({
  796. id: msgId,
  797. role: role || "user",
  798. isImage: true,
  799. imageUrls: [String(imageUrl)],
  800. imageUrl: String(imageUrl),
  801. });
  802. continue;
  803. }
  804. messages.push({
  805. id: msgId,
  806. role: role || (messages.length % 2 === 0 ? "user" : "ai"),
  807. content: content,
  808. });
  809. }
  810. if (!messages.length) return null;
  811. return {
  812. messages: messages,
  813. shareTime:
  814. root.shareTime ||
  815. root.createdAt ||
  816. root.createTime ||
  817. root.updateTime ||
  818. root.timestamp ||
  819. res.timestamp,
  820. firstQuestion: root.firstQuestion || root.title || root.topic || "",
  821. sessionId: root.sessionId || root.session_id || "",
  822. userId: root.userId || root.user_id || "",
  823. };
  824. }
  825. function formatJsonForDebug(value) {
  826. if (value == null) return "(无)";
  827. try {
  828. return JSON.stringify(value, null, 2);
  829. } catch (e) {
  830. return String(value);
  831. }
  832. }
  833. function setConversationApiDebugInfo(info) {
  834. conversationApiDebugInfo = info;
  835. renderApiDebugModal();
  836. }
  837. function renderApiDebugModal() {
  838. var body = document.getElementById("apiDebugBody");
  839. if (!body) return;
  840. if (!conversationApiDebugInfo) {
  841. body.innerHTML =
  842. '<div class="api-debug-section"><div class="api-debug-section__label">说明</div>' +
  843. '<pre class="api-debug-section__pre">尚未请求聊天记录接口(缺少 session_id / user_id 参数时使用 payload 渲染)</pre></div>';
  844. return;
  845. }
  846. var info = conversationApiDebugInfo;
  847. var html =
  848. '<div class="api-debug-section"><div class="api-debug-section__label">接口地址</div>' +
  849. '<pre class="api-debug-section__pre">' +
  850. escHtml(info.apiBase || info.requestUrl || "(无)") +
  851. "</pre></div>" +
  852. '<div class="api-debug-section"><div class="api-debug-section__label">请求方式</div>' +
  853. '<pre class="api-debug-section__pre">' +
  854. escHtml(info.method || "GET") +
  855. "</pre></div>" +
  856. '<div class="api-debug-section"><div class="api-debug-section__label">完整请求 URL</div>' +
  857. '<pre class="api-debug-section__pre">' +
  858. escHtml(info.requestUrl || "(无)") +
  859. "</pre></div>" +
  860. '<div class="api-debug-section"><div class="api-debug-section__label">请求参数</div>' +
  861. '<pre class="api-debug-section__pre">' +
  862. escHtml(formatJsonForDebug(info.params)) +
  863. "</pre></div>";
  864. if (info.error) {
  865. html +=
  866. '<div class="api-debug-section"><div class="api-debug-section__label">请求错误</div>' +
  867. '<pre class="api-debug-section__pre">' +
  868. escHtml(info.error) +
  869. "</pre></div>";
  870. }
  871. html +=
  872. '<div class="api-debug-section"><div class="api-debug-section__label">接口返回数据</div>' +
  873. '<pre class="api-debug-section__pre">' +
  874. escHtml(formatJsonForDebug(info.response)) +
  875. "</pre></div>";
  876. body.innerHTML = html;
  877. }
  878. function showApiDebugModal() {
  879. renderApiDebugModal();
  880. var mask = document.getElementById("apiDebugMask");
  881. if (mask) {
  882. mask.classList.add("is-open");
  883. mask.setAttribute("aria-hidden", "false");
  884. }
  885. }
  886. function hideApiDebugModal() {
  887. var mask = document.getElementById("apiDebugMask");
  888. if (mask) {
  889. mask.classList.remove("is-open");
  890. mask.setAttribute("aria-hidden", "true");
  891. }
  892. }
  893. function bindApiDebugModalEvents() {
  894. var btn = document.getElementById("apiDebugBtn");
  895. var closeBtn = document.getElementById("apiDebugClose");
  896. var mask = document.getElementById("apiDebugMask");
  897. if (btn) btn.addEventListener("click", showApiDebugModal);
  898. if (closeBtn) closeBtn.addEventListener("click", hideApiDebugModal);
  899. if (mask) {
  900. mask.addEventListener("click", function (e) {
  901. if (e.target === mask) hideApiDebugModal();
  902. });
  903. }
  904. }
  905. function showImagePreview(url) {
  906. var urlStr = String(url || "").trim();
  907. if (!urlStr) return;
  908. var mask = document.getElementById("imagePreview");
  909. var img = document.getElementById("imagePreviewImg");
  910. if (!mask || !img) return;
  911. img.src = urlStr;
  912. mask.classList.add("is-open");
  913. mask.setAttribute("aria-hidden", "false");
  914. document.body.style.overflow = "hidden";
  915. }
  916. function hideImagePreview() {
  917. var mask = document.getElementById("imagePreview");
  918. var img = document.getElementById("imagePreviewImg");
  919. if (!mask) return;
  920. mask.classList.remove("is-open");
  921. mask.setAttribute("aria-hidden", "true");
  922. if (img) img.src = "";
  923. document.body.style.overflow = "";
  924. }
  925. function bindImagePreviewEvents() {
  926. var main = document.getElementById("main");
  927. var mask = document.getElementById("imagePreview");
  928. var closeBtn = document.getElementById("imagePreviewClose");
  929. if (main) {
  930. main.addEventListener("click", function (e) {
  931. var target = e.target;
  932. if (!target || target.tagName !== "IMG") return;
  933. if (
  934. target.classList.contains("user-bubble__image") ||
  935. target.classList.contains("ai-card__image")
  936. ) {
  937. showImagePreview(target.getAttribute("src") || target.src);
  938. }
  939. });
  940. }
  941. if (closeBtn) closeBtn.addEventListener("click", hideImagePreview);
  942. if (mask) {
  943. mask.addEventListener("click", function (e) {
  944. if (e.target === mask) hideImagePreview();
  945. });
  946. }
  947. }
  948. function fetchConversationHistory(sessionId, userId, type) {
  949. var requestUrl = buildConversationApiUrl(sessionId, userId, type);
  950. var apiBase = getConversationApiBase(type);
  951. var params = {
  952. session_id: sessionId,
  953. user_id: userId,
  954. type: type || "",
  955. };
  956. setConversationApiDebugInfo({
  957. apiBase: apiBase,
  958. requestUrl: requestUrl,
  959. method: "GET",
  960. params: params,
  961. response: null,
  962. error: null,
  963. });
  964. console.log("[conversation-api] GET", requestUrl);
  965. return fetch(requestUrl, {
  966. method: "GET",
  967. mode: "cors",
  968. credentials: "omit",
  969. headers: { Accept: "application/json" },
  970. })
  971. .then(function (r) {
  972. if (r.ok) return r.json();
  973. return r
  974. .text()
  975. .catch(function () {
  976. return "";
  977. })
  978. .then(function (text) {
  979. var hint = "";
  980. var parsed = null;
  981. try {
  982. parsed = JSON.parse(text);
  983. hint = parsed.msg || parsed.message || "";
  984. } catch (eP) {
  985. if (text) hint = text.slice(0, 120);
  986. }
  987. setConversationApiDebugInfo({
  988. apiBase: apiBase,
  989. requestUrl: requestUrl,
  990. method: "GET",
  991. params: params,
  992. response: parsed || text || null,
  993. error: "HTTP " + r.status + (hint ? ":" + hint : ""),
  994. });
  995. throw new Error("对话接口 HTTP " + r.status + (hint ? ":" + hint : ""));
  996. });
  997. })
  998. .then(function (res) {
  999. setConversationApiDebugInfo({
  1000. apiBase: apiBase,
  1001. requestUrl: requestUrl,
  1002. method: "GET",
  1003. params: params,
  1004. response: res,
  1005. error: null,
  1006. });
  1007. var data = normalizeConversationApiPayload(res);
  1008. if (!data) {
  1009. throw new Error("对话接口返回数据为空或格式无法解析");
  1010. }
  1011. return data;
  1012. })
  1013. .catch(function (e) {
  1014. if (!conversationApiDebugInfo || !conversationApiDebugInfo.error) {
  1015. setConversationApiDebugInfo({
  1016. apiBase: apiBase,
  1017. requestUrl: requestUrl,
  1018. method: "GET",
  1019. params: params,
  1020. response: conversationApiDebugInfo && conversationApiDebugInfo.response,
  1021. error: e && e.message ? e.message : String(e),
  1022. });
  1023. }
  1024. throw e;
  1025. });
  1026. }
  1027. function loadPageData() {
  1028. var main = document.getElementById("main");
  1029. var params = getConversationQueryParams();
  1030. if (!params) {
  1031. setConversationApiDebugInfo(null);
  1032. render(parsePayload());
  1033. return;
  1034. }
  1035. var filterIds = parseMessageIdsFromQuery();
  1036. main.innerHTML = '<div class="empty">对话内容加载中…</div>';
  1037. fetchConversationHistory(params.sessionId, params.userId, params.type)
  1038. .then(function (data) {
  1039. if (filterIds && filterIds.length) {
  1040. var filtered = filterConversationMessagesByIds(data.messages, filterIds);
  1041. if (!filtered.length) {
  1042. throw new Error("未找到所选对话内容");
  1043. }
  1044. data = Object.assign({}, data, { messages: filtered });
  1045. }
  1046. render(data);
  1047. })
  1048. .catch(function (e) {
  1049. var tip = e && e.message ? e.message : "对话加载失败,请稍后重试";
  1050. console.warn("[conversation-api]", tip, e);
  1051. main.innerHTML = '<div class="empty">' + escHtml(tip) + "</div>";
  1052. refreshWxLaunchTagAttrs();
  1053. });
  1054. }
  1055. function getFirstUserQuestion(messages) {
  1056. var list = Array.isArray(messages) ? messages : [];
  1057. for (var i = 0; i < list.length; i++) {
  1058. var m = list[i];
  1059. if (!m || m.role !== "user") continue;
  1060. if (m.isImage) return "[图片]";
  1061. var t = String(m.content || "").trim();
  1062. if (t) return t;
  1063. }
  1064. return "";
  1065. }
  1066. function formatDiscussionTitle(question) {
  1067. var qText = String(question || "").trim();
  1068. if (!qText) return "与AI助手对话";
  1069. if (qText.slice(-3) === "的讨论") return qText;
  1070. return qText + "的讨论";
  1071. }
  1072. function normalizeShareTimestamp(ts) {
  1073. if (ts == null || ts === "") return null;
  1074. var n = Number(ts);
  1075. if (!isFinite(n) || n <= 0) return null;
  1076. if (n < 1e12) n = n * 1000;
  1077. var d = new Date(n);
  1078. if (isNaN(d.getTime()) || d.getFullYear() < 2020) return null;
  1079. return n;
  1080. }
  1081. function resolveDisplayShareTime(data) {
  1082. var fromUrl = q("shareTime") || q("share_time");
  1083. var urlTs = normalizeShareTimestamp(fromUrl);
  1084. if (urlTs != null) return urlTs;
  1085. var dataTs = normalizeShareTimestamp(data && data.shareTime);
  1086. if (dataTs != null) return dataTs;
  1087. return Date.now();
  1088. }
  1089. function formatDate(ts) {
  1090. var normalized = normalizeShareTimestamp(ts);
  1091. var d = normalized != null ? new Date(normalized) : new Date();
  1092. return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
  1093. }
  1094. function renderMessages(messages) {
  1095. var html = "";
  1096. var list = Array.isArray(messages) ? messages : [];
  1097. for (var i = 0; i < list.length; i++) {
  1098. var msg = list[i];
  1099. if (!msg) continue;
  1100. if (msg.role === "user") {
  1101. var imageUrls = getMessageImageUrls(msg);
  1102. if (msg.isImage && imageUrls.length) {
  1103. html +=
  1104. '<div class="row row--user"><div class="user-bubble user-bubble--images">' +
  1105. buildUserBubbleImagesHtml(imageUrls) +
  1106. "</div></div>";
  1107. var imageUserText = String(msg.content || "").trim();
  1108. if (imageUserText) {
  1109. html +=
  1110. '<div class="row row--user"><div class="user-bubble">' +
  1111. escHtml(imageUserText) +
  1112. "</div></div>";
  1113. }
  1114. continue;
  1115. }
  1116. var userText = String(msg.content || "").trim();
  1117. if (!userText) continue;
  1118. html +=
  1119. '<div class="row row--user"><div class="user-bubble">' +
  1120. escHtml(userText) +
  1121. "</div></div>";
  1122. continue;
  1123. }
  1124. if (msg.role === "ai" || msg.role === "assistant") {
  1125. var aiText = String(msg.content || "").trim();
  1126. if (!aiText) continue;
  1127. html +=
  1128. '<div class="row row--ai"><div class="ai-card"><div class="ai-card__text">' +
  1129. renderAiContentHtml(aiText) +
  1130. "</div></div></div>";
  1131. }
  1132. }
  1133. return html;
  1134. }
  1135. function applyWeixinShareMeta() {
  1136. var siteName = "U店在哪";
  1137. var iconUrl =
  1138. "https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png";
  1139. var setMeta = function (key, content) {
  1140. var el =
  1141. document.querySelector('meta[property="' + key + '"]') ||
  1142. document.querySelector('meta[name="' + key + '"]');
  1143. if (!el) {
  1144. el = document.createElement("meta");
  1145. if (key.indexOf("og:") === 0) {
  1146. el.setAttribute("property", key);
  1147. } else {
  1148. el.setAttribute("name", key);
  1149. }
  1150. document.head.appendChild(el);
  1151. }
  1152. el.setAttribute("content", content);
  1153. };
  1154. setMeta("og:site_name", siteName);
  1155. setMeta("application-name", siteName);
  1156. setMeta("og:title", "和U宝的对话");
  1157. setMeta("og:description", "点击查看对话内容");
  1158. var links = document.querySelectorAll('link[rel="icon"], link[rel="apple-touch-icon"]');
  1159. for (var i = 0; i < links.length; i++) {
  1160. links[i].setAttribute("href", iconUrl);
  1161. }
  1162. }
  1163. function countDisplayableMessages(messages) {
  1164. var list = Array.isArray(messages) ? messages : [];
  1165. var count = 0;
  1166. for (var i = 0; i < list.length; i++) {
  1167. var msg = list[i];
  1168. if (!msg) continue;
  1169. if (msg.role === "user") {
  1170. if (msg.isImage && getMessageImageUrls(msg).length) {
  1171. count += 1;
  1172. continue;
  1173. }
  1174. if (String(msg.content || "").trim()) count += 1;
  1175. continue;
  1176. }
  1177. if (msg.role === "ai" || msg.role === "assistant") {
  1178. if (String(msg.content || "").trim()) count += 1;
  1179. }
  1180. }
  1181. return count;
  1182. }
  1183. function parseMessagesFromContent(text) {
  1184. var raw = String(text || "").trim();
  1185. if (!raw) return [];
  1186. var list = [];
  1187. var blocks = raw.split(/\n\n+/);
  1188. for (var i = 0; i < blocks.length; i++) {
  1189. var block = String(blocks[i] || "").trim();
  1190. if (!block) continue;
  1191. var userMatch = block.match(/^我[::]\s*([\s\S]*)$/);
  1192. if (userMatch) {
  1193. var userText = String(userMatch[1] || "").trim();
  1194. if (userText) list.push({ role: "user", content: userText });
  1195. continue;
  1196. }
  1197. var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
  1198. if (aiMatch) {
  1199. var aiText = String(aiMatch[1] || "").trim();
  1200. if (aiText) list.push({ role: "ai", content: aiText });
  1201. }
  1202. }
  1203. if (list.length) return list;
  1204. var current = null;
  1205. var lines = raw.split(/\n/);
  1206. for (var j = 0; j < lines.length; j++) {
  1207. var line = String(lines[j] || "");
  1208. var userLine = line.match(/^我[::]\s*(.*)$/);
  1209. var aiLine = line.match(/^UBAO[::]\s*(.*)$/i);
  1210. if (userLine) {
  1211. if (current) list.push(current);
  1212. current = { role: "user", content: String(userLine[1] || "").trim() };
  1213. continue;
  1214. }
  1215. if (aiLine) {
  1216. if (current) list.push(current);
  1217. current = { role: "ai", content: String(aiLine[1] || "").trim() };
  1218. continue;
  1219. }
  1220. if (current && line.trim()) {
  1221. current.content = (current.content ? current.content + "\n" : "") + line.trim();
  1222. }
  1223. }
  1224. if (current && String(current.content || "").trim()) list.push(current);
  1225. return list;
  1226. }
  1227. function resolveShareMessagesForDisplay(data) {
  1228. var fromArray = Array.isArray(data && data.messages) ? data.messages : [];
  1229. var fromContent = parseMessagesFromContent((data && data.content) || "");
  1230. var arrayCount = countDisplayableMessages(fromArray);
  1231. var contentCount = countDisplayableMessages(fromContent);
  1232. // 分享链接超长时 messages 会被截断,但 content 仍保留完整对话文本
  1233. if (contentCount > arrayCount) return fromContent;
  1234. if (arrayCount) return fromArray;
  1235. return fromContent;
  1236. }
  1237. function render(data) {
  1238. applyWeixinShareMeta();
  1239. sharePayloadCache = data || null;
  1240. var main = document.getElementById("main");
  1241. if (!data) {
  1242. main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
  1243. refreshWxLaunchTagAttrs();
  1244. return;
  1245. }
  1246. var messages = resolveShareMessagesForDisplay(data);
  1247. var firstQuestion =
  1248. String(data.firstQuestion || "").trim() ||
  1249. getFirstUserQuestion(messages) ||
  1250. (function () {
  1251. var text = String(data.content || "").trim();
  1252. var m = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
  1253. return m ? String(m[1] || "").trim() : "";
  1254. })();
  1255. var pageTitle = formatDiscussionTitle(firstQuestion);
  1256. var dateText = formatDate(resolveDisplayShareTime(data));
  1257. document.title = pageTitle;
  1258. var bodyHtml =
  1259. '<section class="hero">' +
  1260. '<h1 class="hero__title">' +
  1261. escHtml(pageTitle) +
  1262. "</h1>" +
  1263. '<p class="hero__meta">' +
  1264. escHtml(dateText) +
  1265. " · 内容由AI生成,不能完全保障真实</p>" +
  1266. '<div class="hero__divider"></div>' +
  1267. "</section>";
  1268. var convHtml = renderMessages(messages);
  1269. if (convHtml) {
  1270. bodyHtml +=
  1271. '<section class="conversation">' +
  1272. convHtml +
  1273. '</section><div class="scroll-spacer" aria-hidden="true"></div>';
  1274. } else {
  1275. bodyHtml += '<div class="empty">暂无对话内容</div>';
  1276. }
  1277. main.innerHTML = bodyHtml;
  1278. refreshWxLaunchTagAttrs();
  1279. }
  1280. function buildAiConsultOpenParams() {
  1281. var params = new URLSearchParams();
  1282. params.set("pageType", "home");
  1283. params.set("fromShareAiConsult", "1");
  1284. return params;
  1285. }
  1286. function buildAppDeepLink() {
  1287. var path = APP_UNI_AI_PATH;
  1288. var qs = buildAiConsultOpenParams().toString();
  1289. var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
  1290. return root + "/" + path + (qs ? "?" + qs : "");
  1291. }
  1292. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  1293. var path = APP_UNI_AI_PATH.replace(/^\//, "");
  1294. if (useBarePathOnly) return path;
  1295. var qs = buildAiConsultOpenParams().toString();
  1296. var uniPage = qs ? path + "?" + qs : path;
  1297. if (uniPage.length <= 1024) return uniPage;
  1298. return path + "?pageType=home&fromShareAiConsult=1";
  1299. }
  1300. function isWeChatInAppBrowser() {
  1301. return /MicroMessenger/i.test(navigator.userAgent || "");
  1302. }
  1303. function getWxShareEntryFrom() {
  1304. var from = q("from");
  1305. if (from) return String(from).trim().toLowerCase();
  1306. try {
  1307. var h = location.hash || "";
  1308. var qi = h.indexOf("?");
  1309. if (qi >= 0) {
  1310. var hf = new URLSearchParams(h.slice(qi + 1)).get("from");
  1311. if (hf) return String(hf).trim().toLowerCase();
  1312. }
  1313. } catch (eH) {}
  1314. return "";
  1315. }
  1316. function logWxEntryDiagnostics() {
  1317. if (!isWeChatInAppBrowser()) return;
  1318. console.log("[wx-entry]", {
  1319. entryFrom: getWxShareEntryFrom() || "(无)",
  1320. wxJssdkReady: weChatJssdkConfigured,
  1321. signUrl: getWxConfigSignUrl(),
  1322. });
  1323. }
  1324. function isIOSWeChatBrowser() {
  1325. var ua = navigator.userAgent || "";
  1326. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  1327. }
  1328. function isWxDebugOn() {
  1329. return q("wxDebug") === "1";
  1330. }
  1331. function isWxForceDebug() {
  1332. return q("wxForce") === "1";
  1333. }
  1334. function isWxConfigOnClickDebug() {
  1335. return q("wxConfigOnClick") === "1";
  1336. }
  1337. function isWxPcAutoDebugHost() {
  1338. var h = (location.hostname || "").toLowerCase();
  1339. if (h === "localhost" || h === "127.0.0.1") return true;
  1340. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  1341. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  1342. }
  1343. return false;
  1344. }
  1345. function isWxPcBrowser() {
  1346. return !isWeChatInAppBrowser();
  1347. }
  1348. function shouldInitWeChatJssdkOnLoad() {
  1349. if (isWeChatInAppBrowser()) return true;
  1350. return isWxForceDebug() || isWxPcAutoDebugHost();
  1351. }
  1352. function shouldFetchWxConfig(fromUserClick) {
  1353. if (isWeChatInAppBrowser()) return true;
  1354. if (fromUserClick) return true;
  1355. return isWxForceDebug() || isWxPcAutoDebugHost();
  1356. }
  1357. function getWxHtmlUrl() {
  1358. var forced = String(q("wxSignUrl") || "").trim();
  1359. if (forced) return forced.split("#")[0];
  1360. return String(location.href || "").split("#")[0];
  1361. }
  1362. function getWxSignPageUrlForApi() {
  1363. var htmlUrl = getWxHtmlUrl();
  1364. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  1365. return WX_GET_CONFIG_SIGN_URL;
  1366. }
  1367. function getWxHtmlUrlBase() {
  1368. var htmlUrl = getWxSignPageUrlForApi();
  1369. try {
  1370. var u = new URL(htmlUrl);
  1371. return u.origin + u.pathname;
  1372. } catch (eU) {
  1373. return WX_GET_CONFIG_SIGN_URL;
  1374. }
  1375. }
  1376. /** 与 secondShareGoods 一致:默认用当前页完整 URL 验签(须与微信地址栏一致,含 query) */
  1377. function getWxConfigSignUrl() {
  1378. if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
  1379. return getWxSignPageUrlForApi();
  1380. }
  1381. function getWxGetConfigApiUrl() {
  1382. return API_BASE.replace(/\/$/, "") + WECHAT_GET_WX_CONFIG_PATH;
  1383. }
  1384. function buildWxGetConfigRequestBody(htmlUrl) {
  1385. return {
  1386. url: String(htmlUrl || "").split("#")[0].trim(),
  1387. };
  1388. }
  1389. function resolveWxConfigAppIdFromSignData(d) {
  1390. if (!d || typeof d !== "object") return "";
  1391. var mp =
  1392. d.mpAppId ||
  1393. d.mpAppid ||
  1394. d.officialAppId ||
  1395. d.gzhAppId ||
  1396. d.serviceAppId;
  1397. if (mp != null && String(mp).trim() !== "") return String(mp).trim();
  1398. var fromQuery = String(q("wxMpAppId") || WECHAT_MP_APP_ID || "").trim();
  1399. if (fromQuery) return fromQuery;
  1400. var raw = d.appId || d.appid || d.wxAppId;
  1401. return raw != null && String(raw).trim() !== "" ? String(raw).trim() : "";
  1402. }
  1403. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  1404. if (!res || typeof res !== "object") return null;
  1405. var d = res.data != null && typeof res.data === "object" ? res.data : res;
  1406. if (!d || typeof d !== "object") return null;
  1407. var appId = resolveWxConfigAppIdFromSignData(d);
  1408. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  1409. var nonceStr =
  1410. d.nonceStr != null && String(d.nonceStr) !== ""
  1411. ? d.nonceStr
  1412. : d.noncestr != null && String(d.noncestr) !== ""
  1413. ? d.noncestr
  1414. : d.nonce;
  1415. var signature = d.signature || d.sign;
  1416. if (!appId || timestamp == null || nonceStr == null || nonceStr === "" || !signature) {
  1417. return null;
  1418. }
  1419. return {
  1420. appId: String(appId),
  1421. timestamp: Number(timestamp),
  1422. nonceStr: String(nonceStr),
  1423. signature: String(signature),
  1424. signUrl: String(signUrlUsed || "")
  1425. .split("#")[0]
  1426. .trim(),
  1427. };
  1428. }
  1429. function getWxErrMsg(err) {
  1430. if (!err) return "";
  1431. if (err.errMsg) return String(err.errMsg);
  1432. if (typeof err === "string") return err;
  1433. try {
  1434. return JSON.stringify(err);
  1435. } catch (e) {
  1436. return String(err);
  1437. }
  1438. }
  1439. function formatWxConfigErrorTip(err, signPageUrl) {
  1440. var errMsg = getWxErrMsg(err);
  1441. var tip = "微信 JSSDK 配置失败";
  1442. if (/invalid signature/i.test(errMsg)) {
  1443. return (
  1444. tip +
  1445. ":签名无效。请核对:①后端用与前端相同的 url 签名;②url=" +
  1446. (signPageUrl || getWxHtmlUrl()) +
  1447. ";③nonceStr/timestamp 与接口返回一致;④appId=" +
  1448. WECHAT_MP_APP_ID
  1449. );
  1450. }
  1451. if (/require\s*subscribe/i.test(errMsg)) {
  1452. return tip + ":" + errMsg + "(服务号需用户已关注)";
  1453. }
  1454. return errMsg ? tip + ":" + errMsg : tip;
  1455. }
  1456. function setWxInitError(msg) {
  1457. wxInitLastError = String(msg || "").trim();
  1458. if (wxInitLastError) console.warn("[wx]", wxInitLastError);
  1459. }
  1460. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  1461. var htmlUrl = String(htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl())
  1462. .split("#")[0]
  1463. .trim();
  1464. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  1465. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  1466. }
  1467. if (isWxDebugOn()) {
  1468. try {
  1469. window.alert("htmlUrl(签名用,应与地址栏一致):\n" + htmlUrl);
  1470. } catch (eDbg) {}
  1471. }
  1472. var requestUrl = getWxGetConfigApiUrl();
  1473. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  1474. console.log("[wx] htmlUrl=", htmlUrl);
  1475. console.log("[wx] POST getWxConfig →", requestUrl, requestBody);
  1476. return fetch(requestUrl, {
  1477. method: "POST",
  1478. mode: "cors",
  1479. credentials: "omit",
  1480. headers: {
  1481. Accept: "application/json",
  1482. "Content-Type": "application/json;charset=UTF-8",
  1483. },
  1484. body: JSON.stringify(requestBody),
  1485. })
  1486. .then(function (r) {
  1487. if (r.ok) return r.json();
  1488. return r
  1489. .text()
  1490. .catch(function () {
  1491. return "";
  1492. })
  1493. .then(function (text) {
  1494. var hint = "";
  1495. try {
  1496. var j = JSON.parse(text);
  1497. hint = j.msg || j.message || "";
  1498. } catch (eP) {
  1499. if (text) hint = text.slice(0, 120);
  1500. }
  1501. throw new Error("getWxConfig HTTP " + r.status + (hint ? ":" + hint : ""));
  1502. });
  1503. })
  1504. .then(function (res) {
  1505. if (res && res.code != null) {
  1506. var c = Number(res.code);
  1507. if (c !== 200 && c !== 0 && res.success !== true) {
  1508. throw new Error(res.msg || res.message || "getWxConfig code " + c);
  1509. }
  1510. }
  1511. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  1512. if (!sign) {
  1513. console.warn("[wx] getWxConfig 响应字段不全", res, "htmlUrl=", htmlUrl);
  1514. throw new Error("getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)");
  1515. }
  1516. if (sign.appId !== WECHAT_MP_APP_ID) {
  1517. console.warn(
  1518. "[wx] 后端 appId=" + sign.appId + ",期望服务号 " + WECHAT_MP_APP_ID
  1519. );
  1520. }
  1521. if (typeof wx === "undefined") {
  1522. if (isWxPcBrowser()) {
  1523. console.log("[wx] PC getWxConfig 成功(无 jweixin)", sign);
  1524. return true;
  1525. }
  1526. setWxInitError("jweixin.js 未加载");
  1527. return false;
  1528. }
  1529. return applyWxConfigFromSign(sign, htmlUrl);
  1530. });
  1531. }
  1532. function applyWxConfigFromSign(sign, htmlUrl) {
  1533. var wxConfigParams = {
  1534. debug: isWxDebugOn(),
  1535. appId: String(sign.appId),
  1536. timestamp: sign.timestamp,
  1537. nonceStr: String(sign.nonceStr),
  1538. signature: String(sign.signature),
  1539. jsApiList: [],
  1540. openTagList: ["wx-open-launch-app"],
  1541. };
  1542. return new Promise(function (resolve) {
  1543. wx.config(wxConfigParams);
  1544. wx.ready(function () {
  1545. weChatJssdkConfigured = true;
  1546. document.body.classList.add("wx-jssdk-ready");
  1547. refreshWxLaunchTagAttrs();
  1548. console.log("[wx.config] ready, htmlUrl=", htmlUrl);
  1549. resolve(true);
  1550. });
  1551. wx.error(function (err) {
  1552. weChatJssdkConfigured = false;
  1553. document.body.classList.remove("wx-jssdk-ready");
  1554. wxJssdkInitPromise = null;
  1555. var errMsg = getWxErrMsg(err);
  1556. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  1557. if (isWxDebugOn()) window.alert(wxInitLastError);
  1558. console.warn("[wx.config]", errMsg, "htmlUrl=", htmlUrl);
  1559. var baseUrl = getWxHtmlUrlBase();
  1560. var fullUrl = getWxSignPageUrlForApi();
  1561. if (
  1562. !/invalid signature/i.test(errMsg) ||
  1563. wxConfigSignRetriedBaseUrl ||
  1564. baseUrl === fullUrl ||
  1565. htmlUrl === baseUrl
  1566. ) {
  1567. resolve(false);
  1568. return;
  1569. }
  1570. wxConfigSignRetriedBaseUrl = true;
  1571. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  1572. });
  1573. });
  1574. }
  1575. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  1576. var tag = document.getElementById("launch-btn");
  1577. if (!tag) return;
  1578. try {
  1579. tag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  1580. tag.setAttribute("extinfo", buildWeChatLaunchExtinfo(!!useBarePathOnly));
  1581. console.log("[wx-open-launch-app] extinfo=", tag.getAttribute("extinfo"));
  1582. } catch (eA) {}
  1583. }
  1584. function bindWeChatLaunchTagEvents() {
  1585. var tag = document.getElementById("launch-btn");
  1586. if (!tag || tag._wxLaunchBound) return;
  1587. tag._wxLaunchBound = true;
  1588. refreshWxLaunchTagAttrs();
  1589. tag.addEventListener("launch", function () {
  1590. console.log("[wx-open-launch-app] launch ok");
  1591. });
  1592. tag.addEventListener("error", function (e) {
  1593. var detail = e && e.detail;
  1594. var errMsg =
  1595. detail && detail.errMsg
  1596. ? String(detail.errMsg)
  1597. : detail && detail.errmsg
  1598. ? String(detail.errmsg)
  1599. : "";
  1600. console.warn(
  1601. "[wx-open-launch-app]",
  1602. detail,
  1603. "extinfo=",
  1604. tag.getAttribute("extinfo")
  1605. );
  1606. if (/launch:fail_check/i.test(errMsg)) {
  1607. showAppOpenFailTip(
  1608. "请用微信分享卡片进入,或确认已安装最新版「U店在哪」"
  1609. );
  1610. return;
  1611. }
  1612. // if (
  1613. // /launch:fail/i.test(errMsg) &&
  1614. // !tag._wxLaunchBareRetried &&
  1615. // tag.getAttribute("extinfo") !== buildWeChatLaunchExtinfo(true)
  1616. // ) {
  1617. // tag._wxLaunchBareRetried = true;
  1618. // refreshWxLaunchTagAttrs(true);
  1619. // showFabToast("请再点一次「和U宝继续聊」");
  1620. // return;
  1621. // }
  1622. if (/launch:fail/i.test(errMsg) && !getWxShareEntryFrom()) {
  1623. showAppOpenFailTip("请前往应用商店下载U店在哪app");
  1624. return;
  1625. }
  1626. showAppOpenFailTip(
  1627. errMsg
  1628. ? "未能打开 App:" + errMsg
  1629. : "未能打开 App,请确认已安装最新版「U店在哪」"
  1630. );
  1631. });
  1632. }
  1633. function initWeChatOpenLaunchApp(fromUserClick) {
  1634. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1635. return Promise.resolve(false);
  1636. }
  1637. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1638. wxConfigSignRetriedBaseUrl = false;
  1639. wxInitLastError = "";
  1640. var htmlUrl = getWxConfigSignUrl();
  1641. bindWeChatLaunchTagEvents();
  1642. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1643. .then(function (ok) {
  1644. if (ok === true) return true;
  1645. if (!wxInitLastError) {
  1646. setWxInitError("wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl");
  1647. }
  1648. return false;
  1649. })
  1650. .catch(function (e) {
  1651. var msg = e && e.message ? e.message : "getWxConfig 请求失败";
  1652. setWxInitError(msg);
  1653. console.warn("[wx] requestWeChatJssdkSignAndConfig failed", msg, "htmlUrl=", htmlUrl);
  1654. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1655. return false;
  1656. })
  1657. .finally(function () {
  1658. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1659. });
  1660. return wxJssdkInitPromise;
  1661. }
  1662. function scheduleWeChatJssdkBootstrap() {
  1663. if (!shouldInitWeChatJssdkOnLoad()) return;
  1664. var attempts = 0;
  1665. function tick() {
  1666. attempts += 1;
  1667. if (weChatJssdkConfigured) return;
  1668. initWeChatOpenLaunchApp();
  1669. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === "undefined") {
  1670. setTimeout(tick, 400);
  1671. }
  1672. }
  1673. if (isIOSWeChatBrowser()) {
  1674. setTimeout(tick, 350);
  1675. } else {
  1676. tick();
  1677. }
  1678. }
  1679. function showFabToast(msg, ms) {
  1680. var tip = String(msg || "").trim();
  1681. if (!tip) return;
  1682. var el = document.getElementById("openAppToast");
  1683. if (el) {
  1684. el.textContent = tip;
  1685. el.style.display = "block";
  1686. if (showFabToast._t) clearTimeout(showFabToast._t);
  1687. showFabToast._t = setTimeout(function () {
  1688. el.style.display = "none";
  1689. }, ms || 2800);
  1690. }
  1691. console.log("[openApp]", tip);
  1692. }
  1693. function showDownloadTip() {
  1694. var ua = navigator.userAgent || "";
  1695. var isIOS = /iP(hone|od|ad)/i.test(ua) || (navigator.platform === "MacIntel" && (navigator.maxTouchPoints || 0) > 1);
  1696. window.location.href = isIOS ? APP_IOS_DOWNLOAD_URL : APP_DOWNLOAD_URL;
  1697. }
  1698. function showAppOpenFailTip(msg) {
  1699. var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
  1700. if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
  1701. uni.showToast({ title: msg, icon: "none", duration: 2800 });
  1702. } else if (isWeChatInAppBrowser()) {
  1703. window.alert(tip);
  1704. } else {
  1705. showFabToast(tip);
  1706. }
  1707. }
  1708. function launchAppDeepLink(deepLink) {
  1709. try {
  1710. var a = document.createElement("a");
  1711. a.href = deepLink;
  1712. a.setAttribute("target", "_self");
  1713. document.body.appendChild(a);
  1714. a.click();
  1715. document.body.removeChild(a);
  1716. } catch (e1) {}
  1717. try {
  1718. window.location.href = deepLink;
  1719. } catch (e2) {}
  1720. }
  1721. function tryOpenHBuilderAppViaScheme() {
  1722. var deepLink = buildAppDeepLink();
  1723. if (typeof plus !== "undefined" && plus.runtime) {
  1724. var installed = null;
  1725. try {
  1726. if (typeof plus.runtime.isApplicationExist === "function") {
  1727. installed = plus.runtime.isApplicationExist({
  1728. pname: APP_ANDROID_PACKAGE,
  1729. action: APP_IOS_URL_SCHEME,
  1730. });
  1731. }
  1732. } catch (e) {
  1733. console.warn(e);
  1734. }
  1735. if (installed === false) {
  1736. showDownloadTip();
  1737. return;
  1738. }
  1739. try {
  1740. plus.runtime.openURL(deepLink);
  1741. } catch (e2) {
  1742. console.warn(e2);
  1743. showDownloadTip();
  1744. }
  1745. return;
  1746. }
  1747. var done = false;
  1748. function finish() {
  1749. if (done) return;
  1750. done = true;
  1751. document.removeEventListener("visibilitychange", onVis);
  1752. window.removeEventListener("pagehide", onHide);
  1753. }
  1754. function onVis() {
  1755. if (document.visibilityState === "hidden") finish();
  1756. }
  1757. function onHide() {
  1758. finish();
  1759. }
  1760. document.addEventListener("visibilitychange", onVis);
  1761. window.addEventListener("pagehide", onHide);
  1762. try {
  1763. launchAppDeepLink(deepLink);
  1764. } catch (e3) {
  1765. finish();
  1766. showDownloadTip();
  1767. return;
  1768. }
  1769. window.setTimeout(function () {
  1770. finish();
  1771. }, 3200);
  1772. }
  1773. function tryFetchWxConfigOnPcClick() {
  1774. if (!isWxPcBrowser()) return Promise.resolve(false);
  1775. showFabToast("正在请求 getWxConfig…");
  1776. wxJssdkInitPromise = null;
  1777. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1778. if (ok) {
  1779. showFabToast(
  1780. weChatJssdkConfigured
  1781. ? "getWxConfig 成功,wx.config 已就绪"
  1782. : "getWxConfig 成功"
  1783. );
  1784. } else {
  1785. showFabToast(wxInitLastError || "getWxConfig 失败");
  1786. }
  1787. return ok;
  1788. });
  1789. }
  1790. function tryOpenHBuilderApp() {
  1791. if (isWeChatInAppBrowser()) return;
  1792. if (!isWxPcBrowser()) {
  1793. tryOpenHBuilderAppViaScheme();
  1794. return;
  1795. }
  1796. tryFetchWxConfigOnPcClick().then(function () {
  1797. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1798. return;
  1799. }
  1800. tryOpenHBuilderAppViaScheme();
  1801. });
  1802. }
  1803. function boot() {
  1804. var launchTag = document.getElementById("launch-btn");
  1805. if (launchTag) launchTag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  1806. bindWeChatLaunchTagEvents();
  1807. if (isWeChatInAppBrowser()) {
  1808. document.body.classList.add("is-wechat");
  1809. logWxEntryDiagnostics();
  1810. }
  1811. if (shouldInitWeChatJssdkOnLoad()) {
  1812. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1813. document.body.classList.add("wx-pc-debug");
  1814. }
  1815. scheduleWeChatJssdkBootstrap();
  1816. }
  1817. document.addEventListener("WeixinOpenTagsError", function (e) {
  1818. console.warn("[WeixinOpenTagsError]", e && e.detail);
  1819. });
  1820. if (isWeChatInAppBrowser()) {
  1821. var openBtnWx = document.getElementById("openApp");
  1822. if (openBtnWx) {
  1823. openBtnWx.addEventListener("click", function () {
  1824. if (!weChatJssdkConfigured) {
  1825. showFabToast(
  1826. wxInitLastError || "微信 SDK 初始化中,请稍候再点底部按钮"
  1827. );
  1828. }
  1829. });
  1830. }
  1831. } else {
  1832. var openAppBtn = document.getElementById("openApp");
  1833. if (openAppBtn) {
  1834. openAppBtn.addEventListener("click", tryOpenHBuilderApp);
  1835. }
  1836. }
  1837. bindApiDebugModalEvents();
  1838. bindImagePreviewEvents();
  1839. loadPageData();
  1840. }
  1841. if (document.readyState === "complete") {
  1842. boot();
  1843. } else {
  1844. window.addEventListener("load", boot);
  1845. }
  1846. })();
  1847. </script>
  1848. </body>
  1849. </html>