shareUndefined.html 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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. /* FAB */
  272. .fab-wrap {
  273. position: fixed;
  274. left: 0;
  275. right: 0;
  276. bottom: 0;
  277. z-index: 200;
  278. padding: 12px 24px calc(12px + var(--safe-bottom));
  279. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  280. pointer-events: none;
  281. }
  282. .fab-dock__slot {
  283. width: 100%;
  284. max-width: 198px;
  285. height: 48px;
  286. margin: 0 auto;
  287. pointer-events: auto;
  288. }
  289. #openApp.fab {
  290. padding: 0 10px;
  291. -webkit-font-smoothing: antialiased;
  292. text-rendering: optimizeLegibility;
  293. }
  294. .fab__brand-clip {
  295. display: block;
  296. flex-shrink: 0;
  297. line-height: 0;
  298. }
  299. .fab__brand-img {
  300. display: block;
  301. height: 26px;
  302. width: auto;
  303. max-width: none;
  304. pointer-events: none;
  305. -webkit-user-drag: none;
  306. }
  307. .fab__label {
  308. font-size: 15px;
  309. line-height: 1;
  310. letter-spacing: 0.04em;
  311. white-space: nowrap;
  312. }
  313. #launch-btn {
  314. display: none;
  315. width: 100%;
  316. height: 48px;
  317. min-height: 48px;
  318. border-radius: 24px;
  319. overflow: hidden;
  320. opacity: 1;
  321. }
  322. /* 与 secondShareGoods 一致:wx 就绪后仅显示开放标签(叠在 openApp 之上) */
  323. body.is-wechat.wx-jssdk-ready #launch-btn {
  324. display: block;
  325. pointer-events: auto;
  326. }
  327. body.is-wechat.wx-jssdk-ready #openApp {
  328. display: none !important;
  329. }
  330. #openAppToast {
  331. display: none;
  332. position: fixed;
  333. left: 16px;
  334. right: 16px;
  335. bottom: calc(72px + var(--safe-bottom));
  336. z-index: 10001;
  337. padding: 10px 14px;
  338. font-size: 13px;
  339. line-height: 1.45;
  340. color: #fff;
  341. text-align: center;
  342. background: rgba(0, 0, 0, 0.78);
  343. border-radius: 8px;
  344. pointer-events: none;
  345. word-break: break-all;
  346. }
  347. #openApp {
  348. touch-action: manipulation;
  349. }
  350. .fab-wrap .fab {
  351. pointer-events: auto;
  352. }
  353. .fab {
  354. display: flex;
  355. align-items: center;
  356. justify-content: center;
  357. gap: 4px;
  358. width: 100%;
  359. max-width: 198px;
  360. margin: 0 auto;
  361. height: 48px;
  362. border: none;
  363. border-radius: 24px;
  364. background: var(--orange);
  365. color: #fff;
  366. font-size: 16px;
  367. font-weight: 600;
  368. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  369. cursor: pointer;
  370. }
  371. .fab__logo {
  372. width: 28px;
  373. height: 28px;
  374. flex-shrink: 0;
  375. }
  376. .home-indicator {
  377. height: 5px;
  378. background: #000;
  379. border-radius: 3px;
  380. width: 134px;
  381. margin: 8px auto 4px;
  382. opacity: 0.2;
  383. }
  384. </style>
  385. </head>
  386. <body>
  387. <div class="hero hero--empty" id="hero" role="status" aria-live="polite">
  388. <img class="hero--empty__illustration" src="images/empty.png" alt="" decoding="async">
  389. <p class="hero--empty__tip">商品已删除/下架/卖出</p>
  390. </div>
  391. <div id="openAppToast" role="status" aria-live="polite"></div>
  392. <div class="fab-wrap">
  393. <div class="fab-dock__slot">
  394. <!-- 与 secondShareGoods 相同顺序:openApp 在下,launch-btn 在上,避免挡住点击 -->
  395. <button type="button" class="fab" id="openApp" aria-label="APP内打开">
  396. <span class="fab__brand-clip" aria-hidden="true">
  397. <img class="fab__brand-img" src="images/uBtn.svg" alt="" decoding="async">
  398. </span>
  399. <span class="fab__label">APP内打开</span>
  400. </button>
  401. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  402. <script type="text/wxtag-template">
  403. <style>
  404. .wx-open-app-btn {
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. gap: 4px;
  409. width: 100%;
  410. height: 48px;
  411. margin: 0;
  412. padding: 0 10px;
  413. border: none;
  414. border-radius: 24px;
  415. background: #F47D1F;
  416. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  417. color: #fff;
  418. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  419. -webkit-font-smoothing: antialiased;
  420. cursor: pointer;
  421. overflow: hidden;
  422. -webkit-tap-highlight-color: transparent;
  423. box-sizing: border-box;
  424. }
  425. .wx-open-app-btn .fab__brand-clip {
  426. display: block;
  427. flex-shrink: 0;
  428. line-height: 0;
  429. }
  430. .wx-open-app-btn .fab__brand-img {
  431. display: block;
  432. height: 26px;
  433. width: auto;
  434. max-width: none;
  435. pointer-events: none;
  436. -webkit-user-drag: none;
  437. }
  438. .wx-open-app-btn .fab__label {
  439. font-size: 15px;
  440. line-height: 1;
  441. letter-spacing: 0.04em;
  442. white-space: nowrap;
  443. }
  444. </style>
  445. <button class="wx-open-app-btn" aria-label="APP内打开">
  446. <span class="fab__brand-clip" aria-hidden="true">
  447. <img class="fab__brand-img" src="https://prod.ailien.shop/h5/HBuilderProjects/images/uBtn.svg" alt="" decoding="async">
  448. </span>
  449. <span class="fab__label">APP内打开</span>
  450. </button>
  451. </script>
  452. </wx-open-launch-app>
  453. </div>
  454. <div class="home-indicator" aria-hidden="true"></div>
  455. </div>
  456. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  457. <script>
  458. (function () {
  459. 'use strict';
  460. /**
  461. * 商品不可用占位页;底部「APP内打开」始终可唤起 App:
  462. * 有 goodsId/id/sourceId → 二手详情页(带 goodsUnavailable 等参数,由 App 展示已删除态);
  463. * 无商品 id → pages/index/login。
  464. *
  465. * 注意:用 file:// 打开本页时,浏览器可能因 CORS 拦截跨域请求。
  466. */
  467. var API_BASE = 'https://prod.ailien.shop/alienStore';
  468. /**
  469. * 微信 JSSDK — 与 shareIndex.html 一致
  470. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  471. */
  472. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  473. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  474. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  475. var H5_PAGE_BASE_FALLBACK = 'https://prod.ailien.shop/h5/HBuilderProjects/';
  476. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'shareUndefined.html';
  477. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'prod.ailien.shop'];
  478. var weChatJssdkConfigured = false;
  479. var wxConfigSignRetriedBaseUrl = false;
  480. var wxInitLastError = '';
  481. var wxJssdkInitPromise = null;
  482. /**
  483. * 与 secondShareGoods.html 一致:唤起 App 打开二手商品详情页(合并 search + hash 内 query)
  484. */
  485. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  486. var APP_IOS_URL_SCHEME = 'shopro://';
  487. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  488. function showDownloadTip() {
  489. var msg = '请到应用商店下载';
  490. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  491. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  492. } else {
  493. window.alert(msg);
  494. }
  495. }
  496. function mergeSearchAndHashParams() {
  497. var params = new URLSearchParams();
  498. function ingestAppend(querySlice) {
  499. if (!querySlice) return;
  500. var p = new URLSearchParams(querySlice);
  501. p.forEach(function (val, key) {
  502. params.append(key, val);
  503. });
  504. }
  505. function ingestSet(querySlice) {
  506. if (!querySlice) return;
  507. var p = new URLSearchParams(querySlice);
  508. p.forEach(function (val, key) {
  509. params.set(key, val);
  510. });
  511. }
  512. if (location.search && location.search.length > 1) {
  513. ingestAppend(location.search.slice(1));
  514. }
  515. var hash = location.hash || '';
  516. var qi = hash.indexOf('?');
  517. if (qi >= 0) {
  518. ingestSet(hash.slice(qi + 1));
  519. }
  520. return params;
  521. }
  522. function q(name) {
  523. var v = mergeSearchAndHashParams().get(name);
  524. return v == null ? '' : String(v);
  525. }
  526. function rawQueryHasGoodsId(qs) {
  527. return /(?:^|&)(goodsId|id|sourceId)=/i.test('&' + String(qs || '') + '&');
  528. }
  529. function getShareGoodsIdForAppOpen() {
  530. return (q('goodsId') || q('id') || q('sourceId') || '').trim();
  531. }
  532. function getRawMergedQueryForAppOpen() {
  533. var rawSearch =
  534. location.search && location.search.length > 1 ? location.search.slice(1) : '';
  535. var hash0 = location.hash || '';
  536. var hqi0 = hash0.indexOf('?');
  537. var rawHashQ = hqi0 >= 0 ? hash0.slice(hqi0 + 1) : '';
  538. if (!rawSearch && !rawHashQ) return '';
  539. if (rawHashQ && rawSearch) {
  540. if (rawQueryHasGoodsId(rawHashQ)) return rawHashQ;
  541. if (rawQueryHasGoodsId(rawSearch)) return rawSearch;
  542. return rawHashQ;
  543. }
  544. return rawHashQ || rawSearch;
  545. }
  546. /** 有商品 id 时进二手详情(已删除也由 App 处理);否则进登录页 */
  547. function getAppUniPathForShareUndefined() {
  548. if (getShareGoodsIdForAppOpen()) {
  549. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  550. /^\//,
  551. ''
  552. );
  553. }
  554. return 'pages/index/login';
  555. }
  556. function buildAppOpenQueryStringMerged() {
  557. var rawQs = getRawMergedQueryForAppOpen();
  558. if (rawQs) {
  559. return '?' + rawQs;
  560. }
  561. var params = mergeSearchAndHashParams();
  562. var gid =
  563. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  564. if (gid && !params.has('goodsId')) {
  565. params.set('goodsId', gid);
  566. }
  567. if (gid && !params.has('id')) {
  568. params.set('id', gid);
  569. }
  570. if (gid && !params.has('sourceId')) {
  571. params.set('sourceId', gid);
  572. }
  573. var sid = params.get('storeId') || '';
  574. if (sid && !params.has('storeId')) {
  575. params.set('storeId', sid);
  576. }
  577. var qsOut = params.toString();
  578. return qsOut ? ('?' + qsOut) : '';
  579. }
  580. /**
  581. * 微信 extinfo 专用 query:禁止透传整段原始 query(易超 1024 或含封面/描述等大字段导致 launch:fail)。
  582. * 与 secondShareGoods / shareDynamic 一致,仅保留 App 登录页解析所需字段。
  583. */
  584. function buildWxLaunchQueryParams() {
  585. var params = mergeSearchAndHashParams();
  586. var mini = new URLSearchParams();
  587. mini.set('goodsUnavailable', '1');
  588. var gs = params.get('goodsStatus');
  589. if (gs != null && String(gs).trim() !== '') {
  590. mini.set('goodsStatus', String(gs).trim());
  591. }
  592. var goodsId =
  593. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  594. if (goodsId) {
  595. mini.set('goodsId', String(goodsId).trim());
  596. mini.set('id', String(goodsId).trim());
  597. mini.set('sourceId', String(goodsId).trim());
  598. }
  599. var userId = params.get('userId');
  600. if (userId != null && String(userId).trim() !== '') {
  601. mini.set('userId', String(userId).trim());
  602. }
  603. var sid = params.get('storeId');
  604. if (sid != null && String(sid).trim() !== '') {
  605. mini.set('storeId', String(sid).trim());
  606. }
  607. var lon =
  608. params.get('longitude') ||
  609. params.get('lon') ||
  610. params.get('lng') ||
  611. params.get('jingdu') ||
  612. '';
  613. if (lon !== '' && !isNaN(Number(lon))) {
  614. mini.set('longitude', String(lon));
  615. }
  616. var lat =
  617. params.get('latitude') ||
  618. params.get('lat') ||
  619. params.get('weidu') ||
  620. '';
  621. if (lat !== '' && !isNaN(Number(lat))) {
  622. mini.set('latitude', String(lat));
  623. }
  624. var city = params.get('userCity') || params.get('city');
  625. if (city != null && String(city).trim() !== '') {
  626. mini.set('userCity', String(city).trim());
  627. }
  628. return mini;
  629. }
  630. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  631. function buildAppUniPageLaunchUrl() {
  632. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  633. var qs = buildWxLaunchQueryParams().toString();
  634. return qs ? path + '?' + qs : path;
  635. }
  636. /**
  637. * wx-open-launch-app extinfo:二手详情或登录页 + 精简 query(含 goodsUnavailable)
  638. */
  639. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  640. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  641. if (useBarePathOnly) return path;
  642. var mini = buildWxLaunchQueryParams();
  643. var goodsId = mini.get('goodsId') || mini.get('id') || '';
  644. if (goodsId) {
  645. mini.set('goodsId', goodsId);
  646. mini.set('id', goodsId);
  647. }
  648. var qs = mini.toString();
  649. var uniPage = qs ? path + '?' + qs : path;
  650. if (uniPage.length <= 1024) return uniPage;
  651. var shortKeys = [
  652. 'goodsUnavailable',
  653. 'goodsStatus',
  654. 'goodsId',
  655. 'id',
  656. 'sourceId',
  657. 'userId'
  658. ];
  659. var shortMini = new URLSearchParams();
  660. shortKeys.forEach(function (key) {
  661. var val = mini.get(key);
  662. if (val != null && String(val).trim() !== '') {
  663. shortMini.set(key, String(val).trim());
  664. }
  665. });
  666. var shortPage = shortMini.toString() ? path + '?' + shortMini.toString() : path;
  667. return shortPage.length <= 1024 ? shortPage : path;
  668. }
  669. /** 供 App 内嵌 WebView:uni 路由与深链一致(二手详情或登录) */
  670. function buildUniAppOpenPageUrl() {
  671. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  672. var tail = buildAppOpenQueryStringMerged();
  673. var u = '/' + path + (tail || '');
  674. var fallbackPath = getShareGoodsIdForAppOpen()
  675. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  676. : 'pages/index/login';
  677. return u.length > 1800 ? '/' + fallbackPath : 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 getWxShareEntryFrom() {
  692. var from = q('from');
  693. if (from) return String(from).trim().toLowerCase();
  694. try {
  695. var h = location.hash || '';
  696. var qi = h.indexOf('?');
  697. if (qi >= 0) {
  698. var hf = new URLSearchParams(h.slice(qi + 1)).get('from');
  699. if (hf) return String(hf).trim().toLowerCase();
  700. }
  701. } catch (eH) {}
  702. try {
  703. var sf = new URLSearchParams(location.search || '').get('from');
  704. if (sf) return String(sf).trim().toLowerCase();
  705. } catch (eS) {}
  706. return '';
  707. }
  708. function isIOSWeChatBrowser() {
  709. var ua = navigator.userAgent || '';
  710. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  711. }
  712. function logWxEntryDiagnostics() {
  713. if (!isWeChatInAppBrowser()) return;
  714. console.log('[wx-entry]', {
  715. entryFrom: getWxShareEntryFrom() || '(无)',
  716. wxJssdkReady: weChatJssdkConfigured,
  717. signUrl: getWxConfigSignUrl()
  718. });
  719. }
  720. function readQueryParam(name) {
  721. return q(name);
  722. }
  723. function isWxDebugOn() {
  724. return readQueryParam('wxDebug') === '1';
  725. }
  726. function isWxForceDebug() {
  727. return readQueryParam('wxForce') === '1';
  728. }
  729. function isWxConfigOnClickDebug() {
  730. return readQueryParam('wxConfigOnClick') === '1';
  731. }
  732. function isWxPcAutoDebugHost() {
  733. var h = (location.hostname || '').toLowerCase();
  734. if (h === 'localhost' || h === '127.0.0.1') return true;
  735. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  736. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  737. }
  738. return false;
  739. }
  740. function isWxPcBrowser() {
  741. return !isWeChatInAppBrowser();
  742. }
  743. function shouldInitWeChatJssdkOnLoad() {
  744. if (isWeChatInAppBrowser()) return true;
  745. return isWxForceDebug() || isWxPcAutoDebugHost();
  746. }
  747. function shouldFetchWxConfig(fromUserClick) {
  748. if (isWeChatInAppBrowser()) return true;
  749. if (fromUserClick) return true;
  750. return isWxForceDebug() || isWxPcAutoDebugHost();
  751. }
  752. function getWxHtmlUrl() {
  753. var forced = String(q('wxSignUrl') || '').trim();
  754. if (forced) return forced.split('#')[0];
  755. return String(location.href || '').split('#')[0];
  756. }
  757. function getWxSignPageUrlForApi() {
  758. var htmlUrl = getWxHtmlUrl();
  759. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  760. return WX_GET_CONFIG_SIGN_URL;
  761. }
  762. function getWxHtmlUrlBase() {
  763. var htmlUrl = getWxSignPageUrlForApi();
  764. try {
  765. var u = new URL(htmlUrl);
  766. return u.origin + u.pathname;
  767. } catch (eU) {
  768. return WX_GET_CONFIG_SIGN_URL;
  769. }
  770. }
  771. function getWxConfigSignUrl() {
  772. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  773. return getWxSignPageUrlForApi();
  774. }
  775. function getWxGetConfigApiUrl() {
  776. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  777. }
  778. function buildWxGetConfigRequestBody(htmlUrl) {
  779. return {
  780. url: String(htmlUrl || '').split('#')[0].trim()
  781. };
  782. }
  783. function resolveWxConfigAppIdFromSignData(d) {
  784. if (!d || typeof d !== 'object') return '';
  785. var mp =
  786. d.mpAppId ||
  787. d.mpAppid ||
  788. d.officialAppId ||
  789. d.gzhAppId ||
  790. d.serviceAppId;
  791. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  792. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  793. if (fromQuery) return fromQuery;
  794. var raw = d.appId || d.appid || d.wxAppId;
  795. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  796. }
  797. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  798. if (!res || typeof res !== 'object') return null;
  799. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  800. if (!d || typeof d !== 'object') return null;
  801. var appId = resolveWxConfigAppIdFromSignData(d);
  802. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  803. var nonceStr =
  804. d.nonceStr != null && String(d.nonceStr) !== ''
  805. ? d.nonceStr
  806. : d.noncestr != null && String(d.noncestr) !== ''
  807. ? d.noncestr
  808. : d.nonce;
  809. var signature = d.signature || d.sign;
  810. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  811. return null;
  812. }
  813. return {
  814. appId: String(appId),
  815. timestamp: Number(timestamp),
  816. nonceStr: String(nonceStr),
  817. signature: String(signature),
  818. signUrl: String(signUrlUsed || '')
  819. .split('#')[0]
  820. .trim()
  821. };
  822. }
  823. function getWxErrMsg(err) {
  824. if (!err) return '';
  825. if (err.errMsg) return String(err.errMsg);
  826. if (typeof err === 'string') return err;
  827. try {
  828. return JSON.stringify(err);
  829. } catch (e) {
  830. return String(err);
  831. }
  832. }
  833. function formatWxConfigErrorTip(err, signPageUrl) {
  834. var errMsg = getWxErrMsg(err);
  835. var tip = '微信 JSSDK 配置失败';
  836. if (/invalid signature/i.test(errMsg)) {
  837. return (
  838. tip +
  839. ':签名无效。请核对:①后端用与前端相同的 url 签名;②url=' +
  840. (signPageUrl || getWxHtmlUrl()) +
  841. ';③nonceStr/timestamp 与接口返回一致;④appId=' +
  842. WECHAT_MP_APP_ID
  843. );
  844. }
  845. if (/require\s*subscribe/i.test(errMsg)) {
  846. return tip + ':' + errMsg + '(服务号需用户已关注)';
  847. }
  848. return errMsg ? tip + ':' + errMsg : tip;
  849. }
  850. function setWxInitError(msg) {
  851. wxInitLastError = String(msg || '').trim();
  852. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  853. }
  854. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  855. var htmlUrl = String(
  856. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  857. )
  858. .split('#')[0]
  859. .trim();
  860. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  861. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  862. }
  863. if (isWxDebugOn()) {
  864. try {
  865. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  866. } catch (eDbg) {}
  867. }
  868. var requestUrl = getWxGetConfigApiUrl();
  869. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  870. console.log('[wx] htmlUrl=', htmlUrl);
  871. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  872. return fetch(requestUrl, {
  873. method: 'POST',
  874. mode: 'cors',
  875. credentials: 'omit',
  876. headers: {
  877. Accept: 'application/json',
  878. 'Content-Type': 'application/json;charset=UTF-8'
  879. },
  880. body: JSON.stringify(requestBody)
  881. })
  882. .then(function (r) {
  883. if (r.ok) return r.json();
  884. return r
  885. .text()
  886. .catch(function () {
  887. return '';
  888. })
  889. .then(function (text) {
  890. var hint = '';
  891. try {
  892. var j = JSON.parse(text);
  893. hint = j.msg || j.message || '';
  894. } catch (eP) {
  895. if (text) hint = text.slice(0, 120);
  896. }
  897. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  898. });
  899. })
  900. .then(function (res) {
  901. if (res && res.code != null) {
  902. var c = Number(res.code);
  903. if (c !== 200 && c !== 0 && res.success !== true) {
  904. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  905. }
  906. }
  907. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  908. if (!sign) {
  909. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  910. throw new Error(
  911. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  912. );
  913. }
  914. if (sign.appId !== WECHAT_MP_APP_ID) {
  915. console.warn(
  916. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  917. );
  918. }
  919. if (typeof wx === 'undefined') {
  920. if (isWxPcBrowser()) {
  921. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  922. return true;
  923. }
  924. setWxInitError('jweixin.js 未加载');
  925. return false;
  926. }
  927. return applyWxConfigFromSign(sign, htmlUrl);
  928. });
  929. }
  930. function applyWxConfigFromSign(sign, htmlUrl) {
  931. var wxConfigParams = {
  932. debug: isWxDebugOn(),
  933. appId: String(sign.appId),
  934. timestamp: sign.timestamp,
  935. nonceStr: String(sign.nonceStr),
  936. signature: String(sign.signature),
  937. jsApiList: [],
  938. openTagList: ['wx-open-launch-app']
  939. };
  940. return new Promise(function (resolve) {
  941. wx.config(wxConfigParams);
  942. wx.ready(function () {
  943. weChatJssdkConfigured = true;
  944. document.body.classList.add('wx-jssdk-ready');
  945. refreshWxLaunchTagAttrs(false);
  946. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  947. resolve(true);
  948. });
  949. wx.error(function (err) {
  950. weChatJssdkConfigured = false;
  951. document.body.classList.remove('wx-jssdk-ready');
  952. wxJssdkInitPromise = null;
  953. var errMsg = getWxErrMsg(err);
  954. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  955. if (isWxDebugOn()) window.alert(wxInitLastError);
  956. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  957. var baseUrl = getWxHtmlUrlBase();
  958. var fullUrl = getWxSignPageUrlForApi();
  959. if (
  960. !/invalid signature/i.test(errMsg) ||
  961. wxConfigSignRetriedBaseUrl ||
  962. baseUrl === fullUrl ||
  963. htmlUrl === baseUrl
  964. ) {
  965. resolve(false);
  966. return;
  967. }
  968. wxConfigSignRetriedBaseUrl = true;
  969. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  970. });
  971. });
  972. }
  973. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  974. var tag = document.getElementById('launch-btn');
  975. if (!tag) return;
  976. try {
  977. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  978. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo(!!useBarePathOnly));
  979. console.log('[wx-open-launch-app] extinfo=', tag.getAttribute('extinfo'));
  980. } catch (eA) {}
  981. }
  982. function bindWeChatLaunchTagEvents() {
  983. var tag = document.getElementById('launch-btn');
  984. if (!tag || tag._wxLaunchBound) return;
  985. tag._wxLaunchBound = true;
  986. tag._wxLaunchBareRetried = false;
  987. refreshWxLaunchTagAttrs(false);
  988. tag.addEventListener('launch', function () {
  989. if (tag._launchTapTimer) {
  990. clearTimeout(tag._launchTapTimer);
  991. tag._launchTapTimer = null;
  992. }
  993. tag._wxLaunchBareRetried = false;
  994. console.log('[wx-open-launch-app] launch ok');
  995. // showFabToast('正在打开 U店在哪…');
  996. });
  997. tag.addEventListener('click', function () {
  998. if (!weChatJssdkConfigured) return;
  999. if (tag._launchTapTimer) clearTimeout(tag._launchTapTimer);
  1000. tag._launchTapTimer = setTimeout(function () {
  1001. tag._launchTapTimer = null;
  1002. // if (!tag._wxLaunchBareRetried) {
  1003. // showFabToast('正在唤起 App,请稍候…');
  1004. // }
  1005. }, 600);
  1006. });
  1007. tag.addEventListener('error', function (e) {
  1008. var detail = e && e.detail;
  1009. var errMsg =
  1010. detail && detail.errMsg
  1011. ? String(detail.errMsg)
  1012. : detail && detail.errmsg
  1013. ? String(detail.errmsg)
  1014. : '';
  1015. console.warn('[wx-open-launch-app]', detail, 'extinfo=', tag.getAttribute('extinfo'));
  1016. if (/launch:fail_check/i.test(errMsg)) {
  1017. showAppOpenFailTip(
  1018. '请用微信分享卡片进入,或确认已安装最新版「U店在哪」'
  1019. );
  1020. return;
  1021. }
  1022. if (
  1023. /launch:fail/i.test(errMsg) &&
  1024. !tag._wxLaunchBareRetried &&
  1025. tag.getAttribute('extinfo') !== buildWeChatLaunchExtinfo(true)
  1026. ) {
  1027. tag._wxLaunchBareRetried = true;
  1028. refreshWxLaunchTagAttrs(true);
  1029. showFabToast('请再点一次「APP内打开」');
  1030. return;
  1031. }
  1032. showAppOpenFailTip(
  1033. errMsg
  1034. ? '未能打开 App:' + errMsg
  1035. : '未能打开 App,请确认已安装最新版「U店在哪」'
  1036. );
  1037. });
  1038. }
  1039. function initWeChatOpenLaunchApp(fromUserClick) {
  1040. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1041. console.log('[wx] 未调用 getWxConfig');
  1042. return Promise.resolve(false);
  1043. }
  1044. if (isWxPcBrowser()) {
  1045. console.warn(
  1046. '[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
  1047. );
  1048. }
  1049. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1050. wxConfigSignRetriedBaseUrl = false;
  1051. wxInitLastError = '';
  1052. var htmlUrl = getWxConfigSignUrl();
  1053. bindWeChatLaunchTagEvents();
  1054. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1055. .then(function (ok) {
  1056. if (ok === true) return true;
  1057. if (!wxInitLastError) {
  1058. setWxInitError('wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl');
  1059. }
  1060. return false;
  1061. })
  1062. .catch(function (e) {
  1063. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  1064. setWxInitError(msg);
  1065. console.warn('[wx] requestWeChatJssdkSignAndConfig failed', msg, 'htmlUrl=', htmlUrl);
  1066. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1067. return false;
  1068. })
  1069. .finally(function () {
  1070. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1071. });
  1072. return wxJssdkInitPromise;
  1073. }
  1074. /** 进页即尝试拉签名;jweixin 晚到时自动重试 */
  1075. function scheduleWeChatJssdkBootstrap() {
  1076. if (!shouldInitWeChatJssdkOnLoad()) return;
  1077. var attempts = 0;
  1078. function tick() {
  1079. if (weChatJssdkConfigured) return;
  1080. attempts += 1;
  1081. var pending = initWeChatOpenLaunchApp();
  1082. if (pending && typeof pending.then === 'function') {
  1083. pending.then(function () {
  1084. if (!weChatJssdkConfigured && attempts < 10) {
  1085. setTimeout(tick, 500);
  1086. }
  1087. });
  1088. }
  1089. if (!weChatJssdkConfigured && attempts < 10 && typeof wx === 'undefined') {
  1090. setTimeout(tick, 400);
  1091. }
  1092. }
  1093. if (isIOSWeChatBrowser()) {
  1094. setTimeout(tick, 350);
  1095. } else {
  1096. tick();
  1097. }
  1098. }
  1099. function showFabToast(msg, ms) {
  1100. var tip = String(msg || '').trim();
  1101. if (!tip) return;
  1102. var el = document.getElementById('openAppToast');
  1103. if (el) {
  1104. el.textContent = tip;
  1105. el.style.display = 'block';
  1106. if (showFabToast._t) clearTimeout(showFabToast._t);
  1107. showFabToast._t = setTimeout(function () {
  1108. el.style.display = 'none';
  1109. }, ms || 2800);
  1110. }
  1111. console.log('[openApp]', tip);
  1112. }
  1113. function showAppOpenFailTip(msg) {
  1114. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  1115. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  1116. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  1117. } else if (isWeChatInAppBrowser()) {
  1118. window.alert(tip);
  1119. } else {
  1120. console.warn('[openApp]', tip);
  1121. }
  1122. }
  1123. function tryFetchWxConfigOnPcClick() {
  1124. if (!isWxPcBrowser()) return Promise.resolve(false);
  1125. showFabToast('正在请求 getWxConfig…');
  1126. wxJssdkInitPromise = null;
  1127. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1128. if (ok) {
  1129. showFabToast(
  1130. weChatJssdkConfigured
  1131. ? 'getWxConfig 成功,wx.config 已就绪'
  1132. : 'getWxConfig 成功'
  1133. );
  1134. } else {
  1135. showFabToast(wxInitLastError || 'getWxConfig 失败');
  1136. }
  1137. return ok;
  1138. });
  1139. }
  1140. function launchAppDeepLink(deepLink) {
  1141. try {
  1142. var a = document.createElement('a');
  1143. a.href = deepLink;
  1144. a.setAttribute('target', '_self');
  1145. document.body.appendChild(a);
  1146. a.click();
  1147. document.body.removeChild(a);
  1148. } catch (e1) {}
  1149. try {
  1150. window.location.href = deepLink;
  1151. } catch (e2) {}
  1152. }
  1153. function tryOpenUShopApp() {
  1154. /* 微信内须直接点击 wx-open-launch-app,scheme 会被拦截 */
  1155. if (isWeChatInAppBrowser()) return;
  1156. tryFetchWxConfigOnPcClick().then(function () {
  1157. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1158. return;
  1159. }
  1160. tryOpenUShopAppViaScheme();
  1161. });
  1162. }
  1163. function tryOpenUShopAppViaScheme() {
  1164. function openBySchemeOrPlus() {
  1165. // showFabToast('正在打开 U店在哪…');
  1166. var deepLink = buildAppDeepLink();
  1167. if (typeof plus !== 'undefined' && plus.runtime) {
  1168. var installed = null;
  1169. try {
  1170. if (typeof plus.runtime.isApplicationExist === 'function') {
  1171. installed = plus.runtime.isApplicationExist({
  1172. pname: APP_ANDROID_PACKAGE,
  1173. action: APP_IOS_URL_SCHEME
  1174. });
  1175. }
  1176. } catch (e) {
  1177. console.warn(e);
  1178. }
  1179. if (installed === false) {
  1180. showDownloadTip();
  1181. return;
  1182. }
  1183. try {
  1184. plus.runtime.openURL(deepLink);
  1185. } catch (e2) {
  1186. console.warn(e2);
  1187. showDownloadTip();
  1188. }
  1189. return;
  1190. }
  1191. var done = false;
  1192. function finish() {
  1193. if (done) return;
  1194. done = true;
  1195. document.removeEventListener('visibilitychange', onVis);
  1196. window.removeEventListener('pagehide', onHide);
  1197. }
  1198. function onVis() {
  1199. if (document.visibilityState === 'hidden') finish();
  1200. }
  1201. function onHide() {
  1202. finish();
  1203. }
  1204. document.addEventListener('visibilitychange', onVis);
  1205. window.addEventListener('pagehide', onHide);
  1206. try {
  1207. launchAppDeepLink(deepLink);
  1208. } catch (e3) {
  1209. finish();
  1210. showDownloadTip();
  1211. return;
  1212. }
  1213. window.setTimeout(function () {
  1214. finish();
  1215. }, 2600);
  1216. }
  1217. if (typeof uni !== 'undefined' && typeof uni.navigateTo === 'function') {
  1218. var uniUrl = buildUniAppOpenPageUrl();
  1219. var uniFallback =
  1220. '/' +
  1221. (getShareGoodsIdForAppOpen()
  1222. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  1223. : 'pages/index/login');
  1224. try {
  1225. uni.navigateTo({
  1226. url: uniUrl,
  1227. fail: function () {
  1228. if (typeof uni.reLaunch === 'function') {
  1229. try {
  1230. uni.reLaunch({
  1231. url: uniUrl.length > 1800 ? uniFallback : uniUrl,
  1232. fail: function () {
  1233. openBySchemeOrPlus();
  1234. }
  1235. });
  1236. return;
  1237. } catch (eRl) {}
  1238. }
  1239. openBySchemeOrPlus();
  1240. }
  1241. });
  1242. return;
  1243. } catch (eUni) {
  1244. openBySchemeOrPlus();
  1245. return;
  1246. }
  1247. }
  1248. openBySchemeOrPlus();
  1249. }
  1250. function showErr(msg) {
  1251. var el = document.getElementById('pageError');
  1252. el.textContent = msg;
  1253. el.style.display = 'block';
  1254. }
  1255. function getStoreId() {
  1256. return q('id') || q('storeId');
  1257. }
  1258. function apiFetch(path) {
  1259. return fetch(API_BASE + path, {
  1260. method: 'GET',
  1261. mode: 'cors',
  1262. credentials: 'omit',
  1263. headers: { Accept: 'application/json' }
  1264. }).then(function (res) {
  1265. if (!res.ok) throw new Error('HTTP ' + res.status);
  1266. return res.json();
  1267. });
  1268. }
  1269. function isApiOk(res) {
  1270. if (!res || typeof res !== 'object') return false;
  1271. if (res.success === false) return false;
  1272. var c = res.code;
  1273. return c === 200 || c === '200' || Number(c) === 200;
  1274. }
  1275. function buildHeroSlides(urls) {
  1276. var track = document.getElementById('heroTrack');
  1277. var dotsWrap = document.getElementById('heroDots');
  1278. track.innerHTML = '';
  1279. dotsWrap.innerHTML = '';
  1280. var list = (urls || []).filter(Boolean);
  1281. if (!list.length) {
  1282. var slide = document.createElement('div');
  1283. slide.className = 'hero__slide';
  1284. var img = document.createElement('img');
  1285. img.src = 'images/hero.png';
  1286. img.alt = '店铺';
  1287. slide.appendChild(img);
  1288. track.appendChild(slide);
  1289. var dot = document.createElement('span');
  1290. dot.className = 'hero__dot is-active';
  1291. dotsWrap.appendChild(dot);
  1292. return initHeroCarousel(1);
  1293. }
  1294. list.forEach(function (url, d) {
  1295. var slide = document.createElement('div');
  1296. slide.className = 'hero__slide';
  1297. var img = document.createElement('img');
  1298. img.src = url;
  1299. img.alt = '店铺图';
  1300. slide.appendChild(img);
  1301. track.appendChild(slide);
  1302. var dot = document.createElement('span');
  1303. dot.className = 'hero__dot' + (d === 0 ? ' is-active' : '');
  1304. dotsWrap.appendChild(dot);
  1305. });
  1306. initHeroCarousel(list.length);
  1307. }
  1308. var heroI = 0;
  1309. var heroTimer = null;
  1310. function initHeroCarousel(slides) {
  1311. var track = document.getElementById('heroTrack');
  1312. var dotsWrap = document.getElementById('heroDots');
  1313. var dots = dotsWrap.querySelectorAll('.hero__dot');
  1314. if (slides < 2) return;
  1315. function go(n) {
  1316. heroI = (n + slides) % slides;
  1317. track.style.transform = 'translateX(' + (-heroI * 100) + '%)';
  1318. dots.forEach(function (el, idx) {
  1319. el.classList.toggle('is-active', idx === heroI);
  1320. });
  1321. }
  1322. if (heroTimer) clearInterval(heroTimer);
  1323. heroTimer = setInterval(function () { go(heroI + 1); }, 4000);
  1324. var hero = document.getElementById('hero');
  1325. var startX = 0;
  1326. hero.addEventListener('touchstart', function (e) {
  1327. startX = e.changedTouches[0].clientX;
  1328. }, { passive: true });
  1329. hero.addEventListener('touchend', function (e) {
  1330. var dx = e.changedTouches[0].clientX - startX;
  1331. if (Math.abs(dx) > 40) go(dx < 0 ? heroI + 1 : heroI - 1);
  1332. }, { passive: true });
  1333. }
  1334. function timeToMinutes(t) {
  1335. var parts = String(t || '').trim().split(':');
  1336. var h = parseInt(parts[0], 10) || 0;
  1337. var m = parseInt(parts[1], 10) || 0;
  1338. return h * 60 + m;
  1339. }
  1340. function isTimeInRange(startTime, endTime) {
  1341. var s = String(startTime || '').trim();
  1342. var e = String(endTime || '').trim();
  1343. if (s === '00:00' && e === '00:00') return true;
  1344. if (s === '00:00' && e === '23:59') return true;
  1345. var cur = new Date().getHours() * 60 + new Date().getMinutes();
  1346. var sm = timeToMinutes(s);
  1347. var em = timeToMinutes(e);
  1348. if (em < sm) {
  1349. return cur >= sm || cur <= em;
  1350. }
  1351. return cur >= sm && cur <= em;
  1352. }
  1353. function parseHolidayDate(str) {
  1354. if (!str) return null;
  1355. var d = new Date(String(str).trim().replace(/-/g, '/'));
  1356. return isNaN(d.getTime()) ? null : d;
  1357. }
  1358. function isTodayInHolidayRange(holidayInfo) {
  1359. if (!holidayInfo) return false;
  1360. var hi = holidayInfo;
  1361. if (typeof hi === 'string') {
  1362. try {
  1363. hi = JSON.parse(hi);
  1364. } catch (err) {
  1365. return false;
  1366. }
  1367. }
  1368. var start = hi.startDate || hi.holidayStartDate || hi.beginDate || hi.start || hi.holidayStart;
  1369. var end = hi.endDate || hi.holidayEndDate || hi.finishDate || hi.end || hi.holidayEnd;
  1370. if (!start || !end) return false;
  1371. var startD = parseHolidayDate(start);
  1372. var endD = parseHolidayDate(end);
  1373. if (!startD || !endD) return false;
  1374. var today = new Date();
  1375. today.setHours(0, 0, 0, 0);
  1376. startD.setHours(0, 0, 0, 0);
  1377. endD.setHours(0, 0, 0, 0);
  1378. return today >= startD && today <= endD;
  1379. }
  1380. function findNormalBusinessInfo(list) {
  1381. var wdJs = new Date().getDay();
  1382. var i;
  1383. var x;
  1384. var w;
  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) === wdJs) return x;
  1391. }
  1392. var wdMap = wdJs === 0 ? 7 : wdJs;
  1393. for (i = 0; i < list.length; i++) {
  1394. x = list[i];
  1395. if (!x || x.holidayInfo) continue;
  1396. w = x.weekDay != null ? x.weekDay : x.week;
  1397. if (w === undefined || w === null) continue;
  1398. if (Number(w) === wdMap) return x;
  1399. }
  1400. for (i = 0; i < list.length; i++) {
  1401. x = list[i];
  1402. if (x && !x.holidayInfo && (x.startTime || x.endTime)) return x;
  1403. }
  1404. return null;
  1405. }
  1406. /** 营业状态:暂停营业 | 商家暂未配置营业时间 | 休息中 | 营业中 xx:xx至xx:xx | 营业中 全天营业 */
  1407. function computeBusinessStatusDisplay(d) {
  1408. if (!d) return { text: '—', isOpen: false };
  1409. if (Number(d.businessStatus) === 1) {
  1410. return { text: '暂停营业', isOpen: false };
  1411. }
  1412. var list = d.storeBusinessInfoVos || d.storeBusinessInfos || [];
  1413. if (!list.length) {
  1414. return { text: '商家暂未配置营业时间', isOpen: false };
  1415. }
  1416. var holidayList = Array.isArray(d.holidayBusinessInfoList) && d.holidayBusinessInfoList.length
  1417. ? d.holidayBusinessInfoList
  1418. : list.filter(function (item) { return item && item.holidayInfo; });
  1419. var todayHolidayItem = holidayList.find(function (item) {
  1420. return isTodayInHolidayRange(item.holidayInfo);
  1421. });
  1422. var normal = d.normalBusinessInfo || d.normalBusinessInfoVo || findNormalBusinessInfo(list);
  1423. var isOpen = false;
  1424. var currentItem = null;
  1425. if (todayHolidayItem) {
  1426. isOpen = isTimeInRange(todayHolidayItem.startTime, todayHolidayItem.endTime);
  1427. currentItem = todayHolidayItem;
  1428. } else if (normal) {
  1429. isOpen = isTimeInRange(normal.startTime, normal.endTime);
  1430. currentItem = normal;
  1431. }
  1432. if (!currentItem) return { text: '休息中', isOpen: false };
  1433. if (!isOpen) return { text: '休息中', isOpen: false };
  1434. var st = String(currentItem.startTime || '').trim();
  1435. var et = String(currentItem.endTime || '').trim();
  1436. if (st === '00:00' && et === '00:00') return { text: '营业中 全天营业', isOpen: true };
  1437. if (st === '00:00' && et === '23:59') return { text: '营业中 全天营业', isOpen: true };
  1438. var needNextDay = timeToMinutes(et) < timeToMinutes(st);
  1439. var suffix = (needNextDay ? '次日' : '') + et;
  1440. return { text: ('营业中 ' + st + ' 至 ' + suffix).trim(), isOpen: true };
  1441. }
  1442. function renderDetail(d) {
  1443. if (!d) return;
  1444. document.getElementById('storeName').textContent = d.storeName || '—';
  1445. var score = d.scoreAvg != null ? Number(d.scoreAvg) : NaN;
  1446. document.getElementById('scoreAvg').textContent = !isNaN(score) ? score.toFixed(1) : '—';
  1447. document.getElementById('commitCount').textContent = d.commitCount != null ? String(d.commitCount) : '0';
  1448. var bizDisp = computeBusinessStatusDisplay(d);
  1449. var bizEl = document.getElementById('bizStatus');
  1450. bizEl.textContent = bizDisp.text;
  1451. bizEl.className = 'status' + (bizDisp.isOpen ? ' is-open' : '');
  1452. document.getElementById('hoursText').textContent = '';
  1453. document.getElementById('storeAddr').textContent = d.queryAddress || d.storeAddress || '—';
  1454. if (d.distance != null) {
  1455. document.getElementById('metaDistance').style.display = 'flex';
  1456. document.getElementById('distanceText').textContent =
  1457. '距您' + (Number(d.distance) > 1 ? d.distance + '千米' : Math.round(Number(d.distance) * 1000) + '米');
  1458. }
  1459. if (d.subwayName && d.distance2 != null) {
  1460. document.getElementById('metaSubway').style.display = 'flex';
  1461. document.getElementById('subwayText').textContent =
  1462. '距' + d.subwayName + '步行' + (Number(d.distance2) >= 1000
  1463. ? (Number(d.distance2) / 1000).toFixed(1) + 'km'
  1464. : Math.round(Number(d.distance2)) + 'm');
  1465. }
  1466. var imgs = [];
  1467. if (Array.isArray(d.storeAlbumUrlList) && d.storeAlbumUrlList.length) imgs = d.storeAlbumUrlList.slice();
  1468. else if (d.entranceImage) imgs = [d.entranceImage];
  1469. buildHeroSlides(imgs);
  1470. }
  1471. function boot() {
  1472. var launchTag = document.getElementById('launch-btn');
  1473. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1474. bindWeChatLaunchTagEvents();
  1475. if (isWeChatInAppBrowser()) {
  1476. document.body.classList.add('is-wechat');
  1477. logWxEntryDiagnostics();
  1478. }
  1479. if (shouldInitWeChatJssdkOnLoad()) {
  1480. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1481. document.body.classList.add('wx-pc-debug');
  1482. }
  1483. scheduleWeChatJssdkBootstrap();
  1484. }
  1485. document.addEventListener('WeixinOpenTagsError', function (e) {
  1486. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1487. var d = e && e.detail;
  1488. var em =
  1489. d && d.errMsg
  1490. ? String(d.errMsg)
  1491. : d && d.errmsg
  1492. ? String(d.errmsg)
  1493. : '';
  1494. showFabToast(em || '微信开放标签不可用,请升级微信后重试');
  1495. });
  1496. if (isWeChatInAppBrowser()) {
  1497. var openBtnWx = document.getElementById('openApp');
  1498. if (openBtnWx) {
  1499. openBtnWx.addEventListener('click', function () {
  1500. if (!weChatJssdkConfigured) {
  1501. showFabToast(
  1502. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1503. );
  1504. initWeChatOpenLaunchApp(true);
  1505. }
  1506. });
  1507. }
  1508. } else {
  1509. var openBtn = document.getElementById('openApp');
  1510. if (openBtn) {
  1511. openBtn.addEventListener('click', tryOpenUShopApp);
  1512. }
  1513. }
  1514. }
  1515. if (document.readyState === 'complete') {
  1516. boot();
  1517. } else {
  1518. window.onload = boot;
  1519. }
  1520. })();
  1521. </script>
  1522. </body>
  1523. </html>