shareUndefined.html 45 KB

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