shareCheckInUndefined.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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>打卡分享</title>
  8. <style>
  9. :root {
  10. --orange: #F58220;
  11. --text: #333333;
  12. --text-secondary: #999999;
  13. --border: #EEEEEE;
  14. --bg: #FFFFFF;
  15. --safe-bottom: env(safe-area-inset-bottom, 0px);
  16. }
  17. * {
  18. margin: 0;
  19. padding: 0;
  20. box-sizing: border-box;
  21. }
  22. html {
  23. font-size: 16px;
  24. -webkit-tap-highlight-color: transparent;
  25. overflow-x: hidden;
  26. }
  27. body {
  28. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  29. background: var(--bg);
  30. color: var(--text);
  31. padding-bottom: calc(88px + var(--safe-bottom));
  32. min-height: 100vh;
  33. overflow-x: hidden;
  34. }
  35. .hero.hero--empty {
  36. display: flex;
  37. flex-direction: column;
  38. align-items: center;
  39. justify-content: center;
  40. padding: 48px 24px 56px;
  41. min-height: min(52vh, 440px);
  42. background: var(--bg);
  43. }
  44. .hero--empty__illustration {
  45. display: block;
  46. width: 100%;
  47. max-width: 280px;
  48. height: auto;
  49. object-fit: contain;
  50. }
  51. .hero--empty__tip {
  52. padding: 0 16px;
  53. margin-top: 12px;
  54. font-size: 15px;
  55. line-height: 1.5;
  56. color: var(--text-secondary);
  57. text-align: center;
  58. font-weight: 400;
  59. }
  60. .divider {
  61. height: 8px;
  62. background: #F7F7F7;
  63. margin: 0;
  64. }
  65. .more-title {
  66. padding: 8px 15px 12px;
  67. font-size: 16px;
  68. font-weight: 700;
  69. }
  70. .more-scroll {
  71. display: grid;
  72. grid-template-columns: repeat(2, 1fr);
  73. gap: 10px;
  74. padding: 0 15px 20px;
  75. }
  76. #recEmpty {
  77. grid-column: 1 / -1;
  78. }
  79. .rec-card {
  80. min-width: 0;
  81. background: #fff;
  82. border-radius: 10px;
  83. overflow: hidden;
  84. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  85. }
  86. .rec-card__img {
  87. aspect-ratio: 4 / 3;
  88. background: #eee;
  89. }
  90. .rec-card__img img {
  91. width: 100%;
  92. height: 100%;
  93. object-fit: cover;
  94. display: block;
  95. border-radius: 0;
  96. }
  97. .rec-card__body {
  98. padding: 10px;
  99. }
  100. .rec-card__top {
  101. display: flex;
  102. justify-content: space-between;
  103. align-items: baseline;
  104. gap: 8px;
  105. margin-bottom: 6px;
  106. }
  107. .rec-card__name {
  108. font-size: 15px;
  109. font-weight: 700;
  110. flex: 1;
  111. min-width: 0;
  112. overflow: hidden;
  113. text-overflow: ellipsis;
  114. white-space: nowrap;
  115. }
  116. .rec-card__dist {
  117. font-size: 12px;
  118. color: var(--text-secondary);
  119. flex-shrink: 0;
  120. }
  121. .rec-card__rating {
  122. display: flex;
  123. align-items: center;
  124. flex-wrap: wrap;
  125. gap: 4px 6px;
  126. }
  127. .rec-card__rating .stars {
  128. display: inline-flex;
  129. align-items: center;
  130. gap: 2px;
  131. }
  132. .rec-card__rating .rec-star {
  133. display: block;
  134. flex-shrink: 0;
  135. }
  136. .rec-card__rating .rating-num {
  137. font-size: 12px;
  138. font-weight: 600;
  139. color: var(--orange);
  140. }
  141. .rec-meta {
  142. font-size: 12px;
  143. color: var(--text-secondary);
  144. }
  145. .rec-card__footer {
  146. margin-top: 8px;
  147. font-size: 12px;
  148. color: var(--text-secondary);
  149. overflow: hidden;
  150. text-overflow: ellipsis;
  151. white-space: nowrap;
  152. }
  153. .fab-wrap {
  154. position: fixed;
  155. left: 0;
  156. right: 0;
  157. bottom: 0;
  158. z-index: 200;
  159. padding: 12px 24px calc(12px + var(--safe-bottom));
  160. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  161. pointer-events: none;
  162. }
  163. .fab-dock__slot {
  164. width: 100%;
  165. max-width: 198px;
  166. height: 48px;
  167. margin: 0 auto;
  168. pointer-events: auto;
  169. }
  170. #openApp img {
  171. display: block;
  172. width: 100%;
  173. height: 48px;
  174. object-fit: contain;
  175. pointer-events: none;
  176. }
  177. #launch-btn {
  178. display: none;
  179. width: 100%;
  180. height: 48px;
  181. min-height: 48px;
  182. border-radius: 24px;
  183. overflow: hidden;
  184. opacity: 1;
  185. }
  186. body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
  187. display: block;
  188. }
  189. body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
  190. display: none !important;
  191. }
  192. #openAppToast {
  193. display: none;
  194. position: fixed;
  195. left: 16px;
  196. right: 16px;
  197. bottom: calc(72px + var(--safe-bottom));
  198. z-index: 10001;
  199. padding: 10px 14px;
  200. font-size: 13px;
  201. line-height: 1.45;
  202. color: #fff;
  203. text-align: center;
  204. background: rgba(0, 0, 0, 0.78);
  205. border-radius: 8px;
  206. pointer-events: none;
  207. word-break: break-all;
  208. }
  209. #openApp {
  210. touch-action: manipulation;
  211. }
  212. .fab-wrap .fab {
  213. pointer-events: auto;
  214. }
  215. .fab {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. gap: 10px;
  220. width: 100%;
  221. max-width: 198px;
  222. margin: 0 auto;
  223. height: 48px;
  224. border: none;
  225. border-radius: 24px;
  226. background: var(--orange);
  227. color: #fff;
  228. font-size: 16px;
  229. font-weight: 600;
  230. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  231. cursor: pointer;
  232. }
  233. .fab img {
  234. flex-shrink: 0;
  235. }
  236. .home-indicator {
  237. height: 5px;
  238. background: #000;
  239. border-radius: 3px;
  240. width: 134px;
  241. margin: 8px auto 4px;
  242. opacity: 0.2;
  243. }
  244. </style>
  245. </head>
  246. <body>
  247. <div class="hero hero--empty" role="status" aria-live="polite">
  248. <img class="hero--empty__illustration" id="heroEmptyIllustration" src="images/empty.png" alt="" decoding="async">
  249. <p class="hero--empty__tip" id="heroEmptyTip">内容已删除</p>
  250. </div>
  251. <div class="divider"></div>
  252. <h3 class="more-title">更多推荐</h3>
  253. <div class="more-scroll" id="recList">
  254. <p id="recEmpty" style="padding:12px;color:#999;font-size:14px;display:none;">暂无推荐</p>
  255. </div>
  256. <div id="openAppToast" role="status" aria-live="polite"></div>
  257. <div class="fab-wrap">
  258. <div class="fab-dock__slot">
  259. <!-- 非微信 / 微信 JSSDK 未就绪:scheme 唤起 -->
  260. <button type="button" class="fab" id="openApp">
  261. <img src="images/uBtn.png" alt="APP内打开" decoding="async">
  262. </button>
  263. <!-- 微信内 wx.config 成功后:仅此按钮可唤起 App(须用户直接点击) -->
  264. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  265. <script type="text/wxtag-template">
  266. <style>
  267. .wx-open-app-btn {
  268. display: block;
  269. width: 100%;
  270. height: 48px;
  271. margin: 0;
  272. padding: 0;
  273. border: none;
  274. border-radius: 24px;
  275. background: #F47D1F;
  276. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  277. cursor: pointer;
  278. overflow: hidden;
  279. -webkit-tap-highlight-color: transparent;
  280. }
  281. .wx-open-app-btn img {
  282. display: block;
  283. width: 100%;
  284. height: 48px;
  285. object-fit: contain;
  286. opacity: 1;
  287. pointer-events: none;
  288. -webkit-user-drag: none;
  289. }
  290. </style>
  291. <button class="wx-open-app-btn" aria-label="APP内打开">
  292. <img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" width="198" height="48" />
  293. </button>
  294. </script>
  295. </wx-open-launch-app>
  296. </div>
  297. <div class="home-indicator" aria-hidden="true"></div>
  298. </div>
  299. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  300. <script>
  301. (function () {
  302. 'use strict';
  303. /**
  304. * 更多推荐:POST …/dev-life-manager-ai/ai/multimodal-services/api/v1/search/global/store-recommend
  305. * 请求体:page、pageSize、storeId(字符串)、userCity、userLat、userLng;均可由 URL query 覆盖。
  306. *
  307. * businessStatus=99(关店,与 shareIndex.html 一致):点「APP内打开」深链为 shopro://pages/index/login?…,不再进打卡页。
  308. */
  309. var API_BASE = 'https://test.ailien.shop/alienStore';
  310. var API_LIFE_AI_BASE = 'http://183.252.196.135:9100';
  311. var STORE_GLOBAL_RECOMMEND_PATH =
  312. '/ai/multimodal-services/api/v1/search/global/store-recommend';
  313. var DEFAULT_USER_LAT = 38.925747;
  314. var DEFAULT_USER_LNG = 121.662531;
  315. var DEFAULT_USER_CITY = '大连市';
  316. var DEFAULT_STORE_ID = '378';
  317. /**
  318. * 微信 JSSDK — 与 shareIndex.html 一致
  319. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  320. */
  321. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  322. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  323. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  324. var H5_PAGE_BASE_FALLBACK = 'https://test.ailien.shop/h5/HBuilderProjects/';
  325. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'shareCheckInUndefined.html';
  326. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'test.ailien.shop'];
  327. var weChatJssdkConfigured = false;
  328. var wxConfigSignRetriedBaseUrl = false;
  329. var wxInitLastError = '';
  330. var wxJssdkInitPromise = null;
  331. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  332. var APP_IOS_URL_SCHEME = 'shopro://';
  333. var APP_UNI_STORE_PATH = 'pages/checkIn/index';
  334. function q(name) {
  335. var v = mergeSearchAndHashParams().get(name);
  336. return v == null ? '' : String(v);
  337. }
  338. function showDownloadTip() {
  339. var msg = '请到应用商店下载';
  340. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  341. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  342. } else {
  343. window.alert(msg);
  344. }
  345. }
  346. function mergeSearchAndHashParams() {
  347. var params = new URLSearchParams();
  348. function ingestAppend(querySlice) {
  349. if (!querySlice) return;
  350. var p = new URLSearchParams(querySlice);
  351. p.forEach(function (val, key) {
  352. params.append(key, val);
  353. });
  354. }
  355. function ingestSet(querySlice) {
  356. if (!querySlice) return;
  357. var p = new URLSearchParams(querySlice);
  358. p.forEach(function (val, key) {
  359. params.set(key, val);
  360. });
  361. }
  362. if (location.search && location.search.length > 1) {
  363. ingestAppend(location.search.slice(1));
  364. }
  365. var hash = location.hash || '';
  366. var qi = hash.indexOf('?');
  367. if (qi >= 0) {
  368. ingestSet(hash.slice(qi + 1));
  369. }
  370. return params;
  371. }
  372. function getRawMergedQueryForAppOpen() {
  373. var rawSearch =
  374. location.search && location.search.length > 1 ? location.search.slice(1) : '';
  375. var hash0 = location.hash || '';
  376. var hqi0 = hash0.indexOf('?');
  377. var rawHashQ = hqi0 >= 0 ? hash0.slice(hqi0 + 1) : '';
  378. if (!rawSearch && !rawHashQ) return '';
  379. if (rawHashQ && rawSearch) {
  380. return rawHashQ;
  381. }
  382. return rawHashQ || rawSearch;
  383. }
  384. /**
  385. * 关店 businessStatus=99:URL(含 hash)带 businessStatus=99 时,唤起 App 进 pages/index/login(与 shareIndex.html isClosedMerchantForAppOpen)。
  386. */
  387. function isClosedMerchantForAppOpen() {
  388. try {
  389. var bs = String(mergeSearchAndHashParams().get('businessStatus') || '').trim();
  390. if (bs === '99' || Number(bs) === 99) return true;
  391. } catch (e0) {}
  392. return false;
  393. }
  394. function getAppUniPathForCheckInShare() {
  395. if (isClosedMerchantForAppOpen()) {
  396. return 'pages/index/login';
  397. }
  398. var p = mergeSearchAndHashParams();
  399. if (!p.has('isShareCheckInSquare')) {
  400. return String(APP_UNI_STORE_PATH || 'pages/checkIn/index').replace(/^\//, '');
  401. }
  402. var v = String(p.get('isShareCheckInSquare') || '').trim().toLowerCase();
  403. if (v === '' || v === '0' || v === 'false' || v === 'no') {
  404. return String(APP_UNI_STORE_PATH || 'pages/checkIn/index').replace(/^\//, '');
  405. }
  406. return 'pages/checkIn/details';
  407. }
  408. /** businessStatus=99(商户关闭):插图与文案;否则为「内容已删除」 */
  409. function applyEmptyHeroState() {
  410. var merged = mergeSearchAndHashParams();
  411. var bsRaw = merged.get('businessStatus');
  412. var bs = bsRaw == null ? '' : String(bsRaw).trim();
  413. var isClosed = Number(bs) === 99 || bs === '99';
  414. var img = document.getElementById('heroEmptyIllustration');
  415. var tip = document.getElementById('heroEmptyTip');
  416. if (!img || !tip) return;
  417. if (isClosed) {
  418. img.src = 'images/storeNone.png';
  419. img.alt = '';
  420. tip.textContent = '抱歉商户已关闭,看看别的吧';
  421. } else {
  422. img.src = 'images/empty.png';
  423. img.alt = '';
  424. tip.textContent = '内容已删除';
  425. }
  426. img.onerror = function () {
  427. this.onerror = null;
  428. this.src = 'images/empty.png';
  429. };
  430. if (weChatJssdkConfigured) {
  431. refreshWxLaunchTagAttrs();
  432. }
  433. }
  434. function buildAppOpenQueryStringMerged() {
  435. var rawQs = getRawMergedQueryForAppOpen();
  436. if (rawQs) {
  437. return '?' + rawQs;
  438. }
  439. var params = mergeSearchAndHashParams();
  440. var sid = params.get('storeId') || params.get('id') || '';
  441. if (sid && !params.has('storeId')) {
  442. params.set('storeId', sid);
  443. }
  444. var qsOut = params.toString();
  445. return qsOut ? ('?' + qsOut) : '';
  446. }
  447. function buildAppUniPageLaunchUrl() {
  448. var path = getAppUniPathForCheckInShare().replace(/^\//, '');
  449. var qs = buildAppOpenQueryStringMerged().replace(/^\?/, '');
  450. return qs ? path + '?' + qs : path;
  451. }
  452. /**
  453. * wx-open-launch-app extinfo:pages/checkIn/index、pages/checkIn/details 或关店 pages/index/login
  454. */
  455. function buildWeChatLaunchExtinfo() {
  456. var uniPage = buildAppUniPageLaunchUrl();
  457. if (uniPage.length <= 1024) return uniPage;
  458. var path = getAppUniPathForCheckInShare().replace(/^\//, '');
  459. var rawQs = getRawMergedQueryForAppOpen();
  460. if (rawQs) {
  461. var packedRaw = path + '?' + rawQs;
  462. if (packedRaw.length <= 1024) return packedRaw;
  463. }
  464. var params = mergeSearchAndHashParams();
  465. var mini = new URLSearchParams();
  466. var storeId = params.get('storeId') || params.get('id') || '';
  467. if (storeId) mini.set('storeId', storeId);
  468. var square = params.get('isShareCheckInSquare');
  469. if (square != null && String(square).trim() !== '') {
  470. mini.set('isShareCheckInSquare', String(square).trim());
  471. }
  472. var bs = params.get('businessStatus');
  473. if (bs != null && String(bs).trim() !== '') {
  474. mini.set('businessStatus', String(bs).trim());
  475. }
  476. var shortPage = path + '?' + mini.toString();
  477. if (shortPage.length <= 1024) return shortPage;
  478. var deep = buildAppDeepLink().replace(/^shopro:\/\//i, '');
  479. return deep.length <= 1024 ? deep : shortPage.slice(0, 1024);
  480. }
  481. function buildAppDeepLink() {
  482. var path = getAppUniPathForCheckInShare().replace(/^\//, '');
  483. var s = buildAppOpenQueryStringMerged();
  484. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  485. if (!s) {
  486. return root + '/' + path;
  487. }
  488. return root + '/' + path + s;
  489. }
  490. function isWeChatInAppBrowser() {
  491. return /MicroMessenger/i.test(navigator.userAgent || '');
  492. }
  493. function getWxShareEntryFrom() {
  494. var from = q('from');
  495. return from ? String(from).trim().toLowerCase() : '';
  496. }
  497. function isWxOpenLaunchAppSceneSupported() {
  498. if (!isWeChatInAppBrowser()) return false;
  499. if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
  500. return true;
  501. }
  502. var from = getWxShareEntryFrom();
  503. return (
  504. from === 'singlemessage' ||
  505. from === 'groupmessage' ||
  506. from === 'timeline'
  507. );
  508. }
  509. function applyWxOpenLaunchSceneBodyClass() {
  510. if (!isWeChatInAppBrowser()) return;
  511. var ok = isWxOpenLaunchAppSceneSupported();
  512. document.body.classList.toggle('wx-open-tag-scene', ok);
  513. document.body.classList.toggle('wx-copy-link-entry', !ok);
  514. }
  515. function logWxEntryDiagnostics() {
  516. if (!isWeChatInAppBrowser()) return;
  517. console.log('[wx-entry]', {
  518. entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
  519. openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
  520. signUrl: getWxConfigSignUrl()
  521. });
  522. }
  523. function showWxCopyLinkEntryTip() {
  524. showFabToast(
  525. '当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
  526. );
  527. }
  528. function readQueryParam(name) {
  529. return q(name);
  530. }
  531. function isWxDebugOn() {
  532. return readQueryParam('wxDebug') === '1';
  533. }
  534. function isWxForceDebug() {
  535. return readQueryParam('wxForce') === '1';
  536. }
  537. function isWxConfigOnClickDebug() {
  538. return readQueryParam('wxConfigOnClick') === '1';
  539. }
  540. function isWxPcAutoDebugHost() {
  541. var h = (location.hostname || '').toLowerCase();
  542. if (h === 'localhost' || h === '127.0.0.1') return true;
  543. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  544. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  545. }
  546. return false;
  547. }
  548. function isWxPcBrowser() {
  549. return !isWeChatInAppBrowser();
  550. }
  551. function shouldInitWeChatJssdkOnLoad() {
  552. if (isWeChatInAppBrowser()) return true;
  553. return isWxForceDebug() || isWxPcAutoDebugHost();
  554. }
  555. function shouldFetchWxConfig(fromUserClick) {
  556. if (isWeChatInAppBrowser()) return true;
  557. if (fromUserClick) return true;
  558. return isWxForceDebug() || isWxPcAutoDebugHost();
  559. }
  560. function getWxHtmlUrl() {
  561. var forced = String(q('wxSignUrl') || '').trim();
  562. if (forced) return forced.split('#')[0];
  563. return String(location.href || '').split('#')[0];
  564. }
  565. function getWxSignPageUrlForApi() {
  566. var htmlUrl = getWxHtmlUrl();
  567. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  568. return WX_GET_CONFIG_SIGN_URL;
  569. }
  570. function getWxHtmlUrlBase() {
  571. var htmlUrl = getWxSignPageUrlForApi();
  572. try {
  573. var u = new URL(htmlUrl);
  574. return u.origin + u.pathname;
  575. } catch (eU) {
  576. return WX_GET_CONFIG_SIGN_URL;
  577. }
  578. }
  579. function getWxConfigSignUrl() {
  580. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  581. return getWxSignPageUrlForApi();
  582. }
  583. function getWxGetConfigApiUrl() {
  584. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  585. }
  586. function buildWxGetConfigRequestBody(htmlUrl) {
  587. return {
  588. url: String(htmlUrl || '').split('#')[0].trim()
  589. };
  590. }
  591. function resolveWxConfigAppIdFromSignData(d) {
  592. if (!d || typeof d !== 'object') return '';
  593. var mp =
  594. d.mpAppId ||
  595. d.mpAppid ||
  596. d.officialAppId ||
  597. d.gzhAppId ||
  598. d.serviceAppId;
  599. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  600. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  601. if (fromQuery) return fromQuery;
  602. var raw = d.appId || d.appid || d.wxAppId;
  603. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  604. }
  605. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  606. if (!res || typeof res !== 'object') return null;
  607. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  608. if (!d || typeof d !== 'object') return null;
  609. var appId = resolveWxConfigAppIdFromSignData(d);
  610. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  611. var nonceStr =
  612. d.nonceStr != null && String(d.nonceStr) !== ''
  613. ? d.nonceStr
  614. : d.noncestr != null && String(d.noncestr) !== ''
  615. ? d.noncestr
  616. : d.nonce;
  617. var signature = d.signature || d.sign;
  618. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  619. return null;
  620. }
  621. return {
  622. appId: String(appId),
  623. timestamp: Number(timestamp),
  624. nonceStr: String(nonceStr),
  625. signature: String(signature),
  626. signUrl: String(signUrlUsed || '')
  627. .split('#')[0]
  628. .trim()
  629. };
  630. }
  631. function getWxErrMsg(err) {
  632. if (!err) return '';
  633. if (err.errMsg) return String(err.errMsg);
  634. if (typeof err === 'string') return err;
  635. try {
  636. return JSON.stringify(err);
  637. } catch (e) {
  638. return String(err);
  639. }
  640. }
  641. function formatWxConfigErrorTip(err, signPageUrl) {
  642. var errMsg = getWxErrMsg(err);
  643. var tip = '微信 JSSDK 配置失败';
  644. if (/invalid signature/i.test(errMsg)) {
  645. return (
  646. tip +
  647. ':签名无效。请核对:①后端用与前端相同的 url 签名;②url=' +
  648. (signPageUrl || getWxHtmlUrl()) +
  649. ';③nonceStr/timestamp 与接口返回一致;④appId=' +
  650. WECHAT_MP_APP_ID
  651. );
  652. }
  653. if (/require\s*subscribe/i.test(errMsg)) {
  654. return tip + ':' + errMsg + '(服务号需用户已关注)';
  655. }
  656. return errMsg ? tip + ':' + errMsg : tip;
  657. }
  658. function setWxInitError(msg) {
  659. wxInitLastError = String(msg || '').trim();
  660. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  661. }
  662. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  663. var htmlUrl = String(
  664. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  665. )
  666. .split('#')[0]
  667. .trim();
  668. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  669. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  670. }
  671. if (isWxDebugOn()) {
  672. try {
  673. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  674. } catch (eDbg) {}
  675. }
  676. var requestUrl = getWxGetConfigApiUrl();
  677. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  678. console.log('[wx] htmlUrl=', htmlUrl);
  679. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  680. return fetch(requestUrl, {
  681. method: 'POST',
  682. mode: 'cors',
  683. credentials: 'omit',
  684. headers: {
  685. Accept: 'application/json',
  686. 'Content-Type': 'application/json;charset=UTF-8'
  687. },
  688. body: JSON.stringify(requestBody)
  689. })
  690. .then(function (r) {
  691. if (r.ok) return r.json();
  692. return r
  693. .text()
  694. .catch(function () {
  695. return '';
  696. })
  697. .then(function (text) {
  698. var hint = '';
  699. try {
  700. var j = JSON.parse(text);
  701. hint = j.msg || j.message || '';
  702. } catch (eP) {
  703. if (text) hint = text.slice(0, 120);
  704. }
  705. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  706. });
  707. })
  708. .then(function (res) {
  709. if (res && res.code != null) {
  710. var c = Number(res.code);
  711. if (c !== 200 && c !== 0 && res.success !== true) {
  712. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  713. }
  714. }
  715. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  716. if (!sign) {
  717. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  718. throw new Error(
  719. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  720. );
  721. }
  722. if (sign.appId !== WECHAT_MP_APP_ID) {
  723. console.warn(
  724. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  725. );
  726. }
  727. if (typeof wx === 'undefined') {
  728. if (isWxPcBrowser()) {
  729. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  730. return true;
  731. }
  732. setWxInitError('jweixin.js 未加载');
  733. return false;
  734. }
  735. return applyWxConfigFromSign(sign, htmlUrl);
  736. });
  737. }
  738. function applyWxConfigFromSign(sign, htmlUrl) {
  739. var wxConfigParams = {
  740. debug: isWxDebugOn(),
  741. appId: String(sign.appId),
  742. timestamp: sign.timestamp,
  743. nonceStr: String(sign.nonceStr),
  744. signature: String(sign.signature),
  745. jsApiList: [],
  746. openTagList: ['wx-open-launch-app']
  747. };
  748. return new Promise(function (resolve) {
  749. wx.config(wxConfigParams);
  750. wx.ready(function () {
  751. weChatJssdkConfigured = true;
  752. document.body.classList.add('wx-jssdk-ready');
  753. applyWxOpenLaunchSceneBodyClass();
  754. if (isWxOpenLaunchAppSceneSupported()) {
  755. refreshWxLaunchTagAttrs();
  756. }
  757. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  758. resolve(true);
  759. });
  760. wx.error(function (err) {
  761. weChatJssdkConfigured = false;
  762. document.body.classList.remove('wx-jssdk-ready');
  763. wxJssdkInitPromise = null;
  764. var errMsg = getWxErrMsg(err);
  765. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  766. if (isWxDebugOn()) window.alert(wxInitLastError);
  767. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  768. var baseUrl = getWxHtmlUrlBase();
  769. var fullUrl = getWxSignPageUrlForApi();
  770. if (
  771. !/invalid signature/i.test(errMsg) ||
  772. wxConfigSignRetriedBaseUrl ||
  773. baseUrl === fullUrl ||
  774. htmlUrl === baseUrl
  775. ) {
  776. resolve(false);
  777. return;
  778. }
  779. wxConfigSignRetriedBaseUrl = true;
  780. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  781. });
  782. });
  783. }
  784. function refreshWxLaunchTagAttrs() {
  785. var tag = document.getElementById('launch-btn');
  786. if (!tag) return;
  787. try {
  788. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  789. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
  790. } catch (eA) {}
  791. }
  792. function bindWeChatLaunchTagEvents() {
  793. var tag = document.getElementById('launch-btn');
  794. if (!tag || tag._wxLaunchBound) return;
  795. tag._wxLaunchBound = true;
  796. refreshWxLaunchTagAttrs();
  797. tag.addEventListener('launch', function () {
  798. console.log('[wx-open-launch-app] launch ok');
  799. showFabToast('正在打开 U店在哪…');
  800. });
  801. tag.addEventListener('error', function (e) {
  802. var detail = e && e.detail;
  803. var errMsg =
  804. detail && detail.errMsg
  805. ? String(detail.errMsg)
  806. : detail && detail.errmsg
  807. ? String(detail.errmsg)
  808. : '';
  809. console.warn('[wx-open-launch-app]', detail);
  810. if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
  811. showWxCopyLinkEntryTip();
  812. return;
  813. }
  814. showAppOpenFailTip(
  815. errMsg
  816. ? '未能唤起 App:' + errMsg
  817. : '未能唤起 App,请确认已安装 U店在哪,且开放平台已绑定服务号与移动应用。'
  818. );
  819. });
  820. }
  821. function initWeChatOpenLaunchApp(fromUserClick) {
  822. if (!shouldFetchWxConfig(!!fromUserClick)) {
  823. console.log('[wx] 未调用 getWxConfig');
  824. return Promise.resolve(false);
  825. }
  826. if (isWxPcBrowser()) {
  827. console.warn(
  828. '[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
  829. );
  830. }
  831. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  832. wxConfigSignRetriedBaseUrl = false;
  833. wxInitLastError = '';
  834. var htmlUrl = getWxConfigSignUrl();
  835. bindWeChatLaunchTagEvents();
  836. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  837. .then(function (ok) {
  838. if (ok === true) return true;
  839. if (!wxInitLastError) {
  840. setWxInitError('wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl');
  841. }
  842. return false;
  843. })
  844. .catch(function (e) {
  845. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  846. setWxInitError(msg);
  847. console.warn('[wx] requestWeChatJssdkSignAndConfig failed', msg, 'htmlUrl=', htmlUrl);
  848. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  849. return false;
  850. })
  851. .finally(function () {
  852. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  853. });
  854. return wxJssdkInitPromise;
  855. }
  856. /** 进页即尝试拉签名;jweixin 晚到时自动重试 */
  857. function scheduleWeChatJssdkBootstrap() {
  858. if (!shouldInitWeChatJssdkOnLoad()) return;
  859. var attempts = 0;
  860. function tick() {
  861. attempts += 1;
  862. if (weChatJssdkConfigured) return;
  863. initWeChatOpenLaunchApp();
  864. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
  865. setTimeout(tick, 400);
  866. }
  867. }
  868. tick();
  869. }
  870. function showFabToast(msg, ms) {
  871. var tip = String(msg || '').trim();
  872. if (!tip) return;
  873. var el = document.getElementById('openAppToast');
  874. if (el) {
  875. el.textContent = tip;
  876. el.style.display = 'block';
  877. if (showFabToast._t) clearTimeout(showFabToast._t);
  878. showFabToast._t = setTimeout(function () {
  879. el.style.display = 'none';
  880. }, ms || 2800);
  881. }
  882. console.log('[openApp]', tip);
  883. }
  884. function showAppOpenFailTip(msg) {
  885. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  886. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  887. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  888. } else if (isWeChatInAppBrowser()) {
  889. window.alert(tip);
  890. } else {
  891. console.warn('[openApp]', tip);
  892. }
  893. }
  894. function tryFetchWxConfigOnPcClick() {
  895. if (!isWxPcBrowser()) return Promise.resolve(false);
  896. showFabToast('正在请求 getWxConfig…');
  897. wxJssdkInitPromise = null;
  898. return initWeChatOpenLaunchApp(true).then(function (ok) {
  899. if (ok) {
  900. showFabToast(
  901. weChatJssdkConfigured
  902. ? 'getWxConfig 成功,wx.config 已就绪'
  903. : 'getWxConfig 成功'
  904. );
  905. } else {
  906. showFabToast(wxInitLastError || 'getWxConfig 失败');
  907. }
  908. return ok;
  909. });
  910. }
  911. function launchAppDeepLink(deepLink) {
  912. try {
  913. var a = document.createElement('a');
  914. a.href = deepLink;
  915. a.setAttribute('target', '_self');
  916. document.body.appendChild(a);
  917. a.click();
  918. document.body.removeChild(a);
  919. } catch (e1) {}
  920. try {
  921. window.location.href = deepLink;
  922. } catch (e2) {}
  923. }
  924. function tryOpenHBuilderApp() {
  925. /* 微信内须直接点击 wx-open-launch-app,scheme 会被拦截 */
  926. if (isWeChatInAppBrowser()) return;
  927. tryFetchWxConfigOnPcClick().then(function () {
  928. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  929. return;
  930. }
  931. tryOpenHBuilderAppViaScheme();
  932. });
  933. }
  934. function tryOpenHBuilderAppViaScheme() {
  935. showFabToast('正在打开 U店在哪…');
  936. var deepLink = buildAppDeepLink();
  937. if (typeof plus !== 'undefined' && plus.runtime) {
  938. var installed = null;
  939. try {
  940. if (typeof plus.runtime.isApplicationExist === 'function') {
  941. installed = plus.runtime.isApplicationExist({
  942. pname: APP_ANDROID_PACKAGE,
  943. action: APP_IOS_URL_SCHEME
  944. });
  945. }
  946. } catch (e) {
  947. console.warn(e);
  948. }
  949. if (installed === false) {
  950. showDownloadTip();
  951. return;
  952. }
  953. try {
  954. plus.runtime.openURL(deepLink);
  955. } catch (e2) {
  956. console.warn(e2);
  957. showDownloadTip();
  958. }
  959. return;
  960. }
  961. var done = false;
  962. function finish() {
  963. if (done) return;
  964. done = true;
  965. document.removeEventListener('visibilitychange', onVis);
  966. window.removeEventListener('pagehide', onHide);
  967. }
  968. function onVis() {
  969. if (document.visibilityState === 'hidden') finish();
  970. }
  971. function onHide() {
  972. finish();
  973. }
  974. document.addEventListener('visibilitychange', onVis);
  975. window.addEventListener('pagehide', onHide);
  976. try {
  977. launchAppDeepLink(deepLink);
  978. } catch (e3) {
  979. finish();
  980. showDownloadTip();
  981. return;
  982. }
  983. window.setTimeout(function () {
  984. finish();
  985. }, 2600);
  986. }
  987. function isApiOk(res) {
  988. if (!res || typeof res !== 'object') return false;
  989. if (res.success === false) return false;
  990. var c = res.code;
  991. return c === 200 || c === '200' || Number(c) === 200;
  992. }
  993. function fetchStoreGlobalRecommend() {
  994. var latRaw = (q('userLat') || q('latitude') || q('lat') || q('weidu')).trim();
  995. var lngRaw = (q('userLng') || q('longitude') || q('lon') || q('jingdu')).trim();
  996. var userLat =
  997. latRaw !== '' && !isNaN(Number(latRaw)) ? Number(latRaw) : DEFAULT_USER_LAT;
  998. var userLng =
  999. lngRaw !== '' && !isNaN(Number(lngRaw)) ? Number(lngRaw) : DEFAULT_USER_LNG;
  1000. var page = parseInt(q('page') || '1', 10);
  1001. var pageSize = parseInt(q('pageSize') || '10', 10);
  1002. if (isNaN(page) || page < 1) page = 1;
  1003. if (isNaN(pageSize) || pageSize < 1) pageSize = 10;
  1004. var storeIdRaw = (q('storeId') || q('id') || '').trim();
  1005. var storeId = storeIdRaw !== '' ? storeIdRaw : DEFAULT_STORE_ID;
  1006. var userCityRaw = (q('userCity') || q('city') || '').trim();
  1007. var userCity = userCityRaw !== '' ? userCityRaw : DEFAULT_USER_CITY;
  1008. var body = {
  1009. page: page,
  1010. pageSize: pageSize,
  1011. storeId: String(storeId),
  1012. userCity: userCity,
  1013. userLat: userLat,
  1014. userLng: userLng
  1015. };
  1016. return fetch(API_LIFE_AI_BASE + STORE_GLOBAL_RECOMMEND_PATH, {
  1017. method: 'POST',
  1018. mode: 'cors',
  1019. credentials: 'omit',
  1020. headers: {
  1021. Accept: 'application/json',
  1022. 'Content-Type': 'application/json;charset=UTF-8'
  1023. },
  1024. body: JSON.stringify(body)
  1025. }).then(function (res) {
  1026. if (!res.ok) throw new Error('HTTP ' + res.status);
  1027. return res.json();
  1028. });
  1029. }
  1030. function normalizeStoreRecommendList(res) {
  1031. if (!res || typeof res !== 'object') return [];
  1032. var raw = res.data != null ? res.data : res.result;
  1033. if (Array.isArray(raw)) return raw;
  1034. if (raw && typeof raw === 'object') {
  1035. if (Array.isArray(raw.list)) return raw.list;
  1036. if (Array.isArray(raw.records)) return raw.records;
  1037. if (Array.isArray(raw.rows)) return raw.rows;
  1038. if (Array.isArray(raw.content)) return raw.content;
  1039. if (Array.isArray(raw.stores)) return raw.stores;
  1040. if (Array.isArray(raw.storeList)) return raw.storeList;
  1041. if (Array.isArray(raw.storeVos)) return raw.storeVos;
  1042. if (Array.isArray(raw.items)) return raw.items;
  1043. }
  1044. if (Array.isArray(res.list)) return res.list;
  1045. if (Array.isArray(res.records)) return res.records;
  1046. return [];
  1047. }
  1048. function formatRecDistance(item) {
  1049. /** 后端 distance 为千米,展示为米 */
  1050. if (item.distance != null && item.distance !== '') {
  1051. var km = Number(item.distance);
  1052. if (!isNaN(km) && km >= 0) {
  1053. return Math.round(km * 1000) + '米';
  1054. }
  1055. return String(item.distance).trim();
  1056. }
  1057. if (item.position != null && String(item.position).trim() !== '') {
  1058. return String(item.position).trim();
  1059. }
  1060. if (item.dist != null && item.dist !== '') {
  1061. var dn = Number(item.dist);
  1062. if (!isNaN(dn)) {
  1063. return dn >= 1 ? dn.toFixed(dn % 1 === 0 ? 0 : 1) + 'km' : Math.round(dn * 1000) + '米';
  1064. }
  1065. }
  1066. return '';
  1067. }
  1068. function escHtml(s) {
  1069. return String(s == null ? '' : s)
  1070. .replace(/&/g, '&amp;')
  1071. .replace(/</g, '&lt;')
  1072. .replace(/>/g, '&gt;')
  1073. .replace(/"/g, '&quot;');
  1074. }
  1075. var STAR_PATH = 'M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z';
  1076. function starsHtml(score) {
  1077. var s = Number(score);
  1078. if (isNaN(s)) s = 0;
  1079. s = Math.max(0, Math.min(5, s));
  1080. var rounded = Math.round(s);
  1081. var parts = [];
  1082. var i;
  1083. for (i = 1; i <= 5; i++) {
  1084. var fill = i <= rounded ? '#F58220' : '#E5E5E5';
  1085. parts.push(
  1086. '<svg class="rec-star" width="11" height="11" viewBox="0 0 24 24" aria-hidden="true">' +
  1087. '<path fill="' + fill + '" d="' + STAR_PATH + '"/></svg>'
  1088. );
  1089. }
  1090. return '<span class="stars">' + parts.join('') + '</span>';
  1091. }
  1092. function pickScore(item) {
  1093. var x =
  1094. item.scoreAvg != null ? Number(item.scoreAvg)
  1095. : item.score != null ? Number(item.score)
  1096. : item.rating != null ? Number(item.rating)
  1097. : item.starScore != null ? Number(item.starScore)
  1098. : NaN;
  1099. return isNaN(x) ? null : x;
  1100. }
  1101. function pickReviewCount(item) {
  1102. var n =
  1103. item.commitCount != null ? Number(item.commitCount)
  1104. : item.commentCount != null ? Number(item.commentCount)
  1105. : item.reviewCount != null ? Number(item.reviewCount)
  1106. : item.evaluateCount != null ? Number(item.evaluateCount)
  1107. : NaN;
  1108. return isNaN(n) ? 0 : Math.max(0, Math.floor(n));
  1109. }
  1110. function renderRecommended(list) {
  1111. var wrap = document.getElementById('recList');
  1112. var empty = document.getElementById('recEmpty');
  1113. wrap.querySelectorAll('.rec-card').forEach(function (n) {
  1114. n.remove();
  1115. });
  1116. if (!list || !list.length) {
  1117. empty.style.display = 'block';
  1118. return;
  1119. }
  1120. empty.style.display = 'none';
  1121. list.forEach(function (item) {
  1122. if (!item || typeof item !== 'object') return;
  1123. var imgUrlField = item.imgUrl != null ? String(item.imgUrl).trim() : '';
  1124. var home = item.homeImage != null ? String(item.homeImage).trim() : '';
  1125. if (home && /\.mp4(\?|#|$)/i.test(home)) {
  1126. var vf = item.videoFirstFrame != null ? String(item.videoFirstFrame).trim() : '';
  1127. if (vf) home = vf;
  1128. }
  1129. var imgUrl =
  1130. imgUrlField ||
  1131. home ||
  1132. (item.coverUrl != null ? String(item.coverUrl).trim() : '') ||
  1133. (item.mainImage != null ? String(item.mainImage).trim() : '') ||
  1134. (item.goodsImage != null ? String(item.goodsImage).trim() : '') ||
  1135. (item.entranceImage != null ? String(item.entranceImage).trim() : '') ||
  1136. (Array.isArray(item.goodsImageList) && item.goodsImageList[0]) ||
  1137. (Array.isArray(item.imageList) && item.imageList[0]) ||
  1138. (Array.isArray(item.storeAlbumUrlList) && item.storeAlbumUrlList[0]) ||
  1139. '';
  1140. var name = item.title != null && String(item.title).trim() !== ''
  1141. ? String(item.title).replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').trim()
  1142. : (item.storeName || item.goodsName || item.secondGoodsTitle || item.name || '推荐');
  1143. var dist = formatRecDistance(item);
  1144. var scoreVal = pickScore(item);
  1145. var displayScore = scoreVal != null ? scoreVal.toFixed(1) : '—';
  1146. var starScore = scoreVal != null ? scoreVal : 0;
  1147. var rc = pickReviewCount(item);
  1148. var reviewLabel = rc > 0 ? rc + '条评价' : '';
  1149. var seller =
  1150. item.userName != null && String(item.userName).trim() !== ''
  1151. ? String(item.userName).trim()
  1152. : (item.nickName != null && String(item.nickName).trim() !== ''
  1153. ? String(item.nickName).trim()
  1154. : '');
  1155. var card = document.createElement('article');
  1156. card.className = 'rec-card';
  1157. card.innerHTML =
  1158. '<div class="rec-card__img"><img class="rec-card__cover" src="" alt="" decoding="async"></div>' +
  1159. '<div class="rec-card__body">' +
  1160. '<div class="rec-card__top">' +
  1161. '<span class="rec-card__name">' + escHtml(name) + '</span>' +
  1162. (dist ? '<span class="rec-card__dist">' + escHtml(dist) + '</span>' : '') +
  1163. '</div>' +
  1164. '<div class="rec-card__rating">' +
  1165. starsHtml(starScore) +
  1166. '<span class="rating-num">' + escHtml(displayScore) + '</span>' +
  1167. (reviewLabel ? '<span class="rec-meta">' + escHtml(reviewLabel) + '</span>' : '') +
  1168. '</div>' +
  1169. (seller ? '<div class="rec-card__footer">' + escHtml(seller) + '</div>' : '') +
  1170. '</div>';
  1171. var coverIm = card.querySelector('img.rec-card__cover');
  1172. if (coverIm) {
  1173. coverIm.src = imgUrl;
  1174. coverIm.onerror = function () {
  1175. this.onerror = null;
  1176. this.src = '';
  1177. };
  1178. }
  1179. wrap.appendChild(card);
  1180. });
  1181. }
  1182. function run() {
  1183. fetchStoreGlobalRecommend()
  1184. .then(function (res) {
  1185. var list = normalizeStoreRecommendList(res);
  1186. if (!list.length && res && res.msg) {
  1187. console.warn('[store-recommend]', res.msg);
  1188. }
  1189. renderRecommended(list);
  1190. })
  1191. .catch(function (e) {
  1192. console.error(e);
  1193. renderRecommended([]);
  1194. });
  1195. }
  1196. function boot() {
  1197. var launchTag = document.getElementById('launch-btn');
  1198. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1199. bindWeChatLaunchTagEvents();
  1200. if (shouldInitWeChatJssdkOnLoad()) {
  1201. if (isWeChatInAppBrowser()) {
  1202. document.body.classList.add('is-wechat');
  1203. applyWxOpenLaunchSceneBodyClass();
  1204. logWxEntryDiagnostics();
  1205. }
  1206. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1207. document.body.classList.add('wx-pc-debug');
  1208. }
  1209. scheduleWeChatJssdkBootstrap();
  1210. }
  1211. document.addEventListener('WeixinOpenTagsError', function (e) {
  1212. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1213. applyWxOpenLaunchSceneBodyClass();
  1214. });
  1215. applyEmptyHeroState();
  1216. run();
  1217. if (isWeChatInAppBrowser()) {
  1218. var openBtnWx = document.getElementById('openApp');
  1219. if (openBtnWx) {
  1220. openBtnWx.addEventListener('click', function () {
  1221. if (!weChatJssdkConfigured) {
  1222. showFabToast(
  1223. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1224. );
  1225. return;
  1226. }
  1227. if (!isWxOpenLaunchAppSceneSupported()) {
  1228. showWxCopyLinkEntryTip();
  1229. }
  1230. });
  1231. }
  1232. } else {
  1233. var openBtn = document.getElementById('openApp');
  1234. if (openBtn) {
  1235. openBtn.addEventListener('click', tryOpenHBuilderApp);
  1236. }
  1237. }
  1238. }
  1239. if (document.readyState === 'complete') {
  1240. boot();
  1241. } else {
  1242. window.onload = boot;
  1243. }
  1244. })();
  1245. </script>
  1246. </body>
  1247. </html>