shareCheckInUndefined.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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 isIOSWeChatBrowser() {
  516. var ua = navigator.userAgent || '';
  517. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  518. }
  519. function logWxEntryDiagnostics() {
  520. if (!isWeChatInAppBrowser()) return;
  521. console.log('[wx-entry]', {
  522. entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
  523. openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
  524. signUrl: getWxConfigSignUrl()
  525. });
  526. }
  527. function showWxCopyLinkEntryTip() {
  528. showFabToast(
  529. '当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
  530. );
  531. }
  532. function readQueryParam(name) {
  533. return q(name);
  534. }
  535. function isWxDebugOn() {
  536. return readQueryParam('wxDebug') === '1';
  537. }
  538. function isWxForceDebug() {
  539. return readQueryParam('wxForce') === '1';
  540. }
  541. function isWxConfigOnClickDebug() {
  542. return readQueryParam('wxConfigOnClick') === '1';
  543. }
  544. function isWxPcAutoDebugHost() {
  545. var h = (location.hostname || '').toLowerCase();
  546. if (h === 'localhost' || h === '127.0.0.1') return true;
  547. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  548. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  549. }
  550. return false;
  551. }
  552. function isWxPcBrowser() {
  553. return !isWeChatInAppBrowser();
  554. }
  555. function shouldInitWeChatJssdkOnLoad() {
  556. if (isWeChatInAppBrowser()) return true;
  557. return isWxForceDebug() || isWxPcAutoDebugHost();
  558. }
  559. function shouldFetchWxConfig(fromUserClick) {
  560. if (isWeChatInAppBrowser()) return true;
  561. if (fromUserClick) return true;
  562. return isWxForceDebug() || isWxPcAutoDebugHost();
  563. }
  564. function getWxHtmlUrl() {
  565. var forced = String(q('wxSignUrl') || '').trim();
  566. if (forced) return forced.split('#')[0];
  567. return String(location.href || '').split('#')[0];
  568. }
  569. function getWxSignPageUrlForApi() {
  570. var htmlUrl = getWxHtmlUrl();
  571. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  572. return WX_GET_CONFIG_SIGN_URL;
  573. }
  574. function getWxHtmlUrlBase() {
  575. var htmlUrl = getWxSignPageUrlForApi();
  576. try {
  577. var u = new URL(htmlUrl);
  578. return u.origin + u.pathname;
  579. } catch (eU) {
  580. return WX_GET_CONFIG_SIGN_URL;
  581. }
  582. }
  583. function getWxConfigSignUrl() {
  584. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  585. return getWxSignPageUrlForApi();
  586. }
  587. function getWxGetConfigApiUrl() {
  588. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  589. }
  590. function buildWxGetConfigRequestBody(htmlUrl) {
  591. return {
  592. url: String(htmlUrl || '').split('#')[0].trim()
  593. };
  594. }
  595. function resolveWxConfigAppIdFromSignData(d) {
  596. if (!d || typeof d !== 'object') return '';
  597. var mp =
  598. d.mpAppId ||
  599. d.mpAppid ||
  600. d.officialAppId ||
  601. d.gzhAppId ||
  602. d.serviceAppId;
  603. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  604. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  605. if (fromQuery) return fromQuery;
  606. var raw = d.appId || d.appid || d.wxAppId;
  607. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  608. }
  609. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  610. if (!res || typeof res !== 'object') return null;
  611. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  612. if (!d || typeof d !== 'object') return null;
  613. var appId = resolveWxConfigAppIdFromSignData(d);
  614. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  615. var nonceStr =
  616. d.nonceStr != null && String(d.nonceStr) !== ''
  617. ? d.nonceStr
  618. : d.noncestr != null && String(d.noncestr) !== ''
  619. ? d.noncestr
  620. : d.nonce;
  621. var signature = d.signature || d.sign;
  622. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  623. return null;
  624. }
  625. return {
  626. appId: String(appId),
  627. timestamp: Number(timestamp),
  628. nonceStr: String(nonceStr),
  629. signature: String(signature),
  630. signUrl: String(signUrlUsed || '')
  631. .split('#')[0]
  632. .trim()
  633. };
  634. }
  635. function getWxErrMsg(err) {
  636. if (!err) return '';
  637. if (err.errMsg) return String(err.errMsg);
  638. if (typeof err === 'string') return err;
  639. try {
  640. return JSON.stringify(err);
  641. } catch (e) {
  642. return String(err);
  643. }
  644. }
  645. function formatWxConfigErrorTip(err, signPageUrl) {
  646. var errMsg = getWxErrMsg(err);
  647. var tip = '微信 JSSDK 配置失败';
  648. if (/invalid signature/i.test(errMsg)) {
  649. return (
  650. tip +
  651. ':签名无效。请核对:①后端用与前端相同的 url 签名;②url=' +
  652. (signPageUrl || getWxHtmlUrl()) +
  653. ';③nonceStr/timestamp 与接口返回一致;④appId=' +
  654. WECHAT_MP_APP_ID
  655. );
  656. }
  657. if (/require\s*subscribe/i.test(errMsg)) {
  658. return tip + ':' + errMsg + '(服务号需用户已关注)';
  659. }
  660. return errMsg ? tip + ':' + errMsg : tip;
  661. }
  662. function setWxInitError(msg) {
  663. wxInitLastError = String(msg || '').trim();
  664. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  665. }
  666. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  667. var htmlUrl = String(
  668. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  669. )
  670. .split('#')[0]
  671. .trim();
  672. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  673. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  674. }
  675. if (isWxDebugOn()) {
  676. try {
  677. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  678. } catch (eDbg) {}
  679. }
  680. var requestUrl = getWxGetConfigApiUrl();
  681. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  682. console.log('[wx] htmlUrl=', htmlUrl);
  683. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  684. return fetch(requestUrl, {
  685. method: 'POST',
  686. mode: 'cors',
  687. credentials: 'omit',
  688. headers: {
  689. Accept: 'application/json',
  690. 'Content-Type': 'application/json;charset=UTF-8'
  691. },
  692. body: JSON.stringify(requestBody)
  693. })
  694. .then(function (r) {
  695. if (r.ok) return r.json();
  696. return r
  697. .text()
  698. .catch(function () {
  699. return '';
  700. })
  701. .then(function (text) {
  702. var hint = '';
  703. try {
  704. var j = JSON.parse(text);
  705. hint = j.msg || j.message || '';
  706. } catch (eP) {
  707. if (text) hint = text.slice(0, 120);
  708. }
  709. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  710. });
  711. })
  712. .then(function (res) {
  713. if (res && res.code != null) {
  714. var c = Number(res.code);
  715. if (c !== 200 && c !== 0 && res.success !== true) {
  716. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  717. }
  718. }
  719. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  720. if (!sign) {
  721. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  722. throw new Error(
  723. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  724. );
  725. }
  726. if (sign.appId !== WECHAT_MP_APP_ID) {
  727. console.warn(
  728. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  729. );
  730. }
  731. if (typeof wx === 'undefined') {
  732. if (isWxPcBrowser()) {
  733. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  734. return true;
  735. }
  736. setWxInitError('jweixin.js 未加载');
  737. return false;
  738. }
  739. return applyWxConfigFromSign(sign, htmlUrl);
  740. });
  741. }
  742. function applyWxConfigFromSign(sign, htmlUrl) {
  743. var wxConfigParams = {
  744. debug: isWxDebugOn(),
  745. appId: String(sign.appId),
  746. timestamp: sign.timestamp,
  747. nonceStr: String(sign.nonceStr),
  748. signature: String(sign.signature),
  749. jsApiList: [],
  750. openTagList: ['wx-open-launch-app']
  751. };
  752. return new Promise(function (resolve) {
  753. wx.config(wxConfigParams);
  754. wx.ready(function () {
  755. weChatJssdkConfigured = true;
  756. document.body.classList.add('wx-jssdk-ready');
  757. applyWxOpenLaunchSceneBodyClass();
  758. if (isWxOpenLaunchAppSceneSupported()) {
  759. refreshWxLaunchTagAttrs();
  760. }
  761. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  762. resolve(true);
  763. });
  764. wx.error(function (err) {
  765. weChatJssdkConfigured = false;
  766. document.body.classList.remove('wx-jssdk-ready');
  767. wxJssdkInitPromise = null;
  768. var errMsg = getWxErrMsg(err);
  769. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  770. if (isWxDebugOn()) window.alert(wxInitLastError);
  771. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  772. var baseUrl = getWxHtmlUrlBase();
  773. var fullUrl = getWxSignPageUrlForApi();
  774. if (
  775. !/invalid signature/i.test(errMsg) ||
  776. wxConfigSignRetriedBaseUrl ||
  777. baseUrl === fullUrl ||
  778. htmlUrl === baseUrl
  779. ) {
  780. resolve(false);
  781. return;
  782. }
  783. wxConfigSignRetriedBaseUrl = true;
  784. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  785. });
  786. });
  787. }
  788. function refreshWxLaunchTagAttrs() {
  789. var tag = document.getElementById('launch-btn');
  790. if (!tag) return;
  791. try {
  792. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  793. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
  794. } catch (eA) {}
  795. }
  796. function bindWeChatLaunchTagEvents() {
  797. var tag = document.getElementById('launch-btn');
  798. if (!tag || tag._wxLaunchBound) return;
  799. tag._wxLaunchBound = true;
  800. refreshWxLaunchTagAttrs();
  801. tag.addEventListener('launch', function () {
  802. console.log('[wx-open-launch-app] launch ok');
  803. // showFabToast('正在打开 U店在哪…');
  804. });
  805. tag.addEventListener('error', function (e) {
  806. var detail = e && e.detail;
  807. var errMsg =
  808. detail && detail.errMsg
  809. ? String(detail.errMsg)
  810. : detail && detail.errmsg
  811. ? String(detail.errmsg)
  812. : '';
  813. console.warn('[wx-open-launch-app]', detail);
  814. showAppOpenFailTip(
  815. '请确复制链接进入U店在哪'
  816. );
  817. });
  818. }
  819. function initWeChatOpenLaunchApp(fromUserClick) {
  820. if (!shouldFetchWxConfig(!!fromUserClick)) {
  821. console.log('[wx] 未调用 getWxConfig');
  822. return Promise.resolve(false);
  823. }
  824. if (isWxPcBrowser()) {
  825. console.warn(
  826. '[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
  827. );
  828. }
  829. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  830. wxConfigSignRetriedBaseUrl = false;
  831. wxInitLastError = '';
  832. var htmlUrl = getWxConfigSignUrl();
  833. bindWeChatLaunchTagEvents();
  834. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  835. .then(function (ok) {
  836. if (ok === true) return true;
  837. if (!wxInitLastError) {
  838. setWxInitError('wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl');
  839. }
  840. return false;
  841. })
  842. .catch(function (e) {
  843. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  844. setWxInitError(msg);
  845. console.warn('[wx] requestWeChatJssdkSignAndConfig failed', msg, 'htmlUrl=', htmlUrl);
  846. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  847. return false;
  848. })
  849. .finally(function () {
  850. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  851. });
  852. return wxJssdkInitPromise;
  853. }
  854. /** 进页即尝试拉签名;jweixin 晚到时自动重试 */
  855. function scheduleWeChatJssdkBootstrap() {
  856. if (!shouldInitWeChatJssdkOnLoad()) return;
  857. var attempts = 0;
  858. function tick() {
  859. attempts += 1;
  860. if (weChatJssdkConfigured) return;
  861. initWeChatOpenLaunchApp();
  862. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
  863. setTimeout(tick, 400);
  864. }
  865. }
  866. if (isIOSWeChatBrowser()) {
  867. setTimeout(tick, 350);
  868. } else {
  869. tick();
  870. }
  871. }
  872. function showFabToast(msg, ms) {
  873. var tip = String(msg || '').trim();
  874. if (!tip) return;
  875. var el = document.getElementById('openAppToast');
  876. if (el) {
  877. el.textContent = tip;
  878. el.style.display = 'block';
  879. if (showFabToast._t) clearTimeout(showFabToast._t);
  880. showFabToast._t = setTimeout(function () {
  881. el.style.display = 'none';
  882. }, ms || 2800);
  883. }
  884. console.log('[openApp]', tip);
  885. }
  886. function showAppOpenFailTip(msg) {
  887. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  888. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  889. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  890. } else if (isWeChatInAppBrowser()) {
  891. window.alert(tip);
  892. } else {
  893. console.warn('[openApp]', tip);
  894. }
  895. }
  896. function tryFetchWxConfigOnPcClick() {
  897. if (!isWxPcBrowser()) return Promise.resolve(false);
  898. showFabToast('正在请求 getWxConfig…');
  899. wxJssdkInitPromise = null;
  900. return initWeChatOpenLaunchApp(true).then(function (ok) {
  901. if (ok) {
  902. showFabToast(
  903. weChatJssdkConfigured
  904. ? 'getWxConfig 成功,wx.config 已就绪'
  905. : 'getWxConfig 成功'
  906. );
  907. } else {
  908. showFabToast(wxInitLastError || 'getWxConfig 失败');
  909. }
  910. return ok;
  911. });
  912. }
  913. function launchAppDeepLink(deepLink) {
  914. try {
  915. var a = document.createElement('a');
  916. a.href = deepLink;
  917. a.setAttribute('target', '_self');
  918. document.body.appendChild(a);
  919. a.click();
  920. document.body.removeChild(a);
  921. } catch (e1) {}
  922. try {
  923. window.location.href = deepLink;
  924. } catch (e2) {}
  925. }
  926. function tryOpenHBuilderApp() {
  927. /* 微信内须直接点击 wx-open-launch-app,scheme 会被拦截 */
  928. if (isWeChatInAppBrowser()) return;
  929. tryFetchWxConfigOnPcClick().then(function () {
  930. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  931. return;
  932. }
  933. tryOpenHBuilderAppViaScheme();
  934. });
  935. }
  936. function tryOpenHBuilderAppViaScheme() {
  937. // showFabToast('正在打开 U店在哪…');
  938. var deepLink = buildAppDeepLink();
  939. if (typeof plus !== 'undefined' && plus.runtime) {
  940. var installed = null;
  941. try {
  942. if (typeof plus.runtime.isApplicationExist === 'function') {
  943. installed = plus.runtime.isApplicationExist({
  944. pname: APP_ANDROID_PACKAGE,
  945. action: APP_IOS_URL_SCHEME
  946. });
  947. }
  948. } catch (e) {
  949. console.warn(e);
  950. }
  951. if (installed === false) {
  952. showDownloadTip();
  953. return;
  954. }
  955. try {
  956. plus.runtime.openURL(deepLink);
  957. } catch (e2) {
  958. console.warn(e2);
  959. showDownloadTip();
  960. }
  961. return;
  962. }
  963. var done = false;
  964. function finish() {
  965. if (done) return;
  966. done = true;
  967. document.removeEventListener('visibilitychange', onVis);
  968. window.removeEventListener('pagehide', onHide);
  969. }
  970. function onVis() {
  971. if (document.visibilityState === 'hidden') finish();
  972. }
  973. function onHide() {
  974. finish();
  975. }
  976. document.addEventListener('visibilitychange', onVis);
  977. window.addEventListener('pagehide', onHide);
  978. try {
  979. launchAppDeepLink(deepLink);
  980. } catch (e3) {
  981. finish();
  982. showDownloadTip();
  983. return;
  984. }
  985. window.setTimeout(function () {
  986. finish();
  987. }, 2600);
  988. }
  989. function isApiOk(res) {
  990. if (!res || typeof res !== 'object') return false;
  991. if (res.success === false) return false;
  992. var c = res.code;
  993. return c === 200 || c === '200' || Number(c) === 200;
  994. }
  995. function fetchStoreGlobalRecommend() {
  996. var latRaw = (q('userLat') || q('latitude') || q('lat') || q('weidu')).trim();
  997. var lngRaw = (q('userLng') || q('longitude') || q('lon') || q('jingdu')).trim();
  998. var userLat =
  999. latRaw !== '' && !isNaN(Number(latRaw)) ? Number(latRaw) : DEFAULT_USER_LAT;
  1000. var userLng =
  1001. lngRaw !== '' && !isNaN(Number(lngRaw)) ? Number(lngRaw) : DEFAULT_USER_LNG;
  1002. var page = parseInt(q('page') || '1', 10);
  1003. var pageSize = parseInt(q('pageSize') || '10', 10);
  1004. if (isNaN(page) || page < 1) page = 1;
  1005. if (isNaN(pageSize) || pageSize < 1) pageSize = 10;
  1006. var storeIdRaw = (q('storeId') || q('id') || '').trim();
  1007. var storeId = storeIdRaw !== '' ? storeIdRaw : DEFAULT_STORE_ID;
  1008. var userCityRaw = (q('userCity') || q('city') || '').trim();
  1009. var userCity = userCityRaw !== '' ? userCityRaw : DEFAULT_USER_CITY;
  1010. var body = {
  1011. page: page,
  1012. pageSize: pageSize,
  1013. storeId: String(storeId),
  1014. userCity: userCity,
  1015. userLat: userLat,
  1016. userLng: userLng
  1017. };
  1018. return fetch(API_LIFE_AI_BASE + STORE_GLOBAL_RECOMMEND_PATH, {
  1019. method: 'POST',
  1020. mode: 'cors',
  1021. credentials: 'omit',
  1022. headers: {
  1023. Accept: 'application/json',
  1024. 'Content-Type': 'application/json;charset=UTF-8'
  1025. },
  1026. body: JSON.stringify(body)
  1027. }).then(function (res) {
  1028. if (!res.ok) throw new Error('HTTP ' + res.status);
  1029. return res.json();
  1030. });
  1031. }
  1032. function normalizeStoreRecommendList(res) {
  1033. if (!res || typeof res !== 'object') return [];
  1034. var raw = res.data != null ? res.data : res.result;
  1035. if (Array.isArray(raw)) return raw;
  1036. if (raw && typeof raw === 'object') {
  1037. if (Array.isArray(raw.list)) return raw.list;
  1038. if (Array.isArray(raw.records)) return raw.records;
  1039. if (Array.isArray(raw.rows)) return raw.rows;
  1040. if (Array.isArray(raw.content)) return raw.content;
  1041. if (Array.isArray(raw.stores)) return raw.stores;
  1042. if (Array.isArray(raw.storeList)) return raw.storeList;
  1043. if (Array.isArray(raw.storeVos)) return raw.storeVos;
  1044. if (Array.isArray(raw.items)) return raw.items;
  1045. }
  1046. if (Array.isArray(res.list)) return res.list;
  1047. if (Array.isArray(res.records)) return res.records;
  1048. return [];
  1049. }
  1050. function formatRecDistance(item) {
  1051. /** 后端 distance 为千米,展示为米 */
  1052. if (item.distance != null && item.distance !== '') {
  1053. var km = Number(item.distance);
  1054. if (!isNaN(km) && km >= 0) {
  1055. return Math.round(km * 1000) + '米';
  1056. }
  1057. return String(item.distance).trim();
  1058. }
  1059. if (item.position != null && String(item.position).trim() !== '') {
  1060. return String(item.position).trim();
  1061. }
  1062. if (item.dist != null && item.dist !== '') {
  1063. var dn = Number(item.dist);
  1064. if (!isNaN(dn)) {
  1065. return dn >= 1 ? dn.toFixed(dn % 1 === 0 ? 0 : 1) + 'km' : Math.round(dn * 1000) + '米';
  1066. }
  1067. }
  1068. return '';
  1069. }
  1070. function escHtml(s) {
  1071. return String(s == null ? '' : s)
  1072. .replace(/&/g, '&amp;')
  1073. .replace(/</g, '&lt;')
  1074. .replace(/>/g, '&gt;')
  1075. .replace(/"/g, '&quot;');
  1076. }
  1077. 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';
  1078. function starsHtml(score) {
  1079. var s = Number(score);
  1080. if (isNaN(s)) s = 0;
  1081. s = Math.max(0, Math.min(5, s));
  1082. var rounded = Math.round(s);
  1083. var parts = [];
  1084. var i;
  1085. for (i = 1; i <= 5; i++) {
  1086. var fill = i <= rounded ? '#F58220' : '#E5E5E5';
  1087. parts.push(
  1088. '<svg class="rec-star" width="11" height="11" viewBox="0 0 24 24" aria-hidden="true">' +
  1089. '<path fill="' + fill + '" d="' + STAR_PATH + '"/></svg>'
  1090. );
  1091. }
  1092. return '<span class="stars">' + parts.join('') + '</span>';
  1093. }
  1094. function pickScore(item) {
  1095. var x =
  1096. item.scoreAvg != null ? Number(item.scoreAvg)
  1097. : item.score != null ? Number(item.score)
  1098. : item.rating != null ? Number(item.rating)
  1099. : item.starScore != null ? Number(item.starScore)
  1100. : NaN;
  1101. return isNaN(x) ? null : x;
  1102. }
  1103. function pickReviewCount(item) {
  1104. var n =
  1105. item.commitCount != null ? Number(item.commitCount)
  1106. : item.commentCount != null ? Number(item.commentCount)
  1107. : item.reviewCount != null ? Number(item.reviewCount)
  1108. : item.evaluateCount != null ? Number(item.evaluateCount)
  1109. : NaN;
  1110. return isNaN(n) ? 0 : Math.max(0, Math.floor(n));
  1111. }
  1112. function renderRecommended(list) {
  1113. var wrap = document.getElementById('recList');
  1114. var empty = document.getElementById('recEmpty');
  1115. wrap.querySelectorAll('.rec-card').forEach(function (n) {
  1116. n.remove();
  1117. });
  1118. if (!list || !list.length) {
  1119. empty.style.display = 'block';
  1120. return;
  1121. }
  1122. empty.style.display = 'none';
  1123. list.forEach(function (item) {
  1124. if (!item || typeof item !== 'object') return;
  1125. var imgUrlField = item.imgUrl != null ? String(item.imgUrl).trim() : '';
  1126. var home = item.homeImage != null ? String(item.homeImage).trim() : '';
  1127. if (home && /\.mp4(\?|#|$)/i.test(home)) {
  1128. var vf = item.videoFirstFrame != null ? String(item.videoFirstFrame).trim() : '';
  1129. if (vf) home = vf;
  1130. }
  1131. var imgUrl =
  1132. imgUrlField ||
  1133. home ||
  1134. (item.coverUrl != null ? String(item.coverUrl).trim() : '') ||
  1135. (item.mainImage != null ? String(item.mainImage).trim() : '') ||
  1136. (item.goodsImage != null ? String(item.goodsImage).trim() : '') ||
  1137. (item.entranceImage != null ? String(item.entranceImage).trim() : '') ||
  1138. (Array.isArray(item.goodsImageList) && item.goodsImageList[0]) ||
  1139. (Array.isArray(item.imageList) && item.imageList[0]) ||
  1140. (Array.isArray(item.storeAlbumUrlList) && item.storeAlbumUrlList[0]) ||
  1141. '';
  1142. var name = item.title != null && String(item.title).trim() !== ''
  1143. ? String(item.title).replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').trim()
  1144. : (item.storeName || item.goodsName || item.secondGoodsTitle || item.name || '推荐');
  1145. var dist = formatRecDistance(item);
  1146. var scoreVal = pickScore(item);
  1147. var displayScore = scoreVal != null ? scoreVal.toFixed(1) : '—';
  1148. var starScore = scoreVal != null ? scoreVal : 0;
  1149. var rc = pickReviewCount(item);
  1150. var reviewLabel = rc > 0 ? rc + '条评价' : '';
  1151. var seller =
  1152. item.userName != null && String(item.userName).trim() !== ''
  1153. ? String(item.userName).trim()
  1154. : (item.nickName != null && String(item.nickName).trim() !== ''
  1155. ? String(item.nickName).trim()
  1156. : '');
  1157. var card = document.createElement('article');
  1158. card.className = 'rec-card';
  1159. card.innerHTML =
  1160. '<div class="rec-card__img"><img class="rec-card__cover" src="" alt="" decoding="async"></div>' +
  1161. '<div class="rec-card__body">' +
  1162. '<div class="rec-card__top">' +
  1163. '<span class="rec-card__name">' + escHtml(name) + '</span>' +
  1164. (dist ? '<span class="rec-card__dist">' + escHtml(dist) + '</span>' : '') +
  1165. '</div>' +
  1166. '<div class="rec-card__rating">' +
  1167. starsHtml(starScore) +
  1168. '<span class="rating-num">' + escHtml(displayScore) + '</span>' +
  1169. (reviewLabel ? '<span class="rec-meta">' + escHtml(reviewLabel) + '</span>' : '') +
  1170. '</div>' +
  1171. (seller ? '<div class="rec-card__footer">' + escHtml(seller) + '</div>' : '') +
  1172. '</div>';
  1173. var coverIm = card.querySelector('img.rec-card__cover');
  1174. if (coverIm) {
  1175. coverIm.src = imgUrl;
  1176. coverIm.onerror = function () {
  1177. this.onerror = null;
  1178. this.src = '';
  1179. };
  1180. }
  1181. wrap.appendChild(card);
  1182. });
  1183. }
  1184. function run() {
  1185. fetchStoreGlobalRecommend()
  1186. .then(function (res) {
  1187. var list = normalizeStoreRecommendList(res);
  1188. if (!list.length && res && res.msg) {
  1189. console.warn('[store-recommend]', res.msg);
  1190. }
  1191. renderRecommended(list);
  1192. })
  1193. .catch(function (e) {
  1194. console.error(e);
  1195. renderRecommended([]);
  1196. });
  1197. }
  1198. function boot() {
  1199. var launchTag = document.getElementById('launch-btn');
  1200. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1201. bindWeChatLaunchTagEvents();
  1202. if (isWeChatInAppBrowser()) {
  1203. document.body.classList.add('is-wechat');
  1204. applyWxOpenLaunchSceneBodyClass();
  1205. logWxEntryDiagnostics();
  1206. }
  1207. if (shouldInitWeChatJssdkOnLoad()) {
  1208. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1209. document.body.classList.add('wx-pc-debug');
  1210. }
  1211. scheduleWeChatJssdkBootstrap();
  1212. }
  1213. document.addEventListener('WeixinOpenTagsError', function (e) {
  1214. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1215. applyWxOpenLaunchSceneBodyClass();
  1216. });
  1217. applyEmptyHeroState();
  1218. run();
  1219. if (isWeChatInAppBrowser()) {
  1220. var openBtnWx = document.getElementById('openApp');
  1221. if (openBtnWx) {
  1222. openBtnWx.addEventListener('click', function () {
  1223. if (!weChatJssdkConfigured) {
  1224. showFabToast(
  1225. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1226. );
  1227. return;
  1228. }
  1229. if (!isWxOpenLaunchAppSceneSupported()) {
  1230. showWxCopyLinkEntryTip();
  1231. }
  1232. });
  1233. }
  1234. } else {
  1235. var openBtn = document.getElementById('openApp');
  1236. if (openBtn) {
  1237. openBtn.addEventListener('click', tryOpenHBuilderApp);
  1238. }
  1239. }
  1240. }
  1241. if (document.readyState === 'complete') {
  1242. boot();
  1243. } else {
  1244. window.onload = boot;
  1245. }
  1246. })();
  1247. </script>
  1248. </body>
  1249. </html>