shareUndefined.html 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019
  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. <style>
  9. :root {
  10. --orange: #F58220;
  11. --orange-light: #FFF4E8;
  12. --red: #FF4D4F;
  13. --text: #333333;
  14. --text-secondary: #999999;
  15. --border: #EEEEEE;
  16. --bg: #FFFFFF;
  17. --safe-bottom: env(safe-area-inset-bottom, 0px);
  18. }
  19. * {
  20. margin: 0;
  21. padding: 0;
  22. box-sizing: border-box;
  23. }
  24. html {
  25. font-size: 16px;
  26. -webkit-tap-highlight-color: transparent;
  27. overflow-x: hidden;
  28. }
  29. body {
  30. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  31. background: var(--bg);
  32. color: var(--text);
  33. padding-bottom: calc(88px + var(--safe-bottom));
  34. min-height: 100vh;
  35. overflow-x: hidden;
  36. }
  37. /* Header */
  38. .header {
  39. position: sticky;
  40. top: 0;
  41. z-index: 100;
  42. display: flex;
  43. align-items: center;
  44. justify-content: center;
  45. height: 44px;
  46. padding: 0 15px;
  47. background: var(--bg);
  48. border-bottom: 1px solid var(--border);
  49. }
  50. .header__back {
  51. position: absolute;
  52. left: 15px;
  53. width: 24px;
  54. height: 24px;
  55. display: flex;
  56. align-items: center;
  57. justify-content: center;
  58. color: var(--text);
  59. text-decoration: none;
  60. }
  61. .header__title {
  62. font-size: 17px;
  63. font-weight: 600;
  64. color: var(--text);
  65. }
  66. /* Hero carousel */
  67. .hero {
  68. position: relative;
  69. margin: 0 15px;
  70. margin-top: 10px;
  71. border-radius: 0 0 12px 12px;
  72. overflow: hidden;
  73. }
  74. /* 内容不存在 / 已删除:居中插图 + 说明文案 */
  75. .hero.hero--empty {
  76. display: flex;
  77. flex-direction: column;
  78. align-items: center;
  79. justify-content: center;
  80. padding: 48px 24px 56px;
  81. min-height: min(52vh, 440px);
  82. background: var(--bg);
  83. overflow: visible;
  84. }
  85. .hero--empty__illustration {
  86. display: block;
  87. width: 100%;
  88. max-width: 280px;
  89. height: auto;
  90. object-fit: contain;
  91. }
  92. .hero--empty__tip {
  93. padding: 0 16px;
  94. font-size: 15px;
  95. line-height: 1.5;
  96. color: var(--text-secondary);
  97. text-align: center;
  98. font-weight: 400;
  99. }
  100. .hero__track {
  101. display: flex;
  102. transition: transform 0.35s ease;
  103. }
  104. .hero__slide {
  105. flex: 0 0 100%;
  106. aspect-ratio: 16 / 10;
  107. background: #f0f0f0;
  108. }
  109. .hero__slide img {
  110. width: 100%;
  111. height: 100%;
  112. object-fit: cover;
  113. display: block;
  114. vertical-align: middle;
  115. }
  116. .hero__dots {
  117. position: absolute;
  118. bottom: 12px;
  119. left: 0;
  120. right: 0;
  121. display: flex;
  122. justify-content: center;
  123. align-items: center;
  124. gap: 6px;
  125. }
  126. .hero__dot {
  127. width: 6px;
  128. height: 6px;
  129. border-radius: 3px;
  130. background: rgba(255, 255, 255, 0.45);
  131. transition: width 0.25s ease, background 0.25s ease;
  132. }
  133. .hero__dot.is-active {
  134. width: 16px;
  135. background: #fff;
  136. }
  137. /* Store block */
  138. .section {
  139. padding: 16px 15px 0;
  140. }
  141. .store-name {
  142. font-size: 20px;
  143. font-weight: 700;
  144. line-height: 1.35;
  145. margin-bottom: 12px;
  146. }
  147. .row {
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. gap: 10px;
  152. }
  153. .rating-row {
  154. margin-bottom: 12px;
  155. }
  156. .stars {
  157. display: inline-flex;
  158. align-items: center;
  159. gap: 2px;
  160. }
  161. .star {
  162. width: 14px;
  163. height: 14px;
  164. color: var(--orange);
  165. }
  166. .rating-num {
  167. margin-left: 6px;
  168. font-size: 14px;
  169. font-weight: 600;
  170. color: var(--orange);
  171. }
  172. .link-muted {
  173. display: inline-flex;
  174. align-items: center;
  175. gap: 2px;
  176. font-size: 13px;
  177. color: var(--text-secondary);
  178. text-decoration: none;
  179. }
  180. .chevron {
  181. width: 14px;
  182. height: 14px;
  183. opacity: 0.6;
  184. }
  185. .hours-row {
  186. margin-bottom: 16px;
  187. align-items: flex-start;
  188. }
  189. .hours-left {
  190. flex: 1;
  191. min-width: 0;
  192. }
  193. .status {
  194. font-size: 14px;
  195. color: var(--red);
  196. margin-right: 8px;
  197. }
  198. .status.is-open {
  199. color: var(--orange);
  200. }
  201. .hours-text {
  202. font-size: 14px;
  203. color: var(--text-secondary);
  204. }
  205. .divider {
  206. height: 8px;
  207. background: #F7F7F7;
  208. margin: 0;
  209. }
  210. /* Location */
  211. .loc-wrap {
  212. display: flex;
  213. padding: 16px 15px;
  214. gap: 12px;
  215. }
  216. .loc-main {
  217. flex: 1;
  218. min-width: 0;
  219. padding-right: 12px;
  220. }
  221. .addr {
  222. font-size: 15px;
  223. font-weight: 600;
  224. line-height: 1.45;
  225. margin-bottom: 10px;
  226. }
  227. .meta-line {
  228. display: flex;
  229. align-items: flex-start;
  230. gap: 6px;
  231. font-size: 13px;
  232. color: var(--text-secondary);
  233. line-height: 1.45;
  234. margin-top: 6px;
  235. }
  236. .meta-line svg {
  237. flex-shrink: 0;
  238. margin-top: 2px;
  239. opacity: 0.75;
  240. }
  241. .loc-actions {
  242. display: flex;
  243. flex-direction: row;
  244. align-items: center;
  245. justify-content: center;
  246. gap: 18px;
  247. flex-shrink: 0;
  248. }
  249. .act-btn {
  250. display: flex;
  251. flex-direction: column;
  252. align-items: center;
  253. gap: 4px;
  254. background: none;
  255. border: none;
  256. padding: 0;
  257. cursor: pointer;
  258. font-size: 12px;
  259. color: var(--text);
  260. }
  261. .act-btn__icon {
  262. width: 44px;
  263. height: 44px;
  264. border-radius: 50%;
  265. background: #F5F5F5;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. color: var(--orange);
  270. }
  271. /* More */
  272. .more-title {
  273. padding: 8px 15px 12px;
  274. font-size: 16px;
  275. font-weight: 700;
  276. }
  277. .more-scroll {
  278. display: grid;
  279. grid-template-columns: repeat(2, 1fr);
  280. gap: 10px;
  281. padding: 0 15px 20px;
  282. }
  283. #recEmpty {
  284. grid-column: 1 / -1;
  285. }
  286. .rec-card {
  287. min-width: 0;
  288. background: #fff;
  289. border-radius: 8px;
  290. overflow: hidden;
  291. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  292. }
  293. .rec-card__img {
  294. aspect-ratio: 4 / 3;
  295. background: #eee;
  296. }
  297. .rec-card__img img {
  298. width: 100%;
  299. height: 100%;
  300. object-fit: cover;
  301. }
  302. .rec-card__body {
  303. padding: 10px;
  304. }
  305. .rec-card__top {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: baseline;
  309. gap: 8px;
  310. margin-bottom: 6px;
  311. }
  312. .rec-card__name {
  313. font-size: 15px;
  314. font-weight: 700;
  315. flex: 1;
  316. min-width: 0;
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. }
  321. .rec-card__dist {
  322. font-size: 12px;
  323. color: var(--text-secondary);
  324. flex-shrink: 0;
  325. }
  326. .rec-card__rating {
  327. display: flex;
  328. align-items: center;
  329. flex-wrap: wrap;
  330. gap: 4px 8px;
  331. }
  332. .rec-card__rating .stars .star {
  333. width: 11px;
  334. height: 11px;
  335. }
  336. .rec-card__rating .rating-num {
  337. font-size: 12px;
  338. }
  339. .rec-meta {
  340. font-size: 12px;
  341. color: var(--text-secondary);
  342. }
  343. .rec-card__seller {
  344. display: flex;
  345. align-items: center;
  346. gap: 8px;
  347. margin-top: 8px;
  348. min-width: 0;
  349. }
  350. .rec-card__avatar {
  351. width: 22px;
  352. height: 22px;
  353. border-radius: 50%;
  354. object-fit: cover;
  355. flex-shrink: 0;
  356. background: #eee;
  357. }
  358. .rec-card__seller-name {
  359. font-size: 12px;
  360. color: var(--text-secondary);
  361. overflow: hidden;
  362. text-overflow: ellipsis;
  363. white-space: nowrap;
  364. }
  365. /* FAB */
  366. .fab-wrap {
  367. position: fixed;
  368. left: 0;
  369. right: 0;
  370. bottom: 0;
  371. z-index: 200;
  372. padding: 12px 24px calc(12px + var(--safe-bottom));
  373. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  374. pointer-events: none;
  375. }
  376. .fab-dock__slot {
  377. width: 100%;
  378. max-width: 198px;
  379. height: 48px;
  380. margin: 0 auto;
  381. pointer-events: auto;
  382. }
  383. #openApp img {
  384. display: block;
  385. width: 100%;
  386. height: 48px;
  387. object-fit: contain;
  388. pointer-events: none;
  389. }
  390. .fab-dock__slot {
  391. position: relative;
  392. }
  393. #launch-btn {
  394. display: none;
  395. width: 100%;
  396. height: 48px;
  397. min-height: 48px;
  398. border-radius: 24px;
  399. overflow: hidden;
  400. opacity: 1;
  401. position: relative;
  402. z-index: 2;
  403. }
  404. /* 微信内:仅 wx.config 成功后展示开放标签,避免被 #openApp 挡住 */
  405. body.is-wechat.wx-jssdk-ready #launch-btn,
  406. body.wx-jssdk-ready #launch-btn {
  407. display: block !important;
  408. }
  409. body.is-wechat.wx-jssdk-ready #openApp,
  410. body.wx-jssdk-ready #openApp {
  411. display: none !important;
  412. visibility: hidden !important;
  413. pointer-events: none !important;
  414. position: absolute !important;
  415. width: 0 !important;
  416. height: 0 !important;
  417. overflow: hidden !important;
  418. }
  419. body.is-wechat:not(.wx-jssdk-ready) #launch-btn {
  420. display: none !important;
  421. }
  422. body.is-wechat:not(.wx-jssdk-ready) #openApp {
  423. display: block;
  424. width: 100%;
  425. touch-action: manipulation;
  426. }
  427. #openApp {
  428. display: block;
  429. width: 100%;
  430. padding: 0;
  431. border: none;
  432. background: transparent;
  433. cursor: pointer;
  434. touch-action: manipulation;
  435. }
  436. body:not(.is-wechat) #launch-btn {
  437. display: none !important;
  438. }
  439. #openAppToast {
  440. display: none;
  441. position: fixed;
  442. left: 16px;
  443. right: 16px;
  444. bottom: calc(72px + var(--safe-bottom));
  445. z-index: 10001;
  446. padding: 10px 14px;
  447. font-size: 13px;
  448. line-height: 1.45;
  449. color: #fff;
  450. text-align: center;
  451. background: rgba(0, 0, 0, 0.78);
  452. border-radius: 8px;
  453. pointer-events: none;
  454. word-break: break-all;
  455. }
  456. #openApp {
  457. touch-action: manipulation;
  458. }
  459. .fab-wrap .fab {
  460. pointer-events: auto;
  461. }
  462. .fab {
  463. display: flex;
  464. align-items: center;
  465. justify-content: center;
  466. gap: 10px;
  467. width: 100%;
  468. max-width: 198px;
  469. margin: 0 auto;
  470. height: 48px;
  471. border: none;
  472. border-radius: 24px;
  473. background: var(--orange);
  474. color: #fff;
  475. font-size: 16px;
  476. font-weight: 600;
  477. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  478. cursor: pointer;
  479. }
  480. .fab__logo {
  481. width: 28px;
  482. height: 28px;
  483. flex-shrink: 0;
  484. }
  485. .home-indicator {
  486. height: 5px;
  487. background: #000;
  488. border-radius: 3px;
  489. width: 134px;
  490. margin: 8px auto 4px;
  491. opacity: 0.2;
  492. }
  493. </style>
  494. </head>
  495. <body>
  496. <div class="hero hero--empty" id="hero" role="status" aria-live="polite">
  497. <img class="hero--empty__illustration" src="images/empty.png" alt="" decoding="async">
  498. <p class="hero--empty__tip">商品已删除/下架/卖出</p>
  499. </div>
  500. <div class="divider"></div>
  501. <h3 class="more-title">更多推荐</h3>
  502. <div class="more-scroll" id="recList">
  503. <p id="recEmpty" style="padding:12px;color:#999;font-size:14px;display:none;">暂无推荐</p>
  504. </div>
  505. <div id="openAppToast" role="status" aria-live="polite"></div>
  506. <div class="fab-wrap">
  507. <div class="fab-dock__slot">
  508. <!-- 微信内 wx.config 成功后:开放标签须在顶层,避免被 #openApp 遮挡 -->
  509. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  510. <script type="text/wxtag-template">
  511. <style>
  512. .wx-open-app-btn {
  513. display: block;
  514. width: 100%;
  515. height: 48px;
  516. margin: 0;
  517. padding: 0;
  518. border: none;
  519. border-radius: 24px;
  520. background: #F47D1F;
  521. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  522. cursor: pointer;
  523. overflow: hidden;
  524. -webkit-tap-highlight-color: transparent;
  525. }
  526. .wx-open-app-btn img {
  527. display: block;
  528. width: 100%;
  529. height: 48px;
  530. object-fit: contain;
  531. opacity: 1;
  532. pointer-events: none;
  533. -webkit-user-drag: none;
  534. }
  535. </style>
  536. <button type="button" class="wx-open-app-btn" aria-label="APP内打开">
  537. <img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" width="198" height="48" />
  538. </button>
  539. </script>
  540. </wx-open-launch-app>
  541. <!-- 非微信 / 微信 JSSDK 未就绪:scheme 唤起 -->
  542. <button type="button" class="fab" id="openApp">
  543. <img src="images/uBtn.png" alt="APP内打开" decoding="async">
  544. </button>
  545. </div>
  546. <div class="home-indicator" aria-hidden="true"></div>
  547. </div>
  548. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  549. <script>
  550. (function () {
  551. 'use strict';
  552. /**
  553. * 更多推荐:POST http://124.93.18.180:9100/ai/life-manager/api/v1/second_hand/global-recommend
  554. * 常用 query:userId、userLat/userLng 或 lat/weidu、lon/jingdu、radiusKm、page、pageSize、categoryOneId、categoryTwoId
  555. *
  556. * 商品不可用占位页;底部「APP内打开」始终可唤起 App:
  557. * 有 goodsId/id/sourceId → 二手详情页(带 goodsUnavailable 等参数,由 App 展示已删除态);
  558. * 无商品 id → pages/index/login。
  559. *
  560. * 注意:用 file:// 打开本页时,浏览器可能因 CORS 拦截跨域请求。
  561. */
  562. var API_BASE = 'https://test.ailien.shop/alienStore';
  563. var API_LIFE_AI_BASE = 'http://183.252.196.135:9100';
  564. var SECOND_GLOBAL_RECOMMEND_PATH = '/ai/life-manager/api/v1/second_hand/global-recommend';
  565. var DEFAULT_REC_RADIUS_KM = 195.69;
  566. /**
  567. * 微信 JSSDK — 与 shareIndex.html 一致
  568. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  569. */
  570. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  571. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  572. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  573. var H5_PAGE_BASE_FALLBACK = 'https://test.ailien.shop/h5/HBuilderProjects/';
  574. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'shareUndefined.html';
  575. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'test.ailien.shop'];
  576. var weChatJssdkConfigured = false;
  577. var wxConfigSignRetriedBaseUrl = false;
  578. var wxInitLastError = '';
  579. var wxJssdkInitPromise = null;
  580. /**
  581. * 与 secondShareGoods.html 一致:唤起 App 打开二手商品详情页(合并 search + hash 内 query)
  582. */
  583. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  584. var APP_IOS_URL_SCHEME = 'shopro://';
  585. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  586. function showDownloadTip() {
  587. var msg = '请到应用商店下载';
  588. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  589. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  590. } else {
  591. window.alert(msg);
  592. }
  593. }
  594. function mergeSearchAndHashParams() {
  595. var params = new URLSearchParams();
  596. function ingestAppend(querySlice) {
  597. if (!querySlice) return;
  598. var p = new URLSearchParams(querySlice);
  599. p.forEach(function (val, key) {
  600. params.append(key, val);
  601. });
  602. }
  603. function ingestSet(querySlice) {
  604. if (!querySlice) return;
  605. var p = new URLSearchParams(querySlice);
  606. p.forEach(function (val, key) {
  607. params.set(key, val);
  608. });
  609. }
  610. if (location.search && location.search.length > 1) {
  611. ingestAppend(location.search.slice(1));
  612. }
  613. var hash = location.hash || '';
  614. var qi = hash.indexOf('?');
  615. if (qi >= 0) {
  616. ingestSet(hash.slice(qi + 1));
  617. }
  618. return params;
  619. }
  620. function q(name) {
  621. var v = mergeSearchAndHashParams().get(name);
  622. return v == null ? '' : String(v);
  623. }
  624. /** 推荐用户位置:优先 URL 的 longitude/latitude,未带时用默认坐标 */
  625. var DEFAULT_REC_USER_LAT = (function () {
  626. var raw = (q('latitude') || q('lat') || q('weidu') || '').trim();
  627. var n = raw !== '' ? Number(raw) : NaN;
  628. return !isNaN(n) ? n : 38.925756;
  629. })();
  630. var DEFAULT_REC_USER_LNG = (function () {
  631. var raw = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  632. var n = raw !== '' ? Number(raw) : NaN;
  633. return !isNaN(n) ? n : 121.662543;
  634. })();
  635. function rawQueryHasGoodsId(qs) {
  636. return /(?:^|&)(goodsId|id|sourceId)=/i.test('&' + String(qs || '') + '&');
  637. }
  638. function getShareGoodsIdForAppOpen() {
  639. return (q('goodsId') || q('id') || q('sourceId') || '').trim();
  640. }
  641. function getRawMergedQueryForAppOpen() {
  642. var rawSearch =
  643. location.search && location.search.length > 1 ? location.search.slice(1) : '';
  644. var hash0 = location.hash || '';
  645. var hqi0 = hash0.indexOf('?');
  646. var rawHashQ = hqi0 >= 0 ? hash0.slice(hqi0 + 1) : '';
  647. if (!rawSearch && !rawHashQ) return '';
  648. if (rawHashQ && rawSearch) {
  649. if (rawQueryHasGoodsId(rawHashQ)) return rawHashQ;
  650. if (rawQueryHasGoodsId(rawSearch)) return rawSearch;
  651. return rawHashQ;
  652. }
  653. return rawHashQ || rawSearch;
  654. }
  655. /** 有商品 id 时进二手详情(已删除也由 App 处理);否则进登录页 */
  656. function getAppUniPathForShareUndefined() {
  657. if (getShareGoodsIdForAppOpen()) {
  658. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  659. /^\//,
  660. ''
  661. );
  662. }
  663. return 'pages/index/login';
  664. }
  665. function buildAppOpenQueryStringMerged() {
  666. var rawQs = getRawMergedQueryForAppOpen();
  667. if (rawQs) {
  668. return '?' + rawQs;
  669. }
  670. var params = mergeSearchAndHashParams();
  671. var gid =
  672. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  673. if (gid && !params.has('goodsId')) {
  674. params.set('goodsId', gid);
  675. }
  676. if (gid && !params.has('id')) {
  677. params.set('id', gid);
  678. }
  679. if (gid && !params.has('sourceId')) {
  680. params.set('sourceId', gid);
  681. }
  682. var sid = params.get('storeId') || '';
  683. if (sid && !params.has('storeId')) {
  684. params.set('storeId', sid);
  685. }
  686. var qsOut = params.toString();
  687. return qsOut ? ('?' + qsOut) : '';
  688. }
  689. /**
  690. * 微信 extinfo 专用 query:禁止透传整段原始 query(易超 1024 或含封面/描述等大字段导致 launch:fail)。
  691. * 与 secondShareGoods / shareDynamic 一致,仅保留 App 登录页解析所需字段。
  692. */
  693. function buildWxLaunchQueryParams() {
  694. var params = mergeSearchAndHashParams();
  695. var mini = new URLSearchParams();
  696. mini.set('goodsUnavailable', '1');
  697. var gs = params.get('goodsStatus');
  698. if (gs != null && String(gs).trim() !== '') {
  699. mini.set('goodsStatus', String(gs).trim());
  700. }
  701. var goodsId =
  702. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  703. if (goodsId) {
  704. mini.set('goodsId', String(goodsId).trim());
  705. mini.set('id', String(goodsId).trim());
  706. mini.set('sourceId', String(goodsId).trim());
  707. }
  708. var userId = params.get('userId');
  709. if (userId != null && String(userId).trim() !== '') {
  710. mini.set('userId', String(userId).trim());
  711. }
  712. var sid = params.get('storeId');
  713. if (sid != null && String(sid).trim() !== '') {
  714. mini.set('storeId', String(sid).trim());
  715. }
  716. var lon =
  717. params.get('longitude') ||
  718. params.get('lon') ||
  719. params.get('lng') ||
  720. params.get('jingdu') ||
  721. '';
  722. if (lon !== '' && !isNaN(Number(lon))) {
  723. mini.set('longitude', String(lon));
  724. }
  725. var lat =
  726. params.get('latitude') ||
  727. params.get('lat') ||
  728. params.get('weidu') ||
  729. '';
  730. if (lat !== '' && !isNaN(Number(lat))) {
  731. mini.set('latitude', String(lat));
  732. }
  733. var city = params.get('userCity') || params.get('city');
  734. if (city != null && String(city).trim() !== '') {
  735. mini.set('userCity', String(city).trim());
  736. }
  737. return mini;
  738. }
  739. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  740. function buildAppUniPageLaunchUrl() {
  741. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  742. var qs = buildWxLaunchQueryParams().toString();
  743. return qs ? path + '?' + qs : path;
  744. }
  745. /**
  746. * wx-open-launch-app extinfo:二手详情或登录页 + 精简 query(含 goodsUnavailable)
  747. */
  748. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  749. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  750. if (useBarePathOnly) return path;
  751. var mini = buildWxLaunchQueryParams();
  752. var goodsId = mini.get('goodsId') || mini.get('id') || '';
  753. if (goodsId) {
  754. mini.set('goodsId', goodsId);
  755. mini.set('id', goodsId);
  756. }
  757. var qs = mini.toString();
  758. var uniPage = qs ? path + '?' + qs : path;
  759. if (uniPage.length <= 1024) return uniPage;
  760. var shortKeys = [
  761. 'goodsUnavailable',
  762. 'goodsStatus',
  763. 'goodsId',
  764. 'id',
  765. 'sourceId',
  766. 'userId'
  767. ];
  768. var shortMini = new URLSearchParams();
  769. shortKeys.forEach(function (key) {
  770. var val = mini.get(key);
  771. if (val != null && String(val).trim() !== '') {
  772. shortMini.set(key, String(val).trim());
  773. }
  774. });
  775. var shortPage = shortMini.toString() ? path + '?' + shortMini.toString() : path;
  776. return shortPage.length <= 1024 ? shortPage : path;
  777. }
  778. /** 供 App 内嵌 WebView:uni 路由与深链一致(二手详情或登录) */
  779. function buildUniAppOpenPageUrl() {
  780. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  781. var tail = buildAppOpenQueryStringMerged();
  782. var u = '/' + path + (tail || '');
  783. var fallbackPath = getShareGoodsIdForAppOpen()
  784. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  785. : 'pages/index/login';
  786. return u.length > 1800 ? '/' + fallbackPath : u;
  787. }
  788. function buildAppDeepLink() {
  789. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  790. var s = buildAppOpenQueryStringMerged();
  791. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  792. if (!s) {
  793. return root + '/' + path;
  794. }
  795. return root + '/' + path + s;
  796. }
  797. function isWeChatInAppBrowser() {
  798. return /MicroMessenger/i.test(navigator.userAgent || '');
  799. }
  800. function ensureWxShareFromQueryBeforeConfig() {
  801. if (!isWeChatInAppBrowser()) return;
  802. var from = String(q('from') || '').trim();
  803. if (from) return;
  804. try {
  805. var u = new URL(location.href);
  806. u.searchParams.set('from', 'singlemessage');
  807. history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
  808. } catch (eFrom) {
  809. var sep = location.search && location.search.length > 1 ? '&' : '?';
  810. history.replaceState(
  811. null,
  812. '',
  813. location.pathname +
  814. (location.search || '') +
  815. sep +
  816. 'from=singlemessage' +
  817. (location.hash || '')
  818. );
  819. }
  820. }
  821. function logWxEntryDiagnostics() {
  822. if (!isWeChatInAppBrowser()) return;
  823. console.log('[wx-entry]', {
  824. entryFrom: q('from') || '(无)',
  825. signUrl: getWxConfigSignUrl()
  826. });
  827. }
  828. function readQueryParam(name) {
  829. return q(name);
  830. }
  831. function isWxDebugOn() {
  832. return readQueryParam('wxDebug') === '1';
  833. }
  834. function isWxForceDebug() {
  835. return readQueryParam('wxForce') === '1';
  836. }
  837. function isWxConfigOnClickDebug() {
  838. return readQueryParam('wxConfigOnClick') === '1';
  839. }
  840. function isWxPcAutoDebugHost() {
  841. var h = (location.hostname || '').toLowerCase();
  842. if (h === 'localhost' || h === '127.0.0.1') return true;
  843. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  844. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  845. }
  846. return false;
  847. }
  848. function isWxPcBrowser() {
  849. return !isWeChatInAppBrowser();
  850. }
  851. function shouldInitWeChatJssdkOnLoad() {
  852. if (isWeChatInAppBrowser()) return true;
  853. return isWxForceDebug() || isWxPcAutoDebugHost();
  854. }
  855. function shouldFetchWxConfig(fromUserClick) {
  856. if (isWeChatInAppBrowser()) return true;
  857. if (fromUserClick) return true;
  858. return isWxForceDebug() || isWxPcAutoDebugHost();
  859. }
  860. function getWxHtmlUrl() {
  861. var forced = String(q('wxSignUrl') || '').trim();
  862. if (forced) return forced.split('#')[0];
  863. return String(location.href || '').split('#')[0];
  864. }
  865. function getWxSignPageUrlForApi() {
  866. var htmlUrl = getWxHtmlUrl();
  867. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  868. return WX_GET_CONFIG_SIGN_URL;
  869. }
  870. function getWxHtmlUrlBase() {
  871. var htmlUrl = getWxSignPageUrlForApi();
  872. try {
  873. var u = new URL(htmlUrl);
  874. return u.origin + u.pathname;
  875. } catch (eU) {
  876. return WX_GET_CONFIG_SIGN_URL;
  877. }
  878. }
  879. function getWxConfigSignUrl() {
  880. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  881. /* 微信分享链 query 较长时用 pathname 签名,避免 invalid signature 导致开放标签不可用 */
  882. if (isWeChatInAppBrowser()) return getWxHtmlUrlBase();
  883. return getWxSignPageUrlForApi();
  884. }
  885. function getWxGetConfigApiUrl() {
  886. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  887. }
  888. function buildWxGetConfigRequestBody(htmlUrl) {
  889. return {
  890. url: String(htmlUrl || '').split('#')[0].trim()
  891. };
  892. }
  893. function resolveWxConfigAppIdFromSignData(d) {
  894. if (!d || typeof d !== 'object') return '';
  895. var mp =
  896. d.mpAppId ||
  897. d.mpAppid ||
  898. d.officialAppId ||
  899. d.gzhAppId ||
  900. d.serviceAppId;
  901. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  902. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  903. if (fromQuery) return fromQuery;
  904. var raw = d.appId || d.appid || d.wxAppId;
  905. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  906. }
  907. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  908. if (!res || typeof res !== 'object') return null;
  909. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  910. if (!d || typeof d !== 'object') return null;
  911. var appId = resolveWxConfigAppIdFromSignData(d);
  912. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  913. var nonceStr =
  914. d.nonceStr != null && String(d.nonceStr) !== ''
  915. ? d.nonceStr
  916. : d.noncestr != null && String(d.noncestr) !== ''
  917. ? d.noncestr
  918. : d.nonce;
  919. var signature = d.signature || d.sign;
  920. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  921. return null;
  922. }
  923. return {
  924. appId: String(appId),
  925. timestamp: Number(timestamp),
  926. nonceStr: String(nonceStr),
  927. signature: String(signature),
  928. signUrl: String(signUrlUsed || '')
  929. .split('#')[0]
  930. .trim()
  931. };
  932. }
  933. function getWxErrMsg(err) {
  934. if (!err) return '';
  935. if (err.errMsg) return String(err.errMsg);
  936. if (typeof err === 'string') return err;
  937. try {
  938. return JSON.stringify(err);
  939. } catch (e) {
  940. return String(err);
  941. }
  942. }
  943. function formatWxConfigErrorTip(err, signPageUrl) {
  944. var errMsg = getWxErrMsg(err);
  945. var tip = '微信 JSSDK 配置失败';
  946. if (/invalid signature/i.test(errMsg)) {
  947. return (
  948. tip +
  949. ':签名无效。请核对:①后端用与前端相同的 url 签名;②url=' +
  950. (signPageUrl || getWxHtmlUrl()) +
  951. ';③nonceStr/timestamp 与接口返回一致;④appId=' +
  952. WECHAT_MP_APP_ID
  953. );
  954. }
  955. if (/require\s*subscribe/i.test(errMsg)) {
  956. return tip + ':' + errMsg + '(服务号需用户已关注)';
  957. }
  958. return errMsg ? tip + ':' + errMsg : tip;
  959. }
  960. function setWxInitError(msg) {
  961. wxInitLastError = String(msg || '').trim();
  962. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  963. }
  964. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  965. var htmlUrl = String(
  966. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  967. )
  968. .split('#')[0]
  969. .trim();
  970. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  971. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  972. }
  973. if (isWxDebugOn()) {
  974. try {
  975. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  976. } catch (eDbg) {}
  977. }
  978. var requestUrl = getWxGetConfigApiUrl();
  979. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  980. console.log('[wx] htmlUrl=', htmlUrl);
  981. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  982. return fetch(requestUrl, {
  983. method: 'POST',
  984. mode: 'cors',
  985. credentials: 'omit',
  986. headers: {
  987. Accept: 'application/json',
  988. 'Content-Type': 'application/json;charset=UTF-8'
  989. },
  990. body: JSON.stringify(requestBody)
  991. })
  992. .then(function (r) {
  993. if (r.ok) return r.json();
  994. return r
  995. .text()
  996. .catch(function () {
  997. return '';
  998. })
  999. .then(function (text) {
  1000. var hint = '';
  1001. try {
  1002. var j = JSON.parse(text);
  1003. hint = j.msg || j.message || '';
  1004. } catch (eP) {
  1005. if (text) hint = text.slice(0, 120);
  1006. }
  1007. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  1008. });
  1009. })
  1010. .then(function (res) {
  1011. if (res && res.code != null) {
  1012. var c = Number(res.code);
  1013. if (c !== 200 && c !== 0 && res.success !== true) {
  1014. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  1015. }
  1016. }
  1017. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  1018. if (!sign) {
  1019. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  1020. throw new Error(
  1021. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  1022. );
  1023. }
  1024. if (sign.appId !== WECHAT_MP_APP_ID) {
  1025. console.warn(
  1026. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  1027. );
  1028. }
  1029. if (typeof wx === 'undefined') {
  1030. if (isWxPcBrowser()) {
  1031. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  1032. return true;
  1033. }
  1034. setWxInitError('jweixin.js 未加载');
  1035. return false;
  1036. }
  1037. return applyWxConfigFromSign(sign, htmlUrl);
  1038. });
  1039. }
  1040. function applyWxConfigFromSign(sign, htmlUrl) {
  1041. var wxConfigParams = {
  1042. debug: isWxDebugOn(),
  1043. appId: String(sign.appId),
  1044. timestamp: sign.timestamp,
  1045. nonceStr: String(sign.nonceStr),
  1046. signature: String(sign.signature),
  1047. jsApiList: [],
  1048. openTagList: ['wx-open-launch-app']
  1049. };
  1050. return new Promise(function (resolve) {
  1051. wx.config(wxConfigParams);
  1052. wx.ready(function () {
  1053. weChatJssdkConfigured = true;
  1054. document.body.classList.add('wx-jssdk-ready');
  1055. var launchEl = document.getElementById('launch-btn');
  1056. if (launchEl) {
  1057. launchEl._wxLaunchBound = false;
  1058. }
  1059. refreshWxLaunchTagAttrs(false);
  1060. bindWeChatLaunchTagEvents();
  1061. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  1062. resolve(true);
  1063. });
  1064. wx.error(function (err) {
  1065. weChatJssdkConfigured = false;
  1066. document.body.classList.remove('wx-jssdk-ready');
  1067. wxJssdkInitPromise = null;
  1068. var errMsg = getWxErrMsg(err);
  1069. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  1070. if (isWxDebugOn()) window.alert(wxInitLastError);
  1071. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  1072. var baseUrl = getWxHtmlUrlBase();
  1073. var fullUrl = getWxSignPageUrlForApi();
  1074. if (
  1075. !/invalid signature/i.test(errMsg) ||
  1076. wxConfigSignRetriedBaseUrl ||
  1077. baseUrl === fullUrl ||
  1078. htmlUrl === baseUrl
  1079. ) {
  1080. resolve(false);
  1081. return;
  1082. }
  1083. wxConfigSignRetriedBaseUrl = true;
  1084. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  1085. });
  1086. });
  1087. }
  1088. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  1089. var tag = document.getElementById('launch-btn');
  1090. if (!tag) return;
  1091. try {
  1092. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1093. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo(!!useBarePathOnly));
  1094. console.log('[wx-open-launch-app] extinfo=', tag.getAttribute('extinfo'));
  1095. } catch (eA) {}
  1096. }
  1097. function bindWeChatLaunchTagEvents() {
  1098. var tag = document.getElementById('launch-btn');
  1099. if (!tag || tag._wxLaunchBound) return;
  1100. tag._wxLaunchBound = true;
  1101. tag._wxLaunchBareRetried = false;
  1102. refreshWxLaunchTagAttrs(false);
  1103. tag.addEventListener('launch', function () {
  1104. tag._wxLaunchBareRetried = false;
  1105. console.log('[wx-open-launch-app] launch ok');
  1106. showFabToast('正在打开 U店在哪…');
  1107. });
  1108. tag.addEventListener('error', function (e) {
  1109. var detail = e && e.detail;
  1110. var errMsg =
  1111. detail && detail.errMsg
  1112. ? String(detail.errMsg)
  1113. : detail && detail.errmsg
  1114. ? String(detail.errmsg)
  1115. : '';
  1116. console.warn('[wx-open-launch-app]', detail, 'extinfo=', tag.getAttribute('extinfo'));
  1117. if (/launch:fail_check/i.test(errMsg)) {
  1118. showAppOpenFailTip(
  1119. '请用微信分享卡片进入,或确认已安装最新版「U店在哪」'
  1120. );
  1121. return;
  1122. }
  1123. if (
  1124. /launch:fail/i.test(errMsg) &&
  1125. !tag._wxLaunchBareRetried &&
  1126. tag.getAttribute('extinfo') !== buildWeChatLaunchExtinfo(true)
  1127. ) {
  1128. tag._wxLaunchBareRetried = true;
  1129. refreshWxLaunchTagAttrs(true);
  1130. showFabToast('请再点一次「APP内打开」');
  1131. return;
  1132. }
  1133. showAppOpenFailTip(
  1134. errMsg
  1135. ? '未能打开 App:' + errMsg
  1136. : '未能打开 App,请确认已安装最新版「U店在哪」'
  1137. );
  1138. });
  1139. }
  1140. function initWeChatOpenLaunchApp(fromUserClick) {
  1141. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1142. console.log('[wx] 未调用 getWxConfig');
  1143. return Promise.resolve(false);
  1144. }
  1145. ensureWxShareFromQueryBeforeConfig();
  1146. if (isWxPcBrowser()) {
  1147. console.warn(
  1148. '[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
  1149. );
  1150. }
  1151. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1152. wxConfigSignRetriedBaseUrl = false;
  1153. wxInitLastError = '';
  1154. var htmlUrl = getWxConfigSignUrl();
  1155. bindWeChatLaunchTagEvents();
  1156. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1157. .then(function (ok) {
  1158. if (ok === true) return true;
  1159. if (!wxInitLastError) {
  1160. setWxInitError('wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl');
  1161. }
  1162. return false;
  1163. })
  1164. .catch(function (e) {
  1165. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  1166. setWxInitError(msg);
  1167. console.warn('[wx] requestWeChatJssdkSignAndConfig failed', msg, 'htmlUrl=', htmlUrl);
  1168. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1169. return false;
  1170. })
  1171. .finally(function () {
  1172. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1173. });
  1174. return wxJssdkInitPromise;
  1175. }
  1176. /** 进页即尝试拉签名;jweixin 晚到时自动重试 */
  1177. function scheduleWeChatJssdkBootstrap() {
  1178. if (!shouldInitWeChatJssdkOnLoad()) return;
  1179. var attempts = 0;
  1180. function tick() {
  1181. if (weChatJssdkConfigured) return;
  1182. attempts += 1;
  1183. var pending = initWeChatOpenLaunchApp();
  1184. if (pending && typeof pending.then === 'function') {
  1185. pending.then(function () {
  1186. if (!weChatJssdkConfigured && attempts < 10) {
  1187. setTimeout(tick, 500);
  1188. }
  1189. });
  1190. }
  1191. if (!weChatJssdkConfigured && attempts < 10 && typeof wx === 'undefined') {
  1192. setTimeout(tick, 400);
  1193. }
  1194. }
  1195. tick();
  1196. }
  1197. function showFabToast(msg, ms) {
  1198. var tip = String(msg || '').trim();
  1199. if (!tip) return;
  1200. var el = document.getElementById('openAppToast');
  1201. if (el) {
  1202. el.textContent = tip;
  1203. el.style.display = 'block';
  1204. if (showFabToast._t) clearTimeout(showFabToast._t);
  1205. showFabToast._t = setTimeout(function () {
  1206. el.style.display = 'none';
  1207. }, ms || 2800);
  1208. }
  1209. console.log('[openApp]', tip);
  1210. }
  1211. function showAppOpenFailTip(msg) {
  1212. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  1213. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  1214. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  1215. } else if (isWeChatInAppBrowser()) {
  1216. window.alert(tip);
  1217. } else {
  1218. console.warn('[openApp]', tip);
  1219. }
  1220. }
  1221. function tryFetchWxConfigOnPcClick() {
  1222. if (!isWxPcBrowser()) return Promise.resolve(false);
  1223. showFabToast('正在请求 getWxConfig…');
  1224. wxJssdkInitPromise = null;
  1225. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1226. if (ok) {
  1227. showFabToast(
  1228. weChatJssdkConfigured
  1229. ? 'getWxConfig 成功,wx.config 已就绪'
  1230. : 'getWxConfig 成功'
  1231. );
  1232. } else {
  1233. showFabToast(wxInitLastError || 'getWxConfig 失败');
  1234. }
  1235. return ok;
  1236. });
  1237. }
  1238. function launchAppDeepLink(deepLink) {
  1239. try {
  1240. var a = document.createElement('a');
  1241. a.href = deepLink;
  1242. a.setAttribute('target', '_self');
  1243. document.body.appendChild(a);
  1244. a.click();
  1245. document.body.removeChild(a);
  1246. } catch (e1) {}
  1247. try {
  1248. window.location.href = deepLink;
  1249. } catch (e2) {}
  1250. }
  1251. function tryOpenUShopApp() {
  1252. /* 微信内须直接点击 wx-open-launch-app,scheme 会被拦截 */
  1253. if (isWeChatInAppBrowser()) return;
  1254. tryFetchWxConfigOnPcClick().then(function () {
  1255. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1256. return;
  1257. }
  1258. tryOpenUShopAppViaScheme();
  1259. });
  1260. }
  1261. function tryOpenUShopAppViaScheme() {
  1262. function openBySchemeOrPlus() {
  1263. // showFabToast('正在打开 U店在哪…');
  1264. var deepLink = buildAppDeepLink();
  1265. if (typeof plus !== 'undefined' && plus.runtime) {
  1266. var installed = null;
  1267. try {
  1268. if (typeof plus.runtime.isApplicationExist === 'function') {
  1269. installed = plus.runtime.isApplicationExist({
  1270. pname: APP_ANDROID_PACKAGE,
  1271. action: APP_IOS_URL_SCHEME
  1272. });
  1273. }
  1274. } catch (e) {
  1275. console.warn(e);
  1276. }
  1277. if (installed === false) {
  1278. showDownloadTip();
  1279. return;
  1280. }
  1281. try {
  1282. plus.runtime.openURL(deepLink);
  1283. } catch (e2) {
  1284. console.warn(e2);
  1285. showDownloadTip();
  1286. }
  1287. return;
  1288. }
  1289. var done = false;
  1290. function finish() {
  1291. if (done) return;
  1292. done = true;
  1293. document.removeEventListener('visibilitychange', onVis);
  1294. window.removeEventListener('pagehide', onHide);
  1295. }
  1296. function onVis() {
  1297. if (document.visibilityState === 'hidden') finish();
  1298. }
  1299. function onHide() {
  1300. finish();
  1301. }
  1302. document.addEventListener('visibilitychange', onVis);
  1303. window.addEventListener('pagehide', onHide);
  1304. try {
  1305. launchAppDeepLink(deepLink);
  1306. } catch (e3) {
  1307. finish();
  1308. showDownloadTip();
  1309. return;
  1310. }
  1311. window.setTimeout(function () {
  1312. finish();
  1313. }, 2600);
  1314. }
  1315. if (typeof uni !== 'undefined' && typeof uni.navigateTo === 'function') {
  1316. var uniUrl = buildUniAppOpenPageUrl();
  1317. var uniFallback =
  1318. '/' +
  1319. (getShareGoodsIdForAppOpen()
  1320. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  1321. : 'pages/index/login');
  1322. try {
  1323. uni.navigateTo({
  1324. url: uniUrl,
  1325. fail: function () {
  1326. if (typeof uni.reLaunch === 'function') {
  1327. try {
  1328. uni.reLaunch({
  1329. url: uniUrl.length > 1800 ? uniFallback : uniUrl,
  1330. fail: function () {
  1331. openBySchemeOrPlus();
  1332. }
  1333. });
  1334. return;
  1335. } catch (eRl) {}
  1336. }
  1337. openBySchemeOrPlus();
  1338. }
  1339. });
  1340. return;
  1341. } catch (eUni) {
  1342. openBySchemeOrPlus();
  1343. return;
  1344. }
  1345. }
  1346. openBySchemeOrPlus();
  1347. }
  1348. function showErr(msg) {
  1349. var el = document.getElementById('pageError');
  1350. el.textContent = msg;
  1351. el.style.display = 'block';
  1352. }
  1353. function getStoreId() {
  1354. return q('id') || q('storeId');
  1355. }
  1356. function apiFetch(path) {
  1357. return fetch(API_BASE + path, {
  1358. method: 'GET',
  1359. mode: 'cors',
  1360. credentials: 'omit',
  1361. headers: { Accept: 'application/json' }
  1362. }).then(function (res) {
  1363. if (!res.ok) throw new Error('HTTP ' + res.status);
  1364. return res.json();
  1365. });
  1366. }
  1367. function isApiOk(res) {
  1368. if (!res || typeof res !== 'object') return false;
  1369. if (res.success === false) return false;
  1370. var c = res.code;
  1371. return c === 200 || c === '200' || Number(c) === 200;
  1372. }
  1373. function fetchSecondGlobalRecommend() {
  1374. var userIdRaw = q('userId').trim();
  1375. var userId =
  1376. userIdRaw !== '' && !isNaN(Number(userIdRaw)) ? Number(userIdRaw) : null;
  1377. var latRaw = (q('userLat') || q('latitude') || q('lat') || q('weidu')).trim();
  1378. var lngRaw = (q('userLng') || q('longitude') || q('lon') || q('jingdu')).trim();
  1379. var userLat =
  1380. latRaw !== '' && !isNaN(Number(latRaw)) ? Number(latRaw) : DEFAULT_REC_USER_LAT;
  1381. var userLng =
  1382. lngRaw !== '' && !isNaN(Number(lngRaw)) ? Number(lngRaw) : DEFAULT_REC_USER_LNG;
  1383. var rkRaw = q('radiusKm').trim();
  1384. var radiusKm =
  1385. rkRaw !== '' && !isNaN(Number(rkRaw)) ? Number(rkRaw) : DEFAULT_REC_RADIUS_KM;
  1386. var page = parseInt(q('page') || '1', 10);
  1387. var pageSize = parseInt(q('pageSize') || '20', 10);
  1388. if (isNaN(page) || page < 1) page = 1;
  1389. if (isNaN(pageSize) || pageSize < 1) pageSize = 20;
  1390. var c1Raw = q('categoryOneId').trim();
  1391. var c2Raw = q('categoryTwoId').trim();
  1392. var categoryOneId =
  1393. c1Raw === '' || c1Raw.toLowerCase() === 'null'
  1394. ? null
  1395. : isNaN(Number(c1Raw))
  1396. ? null
  1397. : Number(c1Raw);
  1398. var categoryTwoId =
  1399. c2Raw === '' || c2Raw.toLowerCase() === 'null'
  1400. ? null
  1401. : isNaN(Number(c2Raw))
  1402. ? null
  1403. : Number(c2Raw);
  1404. var body = {
  1405. categoryOneId: categoryOneId,
  1406. categoryTwoId: categoryTwoId,
  1407. page: page,
  1408. pageSize: pageSize,
  1409. radiusKm: radiusKm,
  1410. userLat: userLat,
  1411. userLng: userLng,
  1412. userId: userId
  1413. };
  1414. return fetch(API_LIFE_AI_BASE + SECOND_GLOBAL_RECOMMEND_PATH, {
  1415. method: 'POST',
  1416. mode: 'cors',
  1417. credentials: 'omit',
  1418. headers: {
  1419. Accept: 'application/json',
  1420. 'Content-Type': 'application/json;charset=UTF-8'
  1421. },
  1422. body: JSON.stringify(body)
  1423. }).then(function (res) {
  1424. if (!res.ok) throw new Error('HTTP ' + res.status);
  1425. return res.json();
  1426. });
  1427. }
  1428. function normalizeGlobalRecommendList(res) {
  1429. if (!res || typeof res !== 'object') return [];
  1430. var raw = null;
  1431. if (isApiOk(res)) {
  1432. raw = res.data != null ? res.data : res.result;
  1433. }
  1434. if (Array.isArray(raw)) return raw;
  1435. if (raw && typeof raw === 'object') {
  1436. if (Array.isArray(raw.list)) return raw.list;
  1437. if (Array.isArray(raw.records)) return raw.records;
  1438. if (Array.isArray(raw.rows)) return raw.rows;
  1439. if (Array.isArray(raw.content)) return raw.content;
  1440. }
  1441. return [];
  1442. }
  1443. function buildHeroSlides(urls) {
  1444. var track = document.getElementById('heroTrack');
  1445. var dotsWrap = document.getElementById('heroDots');
  1446. track.innerHTML = '';
  1447. dotsWrap.innerHTML = '';
  1448. var list = (urls || []).filter(Boolean);
  1449. if (!list.length) {
  1450. var slide = document.createElement('div');
  1451. slide.className = 'hero__slide';
  1452. var img = document.createElement('img');
  1453. img.src = 'images/hero.png';
  1454. img.alt = '店铺';
  1455. slide.appendChild(img);
  1456. track.appendChild(slide);
  1457. var dot = document.createElement('span');
  1458. dot.className = 'hero__dot is-active';
  1459. dotsWrap.appendChild(dot);
  1460. return initHeroCarousel(1);
  1461. }
  1462. list.forEach(function (url, d) {
  1463. var slide = document.createElement('div');
  1464. slide.className = 'hero__slide';
  1465. var img = document.createElement('img');
  1466. img.src = url;
  1467. img.alt = '店铺图';
  1468. slide.appendChild(img);
  1469. track.appendChild(slide);
  1470. var dot = document.createElement('span');
  1471. dot.className = 'hero__dot' + (d === 0 ? ' is-active' : '');
  1472. dotsWrap.appendChild(dot);
  1473. });
  1474. initHeroCarousel(list.length);
  1475. }
  1476. var heroI = 0;
  1477. var heroTimer = null;
  1478. function initHeroCarousel(slides) {
  1479. var track = document.getElementById('heroTrack');
  1480. var dotsWrap = document.getElementById('heroDots');
  1481. var dots = dotsWrap.querySelectorAll('.hero__dot');
  1482. if (slides < 2) return;
  1483. function go(n) {
  1484. heroI = (n + slides) % slides;
  1485. track.style.transform = 'translateX(' + (-heroI * 100) + '%)';
  1486. dots.forEach(function (el, idx) {
  1487. el.classList.toggle('is-active', idx === heroI);
  1488. });
  1489. }
  1490. if (heroTimer) clearInterval(heroTimer);
  1491. heroTimer = setInterval(function () { go(heroI + 1); }, 4000);
  1492. var hero = document.getElementById('hero');
  1493. var startX = 0;
  1494. hero.addEventListener('touchstart', function (e) {
  1495. startX = e.changedTouches[0].clientX;
  1496. }, { passive: true });
  1497. hero.addEventListener('touchend', function (e) {
  1498. var dx = e.changedTouches[0].clientX - startX;
  1499. if (Math.abs(dx) > 40) go(dx < 0 ? heroI + 1 : heroI - 1);
  1500. }, { passive: true });
  1501. }
  1502. function timeToMinutes(t) {
  1503. var parts = String(t || '').trim().split(':');
  1504. var h = parseInt(parts[0], 10) || 0;
  1505. var m = parseInt(parts[1], 10) || 0;
  1506. return h * 60 + m;
  1507. }
  1508. function isTimeInRange(startTime, endTime) {
  1509. var s = String(startTime || '').trim();
  1510. var e = String(endTime || '').trim();
  1511. if (s === '00:00' && e === '00:00') return true;
  1512. if (s === '00:00' && e === '23:59') return true;
  1513. var cur = new Date().getHours() * 60 + new Date().getMinutes();
  1514. var sm = timeToMinutes(s);
  1515. var em = timeToMinutes(e);
  1516. if (em < sm) {
  1517. return cur >= sm || cur <= em;
  1518. }
  1519. return cur >= sm && cur <= em;
  1520. }
  1521. function parseHolidayDate(str) {
  1522. if (!str) return null;
  1523. var d = new Date(String(str).trim().replace(/-/g, '/'));
  1524. return isNaN(d.getTime()) ? null : d;
  1525. }
  1526. function isTodayInHolidayRange(holidayInfo) {
  1527. if (!holidayInfo) return false;
  1528. var hi = holidayInfo;
  1529. if (typeof hi === 'string') {
  1530. try {
  1531. hi = JSON.parse(hi);
  1532. } catch (err) {
  1533. return false;
  1534. }
  1535. }
  1536. var start = hi.startDate || hi.holidayStartDate || hi.beginDate || hi.start || hi.holidayStart;
  1537. var end = hi.endDate || hi.holidayEndDate || hi.finishDate || hi.end || hi.holidayEnd;
  1538. if (!start || !end) return false;
  1539. var startD = parseHolidayDate(start);
  1540. var endD = parseHolidayDate(end);
  1541. if (!startD || !endD) return false;
  1542. var today = new Date();
  1543. today.setHours(0, 0, 0, 0);
  1544. startD.setHours(0, 0, 0, 0);
  1545. endD.setHours(0, 0, 0, 0);
  1546. return today >= startD && today <= endD;
  1547. }
  1548. function findNormalBusinessInfo(list) {
  1549. var wdJs = new Date().getDay();
  1550. var i;
  1551. var x;
  1552. var w;
  1553. for (i = 0; i < list.length; i++) {
  1554. x = list[i];
  1555. if (!x || x.holidayInfo) continue;
  1556. w = x.weekDay != null ? x.weekDay : x.week;
  1557. if (w === undefined || w === null) continue;
  1558. if (Number(w) === wdJs) return x;
  1559. }
  1560. var wdMap = wdJs === 0 ? 7 : wdJs;
  1561. for (i = 0; i < list.length; i++) {
  1562. x = list[i];
  1563. if (!x || x.holidayInfo) continue;
  1564. w = x.weekDay != null ? x.weekDay : x.week;
  1565. if (w === undefined || w === null) continue;
  1566. if (Number(w) === wdMap) return x;
  1567. }
  1568. for (i = 0; i < list.length; i++) {
  1569. x = list[i];
  1570. if (x && !x.holidayInfo && (x.startTime || x.endTime)) return x;
  1571. }
  1572. return null;
  1573. }
  1574. /** 营业状态:暂停营业 | 商家暂未配置营业时间 | 休息中 | 营业中 xx:xx至xx:xx | 营业中 全天营业 */
  1575. function computeBusinessStatusDisplay(d) {
  1576. if (!d) return { text: '—', isOpen: false };
  1577. if (Number(d.businessStatus) === 1) {
  1578. return { text: '暂停营业', isOpen: false };
  1579. }
  1580. var list = d.storeBusinessInfoVos || d.storeBusinessInfos || [];
  1581. if (!list.length) {
  1582. return { text: '商家暂未配置营业时间', isOpen: false };
  1583. }
  1584. var holidayList = Array.isArray(d.holidayBusinessInfoList) && d.holidayBusinessInfoList.length
  1585. ? d.holidayBusinessInfoList
  1586. : list.filter(function (item) { return item && item.holidayInfo; });
  1587. var todayHolidayItem = holidayList.find(function (item) {
  1588. return isTodayInHolidayRange(item.holidayInfo);
  1589. });
  1590. var normal = d.normalBusinessInfo || d.normalBusinessInfoVo || findNormalBusinessInfo(list);
  1591. var isOpen = false;
  1592. var currentItem = null;
  1593. if (todayHolidayItem) {
  1594. isOpen = isTimeInRange(todayHolidayItem.startTime, todayHolidayItem.endTime);
  1595. currentItem = todayHolidayItem;
  1596. } else if (normal) {
  1597. isOpen = isTimeInRange(normal.startTime, normal.endTime);
  1598. currentItem = normal;
  1599. }
  1600. if (!currentItem) return { text: '休息中', isOpen: false };
  1601. if (!isOpen) return { text: '休息中', isOpen: false };
  1602. var st = String(currentItem.startTime || '').trim();
  1603. var et = String(currentItem.endTime || '').trim();
  1604. if (st === '00:00' && et === '00:00') return { text: '营业中 全天营业', isOpen: true };
  1605. if (st === '00:00' && et === '23:59') return { text: '营业中 全天营业', isOpen: true };
  1606. var needNextDay = timeToMinutes(et) < timeToMinutes(st);
  1607. var suffix = (needNextDay ? '次日' : '') + et;
  1608. return { text: ('营业中 ' + st + ' 至 ' + suffix).trim(), isOpen: true };
  1609. }
  1610. function renderDetail(d) {
  1611. if (!d) return;
  1612. document.getElementById('storeName').textContent = d.storeName || '—';
  1613. var score = d.scoreAvg != null ? Number(d.scoreAvg) : NaN;
  1614. document.getElementById('scoreAvg').textContent = !isNaN(score) ? score.toFixed(1) : '—';
  1615. document.getElementById('commitCount').textContent = d.commitCount != null ? String(d.commitCount) : '0';
  1616. var bizDisp = computeBusinessStatusDisplay(d);
  1617. var bizEl = document.getElementById('bizStatus');
  1618. bizEl.textContent = bizDisp.text;
  1619. bizEl.className = 'status' + (bizDisp.isOpen ? ' is-open' : '');
  1620. document.getElementById('hoursText').textContent = '';
  1621. document.getElementById('storeAddr').textContent = d.queryAddress || d.storeAddress || '—';
  1622. if (d.distance != null) {
  1623. document.getElementById('metaDistance').style.display = 'flex';
  1624. document.getElementById('distanceText').textContent =
  1625. '距您' + (Number(d.distance) > 1 ? d.distance + '千米' : Math.round(Number(d.distance) * 1000) + '米');
  1626. }
  1627. if (d.subwayName && d.distance2 != null) {
  1628. document.getElementById('metaSubway').style.display = 'flex';
  1629. document.getElementById('subwayText').textContent =
  1630. '距' + d.subwayName + '步行' + (Number(d.distance2) >= 1000
  1631. ? (Number(d.distance2) / 1000).toFixed(1) + 'km'
  1632. : Math.round(Number(d.distance2)) + 'm');
  1633. }
  1634. var imgs = [];
  1635. if (Array.isArray(d.storeAlbumUrlList) && d.storeAlbumUrlList.length) imgs = d.storeAlbumUrlList.slice();
  1636. else if (d.entranceImage) imgs = [d.entranceImage];
  1637. buildHeroSlides(imgs);
  1638. }
  1639. function formatRecDist(m) {
  1640. if (m == null || m === '') return '';
  1641. var n = Number(m);
  1642. if (isNaN(n)) return String(m);
  1643. return n >= 1000 ? (n / 1000).toFixed(1) + 'km' : Math.round(n) + 'm';
  1644. }
  1645. function escHtml(s) {
  1646. return String(s == null ? '' : s)
  1647. .replace(/&/g, '&amp;')
  1648. .replace(/</g, '&lt;')
  1649. .replace(/>/g, '&gt;')
  1650. .replace(/"/g, '&quot;');
  1651. }
  1652. /** global-recommend records:homeImage、title、position、dist、price、amount、likeCount、collectCount、userName、userImage */
  1653. function renderRecommended(list) {
  1654. var wrap = document.getElementById('recList');
  1655. var empty = document.getElementById('recEmpty');
  1656. wrap.querySelectorAll('.rec-card').forEach(function (n) {
  1657. n.remove();
  1658. });
  1659. if (!list || !list.length) {
  1660. empty.style.display = 'block';
  1661. return;
  1662. }
  1663. empty.style.display = 'none';
  1664. list.forEach(function (item) {
  1665. if (!item || typeof item !== 'object') return;
  1666. var card = document.createElement('article');
  1667. card.className = 'rec-card';
  1668. var home = item.homeImage != null ? String(item.homeImage).trim() : '';
  1669. if (home && /\.mp4(\?|#|$)/i.test(home)) {
  1670. var vf = item.videoFirstFrame != null ? String(item.videoFirstFrame).trim() : '';
  1671. if (vf) home = vf;
  1672. }
  1673. var imgUrl =
  1674. home ||
  1675. (item.coverUrl != null ? String(item.coverUrl).trim() : '') ||
  1676. (item.mainImage != null ? String(item.mainImage).trim() : '') ||
  1677. (item.goodsImage != null ? String(item.goodsImage).trim() : '') ||
  1678. (Array.isArray(item.goodsImageList) && item.goodsImageList[0]) ||
  1679. (Array.isArray(item.imageList) && item.imageList[0]) ||
  1680. 'images/hero.png';
  1681. var name = item.title != null && String(item.title).trim() !== ''
  1682. ? String(item.title).replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').trim()
  1683. : (item.goodsName ||
  1684. item.secondGoodsTitle ||
  1685. item.name ||
  1686. '商品');
  1687. var dist = '';
  1688. if (item.position != null && String(item.position).trim() !== '') {
  1689. dist = String(item.position).trim();
  1690. } else if (item.dist != null && item.dist !== '') {
  1691. var dn = Number(item.dist);
  1692. if (!isNaN(dn)) {
  1693. dist = dn.toFixed(dn % 1 === 0 ? 0 : 2) + 'km';
  1694. }
  1695. } else if (item.distance != null && item.distance !== '') {
  1696. var d2 = Number(item.distance);
  1697. dist = !isNaN(d2) ? d2.toFixed(d2 % 1 === 0 ? 0 : 2) + 'km' : String(item.distance);
  1698. }
  1699. var priceStr = '';
  1700. if (item.price != null && String(item.price).trim() !== '') {
  1701. var ps = String(item.price).trim();
  1702. var pNum = parseFloat(ps.replace(/[^\d.]/g, ''));
  1703. priceStr = !isNaN(pNum) ? pNum.toFixed(2) : ps;
  1704. } else if (item.amount != null && item.amount !== '') {
  1705. var an = Number(item.amount);
  1706. priceStr = !isNaN(an) ? an.toFixed(2) : String(item.amount);
  1707. } else {
  1708. priceStr = '—';
  1709. }
  1710. var seller =
  1711. item.userName != null && String(item.userName).trim() !== ''
  1712. ? String(item.userName).trim()
  1713. : '';
  1714. var userImg =
  1715. item.userImage != null && String(item.userImage).trim() !== ''
  1716. ? String(item.userImage).trim()
  1717. : '';
  1718. var likeN = item.likeCount != null ? Number(item.likeCount) : NaN;
  1719. var colN = item.collectCount != null ? Number(item.collectCount) : NaN;
  1720. var metaBits = [];
  1721. // if (!isNaN(likeN)) metaBits.push(likeN + '赞');
  1722. // if (!isNaN(colN)) metaBits.push(colN + '想要');
  1723. var metaRight = metaBits.join(' · ');
  1724. var showSellerRow = !!(seller || userImg);
  1725. card.innerHTML =
  1726. '<div class="rec-card__img"><img class="rec-card__cover" src="" alt=""></div>' +
  1727. '<div class="rec-card__body">' +
  1728. '<div class="rec-card__top">' +
  1729. '<span class="rec-card__name">' + escHtml(name) + '</span>' +
  1730. (dist ? '<span class="rec-card__dist">' + escHtml(dist) + '</span>' : '') +
  1731. '</div>' +
  1732. '<div class="rec-card__rating">' +
  1733. '<span class="rec-meta" style="color:#E62E2E;font-weight:600;">¥' + escHtml(priceStr) + '</span>' +
  1734. (metaRight
  1735. ? '<span class="rec-meta">' + escHtml(metaRight) + '</span>'
  1736. : '') +
  1737. '</div>' +
  1738. (showSellerRow
  1739. ? '<div class="rec-card__seller">' +
  1740. '<img class="rec-card__avatar" src="" alt="" width="22" height="22" decoding="async">' +
  1741. (seller ? '<span class="rec-card__seller-name">' + escHtml(seller) + '</span>' : '') +
  1742. '</div>'
  1743. : '') +
  1744. '</div>';
  1745. var coverIm = card.querySelector('img.rec-card__cover');
  1746. if (coverIm) {
  1747. coverIm.src = imgUrl;
  1748. coverIm.onerror = function () {
  1749. this.onerror = null;
  1750. this.src = 'images/hero.png';
  1751. };
  1752. }
  1753. var avIm = card.querySelector('img.rec-card__avatar');
  1754. if (avIm) {
  1755. avIm.src = userImg || 'images/demouser.png';
  1756. avIm.onerror = function () {
  1757. this.onerror = null;
  1758. this.src = 'images/demouser.png';
  1759. };
  1760. }
  1761. wrap.appendChild(card);
  1762. });
  1763. }
  1764. function run() {
  1765. fetchSecondGlobalRecommend()
  1766. .then(function (res) {
  1767. var list = normalizeGlobalRecommendList(res);
  1768. if (!list.length && res && res.msg) {
  1769. console.warn('[global-recommend]', res.msg);
  1770. }
  1771. renderRecommended(list);
  1772. })
  1773. .catch(function (e) {
  1774. console.error(e);
  1775. renderRecommended([]);
  1776. });
  1777. }
  1778. function boot() {
  1779. var launchTag = document.getElementById('launch-btn');
  1780. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1781. bindWeChatLaunchTagEvents();
  1782. if (isWeChatInAppBrowser()) {
  1783. document.body.classList.add('is-wechat');
  1784. ensureWxShareFromQueryBeforeConfig();
  1785. logWxEntryDiagnostics();
  1786. }
  1787. if (shouldInitWeChatJssdkOnLoad()) {
  1788. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1789. document.body.classList.add('wx-pc-debug');
  1790. }
  1791. scheduleWeChatJssdkBootstrap();
  1792. }
  1793. document.addEventListener('WeixinOpenTagsError', function (e) {
  1794. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1795. var d = e && e.detail;
  1796. var em =
  1797. d && d.errMsg
  1798. ? String(d.errMsg)
  1799. : d && d.errmsg
  1800. ? String(d.errmsg)
  1801. : '';
  1802. showFabToast(em || '微信开放标签不可用,请升级微信后重试');
  1803. });
  1804. run();
  1805. if (isWeChatInAppBrowser()) {
  1806. var openBtnWx = document.getElementById('openApp');
  1807. if (openBtnWx) {
  1808. openBtnWx.addEventListener('click', function () {
  1809. if (!weChatJssdkConfigured) {
  1810. showFabToast(
  1811. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1812. );
  1813. initWeChatOpenLaunchApp(true);
  1814. }
  1815. });
  1816. }
  1817. } else {
  1818. var openBtn = document.getElementById('openApp');
  1819. if (openBtn) {
  1820. openBtn.addEventListener('click', tryOpenUShopApp);
  1821. }
  1822. }
  1823. }
  1824. if (document.readyState === 'complete') {
  1825. boot();
  1826. } else {
  1827. window.onload = boot;
  1828. }
  1829. })();
  1830. </script>
  1831. </body>
  1832. </html>