shareAiConsult.html 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  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_IOS_URL_SCHEME = "shopro://";
  513. var APP_UNI_AI_PATH = "pages/aiSearchResult/index";
  514. var AI_LEGAL_CONVERSATION_API =
  515. "https://prod.ailien.shop/ai/life-manager/api/v1/legal-consultation/history/conversation";
  516. var AI_UBAO_CONVERSATION_API =
  517. "https://prod.ailien.shop/ai/life-manager/api/v1/ubao-conversation/history/conversation";
  518. var sharePayloadCache = null;
  519. var conversationApiDebugInfo = null;
  520. var weChatJssdkConfigured = false;
  521. var wxConfigSignRetriedBaseUrl = false;
  522. var wxInitLastError = "";
  523. var wxJssdkInitPromise = null;
  524. function escHtml(s) {
  525. return String(s || "")
  526. .replace(/&/g, "&amp;")
  527. .replace(/</g, "&lt;")
  528. .replace(/>/g, "&gt;")
  529. .replace(/"/g, "&quot;");
  530. }
  531. var IMAGE_EXT = "(?:jpe?g|png|gif|webp|bmp|avif)";
  532. var IMAGE_URL_PATTERN =
  533. "https?:\\/\\/[^\\s))\\]]+\\." + IMAGE_EXT + "(?:\\?[^\\s))\\]]*)?";
  534. function isInsideImageUrlSyntax(full, offset) {
  535. if (offset >= 2 && full.slice(offset - 2, offset) === "](") return true;
  536. if (offset >= 1 && full[offset - 1] === "(") return true;
  537. if (offset >= 6 && full.slice(offset - 6, offset) === "{{IMG|") return true;
  538. return false;
  539. }
  540. /** AI 回复常见:店名(https://...jpg) — 转为可渲染的图片占位 */
  541. function embedInlineImageUrls(text) {
  542. if (text == null) return "";
  543. var t = String(text);
  544. t = t.replace(
  545. new RegExp("([^\\n((]+?)\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  546. function (_, label, url) {
  547. var name = String(label).trim();
  548. if (!name) return "\n\n{{IMG|" + url + "|}}\n\n";
  549. var alt = name.length > 24 ? "图片" : name.replace(/[\[\]]/g, "");
  550. return name + "\n\n{{IMG|" + url + "|" + alt + "}}\n\n";
  551. }
  552. );
  553. t = t.replace(
  554. new RegExp("\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  555. function (_, url) {
  556. return "\n\n{{IMG|" + url + "|}}\n\n";
  557. }
  558. );
  559. t = t.replace(new RegExp(IMAGE_URL_PATTERN, "gi"), function (url, offset, full) {
  560. if (isInsideImageUrlSyntax(full, offset)) return url;
  561. return "\n\n{{IMG|" + url + "|}}\n\n";
  562. });
  563. return t.replace(/\n{3,}/g, "\n\n");
  564. }
  565. function formatTextBlockHtml(text) {
  566. return escHtml(text).replace(/\n/g, "<br>");
  567. }
  568. function buildAiImageTag(url, alt) {
  569. var safeUrl = escHtml(url);
  570. var safeAlt = escHtml(alt || "图片");
  571. return (
  572. '<img class="ai-card__image" src="' +
  573. safeUrl +
  574. '" alt="' +
  575. safeAlt +
  576. '" loading="lazy" decoding="async" />'
  577. );
  578. }
  579. function renderAiContentHtml(text) {
  580. var t = embedInlineImageUrls(text);
  581. var html = "";
  582. var tokenRe = /\{\{IMG\|([^|]+)\|([^}]*)\}\}/g;
  583. var lastIndex = 0;
  584. var match;
  585. while ((match = tokenRe.exec(t)) !== null) {
  586. if (match.index > lastIndex) {
  587. html += formatTextBlockHtml(t.slice(lastIndex, match.index));
  588. }
  589. html += buildAiImageTag(match[1], match[2]);
  590. lastIndex = tokenRe.lastIndex;
  591. }
  592. if (lastIndex < t.length) {
  593. html += formatTextBlockHtml(t.slice(lastIndex));
  594. }
  595. return html;
  596. }
  597. function q(name) {
  598. try {
  599. var v = new URLSearchParams(location.search || "").get(name);
  600. return v == null ? "" : String(v);
  601. } catch (e) {
  602. return "";
  603. }
  604. }
  605. function getQueryParam(name) {
  606. var m = new RegExp("[?&]" + name + "=([^&]*)").exec(window.location.search);
  607. if (!m) return "";
  608. try {
  609. return decodeURIComponent(m[1].replace(/\+/g, " "));
  610. } catch (e) {
  611. return "";
  612. }
  613. }
  614. function parsePayload() {
  615. var raw = getQueryParam("payload");
  616. if (!raw) return null;
  617. try {
  618. return JSON.parse(raw);
  619. } catch (e) {
  620. return null;
  621. }
  622. }
  623. function getConversationQueryParams() {
  624. var sessionId = String(q("session_id") || q("sessionId") || "").trim();
  625. var userId = String(q("user_id") || q("userId") || "").trim();
  626. var type = String(q("type") || "").trim();
  627. if (!sessionId || !userId) return null;
  628. return { sessionId: sessionId, userId: userId, type: type };
  629. }
  630. function parseMessageIdsFromQuery() {
  631. var raw = String(q("message_ids") || q("messageIds") || "").trim();
  632. if (!raw) return null;
  633. return raw
  634. .split(",")
  635. .map(function (s) {
  636. return String(s || "").trim();
  637. })
  638. .filter(Boolean);
  639. }
  640. function getMessageImageUrls(msg) {
  641. if (!msg) return [];
  642. if (Array.isArray(msg.imageUrls) && msg.imageUrls.length) {
  643. return msg.imageUrls
  644. .map(function (u) {
  645. return String(u || "").trim();
  646. })
  647. .filter(Boolean);
  648. }
  649. if (msg.imageUrl) return [String(msg.imageUrl)];
  650. return [];
  651. }
  652. function buildUserBubbleImagesHtml(imageUrls) {
  653. if (!Array.isArray(imageUrls) || !imageUrls.length) return "";
  654. var imgs = "";
  655. for (var j = 0; j < imageUrls.length; j++) {
  656. imgs +=
  657. '<img class="user-bubble__image" src="' +
  658. escHtml(imageUrls[j]) +
  659. '" alt="图片" loading="lazy" decoding="async" />';
  660. }
  661. return '<div class="user-bubble__images">' + imgs + "</div>";
  662. }
  663. function normalizeHistoryRowImageUrls(item) {
  664. var raw = item.image_urls || item.imageUrls || item.images;
  665. if (Array.isArray(raw)) {
  666. return raw
  667. .map(function (u) {
  668. return String(u || "").trim();
  669. })
  670. .filter(Boolean);
  671. }
  672. if (typeof raw === "string" && raw.trim()) {
  673. return raw
  674. .split(",")
  675. .map(function (s) {
  676. return s.trim();
  677. })
  678. .filter(Boolean);
  679. }
  680. return [];
  681. }
  682. function filterConversationMessagesByIds(messages, idList) {
  683. if (!Array.isArray(idList) || !idList.length) return messages;
  684. var idSet = {};
  685. for (var i = 0; i < idList.length; i++) {
  686. idSet[String(idList[i])] = true;
  687. }
  688. return (Array.isArray(messages) ? messages : []).filter(function (msg) {
  689. if (!msg || msg.id == null || msg.id === "") return false;
  690. return !!idSet[String(msg.id)];
  691. });
  692. }
  693. function getConversationApiBase(type) {
  694. return String(type || "").trim() === "1"
  695. ? AI_UBAO_CONVERSATION_API
  696. : AI_LEGAL_CONVERSATION_API;
  697. }
  698. function buildConversationApiUrl(sessionId, userId, type) {
  699. var params = new URLSearchParams();
  700. params.set("session_id", sessionId);
  701. params.set("user_id", userId);
  702. return getConversationApiBase(type) + "?" + params.toString();
  703. }
  704. function normalizeConversationRole(raw) {
  705. var role = String(raw || "").trim().toLowerCase();
  706. if (
  707. role === "user" ||
  708. role === "human" ||
  709. role === "customer" ||
  710. role === "question" ||
  711. role === "1" ||
  712. role === "我"
  713. ) {
  714. return "user";
  715. }
  716. if (
  717. role === "ai" ||
  718. role === "assistant" ||
  719. role === "bot" ||
  720. role === "ubao" ||
  721. role === "answer" ||
  722. role === "2" ||
  723. role === "system"
  724. ) {
  725. return "ai";
  726. }
  727. return "";
  728. }
  729. function normalizeConversationApiPayload(res) {
  730. if (!res || typeof res !== "object") return null;
  731. if (res.code != null) {
  732. var code = Number(res.code);
  733. if (code !== 200 && code !== 0 && res.success !== true) {
  734. throw new Error(res.msg || res.message || "对话接口返回 code " + code);
  735. }
  736. }
  737. var root = res.data != null && typeof res.data === "object" ? res.data : res;
  738. var rawList =
  739. (Array.isArray(root) && root) ||
  740. (Array.isArray(root.messages) && root.messages) ||
  741. (Array.isArray(root.messageList) && root.messageList) ||
  742. (Array.isArray(root.conversation) && root.conversation) ||
  743. (Array.isArray(root.conversations) && root.conversations) ||
  744. (Array.isArray(root.records) && root.records) ||
  745. (Array.isArray(root.list) && root.list) ||
  746. null;
  747. if (!rawList) return null;
  748. var messages = [];
  749. for (var i = 0; i < rawList.length; i++) {
  750. var item = rawList[i];
  751. if (!item || typeof item !== "object") continue;
  752. var msgId = item.id != null ? item.id : item.message_id;
  753. var role = normalizeConversationRole(
  754. item.role || item.sender || item.messageRole || item.type || item.messageType || item.senderType
  755. );
  756. var content = String(
  757. item.content != null
  758. ? item.content
  759. : item.message != null
  760. ? item.message
  761. : item.text != null
  762. ? item.text
  763. : ""
  764. ).trim();
  765. if (!role && item.question) {
  766. role = "user";
  767. content = String(item.question).trim();
  768. } else if (!role && item.answer) {
  769. role = "ai";
  770. content = String(item.answer).trim();
  771. } else if (!role && item.userMessage) {
  772. role = "user";
  773. content = String(item.userMessage).trim();
  774. } else if (!role && (item.aiMessage || item.assistantMessage)) {
  775. role = "ai";
  776. content = String(item.aiMessage || item.assistantMessage).trim();
  777. }
  778. var imageUrls = normalizeHistoryRowImageUrls(item);
  779. if (imageUrls.length) {
  780. messages.push({
  781. id: msgId,
  782. role: role || "user",
  783. isImage: true,
  784. imageUrls: imageUrls,
  785. imageUrl: imageUrls[0],
  786. content: content,
  787. });
  788. continue;
  789. }
  790. if (!content) continue;
  791. var imageUrl = item.imageUrl || item.image || item.imgUrl || item.url;
  792. if (imageUrl && /^(https?:)?\/\//i.test(String(imageUrl))) {
  793. messages.push({
  794. id: msgId,
  795. role: role || "user",
  796. isImage: true,
  797. imageUrls: [String(imageUrl)],
  798. imageUrl: String(imageUrl),
  799. });
  800. continue;
  801. }
  802. messages.push({
  803. id: msgId,
  804. role: role || (messages.length % 2 === 0 ? "user" : "ai"),
  805. content: content,
  806. });
  807. }
  808. if (!messages.length) return null;
  809. return {
  810. messages: messages,
  811. shareTime:
  812. root.shareTime ||
  813. root.createdAt ||
  814. root.createTime ||
  815. root.updateTime ||
  816. root.timestamp ||
  817. res.timestamp,
  818. firstQuestion: root.firstQuestion || root.title || root.topic || "",
  819. sessionId: root.sessionId || root.session_id || "",
  820. userId: root.userId || root.user_id || "",
  821. };
  822. }
  823. function formatJsonForDebug(value) {
  824. if (value == null) return "(无)";
  825. try {
  826. return JSON.stringify(value, null, 2);
  827. } catch (e) {
  828. return String(value);
  829. }
  830. }
  831. function setConversationApiDebugInfo(info) {
  832. conversationApiDebugInfo = info;
  833. renderApiDebugModal();
  834. }
  835. function renderApiDebugModal() {
  836. var body = document.getElementById("apiDebugBody");
  837. if (!body) return;
  838. if (!conversationApiDebugInfo) {
  839. body.innerHTML =
  840. '<div class="api-debug-section"><div class="api-debug-section__label">说明</div>' +
  841. '<pre class="api-debug-section__pre">尚未请求聊天记录接口(缺少 session_id / user_id 参数时使用 payload 渲染)</pre></div>';
  842. return;
  843. }
  844. var info = conversationApiDebugInfo;
  845. var html =
  846. '<div class="api-debug-section"><div class="api-debug-section__label">接口地址</div>' +
  847. '<pre class="api-debug-section__pre">' +
  848. escHtml(info.apiBase || info.requestUrl || "(无)") +
  849. "</pre></div>" +
  850. '<div class="api-debug-section"><div class="api-debug-section__label">请求方式</div>' +
  851. '<pre class="api-debug-section__pre">' +
  852. escHtml(info.method || "GET") +
  853. "</pre></div>" +
  854. '<div class="api-debug-section"><div class="api-debug-section__label">完整请求 URL</div>' +
  855. '<pre class="api-debug-section__pre">' +
  856. escHtml(info.requestUrl || "(无)") +
  857. "</pre></div>" +
  858. '<div class="api-debug-section"><div class="api-debug-section__label">请求参数</div>' +
  859. '<pre class="api-debug-section__pre">' +
  860. escHtml(formatJsonForDebug(info.params)) +
  861. "</pre></div>";
  862. if (info.error) {
  863. html +=
  864. '<div class="api-debug-section"><div class="api-debug-section__label">请求错误</div>' +
  865. '<pre class="api-debug-section__pre">' +
  866. escHtml(info.error) +
  867. "</pre></div>";
  868. }
  869. html +=
  870. '<div class="api-debug-section"><div class="api-debug-section__label">接口返回数据</div>' +
  871. '<pre class="api-debug-section__pre">' +
  872. escHtml(formatJsonForDebug(info.response)) +
  873. "</pre></div>";
  874. body.innerHTML = html;
  875. }
  876. function showApiDebugModal() {
  877. renderApiDebugModal();
  878. var mask = document.getElementById("apiDebugMask");
  879. if (mask) {
  880. mask.classList.add("is-open");
  881. mask.setAttribute("aria-hidden", "false");
  882. }
  883. }
  884. function hideApiDebugModal() {
  885. var mask = document.getElementById("apiDebugMask");
  886. if (mask) {
  887. mask.classList.remove("is-open");
  888. mask.setAttribute("aria-hidden", "true");
  889. }
  890. }
  891. function bindApiDebugModalEvents() {
  892. var btn = document.getElementById("apiDebugBtn");
  893. var closeBtn = document.getElementById("apiDebugClose");
  894. var mask = document.getElementById("apiDebugMask");
  895. if (btn) btn.addEventListener("click", showApiDebugModal);
  896. if (closeBtn) closeBtn.addEventListener("click", hideApiDebugModal);
  897. if (mask) {
  898. mask.addEventListener("click", function (e) {
  899. if (e.target === mask) hideApiDebugModal();
  900. });
  901. }
  902. }
  903. function showImagePreview(url) {
  904. var urlStr = String(url || "").trim();
  905. if (!urlStr) return;
  906. var mask = document.getElementById("imagePreview");
  907. var img = document.getElementById("imagePreviewImg");
  908. if (!mask || !img) return;
  909. img.src = urlStr;
  910. mask.classList.add("is-open");
  911. mask.setAttribute("aria-hidden", "false");
  912. document.body.style.overflow = "hidden";
  913. }
  914. function hideImagePreview() {
  915. var mask = document.getElementById("imagePreview");
  916. var img = document.getElementById("imagePreviewImg");
  917. if (!mask) return;
  918. mask.classList.remove("is-open");
  919. mask.setAttribute("aria-hidden", "true");
  920. if (img) img.src = "";
  921. document.body.style.overflow = "";
  922. }
  923. function bindImagePreviewEvents() {
  924. var main = document.getElementById("main");
  925. var mask = document.getElementById("imagePreview");
  926. var closeBtn = document.getElementById("imagePreviewClose");
  927. if (main) {
  928. main.addEventListener("click", function (e) {
  929. var target = e.target;
  930. if (!target || target.tagName !== "IMG") return;
  931. if (
  932. target.classList.contains("user-bubble__image") ||
  933. target.classList.contains("ai-card__image")
  934. ) {
  935. showImagePreview(target.getAttribute("src") || target.src);
  936. }
  937. });
  938. }
  939. if (closeBtn) closeBtn.addEventListener("click", hideImagePreview);
  940. if (mask) {
  941. mask.addEventListener("click", function (e) {
  942. if (e.target === mask) hideImagePreview();
  943. });
  944. }
  945. }
  946. function fetchConversationHistory(sessionId, userId, type) {
  947. var requestUrl = buildConversationApiUrl(sessionId, userId, type);
  948. var apiBase = getConversationApiBase(type);
  949. var params = {
  950. session_id: sessionId,
  951. user_id: userId,
  952. type: type || "",
  953. };
  954. setConversationApiDebugInfo({
  955. apiBase: apiBase,
  956. requestUrl: requestUrl,
  957. method: "GET",
  958. params: params,
  959. response: null,
  960. error: null,
  961. });
  962. console.log("[conversation-api] GET", requestUrl);
  963. return fetch(requestUrl, {
  964. method: "GET",
  965. mode: "cors",
  966. credentials: "omit",
  967. headers: { Accept: "application/json" },
  968. })
  969. .then(function (r) {
  970. if (r.ok) return r.json();
  971. return r
  972. .text()
  973. .catch(function () {
  974. return "";
  975. })
  976. .then(function (text) {
  977. var hint = "";
  978. var parsed = null;
  979. try {
  980. parsed = JSON.parse(text);
  981. hint = parsed.msg || parsed.message || "";
  982. } catch (eP) {
  983. if (text) hint = text.slice(0, 120);
  984. }
  985. setConversationApiDebugInfo({
  986. apiBase: apiBase,
  987. requestUrl: requestUrl,
  988. method: "GET",
  989. params: params,
  990. response: parsed || text || null,
  991. error: "HTTP " + r.status + (hint ? ":" + hint : ""),
  992. });
  993. throw new Error("对话接口 HTTP " + r.status + (hint ? ":" + hint : ""));
  994. });
  995. })
  996. .then(function (res) {
  997. setConversationApiDebugInfo({
  998. apiBase: apiBase,
  999. requestUrl: requestUrl,
  1000. method: "GET",
  1001. params: params,
  1002. response: res,
  1003. error: null,
  1004. });
  1005. var data = normalizeConversationApiPayload(res);
  1006. if (!data) {
  1007. throw new Error("对话接口返回数据为空或格式无法解析");
  1008. }
  1009. return data;
  1010. })
  1011. .catch(function (e) {
  1012. if (!conversationApiDebugInfo || !conversationApiDebugInfo.error) {
  1013. setConversationApiDebugInfo({
  1014. apiBase: apiBase,
  1015. requestUrl: requestUrl,
  1016. method: "GET",
  1017. params: params,
  1018. response: conversationApiDebugInfo && conversationApiDebugInfo.response,
  1019. error: e && e.message ? e.message : String(e),
  1020. });
  1021. }
  1022. throw e;
  1023. });
  1024. }
  1025. function loadPageData() {
  1026. var main = document.getElementById("main");
  1027. var params = getConversationQueryParams();
  1028. if (!params) {
  1029. setConversationApiDebugInfo(null);
  1030. render(parsePayload());
  1031. return;
  1032. }
  1033. var filterIds = parseMessageIdsFromQuery();
  1034. main.innerHTML = '<div class="empty">对话内容加载中…</div>';
  1035. fetchConversationHistory(params.sessionId, params.userId, params.type)
  1036. .then(function (data) {
  1037. if (filterIds && filterIds.length) {
  1038. var filtered = filterConversationMessagesByIds(data.messages, filterIds);
  1039. if (!filtered.length) {
  1040. throw new Error("未找到所选对话内容");
  1041. }
  1042. data = Object.assign({}, data, { messages: filtered });
  1043. }
  1044. render(data);
  1045. })
  1046. .catch(function (e) {
  1047. var tip = e && e.message ? e.message : "对话加载失败,请稍后重试";
  1048. console.warn("[conversation-api]", tip, e);
  1049. main.innerHTML = '<div class="empty">' + escHtml(tip) + "</div>";
  1050. refreshWxLaunchTagAttrs();
  1051. });
  1052. }
  1053. function getFirstUserQuestion(messages) {
  1054. var list = Array.isArray(messages) ? messages : [];
  1055. for (var i = 0; i < list.length; i++) {
  1056. var m = list[i];
  1057. if (!m || m.role !== "user") continue;
  1058. if (m.isImage) return "[图片]";
  1059. var t = String(m.content || "").trim();
  1060. if (t) return t;
  1061. }
  1062. return "";
  1063. }
  1064. function formatDiscussionTitle(question) {
  1065. var qText = String(question || "").trim();
  1066. if (!qText) return "与AI助手对话";
  1067. if (qText.slice(-3) === "的讨论") return qText;
  1068. return qText + "的讨论";
  1069. }
  1070. function normalizeShareTimestamp(ts) {
  1071. if (ts == null || ts === "") return null;
  1072. var n = Number(ts);
  1073. if (!isFinite(n) || n <= 0) return null;
  1074. if (n < 1e12) n = n * 1000;
  1075. var d = new Date(n);
  1076. if (isNaN(d.getTime()) || d.getFullYear() < 2020) return null;
  1077. return n;
  1078. }
  1079. function resolveDisplayShareTime(data) {
  1080. var fromUrl = q("shareTime") || q("share_time");
  1081. var urlTs = normalizeShareTimestamp(fromUrl);
  1082. if (urlTs != null) return urlTs;
  1083. var dataTs = normalizeShareTimestamp(data && data.shareTime);
  1084. if (dataTs != null) return dataTs;
  1085. return Date.now();
  1086. }
  1087. function formatDate(ts) {
  1088. var normalized = normalizeShareTimestamp(ts);
  1089. var d = normalized != null ? new Date(normalized) : new Date();
  1090. return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
  1091. }
  1092. function renderMessages(messages) {
  1093. var html = "";
  1094. var list = Array.isArray(messages) ? messages : [];
  1095. for (var i = 0; i < list.length; i++) {
  1096. var msg = list[i];
  1097. if (!msg) continue;
  1098. if (msg.role === "user") {
  1099. var imageUrls = getMessageImageUrls(msg);
  1100. if (msg.isImage && imageUrls.length) {
  1101. html +=
  1102. '<div class="row row--user"><div class="user-bubble user-bubble--images">' +
  1103. buildUserBubbleImagesHtml(imageUrls) +
  1104. "</div></div>";
  1105. var imageUserText = String(msg.content || "").trim();
  1106. if (imageUserText) {
  1107. html +=
  1108. '<div class="row row--user"><div class="user-bubble">' +
  1109. escHtml(imageUserText) +
  1110. "</div></div>";
  1111. }
  1112. continue;
  1113. }
  1114. var userText = String(msg.content || "").trim();
  1115. if (!userText) continue;
  1116. html +=
  1117. '<div class="row row--user"><div class="user-bubble">' +
  1118. escHtml(userText) +
  1119. "</div></div>";
  1120. continue;
  1121. }
  1122. if (msg.role === "ai" || msg.role === "assistant") {
  1123. var aiText = String(msg.content || "").trim();
  1124. if (!aiText) continue;
  1125. html +=
  1126. '<div class="row row--ai"><div class="ai-card"><div class="ai-card__text">' +
  1127. renderAiContentHtml(aiText) +
  1128. "</div></div></div>";
  1129. }
  1130. }
  1131. return html;
  1132. }
  1133. function applyWeixinShareMeta() {
  1134. var siteName = "U店在哪";
  1135. var iconUrl =
  1136. "https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png";
  1137. var setMeta = function (key, content) {
  1138. var el =
  1139. document.querySelector('meta[property="' + key + '"]') ||
  1140. document.querySelector('meta[name="' + key + '"]');
  1141. if (!el) {
  1142. el = document.createElement("meta");
  1143. if (key.indexOf("og:") === 0) {
  1144. el.setAttribute("property", key);
  1145. } else {
  1146. el.setAttribute("name", key);
  1147. }
  1148. document.head.appendChild(el);
  1149. }
  1150. el.setAttribute("content", content);
  1151. };
  1152. setMeta("og:site_name", siteName);
  1153. setMeta("application-name", siteName);
  1154. setMeta("og:title", "和U宝的对话");
  1155. setMeta("og:description", "点击查看对话内容");
  1156. var links = document.querySelectorAll('link[rel="icon"], link[rel="apple-touch-icon"]');
  1157. for (var i = 0; i < links.length; i++) {
  1158. links[i].setAttribute("href", iconUrl);
  1159. }
  1160. }
  1161. function countDisplayableMessages(messages) {
  1162. var list = Array.isArray(messages) ? messages : [];
  1163. var count = 0;
  1164. for (var i = 0; i < list.length; i++) {
  1165. var msg = list[i];
  1166. if (!msg) continue;
  1167. if (msg.role === "user") {
  1168. if (msg.isImage && getMessageImageUrls(msg).length) {
  1169. count += 1;
  1170. continue;
  1171. }
  1172. if (String(msg.content || "").trim()) count += 1;
  1173. continue;
  1174. }
  1175. if (msg.role === "ai" || msg.role === "assistant") {
  1176. if (String(msg.content || "").trim()) count += 1;
  1177. }
  1178. }
  1179. return count;
  1180. }
  1181. function parseMessagesFromContent(text) {
  1182. var raw = String(text || "").trim();
  1183. if (!raw) return [];
  1184. var list = [];
  1185. var blocks = raw.split(/\n\n+/);
  1186. for (var i = 0; i < blocks.length; i++) {
  1187. var block = String(blocks[i] || "").trim();
  1188. if (!block) continue;
  1189. var userMatch = block.match(/^我[::]\s*([\s\S]*)$/);
  1190. if (userMatch) {
  1191. var userText = String(userMatch[1] || "").trim();
  1192. if (userText) list.push({ role: "user", content: userText });
  1193. continue;
  1194. }
  1195. var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
  1196. if (aiMatch) {
  1197. var aiText = String(aiMatch[1] || "").trim();
  1198. if (aiText) list.push({ role: "ai", content: aiText });
  1199. }
  1200. }
  1201. if (list.length) return list;
  1202. var current = null;
  1203. var lines = raw.split(/\n/);
  1204. for (var j = 0; j < lines.length; j++) {
  1205. var line = String(lines[j] || "");
  1206. var userLine = line.match(/^我[::]\s*(.*)$/);
  1207. var aiLine = line.match(/^UBAO[::]\s*(.*)$/i);
  1208. if (userLine) {
  1209. if (current) list.push(current);
  1210. current = { role: "user", content: String(userLine[1] || "").trim() };
  1211. continue;
  1212. }
  1213. if (aiLine) {
  1214. if (current) list.push(current);
  1215. current = { role: "ai", content: String(aiLine[1] || "").trim() };
  1216. continue;
  1217. }
  1218. if (current && line.trim()) {
  1219. current.content = (current.content ? current.content + "\n" : "") + line.trim();
  1220. }
  1221. }
  1222. if (current && String(current.content || "").trim()) list.push(current);
  1223. return list;
  1224. }
  1225. function resolveShareMessagesForDisplay(data) {
  1226. var fromArray = Array.isArray(data && data.messages) ? data.messages : [];
  1227. var fromContent = parseMessagesFromContent((data && data.content) || "");
  1228. var arrayCount = countDisplayableMessages(fromArray);
  1229. var contentCount = countDisplayableMessages(fromContent);
  1230. // 分享链接超长时 messages 会被截断,但 content 仍保留完整对话文本
  1231. if (contentCount > arrayCount) return fromContent;
  1232. if (arrayCount) return fromArray;
  1233. return fromContent;
  1234. }
  1235. function render(data) {
  1236. applyWeixinShareMeta();
  1237. sharePayloadCache = data || null;
  1238. var main = document.getElementById("main");
  1239. if (!data) {
  1240. main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
  1241. refreshWxLaunchTagAttrs();
  1242. return;
  1243. }
  1244. var messages = resolveShareMessagesForDisplay(data);
  1245. var firstQuestion =
  1246. String(data.firstQuestion || "").trim() ||
  1247. getFirstUserQuestion(messages) ||
  1248. (function () {
  1249. var text = String(data.content || "").trim();
  1250. var m = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
  1251. return m ? String(m[1] || "").trim() : "";
  1252. })();
  1253. var pageTitle = formatDiscussionTitle(firstQuestion);
  1254. var dateText = formatDate(resolveDisplayShareTime(data));
  1255. document.title = pageTitle;
  1256. var bodyHtml =
  1257. '<section class="hero">' +
  1258. '<h1 class="hero__title">' +
  1259. escHtml(pageTitle) +
  1260. "</h1>" +
  1261. '<p class="hero__meta">' +
  1262. escHtml(dateText) +
  1263. " · 内容由AI生成,不能完全保障真实</p>" +
  1264. '<div class="hero__divider"></div>' +
  1265. "</section>";
  1266. var convHtml = renderMessages(messages);
  1267. if (convHtml) {
  1268. bodyHtml +=
  1269. '<section class="conversation">' +
  1270. convHtml +
  1271. '</section><div class="scroll-spacer" aria-hidden="true"></div>';
  1272. } else {
  1273. bodyHtml += '<div class="empty">暂无对话内容</div>';
  1274. }
  1275. main.innerHTML = bodyHtml;
  1276. refreshWxLaunchTagAttrs();
  1277. }
  1278. function buildAiConsultOpenParams() {
  1279. var params = new URLSearchParams();
  1280. params.set("pageType", "home");
  1281. params.set("fromShareAiConsult", "1");
  1282. return params;
  1283. }
  1284. function buildAppDeepLink() {
  1285. var path = APP_UNI_AI_PATH;
  1286. var qs = buildAiConsultOpenParams().toString();
  1287. var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
  1288. return root + "/" + path + (qs ? "?" + qs : "");
  1289. }
  1290. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  1291. var path = APP_UNI_AI_PATH.replace(/^\//, "");
  1292. if (useBarePathOnly) return path;
  1293. var qs = buildAiConsultOpenParams().toString();
  1294. var uniPage = qs ? path + "?" + qs : path;
  1295. if (uniPage.length <= 1024) return uniPage;
  1296. return path + "?pageType=home&fromShareAiConsult=1";
  1297. }
  1298. function isWeChatInAppBrowser() {
  1299. return /MicroMessenger/i.test(navigator.userAgent || "");
  1300. }
  1301. function getWxShareEntryFrom() {
  1302. var from = q("from");
  1303. if (from) return String(from).trim().toLowerCase();
  1304. try {
  1305. var h = location.hash || "";
  1306. var qi = h.indexOf("?");
  1307. if (qi >= 0) {
  1308. var hf = new URLSearchParams(h.slice(qi + 1)).get("from");
  1309. if (hf) return String(hf).trim().toLowerCase();
  1310. }
  1311. } catch (eH) {}
  1312. return "";
  1313. }
  1314. function logWxEntryDiagnostics() {
  1315. if (!isWeChatInAppBrowser()) return;
  1316. console.log("[wx-entry]", {
  1317. entryFrom: getWxShareEntryFrom() || "(无)",
  1318. wxJssdkReady: weChatJssdkConfigured,
  1319. signUrl: getWxConfigSignUrl(),
  1320. });
  1321. }
  1322. function isIOSWeChatBrowser() {
  1323. var ua = navigator.userAgent || "";
  1324. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  1325. }
  1326. function isWxDebugOn() {
  1327. return q("wxDebug") === "1";
  1328. }
  1329. function isWxForceDebug() {
  1330. return q("wxForce") === "1";
  1331. }
  1332. function isWxConfigOnClickDebug() {
  1333. return q("wxConfigOnClick") === "1";
  1334. }
  1335. function isWxPcAutoDebugHost() {
  1336. var h = (location.hostname || "").toLowerCase();
  1337. if (h === "localhost" || h === "127.0.0.1") return true;
  1338. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  1339. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  1340. }
  1341. return false;
  1342. }
  1343. function isWxPcBrowser() {
  1344. return !isWeChatInAppBrowser();
  1345. }
  1346. function shouldInitWeChatJssdkOnLoad() {
  1347. if (isWeChatInAppBrowser()) return true;
  1348. return isWxForceDebug() || isWxPcAutoDebugHost();
  1349. }
  1350. function shouldFetchWxConfig(fromUserClick) {
  1351. if (isWeChatInAppBrowser()) return true;
  1352. if (fromUserClick) return true;
  1353. return isWxForceDebug() || isWxPcAutoDebugHost();
  1354. }
  1355. function getWxHtmlUrl() {
  1356. var forced = String(q("wxSignUrl") || "").trim();
  1357. if (forced) return forced.split("#")[0];
  1358. return String(location.href || "").split("#")[0];
  1359. }
  1360. function getWxSignPageUrlForApi() {
  1361. var htmlUrl = getWxHtmlUrl();
  1362. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  1363. return WX_GET_CONFIG_SIGN_URL;
  1364. }
  1365. function getWxHtmlUrlBase() {
  1366. var htmlUrl = getWxSignPageUrlForApi();
  1367. try {
  1368. var u = new URL(htmlUrl);
  1369. return u.origin + u.pathname;
  1370. } catch (eU) {
  1371. return WX_GET_CONFIG_SIGN_URL;
  1372. }
  1373. }
  1374. /** 与 secondShareGoods 一致:默认用当前页完整 URL 验签(须与微信地址栏一致,含 query) */
  1375. function getWxConfigSignUrl() {
  1376. if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
  1377. return getWxSignPageUrlForApi();
  1378. }
  1379. function getWxGetConfigApiUrl() {
  1380. return API_BASE.replace(/\/$/, "") + WECHAT_GET_WX_CONFIG_PATH;
  1381. }
  1382. function buildWxGetConfigRequestBody(htmlUrl) {
  1383. return {
  1384. url: String(htmlUrl || "").split("#")[0].trim(),
  1385. };
  1386. }
  1387. function resolveWxConfigAppIdFromSignData(d) {
  1388. if (!d || typeof d !== "object") return "";
  1389. var mp =
  1390. d.mpAppId ||
  1391. d.mpAppid ||
  1392. d.officialAppId ||
  1393. d.gzhAppId ||
  1394. d.serviceAppId;
  1395. if (mp != null && String(mp).trim() !== "") return String(mp).trim();
  1396. var fromQuery = String(q("wxMpAppId") || WECHAT_MP_APP_ID || "").trim();
  1397. if (fromQuery) return fromQuery;
  1398. var raw = d.appId || d.appid || d.wxAppId;
  1399. return raw != null && String(raw).trim() !== "" ? String(raw).trim() : "";
  1400. }
  1401. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  1402. if (!res || typeof res !== "object") return null;
  1403. var d = res.data != null && typeof res.data === "object" ? res.data : res;
  1404. if (!d || typeof d !== "object") return null;
  1405. var appId = resolveWxConfigAppIdFromSignData(d);
  1406. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  1407. var nonceStr =
  1408. d.nonceStr != null && String(d.nonceStr) !== ""
  1409. ? d.nonceStr
  1410. : d.noncestr != null && String(d.noncestr) !== ""
  1411. ? d.noncestr
  1412. : d.nonce;
  1413. var signature = d.signature || d.sign;
  1414. if (!appId || timestamp == null || nonceStr == null || nonceStr === "" || !signature) {
  1415. return null;
  1416. }
  1417. return {
  1418. appId: String(appId),
  1419. timestamp: Number(timestamp),
  1420. nonceStr: String(nonceStr),
  1421. signature: String(signature),
  1422. signUrl: String(signUrlUsed || "")
  1423. .split("#")[0]
  1424. .trim(),
  1425. };
  1426. }
  1427. function getWxErrMsg(err) {
  1428. if (!err) return "";
  1429. if (err.errMsg) return String(err.errMsg);
  1430. if (typeof err === "string") return err;
  1431. try {
  1432. return JSON.stringify(err);
  1433. } catch (e) {
  1434. return String(err);
  1435. }
  1436. }
  1437. function formatWxConfigErrorTip(err, signPageUrl) {
  1438. var errMsg = getWxErrMsg(err);
  1439. var tip = "微信 JSSDK 配置失败";
  1440. if (/invalid signature/i.test(errMsg)) {
  1441. return (
  1442. tip +
  1443. ":签名无效。请核对:①后端用与前端相同的 url 签名;②url=" +
  1444. (signPageUrl || getWxHtmlUrl()) +
  1445. ";③nonceStr/timestamp 与接口返回一致;④appId=" +
  1446. WECHAT_MP_APP_ID
  1447. );
  1448. }
  1449. if (/require\s*subscribe/i.test(errMsg)) {
  1450. return tip + ":" + errMsg + "(服务号需用户已关注)";
  1451. }
  1452. return errMsg ? tip + ":" + errMsg : tip;
  1453. }
  1454. function setWxInitError(msg) {
  1455. wxInitLastError = String(msg || "").trim();
  1456. if (wxInitLastError) console.warn("[wx]", wxInitLastError);
  1457. }
  1458. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  1459. var htmlUrl = String(htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl())
  1460. .split("#")[0]
  1461. .trim();
  1462. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  1463. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  1464. }
  1465. if (isWxDebugOn()) {
  1466. try {
  1467. window.alert("htmlUrl(签名用,应与地址栏一致):\n" + htmlUrl);
  1468. } catch (eDbg) {}
  1469. }
  1470. var requestUrl = getWxGetConfigApiUrl();
  1471. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  1472. console.log("[wx] htmlUrl=", htmlUrl);
  1473. console.log("[wx] POST getWxConfig →", requestUrl, requestBody);
  1474. return fetch(requestUrl, {
  1475. method: "POST",
  1476. mode: "cors",
  1477. credentials: "omit",
  1478. headers: {
  1479. Accept: "application/json",
  1480. "Content-Type": "application/json;charset=UTF-8",
  1481. },
  1482. body: JSON.stringify(requestBody),
  1483. })
  1484. .then(function (r) {
  1485. if (r.ok) return r.json();
  1486. return r
  1487. .text()
  1488. .catch(function () {
  1489. return "";
  1490. })
  1491. .then(function (text) {
  1492. var hint = "";
  1493. try {
  1494. var j = JSON.parse(text);
  1495. hint = j.msg || j.message || "";
  1496. } catch (eP) {
  1497. if (text) hint = text.slice(0, 120);
  1498. }
  1499. throw new Error("getWxConfig HTTP " + r.status + (hint ? ":" + hint : ""));
  1500. });
  1501. })
  1502. .then(function (res) {
  1503. if (res && res.code != null) {
  1504. var c = Number(res.code);
  1505. if (c !== 200 && c !== 0 && res.success !== true) {
  1506. throw new Error(res.msg || res.message || "getWxConfig code " + c);
  1507. }
  1508. }
  1509. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  1510. if (!sign) {
  1511. console.warn("[wx] getWxConfig 响应字段不全", res, "htmlUrl=", htmlUrl);
  1512. throw new Error("getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)");
  1513. }
  1514. if (sign.appId !== WECHAT_MP_APP_ID) {
  1515. console.warn(
  1516. "[wx] 后端 appId=" + sign.appId + ",期望服务号 " + WECHAT_MP_APP_ID
  1517. );
  1518. }
  1519. if (typeof wx === "undefined") {
  1520. if (isWxPcBrowser()) {
  1521. console.log("[wx] PC getWxConfig 成功(无 jweixin)", sign);
  1522. return true;
  1523. }
  1524. setWxInitError("jweixin.js 未加载");
  1525. return false;
  1526. }
  1527. return applyWxConfigFromSign(sign, htmlUrl);
  1528. });
  1529. }
  1530. function applyWxConfigFromSign(sign, htmlUrl) {
  1531. var wxConfigParams = {
  1532. debug: isWxDebugOn(),
  1533. appId: String(sign.appId),
  1534. timestamp: sign.timestamp,
  1535. nonceStr: String(sign.nonceStr),
  1536. signature: String(sign.signature),
  1537. jsApiList: [],
  1538. openTagList: ["wx-open-launch-app"],
  1539. };
  1540. return new Promise(function (resolve) {
  1541. wx.config(wxConfigParams);
  1542. wx.ready(function () {
  1543. weChatJssdkConfigured = true;
  1544. document.body.classList.add("wx-jssdk-ready");
  1545. refreshWxLaunchTagAttrs();
  1546. console.log("[wx.config] ready, htmlUrl=", htmlUrl);
  1547. resolve(true);
  1548. });
  1549. wx.error(function (err) {
  1550. weChatJssdkConfigured = false;
  1551. document.body.classList.remove("wx-jssdk-ready");
  1552. wxJssdkInitPromise = null;
  1553. var errMsg = getWxErrMsg(err);
  1554. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  1555. if (isWxDebugOn()) window.alert(wxInitLastError);
  1556. console.warn("[wx.config]", errMsg, "htmlUrl=", htmlUrl);
  1557. var baseUrl = getWxHtmlUrlBase();
  1558. var fullUrl = getWxSignPageUrlForApi();
  1559. if (
  1560. !/invalid signature/i.test(errMsg) ||
  1561. wxConfigSignRetriedBaseUrl ||
  1562. baseUrl === fullUrl ||
  1563. htmlUrl === baseUrl
  1564. ) {
  1565. resolve(false);
  1566. return;
  1567. }
  1568. wxConfigSignRetriedBaseUrl = true;
  1569. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  1570. });
  1571. });
  1572. }
  1573. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  1574. var tag = document.getElementById("launch-btn");
  1575. if (!tag) return;
  1576. try {
  1577. tag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  1578. tag.setAttribute("extinfo", buildWeChatLaunchExtinfo(!!useBarePathOnly));
  1579. console.log("[wx-open-launch-app] extinfo=", tag.getAttribute("extinfo"));
  1580. } catch (eA) {}
  1581. }
  1582. function bindWeChatLaunchTagEvents() {
  1583. var tag = document.getElementById("launch-btn");
  1584. if (!tag || tag._wxLaunchBound) return;
  1585. tag._wxLaunchBound = true;
  1586. refreshWxLaunchTagAttrs();
  1587. tag.addEventListener("launch", function () {
  1588. console.log("[wx-open-launch-app] launch ok");
  1589. });
  1590. tag.addEventListener("error", function (e) {
  1591. var detail = e && e.detail;
  1592. var errMsg =
  1593. detail && detail.errMsg
  1594. ? String(detail.errMsg)
  1595. : detail && detail.errmsg
  1596. ? String(detail.errmsg)
  1597. : "";
  1598. console.warn(
  1599. "[wx-open-launch-app]",
  1600. detail,
  1601. "extinfo=",
  1602. tag.getAttribute("extinfo")
  1603. );
  1604. if (/launch:fail_check/i.test(errMsg)) {
  1605. showAppOpenFailTip(
  1606. "请用微信分享卡片进入,或确认已安装最新版「U店在哪」"
  1607. );
  1608. return;
  1609. }
  1610. // if (
  1611. // /launch:fail/i.test(errMsg) &&
  1612. // !tag._wxLaunchBareRetried &&
  1613. // tag.getAttribute("extinfo") !== buildWeChatLaunchExtinfo(true)
  1614. // ) {
  1615. // tag._wxLaunchBareRetried = true;
  1616. // refreshWxLaunchTagAttrs(true);
  1617. // showFabToast("请再点一次「和U宝继续聊」");
  1618. // return;
  1619. // }
  1620. if (/launch:fail/i.test(errMsg) && !getWxShareEntryFrom()) {
  1621. showAppOpenFailTip("请前往应用商店下载U店在哪app");
  1622. return;
  1623. }
  1624. showAppOpenFailTip(
  1625. errMsg
  1626. ? "未能打开 App:" + errMsg
  1627. : "未能打开 App,请确认已安装最新版「U店在哪」"
  1628. );
  1629. });
  1630. }
  1631. function initWeChatOpenLaunchApp(fromUserClick) {
  1632. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1633. return Promise.resolve(false);
  1634. }
  1635. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1636. wxConfigSignRetriedBaseUrl = false;
  1637. wxInitLastError = "";
  1638. var htmlUrl = getWxConfigSignUrl();
  1639. bindWeChatLaunchTagEvents();
  1640. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1641. .then(function (ok) {
  1642. if (ok === true) return true;
  1643. if (!wxInitLastError) {
  1644. setWxInitError("wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl");
  1645. }
  1646. return false;
  1647. })
  1648. .catch(function (e) {
  1649. var msg = e && e.message ? e.message : "getWxConfig 请求失败";
  1650. setWxInitError(msg);
  1651. console.warn("[wx] requestWeChatJssdkSignAndConfig failed", msg, "htmlUrl=", htmlUrl);
  1652. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1653. return false;
  1654. })
  1655. .finally(function () {
  1656. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1657. });
  1658. return wxJssdkInitPromise;
  1659. }
  1660. function scheduleWeChatJssdkBootstrap() {
  1661. if (!shouldInitWeChatJssdkOnLoad()) return;
  1662. var attempts = 0;
  1663. function tick() {
  1664. attempts += 1;
  1665. if (weChatJssdkConfigured) return;
  1666. initWeChatOpenLaunchApp();
  1667. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === "undefined") {
  1668. setTimeout(tick, 400);
  1669. }
  1670. }
  1671. if (isIOSWeChatBrowser()) {
  1672. setTimeout(tick, 350);
  1673. } else {
  1674. tick();
  1675. }
  1676. }
  1677. function showFabToast(msg, ms) {
  1678. var tip = String(msg || "").trim();
  1679. if (!tip) return;
  1680. var el = document.getElementById("openAppToast");
  1681. if (el) {
  1682. el.textContent = tip;
  1683. el.style.display = "block";
  1684. if (showFabToast._t) clearTimeout(showFabToast._t);
  1685. showFabToast._t = setTimeout(function () {
  1686. el.style.display = "none";
  1687. }, ms || 2800);
  1688. }
  1689. console.log("[openApp]", tip);
  1690. }
  1691. function showDownloadTip() {
  1692. var msg = "请到应用商店下载「U店在哪」";
  1693. if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
  1694. uni.showToast({ title: msg, icon: "none", duration: 2500 });
  1695. } else {
  1696. window.alert(msg);
  1697. }
  1698. }
  1699. function showAppOpenFailTip(msg) {
  1700. var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
  1701. if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
  1702. uni.showToast({ title: msg, icon: "none", duration: 2800 });
  1703. } else if (isWeChatInAppBrowser()) {
  1704. window.alert(tip);
  1705. } else {
  1706. showFabToast(tip);
  1707. }
  1708. }
  1709. function launchAppDeepLink(deepLink) {
  1710. try {
  1711. var a = document.createElement("a");
  1712. a.href = deepLink;
  1713. a.setAttribute("target", "_self");
  1714. document.body.appendChild(a);
  1715. a.click();
  1716. document.body.removeChild(a);
  1717. } catch (e1) {}
  1718. try {
  1719. window.location.href = deepLink;
  1720. } catch (e2) {}
  1721. }
  1722. function tryOpenHBuilderAppViaScheme() {
  1723. var deepLink = buildAppDeepLink();
  1724. if (typeof plus !== "undefined" && plus.runtime) {
  1725. var installed = null;
  1726. try {
  1727. if (typeof plus.runtime.isApplicationExist === "function") {
  1728. installed = plus.runtime.isApplicationExist({
  1729. pname: APP_ANDROID_PACKAGE,
  1730. action: APP_IOS_URL_SCHEME,
  1731. });
  1732. }
  1733. } catch (e) {
  1734. console.warn(e);
  1735. }
  1736. if (installed === false) {
  1737. showDownloadTip();
  1738. return;
  1739. }
  1740. try {
  1741. plus.runtime.openURL(deepLink);
  1742. } catch (e2) {
  1743. console.warn(e2);
  1744. showDownloadTip();
  1745. }
  1746. return;
  1747. }
  1748. var done = false;
  1749. function finish() {
  1750. if (done) return;
  1751. done = true;
  1752. document.removeEventListener("visibilitychange", onVis);
  1753. window.removeEventListener("pagehide", onHide);
  1754. }
  1755. function onVis() {
  1756. if (document.visibilityState === "hidden") finish();
  1757. }
  1758. function onHide() {
  1759. finish();
  1760. }
  1761. document.addEventListener("visibilitychange", onVis);
  1762. window.addEventListener("pagehide", onHide);
  1763. try {
  1764. launchAppDeepLink(deepLink);
  1765. } catch (e3) {
  1766. finish();
  1767. showDownloadTip();
  1768. return;
  1769. }
  1770. window.setTimeout(function () {
  1771. finish();
  1772. }, 3200);
  1773. }
  1774. function tryFetchWxConfigOnPcClick() {
  1775. if (!isWxPcBrowser()) return Promise.resolve(false);
  1776. showFabToast("正在请求 getWxConfig…");
  1777. wxJssdkInitPromise = null;
  1778. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1779. if (ok) {
  1780. showFabToast(
  1781. weChatJssdkConfigured
  1782. ? "getWxConfig 成功,wx.config 已就绪"
  1783. : "getWxConfig 成功"
  1784. );
  1785. } else {
  1786. showFabToast(wxInitLastError || "getWxConfig 失败");
  1787. }
  1788. return ok;
  1789. });
  1790. }
  1791. function tryOpenHBuilderApp() {
  1792. if (isWeChatInAppBrowser()) return;
  1793. if (!isWxPcBrowser()) {
  1794. tryOpenHBuilderAppViaScheme();
  1795. return;
  1796. }
  1797. tryFetchWxConfigOnPcClick().then(function () {
  1798. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1799. return;
  1800. }
  1801. tryOpenHBuilderAppViaScheme();
  1802. });
  1803. }
  1804. function boot() {
  1805. var launchTag = document.getElementById("launch-btn");
  1806. if (launchTag) launchTag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  1807. bindWeChatLaunchTagEvents();
  1808. if (isWeChatInAppBrowser()) {
  1809. document.body.classList.add("is-wechat");
  1810. logWxEntryDiagnostics();
  1811. }
  1812. if (shouldInitWeChatJssdkOnLoad()) {
  1813. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1814. document.body.classList.add("wx-pc-debug");
  1815. }
  1816. scheduleWeChatJssdkBootstrap();
  1817. }
  1818. document.addEventListener("WeixinOpenTagsError", function (e) {
  1819. console.warn("[WeixinOpenTagsError]", e && e.detail);
  1820. });
  1821. if (isWeChatInAppBrowser()) {
  1822. var openBtnWx = document.getElementById("openApp");
  1823. if (openBtnWx) {
  1824. openBtnWx.addEventListener("click", function () {
  1825. if (!weChatJssdkConfigured) {
  1826. showFabToast(
  1827. wxInitLastError || "微信 SDK 初始化中,请稍候再点底部按钮"
  1828. );
  1829. }
  1830. });
  1831. }
  1832. } else {
  1833. var openAppBtn = document.getElementById("openApp");
  1834. if (openAppBtn) {
  1835. openAppBtn.addEventListener("click", tryOpenHBuilderApp);
  1836. }
  1837. }
  1838. bindApiDebugModalEvents();
  1839. bindImagePreviewEvents();
  1840. loadPageData();
  1841. }
  1842. if (document.readyState === "complete") {
  1843. boot();
  1844. } else {
  1845. window.addEventListener("load", boot);
  1846. }
  1847. })();
  1848. </script>
  1849. </body>
  1850. </html>