shareUndefined.html 48 KB

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