shareUndefined.html 53 KB

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