shareUndefined.html 55 KB

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