shareUndefined.html 49 KB

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