shareUndefined.html 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  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_DOWNLOAD_URL = 'https://a.app.qq.com/o/simple.jsp?pkgname=com.alien.Udianzaina';
  487. var APP_IOS_URL_SCHEME = 'shopro://';
  488. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  489. function showDownloadTip() {
  490. window.location.href = APP_DOWNLOAD_URL;
  491. }
  492. function mergeSearchAndHashParams() {
  493. var params = new URLSearchParams();
  494. function ingestAppend(querySlice) {
  495. if (!querySlice) return;
  496. var p = new URLSearchParams(querySlice);
  497. p.forEach(function (val, key) {
  498. params.append(key, val);
  499. });
  500. }
  501. function ingestSet(querySlice) {
  502. if (!querySlice) return;
  503. var p = new URLSearchParams(querySlice);
  504. p.forEach(function (val, key) {
  505. params.set(key, val);
  506. });
  507. }
  508. if (location.search && location.search.length > 1) {
  509. ingestAppend(location.search.slice(1));
  510. }
  511. var hash = location.hash || '';
  512. var qi = hash.indexOf('?');
  513. if (qi >= 0) {
  514. ingestSet(hash.slice(qi + 1));
  515. }
  516. return params;
  517. }
  518. function q(name) {
  519. var v = mergeSearchAndHashParams().get(name);
  520. return v == null ? '' : String(v);
  521. }
  522. function rawQueryHasGoodsId(qs) {
  523. return /(?:^|&)(goodsId|id|sourceId)=/i.test('&' + String(qs || '') + '&');
  524. }
  525. function getShareGoodsIdForAppOpen() {
  526. return (q('goodsId') || q('id') || q('sourceId') || '').trim();
  527. }
  528. function getRawMergedQueryForAppOpen() {
  529. var rawSearch =
  530. location.search && location.search.length > 1 ? location.search.slice(1) : '';
  531. var hash0 = location.hash || '';
  532. var hqi0 = hash0.indexOf('?');
  533. var rawHashQ = hqi0 >= 0 ? hash0.slice(hqi0 + 1) : '';
  534. if (!rawSearch && !rawHashQ) return '';
  535. if (rawHashQ && rawSearch) {
  536. if (rawQueryHasGoodsId(rawHashQ)) return rawHashQ;
  537. if (rawQueryHasGoodsId(rawSearch)) return rawSearch;
  538. return rawHashQ;
  539. }
  540. return rawHashQ || rawSearch;
  541. }
  542. /** 有商品 id 时进二手详情(已删除也由 App 处理);否则进登录页 */
  543. function getAppUniPathForShareUndefined() {
  544. if (getShareGoodsIdForAppOpen()) {
  545. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  546. /^\//,
  547. ''
  548. );
  549. }
  550. return 'pages/index/login';
  551. }
  552. function buildAppOpenQueryStringMerged() {
  553. var rawQs = getRawMergedQueryForAppOpen();
  554. if (rawQs) {
  555. return '?' + rawQs;
  556. }
  557. var params = mergeSearchAndHashParams();
  558. var gid =
  559. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  560. if (gid && !params.has('goodsId')) {
  561. params.set('goodsId', gid);
  562. }
  563. if (gid && !params.has('id')) {
  564. params.set('id', gid);
  565. }
  566. if (gid && !params.has('sourceId')) {
  567. params.set('sourceId', gid);
  568. }
  569. var sid = params.get('storeId') || '';
  570. if (sid && !params.has('storeId')) {
  571. params.set('storeId', sid);
  572. }
  573. var qsOut = params.toString();
  574. return qsOut ? ('?' + qsOut) : '';
  575. }
  576. /**
  577. * 微信 extinfo 专用 query:禁止透传整段原始 query(易超 1024 或含封面/描述等大字段导致 launch:fail)。
  578. * 与 secondShareGoods / shareDynamic 一致,仅保留 App 登录页解析所需字段。
  579. */
  580. function buildWxLaunchQueryParams() {
  581. var params = mergeSearchAndHashParams();
  582. var mini = new URLSearchParams();
  583. mini.set('goodsUnavailable', '1');
  584. var gs = params.get('goodsStatus');
  585. if (gs != null && String(gs).trim() !== '') {
  586. mini.set('goodsStatus', String(gs).trim());
  587. }
  588. var goodsId =
  589. params.get('goodsId') || params.get('id') || params.get('sourceId') || '';
  590. if (goodsId) {
  591. mini.set('goodsId', String(goodsId).trim());
  592. mini.set('id', String(goodsId).trim());
  593. mini.set('sourceId', String(goodsId).trim());
  594. }
  595. var userId = params.get('userId');
  596. if (userId != null && String(userId).trim() !== '') {
  597. mini.set('userId', String(userId).trim());
  598. }
  599. var sid = params.get('storeId');
  600. if (sid != null && String(sid).trim() !== '') {
  601. mini.set('storeId', String(sid).trim());
  602. }
  603. var lon =
  604. params.get('longitude') ||
  605. params.get('lon') ||
  606. params.get('lng') ||
  607. params.get('jingdu') ||
  608. '';
  609. if (lon !== '' && !isNaN(Number(lon))) {
  610. mini.set('longitude', String(lon));
  611. }
  612. var lat =
  613. params.get('latitude') ||
  614. params.get('lat') ||
  615. params.get('weidu') ||
  616. '';
  617. if (lat !== '' && !isNaN(Number(lat))) {
  618. mini.set('latitude', String(lat));
  619. }
  620. var city = params.get('userCity') || params.get('city');
  621. if (city != null && String(city).trim() !== '') {
  622. mini.set('userCity', String(city).trim());
  623. }
  624. return mini;
  625. }
  626. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  627. function buildAppUniPageLaunchUrl() {
  628. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  629. var qs = buildWxLaunchQueryParams().toString();
  630. return qs ? path + '?' + qs : path;
  631. }
  632. /**
  633. * wx-open-launch-app extinfo:二手详情或登录页 + 精简 query(含 goodsUnavailable)
  634. */
  635. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  636. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  637. if (useBarePathOnly) return path;
  638. var mini = buildWxLaunchQueryParams();
  639. var goodsId = mini.get('goodsId') || mini.get('id') || '';
  640. if (goodsId) {
  641. mini.set('goodsId', goodsId);
  642. mini.set('id', goodsId);
  643. }
  644. var qs = mini.toString();
  645. var uniPage = qs ? path + '?' + qs : path;
  646. if (uniPage.length <= 1024) return uniPage;
  647. var shortKeys = [
  648. 'goodsUnavailable',
  649. 'goodsStatus',
  650. 'goodsId',
  651. 'id',
  652. 'sourceId',
  653. 'userId'
  654. ];
  655. var shortMini = new URLSearchParams();
  656. shortKeys.forEach(function (key) {
  657. var val = mini.get(key);
  658. if (val != null && String(val).trim() !== '') {
  659. shortMini.set(key, String(val).trim());
  660. }
  661. });
  662. var shortPage = shortMini.toString() ? path + '?' + shortMini.toString() : path;
  663. return shortPage.length <= 1024 ? shortPage : path;
  664. }
  665. /** 供 App 内嵌 WebView:uni 路由与深链一致(二手详情或登录) */
  666. function buildUniAppOpenPageUrl() {
  667. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  668. var tail = buildAppOpenQueryStringMerged();
  669. var u = '/' + path + (tail || '');
  670. var fallbackPath = getShareGoodsIdForAppOpen()
  671. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  672. : 'pages/index/login';
  673. return u.length > 1800 ? '/' + fallbackPath : u;
  674. }
  675. function buildAppDeepLink() {
  676. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  677. var s = buildAppOpenQueryStringMerged();
  678. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  679. if (!s) {
  680. return root + '/' + path;
  681. }
  682. return root + '/' + path + s;
  683. }
  684. function isWeChatInAppBrowser() {
  685. return /MicroMessenger/i.test(navigator.userAgent || '');
  686. }
  687. function getWxShareEntryFrom() {
  688. var from = q('from');
  689. if (from) return String(from).trim().toLowerCase();
  690. try {
  691. var h = location.hash || '';
  692. var qi = h.indexOf('?');
  693. if (qi >= 0) {
  694. var hf = new URLSearchParams(h.slice(qi + 1)).get('from');
  695. if (hf) return String(hf).trim().toLowerCase();
  696. }
  697. } catch (eH) {}
  698. try {
  699. var sf = new URLSearchParams(location.search || '').get('from');
  700. if (sf) return String(sf).trim().toLowerCase();
  701. } catch (eS) {}
  702. return '';
  703. }
  704. function isIOSWeChatBrowser() {
  705. var ua = navigator.userAgent || '';
  706. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  707. }
  708. function logWxEntryDiagnostics() {
  709. if (!isWeChatInAppBrowser()) return;
  710. console.log('[wx-entry]', {
  711. entryFrom: getWxShareEntryFrom() || '(无)',
  712. wxJssdkReady: weChatJssdkConfigured,
  713. signUrl: getWxConfigSignUrl()
  714. });
  715. }
  716. function readQueryParam(name) {
  717. return q(name);
  718. }
  719. function isWxDebugOn() {
  720. return readQueryParam('wxDebug') === '1';
  721. }
  722. function isWxForceDebug() {
  723. return readQueryParam('wxForce') === '1';
  724. }
  725. function isWxConfigOnClickDebug() {
  726. return readQueryParam('wxConfigOnClick') === '1';
  727. }
  728. function isWxPcAutoDebugHost() {
  729. var h = (location.hostname || '').toLowerCase();
  730. if (h === 'localhost' || h === '127.0.0.1') return true;
  731. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  732. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  733. }
  734. return false;
  735. }
  736. function isWxPcBrowser() {
  737. return !isWeChatInAppBrowser();
  738. }
  739. function shouldInitWeChatJssdkOnLoad() {
  740. if (isWeChatInAppBrowser()) return true;
  741. return isWxForceDebug() || isWxPcAutoDebugHost();
  742. }
  743. function shouldFetchWxConfig(fromUserClick) {
  744. if (isWeChatInAppBrowser()) return true;
  745. if (fromUserClick) return true;
  746. return isWxForceDebug() || isWxPcAutoDebugHost();
  747. }
  748. function getWxHtmlUrl() {
  749. var forced = String(q('wxSignUrl') || '').trim();
  750. if (forced) return forced.split('#')[0];
  751. return String(location.href || '').split('#')[0];
  752. }
  753. function getWxSignPageUrlForApi() {
  754. var htmlUrl = getWxHtmlUrl();
  755. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  756. return WX_GET_CONFIG_SIGN_URL;
  757. }
  758. function getWxHtmlUrlBase() {
  759. var htmlUrl = getWxSignPageUrlForApi();
  760. try {
  761. var u = new URL(htmlUrl);
  762. return u.origin + u.pathname;
  763. } catch (eU) {
  764. return WX_GET_CONFIG_SIGN_URL;
  765. }
  766. }
  767. function getWxConfigSignUrl() {
  768. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  769. return getWxSignPageUrlForApi();
  770. }
  771. function getWxGetConfigApiUrl() {
  772. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  773. }
  774. function buildWxGetConfigRequestBody(htmlUrl) {
  775. return {
  776. url: String(htmlUrl || '').split('#')[0].trim()
  777. };
  778. }
  779. function resolveWxConfigAppIdFromSignData(d) {
  780. if (!d || typeof d !== 'object') return '';
  781. var mp =
  782. d.mpAppId ||
  783. d.mpAppid ||
  784. d.officialAppId ||
  785. d.gzhAppId ||
  786. d.serviceAppId;
  787. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  788. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  789. if (fromQuery) return fromQuery;
  790. var raw = d.appId || d.appid || d.wxAppId;
  791. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  792. }
  793. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  794. if (!res || typeof res !== 'object') return null;
  795. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  796. if (!d || typeof d !== 'object') return null;
  797. var appId = resolveWxConfigAppIdFromSignData(d);
  798. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  799. var nonceStr =
  800. d.nonceStr != null && String(d.nonceStr) !== ''
  801. ? d.nonceStr
  802. : d.noncestr != null && String(d.noncestr) !== ''
  803. ? d.noncestr
  804. : d.nonce;
  805. var signature = d.signature || d.sign;
  806. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  807. return null;
  808. }
  809. return {
  810. appId: String(appId),
  811. timestamp: Number(timestamp),
  812. nonceStr: String(nonceStr),
  813. signature: String(signature),
  814. signUrl: String(signUrlUsed || '')
  815. .split('#')[0]
  816. .trim()
  817. };
  818. }
  819. function getWxErrMsg(err) {
  820. if (!err) return '';
  821. if (err.errMsg) return String(err.errMsg);
  822. if (typeof err === 'string') return err;
  823. try {
  824. return JSON.stringify(err);
  825. } catch (e) {
  826. return String(err);
  827. }
  828. }
  829. function formatWxConfigErrorTip(err, signPageUrl) {
  830. var errMsg = getWxErrMsg(err);
  831. var tip = '微信 JSSDK 配置失败';
  832. if (/invalid signature/i.test(errMsg)) {
  833. return (
  834. tip +
  835. ':签名无效。请核对:①后端用与前端相同的 url 签名;②url=' +
  836. (signPageUrl || getWxHtmlUrl()) +
  837. ';③nonceStr/timestamp 与接口返回一致;④appId=' +
  838. WECHAT_MP_APP_ID
  839. );
  840. }
  841. if (/require\s*subscribe/i.test(errMsg)) {
  842. return tip + ':' + errMsg + '(服务号需用户已关注)';
  843. }
  844. return errMsg ? tip + ':' + errMsg : tip;
  845. }
  846. function setWxInitError(msg) {
  847. wxInitLastError = String(msg || '').trim();
  848. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  849. }
  850. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  851. var htmlUrl = String(
  852. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  853. )
  854. .split('#')[0]
  855. .trim();
  856. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  857. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  858. }
  859. if (isWxDebugOn()) {
  860. try {
  861. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  862. } catch (eDbg) {}
  863. }
  864. var requestUrl = getWxGetConfigApiUrl();
  865. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  866. console.log('[wx] htmlUrl=', htmlUrl);
  867. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  868. return fetch(requestUrl, {
  869. method: 'POST',
  870. mode: 'cors',
  871. credentials: 'omit',
  872. headers: {
  873. Accept: 'application/json',
  874. 'Content-Type': 'application/json;charset=UTF-8'
  875. },
  876. body: JSON.stringify(requestBody)
  877. })
  878. .then(function (r) {
  879. if (r.ok) return r.json();
  880. return r
  881. .text()
  882. .catch(function () {
  883. return '';
  884. })
  885. .then(function (text) {
  886. var hint = '';
  887. try {
  888. var j = JSON.parse(text);
  889. hint = j.msg || j.message || '';
  890. } catch (eP) {
  891. if (text) hint = text.slice(0, 120);
  892. }
  893. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  894. });
  895. })
  896. .then(function (res) {
  897. if (res && res.code != null) {
  898. var c = Number(res.code);
  899. if (c !== 200 && c !== 0 && res.success !== true) {
  900. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  901. }
  902. }
  903. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  904. if (!sign) {
  905. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  906. throw new Error(
  907. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  908. );
  909. }
  910. if (sign.appId !== WECHAT_MP_APP_ID) {
  911. console.warn(
  912. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  913. );
  914. }
  915. if (typeof wx === 'undefined') {
  916. if (isWxPcBrowser()) {
  917. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  918. return true;
  919. }
  920. setWxInitError('jweixin.js 未加载');
  921. return false;
  922. }
  923. return applyWxConfigFromSign(sign, htmlUrl);
  924. });
  925. }
  926. function applyWxConfigFromSign(sign, htmlUrl) {
  927. var wxConfigParams = {
  928. debug: isWxDebugOn(),
  929. appId: String(sign.appId),
  930. timestamp: sign.timestamp,
  931. nonceStr: String(sign.nonceStr),
  932. signature: String(sign.signature),
  933. jsApiList: [],
  934. openTagList: ['wx-open-launch-app']
  935. };
  936. return new Promise(function (resolve) {
  937. wx.config(wxConfigParams);
  938. wx.ready(function () {
  939. weChatJssdkConfigured = true;
  940. document.body.classList.add('wx-jssdk-ready');
  941. refreshWxLaunchTagAttrs(false);
  942. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  943. resolve(true);
  944. });
  945. wx.error(function (err) {
  946. weChatJssdkConfigured = false;
  947. document.body.classList.remove('wx-jssdk-ready');
  948. wxJssdkInitPromise = null;
  949. var errMsg = getWxErrMsg(err);
  950. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  951. if (isWxDebugOn()) window.alert(wxInitLastError);
  952. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  953. var baseUrl = getWxHtmlUrlBase();
  954. var fullUrl = getWxSignPageUrlForApi();
  955. if (
  956. !/invalid signature/i.test(errMsg) ||
  957. wxConfigSignRetriedBaseUrl ||
  958. baseUrl === fullUrl ||
  959. htmlUrl === baseUrl
  960. ) {
  961. resolve(false);
  962. return;
  963. }
  964. wxConfigSignRetriedBaseUrl = true;
  965. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  966. });
  967. });
  968. }
  969. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  970. var tag = document.getElementById('launch-btn');
  971. if (!tag) return;
  972. try {
  973. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  974. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo(!!useBarePathOnly));
  975. console.log('[wx-open-launch-app] extinfo=', tag.getAttribute('extinfo'));
  976. } catch (eA) {}
  977. }
  978. function bindWeChatLaunchTagEvents() {
  979. var tag = document.getElementById('launch-btn');
  980. if (!tag || tag._wxLaunchBound) return;
  981. tag._wxLaunchBound = true;
  982. tag._wxLaunchBareRetried = false;
  983. refreshWxLaunchTagAttrs(false);
  984. tag.addEventListener('launch', function () {
  985. if (tag._launchTapTimer) {
  986. clearTimeout(tag._launchTapTimer);
  987. tag._launchTapTimer = null;
  988. }
  989. tag._wxLaunchBareRetried = false;
  990. console.log('[wx-open-launch-app] launch ok');
  991. // showFabToast('正在打开 U店在哪…');
  992. });
  993. tag.addEventListener('click', function () {
  994. if (!weChatJssdkConfigured) return;
  995. if (tag._launchTapTimer) clearTimeout(tag._launchTapTimer);
  996. tag._launchTapTimer = setTimeout(function () {
  997. tag._launchTapTimer = null;
  998. // if (!tag._wxLaunchBareRetried) {
  999. // showFabToast('正在唤起 App,请稍候…');
  1000. // }
  1001. }, 600);
  1002. });
  1003. tag.addEventListener('error', function (e) {
  1004. var detail = e && e.detail;
  1005. var errMsg =
  1006. detail && detail.errMsg
  1007. ? String(detail.errMsg)
  1008. : detail && detail.errmsg
  1009. ? String(detail.errmsg)
  1010. : '';
  1011. console.warn('[wx-open-launch-app]', detail, 'extinfo=', tag.getAttribute('extinfo'));
  1012. if (/launch:fail_check/i.test(errMsg)) {
  1013. showAppOpenFailTip(
  1014. '请用微信分享卡片进入,或确认已安装最新版「U店在哪」'
  1015. );
  1016. return;
  1017. }
  1018. if (
  1019. /launch:fail/i.test(errMsg) &&
  1020. !tag._wxLaunchBareRetried &&
  1021. tag.getAttribute('extinfo') !== buildWeChatLaunchExtinfo(true)
  1022. ) {
  1023. tag._wxLaunchBareRetried = true;
  1024. refreshWxLaunchTagAttrs(true);
  1025. showFabToast('请再点一次「APP内打开」');
  1026. return;
  1027. }
  1028. if (/launch:fail/i.test(errMsg)) {
  1029. showDownloadTip();
  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. if (done) return;
  1215. finish();
  1216. showDownloadTip();
  1217. }, 2600);
  1218. }
  1219. if (typeof uni !== 'undefined' && typeof uni.navigateTo === 'function') {
  1220. var uniUrl = buildUniAppOpenPageUrl();
  1221. var uniFallback =
  1222. '/' +
  1223. (getShareGoodsIdForAppOpen()
  1224. ? String(APP_UNI_STORE_PATH).replace(/^\//, '')
  1225. : 'pages/index/login');
  1226. try {
  1227. uni.navigateTo({
  1228. url: uniUrl,
  1229. fail: function () {
  1230. if (typeof uni.reLaunch === 'function') {
  1231. try {
  1232. uni.reLaunch({
  1233. url: uniUrl.length > 1800 ? uniFallback : uniUrl,
  1234. fail: function () {
  1235. openBySchemeOrPlus();
  1236. }
  1237. });
  1238. return;
  1239. } catch (eRl) {}
  1240. }
  1241. openBySchemeOrPlus();
  1242. }
  1243. });
  1244. return;
  1245. } catch (eUni) {
  1246. openBySchemeOrPlus();
  1247. return;
  1248. }
  1249. }
  1250. openBySchemeOrPlus();
  1251. }
  1252. function showErr(msg) {
  1253. var el = document.getElementById('pageError');
  1254. el.textContent = msg;
  1255. el.style.display = 'block';
  1256. }
  1257. function getStoreId() {
  1258. return q('id') || q('storeId');
  1259. }
  1260. function apiFetch(path) {
  1261. return fetch(API_BASE + path, {
  1262. method: 'GET',
  1263. mode: 'cors',
  1264. credentials: 'omit',
  1265. headers: { Accept: 'application/json' }
  1266. }).then(function (res) {
  1267. if (!res.ok) throw new Error('HTTP ' + res.status);
  1268. return res.json();
  1269. });
  1270. }
  1271. function isApiOk(res) {
  1272. if (!res || typeof res !== 'object') return false;
  1273. if (res.success === false) return false;
  1274. var c = res.code;
  1275. return c === 200 || c === '200' || Number(c) === 200;
  1276. }
  1277. function buildHeroSlides(urls) {
  1278. var track = document.getElementById('heroTrack');
  1279. var dotsWrap = document.getElementById('heroDots');
  1280. track.innerHTML = '';
  1281. dotsWrap.innerHTML = '';
  1282. var list = (urls || []).filter(Boolean);
  1283. if (!list.length) {
  1284. var slide = document.createElement('div');
  1285. slide.className = 'hero__slide';
  1286. var img = document.createElement('img');
  1287. img.src = 'images/hero.png';
  1288. img.alt = '店铺';
  1289. slide.appendChild(img);
  1290. track.appendChild(slide);
  1291. var dot = document.createElement('span');
  1292. dot.className = 'hero__dot is-active';
  1293. dotsWrap.appendChild(dot);
  1294. return initHeroCarousel(1);
  1295. }
  1296. list.forEach(function (url, d) {
  1297. var slide = document.createElement('div');
  1298. slide.className = 'hero__slide';
  1299. var img = document.createElement('img');
  1300. img.src = url;
  1301. img.alt = '店铺图';
  1302. slide.appendChild(img);
  1303. track.appendChild(slide);
  1304. var dot = document.createElement('span');
  1305. dot.className = 'hero__dot' + (d === 0 ? ' is-active' : '');
  1306. dotsWrap.appendChild(dot);
  1307. });
  1308. initHeroCarousel(list.length);
  1309. }
  1310. var heroI = 0;
  1311. var heroTimer = null;
  1312. function initHeroCarousel(slides) {
  1313. var track = document.getElementById('heroTrack');
  1314. var dotsWrap = document.getElementById('heroDots');
  1315. var dots = dotsWrap.querySelectorAll('.hero__dot');
  1316. if (slides < 2) return;
  1317. function go(n) {
  1318. heroI = (n + slides) % slides;
  1319. track.style.transform = 'translateX(' + (-heroI * 100) + '%)';
  1320. dots.forEach(function (el, idx) {
  1321. el.classList.toggle('is-active', idx === heroI);
  1322. });
  1323. }
  1324. if (heroTimer) clearInterval(heroTimer);
  1325. heroTimer = setInterval(function () { go(heroI + 1); }, 4000);
  1326. var hero = document.getElementById('hero');
  1327. var startX = 0;
  1328. hero.addEventListener('touchstart', function (e) {
  1329. startX = e.changedTouches[0].clientX;
  1330. }, { passive: true });
  1331. hero.addEventListener('touchend', function (e) {
  1332. var dx = e.changedTouches[0].clientX - startX;
  1333. if (Math.abs(dx) > 40) go(dx < 0 ? heroI + 1 : heroI - 1);
  1334. }, { passive: true });
  1335. }
  1336. function timeToMinutes(t) {
  1337. var parts = String(t || '').trim().split(':');
  1338. var h = parseInt(parts[0], 10) || 0;
  1339. var m = parseInt(parts[1], 10) || 0;
  1340. return h * 60 + m;
  1341. }
  1342. function isTimeInRange(startTime, endTime) {
  1343. var s = String(startTime || '').trim();
  1344. var e = String(endTime || '').trim();
  1345. if (s === '00:00' && e === '00:00') return true;
  1346. if (s === '00:00' && e === '23:59') return true;
  1347. var cur = new Date().getHours() * 60 + new Date().getMinutes();
  1348. var sm = timeToMinutes(s);
  1349. var em = timeToMinutes(e);
  1350. if (em < sm) {
  1351. return cur >= sm || cur <= em;
  1352. }
  1353. return cur >= sm && cur <= em;
  1354. }
  1355. function parseHolidayDate(str) {
  1356. if (!str) return null;
  1357. var d = new Date(String(str).trim().replace(/-/g, '/'));
  1358. return isNaN(d.getTime()) ? null : d;
  1359. }
  1360. function isTodayInHolidayRange(holidayInfo) {
  1361. if (!holidayInfo) return false;
  1362. var hi = holidayInfo;
  1363. if (typeof hi === 'string') {
  1364. try {
  1365. hi = JSON.parse(hi);
  1366. } catch (err) {
  1367. return false;
  1368. }
  1369. }
  1370. var start = hi.startDate || hi.holidayStartDate || hi.beginDate || hi.start || hi.holidayStart;
  1371. var end = hi.endDate || hi.holidayEndDate || hi.finishDate || hi.end || hi.holidayEnd;
  1372. if (!start || !end) return false;
  1373. var startD = parseHolidayDate(start);
  1374. var endD = parseHolidayDate(end);
  1375. if (!startD || !endD) return false;
  1376. var today = new Date();
  1377. today.setHours(0, 0, 0, 0);
  1378. startD.setHours(0, 0, 0, 0);
  1379. endD.setHours(0, 0, 0, 0);
  1380. return today >= startD && today <= endD;
  1381. }
  1382. function findNormalBusinessInfo(list) {
  1383. var wdJs = new Date().getDay();
  1384. var i;
  1385. var x;
  1386. var w;
  1387. for (i = 0; i < list.length; i++) {
  1388. x = list[i];
  1389. if (!x || x.holidayInfo) continue;
  1390. w = x.weekDay != null ? x.weekDay : x.week;
  1391. if (w === undefined || w === null) continue;
  1392. if (Number(w) === wdJs) return x;
  1393. }
  1394. var wdMap = wdJs === 0 ? 7 : wdJs;
  1395. for (i = 0; i < list.length; i++) {
  1396. x = list[i];
  1397. if (!x || x.holidayInfo) continue;
  1398. w = x.weekDay != null ? x.weekDay : x.week;
  1399. if (w === undefined || w === null) continue;
  1400. if (Number(w) === wdMap) return x;
  1401. }
  1402. for (i = 0; i < list.length; i++) {
  1403. x = list[i];
  1404. if (x && !x.holidayInfo && (x.startTime || x.endTime)) return x;
  1405. }
  1406. return null;
  1407. }
  1408. /** 营业状态:暂停营业 | 商家暂未配置营业时间 | 休息中 | 营业中 xx:xx至xx:xx | 营业中 全天营业 */
  1409. function computeBusinessStatusDisplay(d) {
  1410. if (!d) return { text: '—', isOpen: false };
  1411. if (Number(d.businessStatus) === 1) {
  1412. return { text: '暂停营业', isOpen: false };
  1413. }
  1414. var list = d.storeBusinessInfoVos || d.storeBusinessInfos || [];
  1415. if (!list.length) {
  1416. return { text: '商家暂未配置营业时间', isOpen: false };
  1417. }
  1418. var holidayList = Array.isArray(d.holidayBusinessInfoList) && d.holidayBusinessInfoList.length
  1419. ? d.holidayBusinessInfoList
  1420. : list.filter(function (item) { return item && item.holidayInfo; });
  1421. var todayHolidayItem = holidayList.find(function (item) {
  1422. return isTodayInHolidayRange(item.holidayInfo);
  1423. });
  1424. var normal = d.normalBusinessInfo || d.normalBusinessInfoVo || findNormalBusinessInfo(list);
  1425. var isOpen = false;
  1426. var currentItem = null;
  1427. if (todayHolidayItem) {
  1428. isOpen = isTimeInRange(todayHolidayItem.startTime, todayHolidayItem.endTime);
  1429. currentItem = todayHolidayItem;
  1430. } else if (normal) {
  1431. isOpen = isTimeInRange(normal.startTime, normal.endTime);
  1432. currentItem = normal;
  1433. }
  1434. if (!currentItem) return { text: '休息中', isOpen: false };
  1435. if (!isOpen) return { text: '休息中', isOpen: false };
  1436. var st = String(currentItem.startTime || '').trim();
  1437. var et = String(currentItem.endTime || '').trim();
  1438. if (st === '00:00' && et === '00:00') return { text: '营业中 全天营业', isOpen: true };
  1439. if (st === '00:00' && et === '23:59') return { text: '营业中 全天营业', isOpen: true };
  1440. var needNextDay = timeToMinutes(et) < timeToMinutes(st);
  1441. var suffix = (needNextDay ? '次日' : '') + et;
  1442. return { text: ('营业中 ' + st + ' 至 ' + suffix).trim(), isOpen: true };
  1443. }
  1444. function renderDetail(d) {
  1445. if (!d) return;
  1446. document.getElementById('storeName').textContent = d.storeName || '—';
  1447. var score = d.scoreAvg != null ? Number(d.scoreAvg) : NaN;
  1448. document.getElementById('scoreAvg').textContent = !isNaN(score) ? score.toFixed(1) : '—';
  1449. document.getElementById('commitCount').textContent = d.commitCount != null ? String(d.commitCount) : '0';
  1450. var bizDisp = computeBusinessStatusDisplay(d);
  1451. var bizEl = document.getElementById('bizStatus');
  1452. bizEl.textContent = bizDisp.text;
  1453. bizEl.className = 'status' + (bizDisp.isOpen ? ' is-open' : '');
  1454. document.getElementById('hoursText').textContent = '';
  1455. document.getElementById('storeAddr').textContent = d.queryAddress || d.storeAddress || '—';
  1456. if (d.distance != null) {
  1457. document.getElementById('metaDistance').style.display = 'flex';
  1458. document.getElementById('distanceText').textContent =
  1459. '距您' + (Number(d.distance) > 1 ? d.distance + '千米' : Math.round(Number(d.distance) * 1000) + '米');
  1460. }
  1461. if (d.subwayName && d.distance2 != null) {
  1462. document.getElementById('metaSubway').style.display = 'flex';
  1463. document.getElementById('subwayText').textContent =
  1464. '距' + d.subwayName + '步行' + (Number(d.distance2) >= 1000
  1465. ? (Number(d.distance2) / 1000).toFixed(1) + 'km'
  1466. : Math.round(Number(d.distance2)) + 'm');
  1467. }
  1468. var imgs = [];
  1469. if (Array.isArray(d.storeAlbumUrlList) && d.storeAlbumUrlList.length) imgs = d.storeAlbumUrlList.slice();
  1470. else if (d.entranceImage) imgs = [d.entranceImage];
  1471. buildHeroSlides(imgs);
  1472. }
  1473. function boot() {
  1474. var launchTag = document.getElementById('launch-btn');
  1475. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1476. bindWeChatLaunchTagEvents();
  1477. if (isWeChatInAppBrowser()) {
  1478. document.body.classList.add('is-wechat');
  1479. logWxEntryDiagnostics();
  1480. }
  1481. if (shouldInitWeChatJssdkOnLoad()) {
  1482. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1483. document.body.classList.add('wx-pc-debug');
  1484. }
  1485. scheduleWeChatJssdkBootstrap();
  1486. }
  1487. document.addEventListener('WeixinOpenTagsError', function (e) {
  1488. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1489. var d = e && e.detail;
  1490. var em =
  1491. d && d.errMsg
  1492. ? String(d.errMsg)
  1493. : d && d.errmsg
  1494. ? String(d.errmsg)
  1495. : '';
  1496. showFabToast(em || '微信开放标签不可用,请升级微信后重试');
  1497. });
  1498. if (isWeChatInAppBrowser()) {
  1499. var openBtnWx = document.getElementById('openApp');
  1500. if (openBtnWx) {
  1501. openBtnWx.addEventListener('click', function () {
  1502. if (!weChatJssdkConfigured) {
  1503. showFabToast(
  1504. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1505. );
  1506. initWeChatOpenLaunchApp(true);
  1507. }
  1508. });
  1509. }
  1510. } else {
  1511. var openBtn = document.getElementById('openApp');
  1512. if (openBtn) {
  1513. openBtn.addEventListener('click', tryOpenUShopApp);
  1514. }
  1515. }
  1516. }
  1517. if (document.readyState === 'complete') {
  1518. boot();
  1519. } else {
  1520. window.onload = boot;
  1521. }
  1522. })();
  1523. </script>
  1524. </body>
  1525. </html>