secondShareGoods.html 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  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. --price-red: #E62E2E;
  12. --tag-bg: #fff5e9;
  13. --tag-text: #b05b28;
  14. --text: #1a1a1a;
  15. --text-secondary: #999999;
  16. --safe-bottom: env(safe-area-inset-bottom, 0px);
  17. }
  18. * {
  19. margin: 0;
  20. padding: 0;
  21. box-sizing: border-box;
  22. }
  23. html {
  24. font-size: 16px;
  25. -webkit-tap-highlight-color: transparent;
  26. overflow-x: hidden;
  27. }
  28. body {
  29. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  30. background: #fff;
  31. color: var(--text);
  32. min-height: 100vh;
  33. padding-bottom: calc(100px + var(--safe-bottom));
  34. }
  35. .fab-wrap {
  36. position: fixed;
  37. left: 0;
  38. right: 0;
  39. bottom: 0;
  40. z-index: 200;
  41. padding: 12px 24px calc(12px + var(--safe-bottom));
  42. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  43. pointer-events: none;
  44. }
  45. .fab-dock__slot {
  46. width: 100%;
  47. max-width: 320px;
  48. height: 48px;
  49. margin: 0 auto;
  50. pointer-events: auto;
  51. }
  52. #openApp img {
  53. display: block;
  54. width: 100%;
  55. height: 48px;
  56. object-fit: contain;
  57. pointer-events: none;
  58. }
  59. #launch-btn {
  60. display: none;
  61. width: 100%;
  62. height: 48px;
  63. min-height: 48px;
  64. border-radius: 24px;
  65. overflow: hidden;
  66. opacity: 1;
  67. }
  68. body.is-wechat.wx-jssdk-ready #launch-btn {
  69. display: block;
  70. }
  71. body.is-wechat.wx-jssdk-ready #openApp {
  72. display: none !important;
  73. }
  74. .fab-wrap .fab {
  75. pointer-events: auto;
  76. }
  77. #openAppToast {
  78. display: none;
  79. position: fixed;
  80. left: 16px;
  81. right: 16px;
  82. bottom: calc(72px + var(--safe-bottom));
  83. z-index: 10001;
  84. padding: 10px 14px;
  85. font-size: 13px;
  86. line-height: 1.45;
  87. color: #fff;
  88. text-align: center;
  89. background: rgba(0, 0, 0, 0.78);
  90. border-radius: 8px;
  91. pointer-events: none;
  92. word-break: break-all;
  93. }
  94. #openApp {
  95. touch-action: manipulation;
  96. }
  97. .fab {
  98. display: flex;
  99. align-items: center;
  100. justify-content: center;
  101. gap: 10px;
  102. width: 100%;
  103. max-width: 320px;
  104. margin: 0 auto;
  105. height: 48px;
  106. border: none;
  107. border-radius: 24px;
  108. background: #F47D1F;
  109. color: #fff;
  110. font-size: 16px;
  111. font-weight: 600;
  112. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  113. cursor: pointer;
  114. }
  115. .fab__logo {
  116. width: 28px;
  117. height: 28px;
  118. flex-shrink: 0;
  119. }
  120. .home-indicator {
  121. height: 5px;
  122. background: #000;
  123. border-radius: 3px;
  124. width: 134px;
  125. margin: 8px auto 4px;
  126. opacity: 0.2;
  127. }
  128. /* 顶部大图 + 叠字 */
  129. .goods-hero {
  130. position: relative;
  131. width: 100%;
  132. min-height: 58vh;
  133. max-height: 520px;
  134. background: #e8e8e8 center / cover no-repeat;
  135. overflow: hidden;
  136. }
  137. .goods-hero__img {
  138. position: absolute;
  139. inset: 0;
  140. width: 100%;
  141. height: 100%;
  142. object-fit: cover;
  143. display: block;
  144. }
  145. .goods-hero__shade {
  146. position: absolute;
  147. inset: 0;
  148. background: linear-gradient(
  149. 180deg,
  150. rgba(0, 0, 0, 0.35) 0%,
  151. rgba(0, 0, 0, 0.1) 38%,
  152. rgba(0, 0, 0, 0.45) 100%
  153. );
  154. pointer-events: none;
  155. }
  156. .goods-hero__inner {
  157. position: relative;
  158. z-index: 1;
  159. min-height: 58vh;
  160. max-height: 520px;
  161. padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 28px;
  162. display: flex;
  163. flex-direction: column;
  164. justify-content: space-between;
  165. align-items: flex-start;
  166. }
  167. .goods-hero__user {
  168. display: flex;
  169. align-items: center;
  170. gap: 10px;
  171. }
  172. .goods-hero__avatar {
  173. width: 40px;
  174. height: 40px;
  175. border-radius: 50%;
  176. object-fit: cover;
  177. flex-shrink: 0;
  178. background: rgba(255, 255, 255, 0.3);
  179. }
  180. .goods-hero__user-meta {
  181. display: flex;
  182. flex-direction: column;
  183. gap: 2px;
  184. }
  185. .goods-hero__name {
  186. font-size: 15px;
  187. font-weight: 600;
  188. color: #fff;
  189. text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  190. }
  191. .goods-hero__time {
  192. font-size: 12px;
  193. color: rgba(255, 255, 255, 0.82);
  194. text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  195. }
  196. .goods-hero__slogan {
  197. margin-top: auto;
  198. padding-bottom: 4px;
  199. }
  200. .goods-hero__slogan-line {
  201. font-size: 26px;
  202. font-weight: 800;
  203. line-height: 1.25;
  204. color: #fff;
  205. letter-spacing: 0.02em;
  206. text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  207. }
  208. /* 白色内容区 */
  209. .goods-panel {
  210. background: #fff;
  211. border-radius: 16px 16px 0 0;
  212. margin-top: -16px;
  213. position: relative;
  214. z-index: 2;
  215. padding: 20px 16px 24px;
  216. box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
  217. }
  218. .goods-panel__row-price {
  219. display: flex;
  220. align-items: flex-end;
  221. justify-content: space-between;
  222. gap: 12px;
  223. margin-bottom: 14px;
  224. }
  225. .goods-panel__price {
  226. display: flex;
  227. align-items: baseline;
  228. gap: 2px;
  229. color: var(--price-red);
  230. font-weight: 800;
  231. line-height: 1;
  232. }
  233. .goods-panel__price-yen {
  234. font-size: 18px;
  235. }
  236. .goods-panel__price-num {
  237. font-size: 28px;
  238. letter-spacing: -0.02em;
  239. }
  240. .goods-panel__dist {
  241. display: inline-flex;
  242. align-items: center;
  243. gap: 4px;
  244. font-size: 12px;
  245. color: var(--text-secondary);
  246. flex-shrink: 0;
  247. padding-bottom: 2px;
  248. }
  249. .goods-panel__dist svg,
  250. .goods-panel__dist img {
  251. width: 14px;
  252. height: 14px;
  253. opacity: 0.85;
  254. display: block;
  255. flex-shrink: 0;
  256. object-fit: contain;
  257. }
  258. .goods-panel__title {
  259. font-size: 17px;
  260. font-weight: 700;
  261. line-height: 1.45;
  262. color: var(--text);
  263. margin-bottom: 16px;
  264. }
  265. .goods-panel__row-stats {
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. gap: 12px;
  270. margin-bottom: 16px;
  271. }
  272. .goods-panel__stats {
  273. display: flex;
  274. align-items: center;
  275. gap: 18px;
  276. }
  277. .goods-panel__stat {
  278. display: inline-flex;
  279. align-items: center;
  280. gap: 5px;
  281. font-size: 14px;
  282. color: var(--text-secondary);
  283. }
  284. .goods-panel__stat svg {
  285. width: 16px;
  286. height: 16px;
  287. flex-shrink: 0;
  288. }
  289. .goods-panel__stat img {
  290. width: 16px;
  291. height: 16px;
  292. flex-shrink: 0;
  293. display: block;
  294. object-fit: contain;
  295. }
  296. .goods-panel__share {
  297. display: inline-flex;
  298. align-items: center;
  299. gap: 4px;
  300. padding: 0;
  301. border: none;
  302. background: none;
  303. font-size: 14px;
  304. color: var(--text-secondary);
  305. cursor: pointer;
  306. -webkit-tap-highlight-color: transparent;
  307. }
  308. .goods-panel__share svg {
  309. width: 18px;
  310. height: 18px;
  311. }
  312. .goods-panel__tags {
  313. display: flex;
  314. flex-wrap: wrap;
  315. align-items: center;
  316. gap: 8px;
  317. }
  318. .goods-tag {
  319. display: inline-block;
  320. padding: 2px 8px;
  321. border-radius: 4px;
  322. font-size: 12px;
  323. font-weight: 400;
  324. line-height: 1.35;
  325. background: #fff5e9;
  326. }
  327. .goods-tag--topic {
  328. color: #b05b28;
  329. }
  330. .goods-tag--label {
  331. color: #333333;
  332. }
  333. /* 留言 */
  334. .goods-comments {
  335. margin-top: 20px;
  336. padding-top: 20px;
  337. border-top: 1px solid #eee;
  338. }
  339. .goods-comments__head {
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-between;
  343. margin-bottom: 18px;
  344. }
  345. .goods-comments__title {
  346. font-size: 17px;
  347. font-weight: 700;
  348. color: var(--text);
  349. }
  350. .goods-comments__total {
  351. display: inline-flex;
  352. align-items: center;
  353. gap: 4px;
  354. font-size: 14px;
  355. color: #151515;
  356. }
  357. .goods-comments__total svg {
  358. width: 18px;
  359. height: 18px;
  360. opacity: 0.85;
  361. }
  362. .goods-comments__list {
  363. list-style: none;
  364. }
  365. .goods-comments__empty {
  366. list-style: none;
  367. padding: 24px 12px;
  368. text-align: center;
  369. font-size: 14px;
  370. color: var(--text-secondary);
  371. }
  372. .goods-cmt {
  373. padding-bottom: 18px;
  374. margin-bottom: 18px;
  375. border-bottom: 1px solid #eee;
  376. }
  377. .goods-cmt:last-child {
  378. margin-bottom: 0;
  379. padding-bottom: 0;
  380. border-bottom: none;
  381. }
  382. .goods-cmt__row {
  383. display: flex;
  384. align-items: flex-start;
  385. gap: 12px;
  386. }
  387. .goods-cmt__avatar {
  388. width: 40px;
  389. height: 40px;
  390. border-radius: 50%;
  391. object-fit: cover;
  392. background: #e8e8e8;
  393. flex-shrink: 0;
  394. }
  395. .goods-cmt--nested .goods-cmt__avatar {
  396. width: 32px;
  397. height: 32px;
  398. }
  399. .goods-cmt__body {
  400. flex: 1;
  401. min-width: 0;
  402. }
  403. .goods-cmt__name {
  404. font-size: 15px;
  405. font-weight: 700;
  406. color: var(--text);
  407. line-height: 1.3;
  408. }
  409. .goods-cmt__time {
  410. display: block;
  411. margin-top: 2px;
  412. font-size: 12px;
  413. color: var(--text-secondary);
  414. line-height: 1.35;
  415. }
  416. .goods-cmt__text {
  417. margin-top: 10px;
  418. font-size: 15px;
  419. line-height: 1.5;
  420. color: var(--text);
  421. word-break: break-word;
  422. }
  423. .goods-cmt__actions {
  424. display: flex;
  425. align-items: center;
  426. gap: 20px;
  427. margin-top: 12px;
  428. }
  429. .goods-cmt__action {
  430. display: inline-flex;
  431. align-items: center;
  432. gap: 4px;
  433. padding: 0;
  434. border: none;
  435. background: none;
  436. font-size: 13px;
  437. color: var(--text-secondary);
  438. cursor: pointer;
  439. -webkit-tap-highlight-color: transparent;
  440. }
  441. .goods-cmt__action svg {
  442. width: 16px;
  443. height: 16px;
  444. flex-shrink: 0;
  445. opacity: 0.88;
  446. }
  447. .goods-cmt__thread {
  448. margin-top: 14px;
  449. padding-left: 52px;
  450. }
  451. .goods-cmt__replies-inner.is-collapsed {
  452. display: none;
  453. }
  454. .goods-cmt__thread-bar {
  455. display: flex;
  456. align-items: center;
  457. justify-content: space-between;
  458. width: 100%;
  459. margin-top: 10px;
  460. padding: 10px 12px;
  461. border: none;
  462. border-radius: 8px;
  463. background: #f5f5f5;
  464. font-size: 13px;
  465. color: #888;
  466. cursor: pointer;
  467. -webkit-tap-highlight-color: transparent;
  468. }
  469. .goods-cmt__thread-bar-right {
  470. display: inline-flex;
  471. align-items: center;
  472. gap: 4px;
  473. color: var(--text-secondary);
  474. }
  475. .goods-cmt__thread-chevron {
  476. width: 14px;
  477. height: 14px;
  478. transition: transform 0.2s ease;
  479. flex-shrink: 0;
  480. }
  481. .goods-cmt__thread-bar.is-collapsed .goods-cmt__thread-chevron {
  482. transform: rotate(180deg);
  483. }
  484. .goods-cmt--nested {
  485. padding-bottom: 0;
  486. margin-bottom: 0;
  487. border-bottom: none;
  488. }
  489. .goods-cmt--nested .goods-cmt__text {
  490. margin-top: 8px;
  491. }
  492. </style>
  493. </head>
  494. <body>
  495. <section class="goods-hero" id="goodsHero" aria-label="商品配图">
  496. <img class="goods-hero__img" id="goodsHeroImg" src="" alt="">
  497. <div class="goods-hero__shade" aria-hidden="true"></div>
  498. <div class="goods-hero__inner">
  499. <div class="goods-hero__user">
  500. <img class="goods-hero__avatar" id="goodsUserAvatar" src="images/demouser.png" alt="">
  501. <div class="goods-hero__user-meta">
  502. <span class="goods-hero__name" id="goodsUserName">维尼</span>
  503. <span class="goods-hero__time" id="goodsTimeAgo">11小时前</span>
  504. </div>
  505. </div>
  506. <div class="goods-hero__slogan" id="goodsHeroSloganWrap" style="display:none;">
  507. <div class="goods-hero__slogan-line" id="goodsSlogan1"></div>
  508. <div class="goods-hero__slogan-line" id="goodsSlogan2"></div>
  509. </div>
  510. </div>
  511. </section>
  512. <div class="goods-panel">
  513. <div class="goods-panel__row-price">
  514. <div class="goods-panel__price">
  515. <span class="goods-panel__price-yen">¥</span>
  516. <span class="goods-panel__price-num" id="goodsPrice">690.00</span>
  517. </div>
  518. <div class="goods-panel__dist">
  519. <img src="images/juli.svg" alt="" width="14" height="14" decoding="async" aria-hidden="true">
  520. <span id="goodsDistance">距离 2.5km</span>
  521. </div>
  522. </div>
  523. <h1 class="goods-panel__title" id="goodsTitle">HCK哈士奇BC-330RDE烤漆复古冰箱家用大容量单门冰柜高颜值网红</h1>
  524. <div class="goods-panel__row-stats">
  525. <div class="goods-panel__stats">
  526. <span class="goods-panel__stat goods-panel__stat--hot" id="goodsHotStat">
  527. <img src="images/huo.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  528. <span id="goodsHotCount" style="color:#151515;">510</span>
  529. </span>
  530. <span class="goods-panel__stat">
  531. <img src="images/xing.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  532. <span id="goodsFavCount" style="color:#151515;">260</span>
  533. </span>
  534. </div>
  535. </div>
  536. <div class="goods-panel__tags" id="goodsTags"></div>
  537. <section class="goods-comments" id="goodsComments" aria-label="留言">
  538. <div class="goods-comments__head">
  539. <h2 class="goods-comments__title">留言</h2>
  540. <div class="goods-comments__total">
  541. <img src="images/liuyan.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  542. <span id="goodsCommentTotal">24</span>
  543. </div>
  544. </div>
  545. <ul class="goods-comments__list" id="goodsCommentList"></ul>
  546. </section>
  547. </div>
  548. <div id="openAppToast" role="status" aria-live="polite"></div>
  549. <div class="fab-wrap">
  550. <div class="fab-dock__slot">
  551. <button type="button" class="fab" id="openApp">
  552. <img src="images/uBtn.png" alt="APP内打开" decoding="async">
  553. </button>
  554. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  555. <script type="text/wxtag-template">
  556. <style>
  557. .wx-open-app-btn {
  558. display: block;
  559. width: 100%;
  560. height: 48px;
  561. margin: 0;
  562. padding: 0;
  563. border: none;
  564. border-radius: 24px;
  565. background: #F47D1F;
  566. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  567. cursor: pointer;
  568. overflow: hidden;
  569. -webkit-tap-highlight-color: transparent;
  570. }
  571. .wx-open-app-btn img {
  572. display: block;
  573. width: 100%;
  574. height: 48px;
  575. object-fit: contain;
  576. opacity: 1;
  577. pointer-events: none;
  578. -webkit-user-drag: none;
  579. }
  580. </style>
  581. <button class="wx-open-app-btn" aria-label="APP内打开">
  582. <img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" width="320" height="48" />
  583. </button>
  584. </script>
  585. </wx-open-launch-app>
  586. </div>
  587. <div class="home-indicator" aria-hidden="true"></div>
  588. </div>
  589. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  590. <script>
  591. (function () {
  592. 'use strict';
  593. /**
  594. * 商品详情:POST https://test.ailien.shop/alienSecond/recommend/querySecondGoodsDetail
  595. * body: application/x-www-form-urlencoded(「表单数据」);键 goodsId、longitude、latitude,值均为字符串;经纬度未传时用默认 121.662567 / 38.925757
  596. * 留言:GET {API_BASE}/commonComment/getListBySourceType — 成功时 data 常为数组;项含 parentId、childCommonComments、headName、headImg、createdTime、content、likeCount
  597. * URL 常用:goodsId、userId、longitude/lon/jingdu、latitude/lat/weidu、pageNum、pageSize、sourceType(含 hash 内 ? 参数)
  598. */
  599. /**
  600. * 唤起 App 落地:二手商品详情(与 pages.json 路径一致)
  601. */
  602. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  603. var APP_IOS_URL_SCHEME = 'shopro://';
  604. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  605. var API_BASE = 'https://test.ailien.shop/alienStore';
  606. /**
  607. * 微信 JSSDK — 与 shareIndex.html 一致
  608. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  609. */
  610. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  611. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  612. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  613. var H5_PAGE_BASE_FALLBACK = 'https://test.ailien.shop/h5/HBuilderProjects/';
  614. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'secondShareGoods.html';
  615. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'test.ailien.shop'];
  616. var weChatJssdkConfigured = false;
  617. var wxConfigSignRetriedBaseUrl = false;
  618. var wxInitLastError = '';
  619. var wxJssdkInitPromise = null;
  620. function showDownloadTip() {
  621. var msg = '请到应用商店下载';
  622. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  623. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  624. } else {
  625. window.alert(msg);
  626. }
  627. }
  628. function mergeSearchAndHashParams() {
  629. var params = new URLSearchParams();
  630. function ingestAppend(querySlice) {
  631. if (!querySlice) return;
  632. var p = new URLSearchParams(querySlice);
  633. p.forEach(function (val, key) {
  634. params.append(key, val);
  635. });
  636. }
  637. function ingestSet(querySlice) {
  638. if (!querySlice) return;
  639. var p = new URLSearchParams(querySlice);
  640. p.forEach(function (val, key) {
  641. params.set(key, val);
  642. });
  643. }
  644. if (location.search && location.search.length > 1) {
  645. ingestAppend(location.search.slice(1));
  646. }
  647. var hash = location.hash || '';
  648. var qi = hash.indexOf('?');
  649. if (qi >= 0) {
  650. ingestSet(hash.slice(qi + 1));
  651. }
  652. return params;
  653. }
  654. function q(name) {
  655. var v = mergeSearchAndHashParams().get(name);
  656. return v == null ? '' : String(v);
  657. }
  658. function buildAppOpenQueryStringMerged() {
  659. var params = mergeSearchAndHashParams();
  660. var gid = params.get('goodsId') || params.get('id') || '';
  661. if (gid && !params.has('goodsId')) {
  662. params.set('goodsId', gid);
  663. }
  664. var sid = params.get('storeId') || params.get('id') || '';
  665. if (sid && !params.has('storeId')) {
  666. params.set('storeId', sid);
  667. }
  668. var qsOut = params.toString();
  669. return qsOut ? ('?' + qsOut) : '';
  670. }
  671. function getSecondGoodsAppUniPath() {
  672. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  673. /^\//,
  674. ''
  675. );
  676. }
  677. function buildAppDeepLink() {
  678. var path = getSecondGoodsAppUniPath();
  679. var s = buildAppOpenQueryStringMerged();
  680. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  681. if (!s) {
  682. return root + '/' + path;
  683. }
  684. return root + '/' + path + s;
  685. }
  686. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  687. function buildAppUniPageLaunchUrl() {
  688. var path = getSecondGoodsAppUniPath();
  689. var qs = buildAppOpenQueryStringMerged().replace(/^\?/, '');
  690. return qs ? path + '?' + qs : path;
  691. }
  692. /**
  693. * wx-open-launch-app extinfo:pages/secondHandTransactions/pages/detail/index?goodsId=…
  694. */
  695. function buildWeChatLaunchExtinfo() {
  696. var uniPage = buildAppUniPageLaunchUrl();
  697. if (uniPage.length <= 1024) return uniPage;
  698. var params = mergeSearchAndHashParams();
  699. var mini = new URLSearchParams();
  700. var goodsId = params.get('goodsId') || params.get('id') || '';
  701. if (goodsId) mini.set('goodsId', goodsId);
  702. var path = getSecondGoodsAppUniPath();
  703. var shortPage = path + '?' + mini.toString();
  704. if (shortPage.length <= 1024) return shortPage;
  705. return shortPage.slice(0, 1024);
  706. }
  707. function isWeChatInAppBrowser() {
  708. return /MicroMessenger/i.test(navigator.userAgent || '');
  709. }
  710. function readQueryParam(name) {
  711. return q(name);
  712. }
  713. function isWxDebugOn() {
  714. return readQueryParam('wxDebug') === '1';
  715. }
  716. function isWxForceDebug() {
  717. return readQueryParam('wxForce') === '1';
  718. }
  719. function isWxConfigOnClickDebug() {
  720. return readQueryParam('wxConfigOnClick') === '1';
  721. }
  722. function isWxPcAutoDebugHost() {
  723. var h = (location.hostname || '').toLowerCase();
  724. if (h === 'localhost' || h === '127.0.0.1') return true;
  725. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  726. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  727. }
  728. return false;
  729. }
  730. function isWxPcBrowser() {
  731. return !isWeChatInAppBrowser();
  732. }
  733. function shouldInitWeChatJssdkOnLoad() {
  734. if (isWeChatInAppBrowser()) return true;
  735. return isWxForceDebug() || isWxPcAutoDebugHost();
  736. }
  737. function shouldFetchWxConfig(fromUserClick) {
  738. if (isWeChatInAppBrowser()) return true;
  739. if (fromUserClick) return true;
  740. return isWxForceDebug() || isWxPcAutoDebugHost();
  741. }
  742. function getWxHtmlUrl() {
  743. var forced = String(q('wxSignUrl') || '').trim();
  744. if (forced) return forced.split('#')[0];
  745. return String(location.href || '').split('#')[0];
  746. }
  747. function getWxSignPageUrlForApi() {
  748. var htmlUrl = getWxHtmlUrl();
  749. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  750. return WX_GET_CONFIG_SIGN_URL;
  751. }
  752. function getWxHtmlUrlBase() {
  753. var htmlUrl = getWxSignPageUrlForApi();
  754. try {
  755. var u = new URL(htmlUrl);
  756. return u.origin + u.pathname;
  757. } catch (eU) {
  758. return WX_GET_CONFIG_SIGN_URL;
  759. }
  760. }
  761. function getWxConfigSignUrl() {
  762. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  763. return getWxSignPageUrlForApi();
  764. }
  765. function getWxGetConfigApiUrl() {
  766. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  767. }
  768. function buildWxGetConfigRequestBody(htmlUrl) {
  769. return {
  770. url: String(htmlUrl || '').split('#')[0].trim()
  771. };
  772. }
  773. function resolveWxConfigAppIdFromSignData(d) {
  774. if (!d || typeof d !== 'object') return '';
  775. var mp =
  776. d.mpAppId ||
  777. d.mpAppid ||
  778. d.officialAppId ||
  779. d.gzhAppId ||
  780. d.serviceAppId;
  781. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  782. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  783. if (fromQuery) return fromQuery;
  784. var raw = d.appId || d.appid || d.wxAppId;
  785. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  786. }
  787. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  788. if (!res || typeof res !== 'object') return null;
  789. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  790. if (!d || typeof d !== 'object') return null;
  791. var appId = resolveWxConfigAppIdFromSignData(d);
  792. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  793. var nonceStr =
  794. d.nonceStr != null && String(d.nonceStr) !== ''
  795. ? d.nonceStr
  796. : d.noncestr != null && String(d.noncestr) !== ''
  797. ? d.noncestr
  798. : d.nonce;
  799. var signature = d.signature || d.sign;
  800. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  801. return null;
  802. }
  803. return {
  804. appId: String(appId),
  805. timestamp: Number(timestamp),
  806. nonceStr: String(nonceStr),
  807. signature: String(signature),
  808. signUrl: String(signUrlUsed || '')
  809. .split('#')[0]
  810. .trim()
  811. };
  812. }
  813. function getWxErrMsg(err) {
  814. if (!err) return '';
  815. if (err.errMsg) return String(err.errMsg);
  816. if (typeof err === 'string') return err;
  817. try {
  818. return JSON.stringify(err);
  819. } catch (e) {
  820. return String(err);
  821. }
  822. }
  823. function formatWxConfigErrorTip(err, signPageUrl) {
  824. var errMsg = getWxErrMsg(err);
  825. var tip = '微信 JSSDK 配置失败';
  826. if (/invalid signature/i.test(errMsg)) {
  827. return (
  828. tip +
  829. ':签名无效。url=' +
  830. (signPageUrl || getWxHtmlUrl()) +
  831. ';appId=' +
  832. WECHAT_MP_APP_ID
  833. );
  834. }
  835. if (/require\s*subscribe/i.test(errMsg)) {
  836. return tip + ':' + errMsg + '(服务号需用户已关注)';
  837. }
  838. return errMsg ? tip + ':' + errMsg : tip;
  839. }
  840. function setWxInitError(msg) {
  841. wxInitLastError = String(msg || '').trim();
  842. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  843. }
  844. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  845. var htmlUrl = String(
  846. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  847. )
  848. .split('#')[0]
  849. .trim();
  850. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  851. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  852. }
  853. if (isWxDebugOn()) {
  854. try {
  855. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  856. } catch (eDbg) {}
  857. }
  858. var requestUrl = getWxGetConfigApiUrl();
  859. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  860. console.log('[wx] htmlUrl=', htmlUrl);
  861. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  862. return fetch(requestUrl, {
  863. method: 'POST',
  864. mode: 'cors',
  865. credentials: 'omit',
  866. headers: {
  867. Accept: 'application/json',
  868. 'Content-Type': 'application/json;charset=UTF-8'
  869. },
  870. body: JSON.stringify(requestBody)
  871. })
  872. .then(function (r) {
  873. if (r.ok) return r.json();
  874. return r
  875. .text()
  876. .catch(function () {
  877. return '';
  878. })
  879. .then(function (text) {
  880. var hint = '';
  881. try {
  882. var j = JSON.parse(text);
  883. hint = j.msg || j.message || '';
  884. } catch (eP) {
  885. if (text) hint = text.slice(0, 120);
  886. }
  887. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  888. });
  889. })
  890. .then(function (res) {
  891. if (res && res.code != null) {
  892. var c = Number(res.code);
  893. if (c !== 200 && c !== 0 && res.success !== true) {
  894. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  895. }
  896. }
  897. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  898. if (!sign) {
  899. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  900. throw new Error(
  901. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  902. );
  903. }
  904. if (sign.appId !== WECHAT_MP_APP_ID) {
  905. console.warn(
  906. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  907. );
  908. }
  909. if (typeof wx === 'undefined') {
  910. if (isWxPcBrowser()) {
  911. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  912. return true;
  913. }
  914. setWxInitError('jweixin.js 未加载');
  915. return false;
  916. }
  917. return applyWxConfigFromSign(sign, htmlUrl);
  918. });
  919. }
  920. function applyWxConfigFromSign(sign, htmlUrl) {
  921. var wxConfigParams = {
  922. debug: isWxDebugOn(),
  923. appId: String(sign.appId),
  924. timestamp: sign.timestamp,
  925. nonceStr: String(sign.nonceStr),
  926. signature: String(sign.signature),
  927. jsApiList: [],
  928. openTagList: ['wx-open-launch-app']
  929. };
  930. return new Promise(function (resolve) {
  931. wx.config(wxConfigParams);
  932. wx.ready(function () {
  933. weChatJssdkConfigured = true;
  934. document.body.classList.add('wx-jssdk-ready');
  935. refreshWxLaunchTagAttrs();
  936. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  937. resolve(true);
  938. });
  939. wx.error(function (err) {
  940. weChatJssdkConfigured = false;
  941. document.body.classList.remove('wx-jssdk-ready');
  942. wxJssdkInitPromise = null;
  943. var errMsg = getWxErrMsg(err);
  944. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  945. if (isWxDebugOn()) window.alert(wxInitLastError);
  946. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  947. var baseUrl = getWxHtmlUrlBase();
  948. var fullUrl = getWxSignPageUrlForApi();
  949. if (
  950. !/invalid signature/i.test(errMsg) ||
  951. wxConfigSignRetriedBaseUrl ||
  952. baseUrl === fullUrl ||
  953. htmlUrl === baseUrl
  954. ) {
  955. resolve(false);
  956. return;
  957. }
  958. wxConfigSignRetriedBaseUrl = true;
  959. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  960. });
  961. });
  962. }
  963. function refreshWxLaunchTagAttrs() {
  964. var tag = document.getElementById('launch-btn');
  965. if (!tag) return;
  966. try {
  967. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  968. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
  969. } catch (eA) {}
  970. }
  971. function bindWeChatLaunchTagEvents() {
  972. var tag = document.getElementById('launch-btn');
  973. if (!tag || tag._wxLaunchBound) return;
  974. tag._wxLaunchBound = true;
  975. refreshWxLaunchTagAttrs();
  976. tag.addEventListener('launch', function () {
  977. console.log('[wx-open-launch-app] launch ok');
  978. showFabToast('正在打开 U店在哪…');
  979. });
  980. tag.addEventListener('error', function (e) {
  981. var detail = e && e.detail;
  982. var errMsg =
  983. detail && detail.errMsg
  984. ? String(detail.errMsg)
  985. : detail && detail.errmsg
  986. ? String(detail.errmsg)
  987. : '';
  988. console.warn('[wx-open-launch-app]', detail);
  989. showAppOpenFailTip(
  990. errMsg
  991. ? '未能唤起 App:' + errMsg
  992. : '未能唤起 App,请确认已安装 U店在哪,且开放平台已绑定服务号与移动应用。'
  993. );
  994. });
  995. }
  996. function initWeChatOpenLaunchApp(fromUserClick) {
  997. if (!shouldFetchWxConfig(!!fromUserClick)) {
  998. return Promise.resolve(false);
  999. }
  1000. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1001. wxConfigSignRetriedBaseUrl = false;
  1002. wxInitLastError = '';
  1003. var htmlUrl = getWxConfigSignUrl();
  1004. bindWeChatLaunchTagEvents();
  1005. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1006. .then(function (ok) {
  1007. if (ok === true) return true;
  1008. if (!wxInitLastError) {
  1009. setWxInitError('wx.config 失败,可加 ?wxDebug=1');
  1010. }
  1011. return false;
  1012. })
  1013. .catch(function (e) {
  1014. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  1015. setWxInitError(msg);
  1016. console.warn('[wx] init failed', msg, 'htmlUrl=', htmlUrl);
  1017. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1018. return false;
  1019. })
  1020. .finally(function () {
  1021. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1022. });
  1023. return wxJssdkInitPromise;
  1024. }
  1025. function scheduleWeChatJssdkBootstrap() {
  1026. if (!shouldInitWeChatJssdkOnLoad()) return;
  1027. var attempts = 0;
  1028. function tick() {
  1029. attempts += 1;
  1030. if (weChatJssdkConfigured) return;
  1031. initWeChatOpenLaunchApp();
  1032. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
  1033. setTimeout(tick, 400);
  1034. }
  1035. }
  1036. tick();
  1037. }
  1038. function showFabToast(msg, ms) {
  1039. var tip = String(msg || '').trim();
  1040. if (!tip) return;
  1041. var el = document.getElementById('openAppToast');
  1042. if (el) {
  1043. el.textContent = tip;
  1044. el.style.display = 'block';
  1045. if (showFabToast._t) clearTimeout(showFabToast._t);
  1046. showFabToast._t = setTimeout(function () {
  1047. el.style.display = 'none';
  1048. }, ms || 2800);
  1049. }
  1050. console.log('[openApp]', tip);
  1051. }
  1052. function showAppOpenFailTip(msg) {
  1053. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  1054. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  1055. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  1056. } else if (isWeChatInAppBrowser()) {
  1057. window.alert(tip);
  1058. } else {
  1059. console.warn('[openApp]', tip);
  1060. }
  1061. }
  1062. function tryFetchWxConfigOnPcClick() {
  1063. if (!isWxPcBrowser()) return Promise.resolve(false);
  1064. showFabToast('正在请求 getWxConfig…');
  1065. wxJssdkInitPromise = null;
  1066. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1067. if (ok) {
  1068. showFabToast(
  1069. weChatJssdkConfigured
  1070. ? 'getWxConfig 成功,wx.config 已就绪'
  1071. : 'getWxConfig 成功'
  1072. );
  1073. } else {
  1074. showFabToast(wxInitLastError || 'getWxConfig 失败');
  1075. }
  1076. return ok;
  1077. });
  1078. }
  1079. function launchAppDeepLink(deepLink) {
  1080. try {
  1081. var a = document.createElement('a');
  1082. a.href = deepLink;
  1083. a.setAttribute('target', '_self');
  1084. document.body.appendChild(a);
  1085. a.click();
  1086. document.body.removeChild(a);
  1087. } catch (e1) {}
  1088. try {
  1089. window.location.href = deepLink;
  1090. } catch (e2) {}
  1091. }
  1092. function tryOpenHBuilderApp() {
  1093. if (isWeChatInAppBrowser()) return;
  1094. tryFetchWxConfigOnPcClick().then(function () {
  1095. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1096. return;
  1097. }
  1098. tryOpenHBuilderAppViaScheme();
  1099. });
  1100. }
  1101. function tryOpenHBuilderAppViaScheme() {
  1102. showFabToast('正在打开 U店在哪…');
  1103. var deepLink = buildAppDeepLink();
  1104. if (typeof plus !== 'undefined' && plus.runtime) {
  1105. var installed = null;
  1106. try {
  1107. if (typeof plus.runtime.isApplicationExist === 'function') {
  1108. installed = plus.runtime.isApplicationExist({
  1109. pname: APP_ANDROID_PACKAGE,
  1110. action: APP_IOS_URL_SCHEME
  1111. });
  1112. }
  1113. } catch (e) {
  1114. console.warn(e);
  1115. }
  1116. if (installed === false) {
  1117. showDownloadTip();
  1118. return;
  1119. }
  1120. try {
  1121. plus.runtime.openURL(deepLink);
  1122. } catch (e2) {
  1123. console.warn(e2);
  1124. showDownloadTip();
  1125. }
  1126. return;
  1127. }
  1128. var t0 = Date.now();
  1129. var done = false;
  1130. function finish() {
  1131. if (done) return;
  1132. done = true;
  1133. document.removeEventListener('visibilitychange', onVis);
  1134. window.removeEventListener('pagehide', onHide);
  1135. }
  1136. function onVis() {
  1137. if (document.visibilityState === 'hidden') finish();
  1138. }
  1139. function onHide() {
  1140. finish();
  1141. }
  1142. document.addEventListener('visibilitychange', onVis);
  1143. window.addEventListener('pagehide', onHide);
  1144. try {
  1145. launchAppDeepLink(deepLink);
  1146. } catch (e3) {
  1147. finish();
  1148. showDownloadTip();
  1149. return;
  1150. }
  1151. window.setTimeout(function () {
  1152. finish();
  1153. }, 2600);
  1154. }
  1155. function tryDecode(s) {
  1156. s = String(s || '');
  1157. if (!s) return '';
  1158. try {
  1159. return decodeURIComponent(s.replace(/\+/g, ' '));
  1160. } catch (e) {
  1161. return s;
  1162. }
  1163. }
  1164. var DEFAULT_HERO = '';
  1165. /** 二手商品等业务接口前缀(与 alienStore 分离) */
  1166. var API_BASE_SECOND = 'https://test.ailien.shop/alienSecond';
  1167. /** 与接口调试「表单数据」一致;地址栏未带经纬度时使用 */
  1168. var DEFAULT_REQUEST_LONGITUDE = '121.662567';
  1169. var DEFAULT_REQUEST_LATITUDE = '38.925757';
  1170. var COMMENT_SOURCE_TYPE = 4;
  1171. function apiGet(path) {
  1172. return fetch(API_BASE + path, {
  1173. method: 'GET',
  1174. mode: 'cors',
  1175. credentials: 'omit',
  1176. headers: { Accept: 'application/json' }
  1177. }).then(function (res) {
  1178. if (!res.ok) throw new Error('HTTP ' + res.status);
  1179. return res.json();
  1180. });
  1181. }
  1182. function apiPostJson(path, body) {
  1183. return fetch(API_BASE + path, {
  1184. method: 'POST',
  1185. mode: 'cors',
  1186. credentials: 'omit',
  1187. headers: {
  1188. Accept: 'application/json',
  1189. 'Content-Type': 'application/json'
  1190. },
  1191. body: JSON.stringify(body || {})
  1192. }).then(function (res) {
  1193. if (!res.ok) throw new Error('HTTP ' + res.status);
  1194. return res.json();
  1195. });
  1196. }
  1197. function pick(d, keys) {
  1198. if (!d || typeof d !== 'object') return null;
  1199. for (var i = 0; i < keys.length; i++) {
  1200. var k = keys[i];
  1201. if (d[k] != null && d[k] !== '') return d[k];
  1202. }
  1203. return null;
  1204. }
  1205. function isApiOk(res) {
  1206. if (!res || typeof res !== 'object') return false;
  1207. if (res.success === false) return false;
  1208. var c = res.code;
  1209. return c === 200 || c === '200' || Number(c) === 200;
  1210. }
  1211. function fmtPriceNum(v) {
  1212. var n = v != null ? Number(v) : NaN;
  1213. return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
  1214. }
  1215. /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
  1216. function appendGoodsTag(mount, raw, kind) {
  1217. if (!mount || raw == null) return;
  1218. var s = String(raw).trim();
  1219. if (!s) return;
  1220. var span = document.createElement('span');
  1221. span.className =
  1222. 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
  1223. if (kind === 'label') {
  1224. span.textContent = s.replace(/^#+/, '');
  1225. } else {
  1226. span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
  1227. }
  1228. mount.appendChild(span);
  1229. }
  1230. function renderGoodsDetail(d) {
  1231. if (!d || typeof d !== 'object') return;
  1232. var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
  1233. if (title) {
  1234. var el = document.getElementById('goodsTitle');
  1235. if (el) el.textContent = String(title);
  1236. }
  1237. var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
  1238. if (price != null) {
  1239. var pe = document.getElementById('goodsPrice');
  1240. if (pe) pe.textContent = fmtPriceNum(price);
  1241. }
  1242. var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
  1243. if (dist != null) {
  1244. var dt = String(dist).trim();
  1245. if (dt) {
  1246. if (!/^距离/.test(dt)) dt = '距离 ' + dt;
  1247. if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
  1248. dt = dt.replace(/\s+$/, '') + 'km';
  1249. }
  1250. var de = document.getElementById('goodsDistance');
  1251. if (de) de.textContent = dt;
  1252. }
  1253. }
  1254. var img =
  1255. pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
  1256. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
  1257. (Array.isArray(d.imageList) && d.imageList[0]);
  1258. if (img) {
  1259. var hi = document.getElementById('goodsHeroImg');
  1260. if (hi) {
  1261. hi.src = String(img);
  1262. hi.alt = '商品图';
  1263. }
  1264. }
  1265. var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
  1266. if (nick) {
  1267. var ne = document.getElementById('goodsUserName');
  1268. if (ne) ne.textContent = String(nick);
  1269. }
  1270. var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
  1271. if (av) {
  1272. var ae = document.getElementById('goodsUserAvatar');
  1273. if (ae) ae.src = String(av);
  1274. }
  1275. var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
  1276. if (tm) {
  1277. var te = document.getElementById('goodsTimeAgo');
  1278. if (te) te.textContent = String(tm);
  1279. }
  1280. var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
  1281. var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
  1282. var wrap = document.getElementById('goodsHeroSloganWrap');
  1283. var e1 = document.getElementById('goodsSlogan1');
  1284. var e2 = document.getElementById('goodsSlogan2');
  1285. if (wrap && e1 && e2) {
  1286. if (s1 || s2) {
  1287. if (s1) e1.textContent = String(s1);
  1288. if (s2) e2.textContent = String(s2);
  1289. wrap.style.display = '';
  1290. } else {
  1291. wrap.style.display = 'none';
  1292. }
  1293. }
  1294. var hotStat = document.getElementById('goodsHotStat');
  1295. var cs = pick(d, ['collectStatus']);
  1296. if (hotStat) {
  1297. var hideHot =
  1298. cs != null &&
  1299. (Number(cs) === 0 || String(cs).trim() === '0');
  1300. hotStat.style.display = hideHot ? 'none' : '';
  1301. }
  1302. var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
  1303. if (hot != null) {
  1304. var he = document.getElementById('goodsHotCount');
  1305. if (he) he.textContent = String(hot);
  1306. }
  1307. var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
  1308. if (fav != null) {
  1309. var fe = document.getElementById('goodsFavCount');
  1310. if (fe) fe.textContent = String(fav);
  1311. }
  1312. var topicStr = d.topic != null ? String(d.topic).trim() : '';
  1313. var labelStr = d.label != null ? String(d.label).trim() : '';
  1314. var hasApiTags = topicStr !== '' || labelStr !== '';
  1315. var mount = document.getElementById('goodsTags');
  1316. if (mount) {
  1317. if (hasApiTags) {
  1318. mount.innerHTML = '';
  1319. if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
  1320. if (labelStr) appendGoodsTag(mount, labelStr, 'label');
  1321. } else {
  1322. var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
  1323. if (tags) {
  1324. mount.innerHTML = '';
  1325. var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
  1326. arr.forEach(function (t) {
  1327. if (t == null || t === '') return;
  1328. var label =
  1329. typeof t === 'object'
  1330. ? (t.tagName || t.name || t.label || '')
  1331. : String(t);
  1332. label = String(label).trim();
  1333. if (!label) return;
  1334. var isTopic = label.indexOf('#') === 0;
  1335. appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
  1336. });
  1337. }
  1338. }
  1339. }
  1340. }
  1341. var SVG_LIKE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"/></svg>';
  1342. var SVG_REPLY = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
  1343. var SVG_CHEV = '<svg class="goods-cmt__thread-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>';
  1344. function cmtAvatarUrl(c) {
  1345. return String(
  1346. pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
  1347. ).trim();
  1348. }
  1349. function cmtUserName(c) {
  1350. var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
  1351. return s || '—';
  1352. }
  1353. function cmtTime(c) {
  1354. return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
  1355. }
  1356. function cmtContent(c) {
  1357. return String(pick(c, ['content', 'commentContent', 'text']) || '');
  1358. }
  1359. function cmtLikeCount(c) {
  1360. var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
  1361. return v != null ? String(v) : '0';
  1362. }
  1363. function cmtReplies(c) {
  1364. if (!c || typeof c !== 'object') return [];
  1365. var sub =
  1366. c.childCommonComments ||
  1367. c.replyList ||
  1368. c.replyVOList ||
  1369. c.children ||
  1370. c.subComments ||
  1371. c.replies;
  1372. if (sub == null) return [];
  1373. return Array.isArray(sub) ? sub.filter(Boolean) : [];
  1374. }
  1375. function appendCmtRow(parentBody, c, showReply) {
  1376. var row = document.createElement('div');
  1377. row.className = 'goods-cmt__row';
  1378. var img = document.createElement('img');
  1379. img.className = 'goods-cmt__avatar';
  1380. img.alt = '';
  1381. var au = cmtAvatarUrl(c);
  1382. img.src = au || 'images/demouser.png';
  1383. var body = document.createElement('div');
  1384. body.className = 'goods-cmt__body';
  1385. var name = document.createElement('span');
  1386. name.className = 'goods-cmt__name';
  1387. name.textContent = cmtUserName(c);
  1388. var time = document.createElement('span');
  1389. time.className = 'goods-cmt__time';
  1390. time.textContent = cmtTime(c);
  1391. var text = document.createElement('p');
  1392. text.className = 'goods-cmt__text';
  1393. text.textContent = cmtContent(c);
  1394. var actions = document.createElement('div');
  1395. actions.className = 'goods-cmt__actions';
  1396. var likeBtn = document.createElement('button');
  1397. likeBtn.type = 'button';
  1398. likeBtn.className = 'goods-cmt__action';
  1399. likeBtn.setAttribute('aria-label', '点赞');
  1400. likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
  1401. actions.appendChild(likeBtn);
  1402. if (showReply) {
  1403. var repBtn = document.createElement('button');
  1404. repBtn.type = 'button';
  1405. repBtn.className = 'goods-cmt__action';
  1406. repBtn.setAttribute('aria-label', '回复');
  1407. repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
  1408. actions.appendChild(repBtn);
  1409. }
  1410. body.appendChild(name);
  1411. body.appendChild(time);
  1412. body.appendChild(text);
  1413. body.appendChild(actions);
  1414. row.appendChild(img);
  1415. row.appendChild(body);
  1416. parentBody.appendChild(row);
  1417. return body;
  1418. }
  1419. function buildNestedCmt(c) {
  1420. var wrap = document.createElement('div');
  1421. wrap.className = 'goods-cmt goods-cmt--nested';
  1422. appendCmtRow(wrap, c, false);
  1423. return wrap;
  1424. }
  1425. function filterTopLevelComments(list) {
  1426. if (!Array.isArray(list) || !list.length) return [];
  1427. var top = list.filter(function (c) {
  1428. if (!c) return false;
  1429. var pid = c.parentId != null ? c.parentId : c.pid;
  1430. if (typeof pid === 'string') pid = pid.trim();
  1431. return pid == null || pid === '' || Number(pid) === 0;
  1432. });
  1433. return top.length ? top : list.slice();
  1434. }
  1435. function countCommentsInApiList(records) {
  1436. if (!Array.isArray(records)) return 0;
  1437. var tops = filterTopLevelComments(records);
  1438. var n = 0;
  1439. for (var i = 0; i < tops.length; i++) {
  1440. var c = tops[i];
  1441. if (!c) continue;
  1442. n += 1 + cmtReplies(c).length;
  1443. }
  1444. return n;
  1445. }
  1446. function normalizeCommentListPayload(d) {
  1447. if (typeof d === 'string') {
  1448. try {
  1449. d = JSON.parse(d);
  1450. } catch (e) {
  1451. return { records: [], total: 0 };
  1452. }
  1453. }
  1454. if (Array.isArray(d)) {
  1455. return { records: d, total: countCommentsInApiList(d) };
  1456. }
  1457. if (d && typeof d === 'object') {
  1458. var arr = d.records || d.list || d.rows;
  1459. if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
  1460. if (!Array.isArray(arr)) arr = [];
  1461. var total =
  1462. d.total != null && !isNaN(Number(d.total))
  1463. ? Number(d.total)
  1464. : countCommentsInApiList(arr);
  1465. return { records: arr, total: total };
  1466. }
  1467. return { records: [], total: 0 };
  1468. }
  1469. function renderCommentsList(rows, total) {
  1470. var mount = document.getElementById('goodsCommentList');
  1471. var totEl = document.getElementById('goodsCommentTotal');
  1472. if (!mount) return;
  1473. mount.innerHTML = '';
  1474. var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
  1475. var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
  1476. if (totEl) totEl.textContent = String(n);
  1477. if (!list.length) {
  1478. var empty = document.createElement('li');
  1479. empty.className = 'goods-comments__empty';
  1480. empty.setAttribute('role', 'status');
  1481. empty.textContent = '暂无留言';
  1482. mount.appendChild(empty);
  1483. return;
  1484. }
  1485. list.forEach(function (c) {
  1486. if (!c) return;
  1487. var li = document.createElement('li');
  1488. li.className = 'goods-cmt';
  1489. appendCmtRow(li, c, true);
  1490. var replies = cmtReplies(c);
  1491. if (replies.length) {
  1492. var thread = document.createElement('div');
  1493. thread.className = 'goods-cmt__thread';
  1494. var inner = document.createElement('div');
  1495. inner.className = 'goods-cmt__replies-inner';
  1496. replies.forEach(function (r) {
  1497. if (r) inner.appendChild(buildNestedCmt(r));
  1498. });
  1499. var bar = document.createElement('button');
  1500. bar.type = 'button';
  1501. bar.className = 'goods-cmt__thread-bar';
  1502. bar.setAttribute('aria-expanded', 'true');
  1503. bar.innerHTML =
  1504. '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
  1505. '<span class="goods-cmt__thread-bar-right">' +
  1506. '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
  1507. thread.appendChild(inner);
  1508. thread.appendChild(bar);
  1509. li.appendChild(thread);
  1510. }
  1511. mount.appendChild(li);
  1512. });
  1513. }
  1514. function bindCommentThreadDelegation() {
  1515. var list = document.getElementById('goodsCommentList');
  1516. if (!list || list.dataset.threadDeleg) return;
  1517. list.dataset.threadDeleg = '1';
  1518. list.addEventListener('click', function (e) {
  1519. var bar = e.target.closest('.goods-cmt__thread-bar');
  1520. if (!bar) return;
  1521. var inner = bar.previousElementSibling;
  1522. if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
  1523. var collapsed = inner.classList.toggle('is-collapsed');
  1524. bar.classList.toggle('is-collapsed', collapsed);
  1525. bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
  1526. var lab = bar.querySelector('.js-thread-label');
  1527. if (lab) lab.textContent = collapsed ? '展开' : '收起';
  1528. });
  1529. }
  1530. function pickGoodsStatusFromStatusApi(res) {
  1531. if (!res || typeof res !== 'object') return null;
  1532. var d = isApiOk(res) ? (res.data != null ? res.data : res.result) : null;
  1533. if (d != null && typeof d === 'object' && d.goodsStatus != null) {
  1534. return d.goodsStatus;
  1535. }
  1536. if (res.goodsStatus != null) return res.goodsStatus;
  1537. return null;
  1538. }
  1539. /** 打开页时先拉取商品状态;query 参数名为 id */
  1540. function fetchGoodsStatusById(id) {
  1541. var sid = String(id != null ? id : '').trim();
  1542. if (!sid) return Promise.resolve(null);
  1543. var path =
  1544. '/secondGoods/getGoodsStatusById?id=' + encodeURIComponent(sid);
  1545. return fetch(API_BASE_SECOND + path, {
  1546. method: 'GET',
  1547. mode: 'cors',
  1548. credentials: 'omit',
  1549. headers: { Accept: 'application/json' }
  1550. }).then(function (res) {
  1551. if (!res.ok) throw new Error('HTTP ' + res.status);
  1552. return res.json();
  1553. });
  1554. }
  1555. function fetchSecondGoodsDetail(goodsId, lon, lat, phoneId) {
  1556. var lonStr =
  1557. lon != null && String(lon).trim() !== ''
  1558. ? String(lon).trim()
  1559. : String(DEFAULT_REQUEST_LONGITUDE);
  1560. var latStr =
  1561. lat != null && String(lat).trim() !== ''
  1562. ? String(lat).trim()
  1563. : String(DEFAULT_REQUEST_LATITUDE);
  1564. var pid =
  1565. phoneId != null && String(phoneId).trim() !== ''
  1566. ? String(phoneId).trim()
  1567. : '';
  1568. /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
  1569. var formBody = {
  1570. goodsId: String(goodsId != null ? goodsId : '').trim(),
  1571. longitude: String(lonStr),
  1572. latitude: String(latStr),
  1573. phoneId: pid
  1574. };
  1575. var form = new URLSearchParams();
  1576. form.set('goodsId', formBody.goodsId);
  1577. form.set('longitude', formBody.longitude);
  1578. form.set('latitude', formBody.latitude);
  1579. form.set('phoneId', formBody.phoneId);
  1580. return fetch(API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT', {
  1581. method: 'POST',
  1582. mode: 'cors',
  1583. credentials: 'omit',
  1584. headers: {
  1585. Accept: 'application/json',
  1586. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  1587. },
  1588. body: form.toString()
  1589. }).then(function (res) {
  1590. if (!res.ok) throw new Error('HTTP ' + res.status);
  1591. return res.json();
  1592. }).then(function (res) {
  1593. var d = isApiOk(res) ? res.data || res.result : null;
  1594. if (d && typeof d === 'object') {
  1595. renderGoodsDetail(d);
  1596. } else if (res && res.msg) {
  1597. console.warn('[querySecondGoodsDetail]', res.msg);
  1598. }
  1599. });
  1600. }
  1601. function fetchCommentList(goodsId, userId, pageNum, pageSize) {
  1602. var st = (q('sourceType') || '').trim();
  1603. var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
  1604. var path = '/commonComment/getListBySourceType?' +
  1605. 'sourceType=' + encodeURIComponent(String(sourceType)) +
  1606. '&sourceId=' + encodeURIComponent(String(goodsId)) +
  1607. '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
  1608. '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
  1609. '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
  1610. return apiGet(path).then(function (res) {
  1611. if (!isApiOk(res)) {
  1612. if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
  1613. renderCommentsList([], 0);
  1614. return;
  1615. }
  1616. var raw = res.data != null ? res.data : res.result;
  1617. var pack = normalizeCommentListPayload(raw);
  1618. renderCommentsList(pack.records, pack.total);
  1619. });
  1620. }
  1621. function run() {
  1622. var goodsId = (q('goodsId') || q('id') || '').trim();
  1623. var userId = (q('userId') || '').trim();
  1624. var phoneId = (q('phoneId') || q('phone_id') || '').trim();
  1625. var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  1626. var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
  1627. var pageNum = (q('pageNum') || '1').trim();
  1628. var pageSize = (q('pageSize') || '10').trim();
  1629. bindCommentThreadDelegation();
  1630. if (!goodsId) {
  1631. applyFromUrl();
  1632. return;
  1633. }
  1634. fetchGoodsStatusById(goodsId)
  1635. .catch(function (e) {
  1636. console.warn('[getGoodsStatusById]', e);
  1637. return null;
  1638. })
  1639. .then(function (statusRes) {
  1640. var gs = pickGoodsStatusFromStatusApi(statusRes);
  1641. var gsNum = gs != null ? Number(gs) : NaN;
  1642. var gsStr = gs != null ? String(gs).trim() : '';
  1643. var gsGotoUndefined =
  1644. gs != null &&
  1645. ((!isNaN(gsNum) && (gsNum === 2 || gsNum === 4 || gsNum === 5)) ||
  1646. gsStr === '2' || gsStr === '4' || gsStr === '5');
  1647. if (gsGotoUndefined) {
  1648. var uq = new URLSearchParams();
  1649. uq.set('goodsUnavailable', '1');
  1650. if (gs != null && String(gs).trim() !== '') {
  1651. uq.set('goodsStatus', String(gs).trim());
  1652. }
  1653. if (userId) {
  1654. uq.set('userId', userId);
  1655. }
  1656. window.location.replace('shareUndefined.html?' + uq.toString());
  1657. return { skipRest: true };
  1658. }
  1659. return Promise.all([
  1660. fetchSecondGoodsDetail(goodsId, lon, lat, phoneId).catch(function (e) {
  1661. console.warn('[querySecondGoodsDetail]', e);
  1662. }),
  1663. fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
  1664. console.warn('[getListBySourceType]', e);
  1665. renderCommentsList([], 0);
  1666. })
  1667. ]).then(function () {
  1668. return { skipRest: false };
  1669. });
  1670. })
  1671. .then(function (flag) {
  1672. if (flag && flag.skipRest) return;
  1673. applyFromUrl();
  1674. });
  1675. }
  1676. function applyFromUrl() {
  1677. var heroImg = document.getElementById('goodsHeroImg');
  1678. var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
  1679. imgUrl = tryDecode(imgUrl).trim();
  1680. if (imgUrl) {
  1681. heroImg.src = imgUrl;
  1682. heroImg.alt = '商品图';
  1683. } else {
  1684. heroImg.src = DEFAULT_HERO;
  1685. heroImg.alt = '';
  1686. }
  1687. var av = tryDecode(q('userImage') || q('avatar')).trim();
  1688. document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
  1689. var uname = tryDecode(q('userName') || q('nickname')).trim();
  1690. if (uname) document.getElementById('goodsUserName').textContent = uname;
  1691. var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
  1692. if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
  1693. var s1 = tryDecode(q('slogan1') || q('line1')).trim();
  1694. var s2 = tryDecode(q('slogan2') || q('line2')).trim();
  1695. var elS1 = document.getElementById('goodsSlogan1');
  1696. var elS2 = document.getElementById('goodsSlogan2');
  1697. var elWrap = document.getElementById('goodsHeroSloganWrap');
  1698. if (s1 && elS1) elS1.textContent = s1;
  1699. if (s2 && elS2) elS2.textContent = s2;
  1700. if (elWrap && (s1 || s2)) elWrap.style.display = '';
  1701. var price = tryDecode(q('price')).trim();
  1702. if (price) {
  1703. var pn = parseFloat(price.replace(/[^\d.]/g, ''));
  1704. document.getElementById('goodsPrice').textContent =
  1705. !isNaN(pn) ? pn.toFixed(2) : price;
  1706. }
  1707. var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
  1708. if (dist) {
  1709. if (!/^距离/.test(dist)) dist = '距离 ' + dist;
  1710. if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
  1711. dist = dist.replace(/\s+$/, '') + 'km';
  1712. }
  1713. document.getElementById('goodsDistance').textContent = dist;
  1714. }
  1715. var title = tryDecode(q('title') || q('goodsTitle')).trim();
  1716. if (title) document.getElementById('goodsTitle').textContent = title;
  1717. var hot = tryDecode(q('hotCount') || q('hot')).trim();
  1718. if (hot) document.getElementById('goodsHotCount').textContent = hot;
  1719. var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
  1720. if (fav) document.getElementById('goodsFavCount').textContent = fav;
  1721. var cc = tryDecode(q('commentCount') || q('comments')).trim();
  1722. if (cc) {
  1723. var elTot = document.getElementById('goodsCommentTotal');
  1724. if (elTot) elTot.textContent = cc;
  1725. }
  1726. var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
  1727. var mount = document.getElementById('goodsTags');
  1728. var hasGoodsId = (q('goodsId') || q('id') || '').trim();
  1729. if (mount) {
  1730. if (tagsRaw) {
  1731. mount.innerHTML = '';
  1732. tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
  1733. appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
  1734. });
  1735. } else if (!hasGoodsId) {
  1736. mount.innerHTML = '';
  1737. ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
  1738. appendGoodsTag(mount, t, 'label');
  1739. });
  1740. }
  1741. }
  1742. }
  1743. function sharePage() {
  1744. var title = document.getElementById('goodsTitle').textContent || '商品分享';
  1745. var url = location.href;
  1746. if (navigator.share) {
  1747. navigator.share({ title: title, text: title, url: url }).catch(function () {});
  1748. return;
  1749. }
  1750. if (navigator.clipboard && navigator.clipboard.writeText) {
  1751. navigator.clipboard.writeText(url).then(function () {
  1752. window.alert('链接已复制');
  1753. }).catch(function () {
  1754. window.prompt('复制链接', url);
  1755. });
  1756. } else {
  1757. window.prompt('复制链接', url);
  1758. }
  1759. }
  1760. var shareBtn = document.getElementById('goodsShareBtn');
  1761. if (shareBtn) shareBtn.addEventListener('click', sharePage);
  1762. function boot() {
  1763. var launchTag = document.getElementById('launch-btn');
  1764. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1765. bindWeChatLaunchTagEvents();
  1766. if (shouldInitWeChatJssdkOnLoad()) {
  1767. if (isWeChatInAppBrowser()) document.body.classList.add('is-wechat');
  1768. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1769. document.body.classList.add('wx-pc-debug');
  1770. }
  1771. scheduleWeChatJssdkBootstrap();
  1772. }
  1773. if (isWeChatInAppBrowser()) {
  1774. var openBtnWx = document.getElementById('openApp');
  1775. if (openBtnWx) {
  1776. openBtnWx.addEventListener('click', function () {
  1777. if (!weChatJssdkConfigured) {
  1778. showFabToast(
  1779. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1780. );
  1781. }
  1782. });
  1783. }
  1784. } else {
  1785. var openAppBtn = document.getElementById('openApp');
  1786. if (openAppBtn) {
  1787. openAppBtn.addEventListener('click', tryOpenHBuilderApp);
  1788. }
  1789. }
  1790. run();
  1791. }
  1792. if (document.readyState === 'complete') {
  1793. boot();
  1794. } else {
  1795. window.onload = boot;
  1796. }
  1797. })();
  1798. </script>
  1799. </body>
  1800. </html>