secondShareGoods.html 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  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. /** 与接口调试「表单数据」一致;优先取地址栏 longitude/latitude,未带时用默认坐标 */
  1168. var DEFAULT_REQUEST_LONGITUDE =
  1169. (q('longitude') || q('lon') || q('jingdu') || '').trim() || '121.662567';
  1170. var DEFAULT_REQUEST_LATITUDE =
  1171. (q('latitude') || q('lat') || q('weidu') || '').trim() || '38.925757';
  1172. var COMMENT_SOURCE_TYPE = 4;
  1173. function apiGet(path) {
  1174. return fetch(API_BASE + path, {
  1175. method: 'GET',
  1176. mode: 'cors',
  1177. credentials: 'omit',
  1178. headers: { Accept: 'application/json' }
  1179. }).then(function (res) {
  1180. if (!res.ok) throw new Error('HTTP ' + res.status);
  1181. return res.json();
  1182. });
  1183. }
  1184. function apiPostJson(path, body) {
  1185. return fetch(API_BASE + path, {
  1186. method: 'POST',
  1187. mode: 'cors',
  1188. credentials: 'omit',
  1189. headers: {
  1190. Accept: 'application/json',
  1191. 'Content-Type': 'application/json'
  1192. },
  1193. body: JSON.stringify(body || {})
  1194. }).then(function (res) {
  1195. if (!res.ok) throw new Error('HTTP ' + res.status);
  1196. return res.json();
  1197. });
  1198. }
  1199. function pick(d, keys) {
  1200. if (!d || typeof d !== 'object') return null;
  1201. for (var i = 0; i < keys.length; i++) {
  1202. var k = keys[i];
  1203. if (d[k] != null && d[k] !== '') return d[k];
  1204. }
  1205. return null;
  1206. }
  1207. function isApiOk(res) {
  1208. if (!res || typeof res !== 'object') return false;
  1209. if (res.success === false) return false;
  1210. var c = res.code;
  1211. return c === 200 || c === '200' || Number(c) === 200;
  1212. }
  1213. function fmtPriceNum(v) {
  1214. var n = v != null ? Number(v) : NaN;
  1215. return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
  1216. }
  1217. /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
  1218. function appendGoodsTag(mount, raw, kind) {
  1219. if (!mount || raw == null) return;
  1220. var s = String(raw).trim();
  1221. if (!s) return;
  1222. var span = document.createElement('span');
  1223. span.className =
  1224. 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
  1225. if (kind === 'label') {
  1226. span.textContent = s.replace(/^#+/, '');
  1227. } else {
  1228. span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
  1229. }
  1230. mount.appendChild(span);
  1231. }
  1232. function renderGoodsDetail(d) {
  1233. if (!d || typeof d !== 'object') return;
  1234. var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
  1235. if (title) {
  1236. var el = document.getElementById('goodsTitle');
  1237. if (el) el.textContent = String(title);
  1238. }
  1239. var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
  1240. if (price != null) {
  1241. var pe = document.getElementById('goodsPrice');
  1242. if (pe) pe.textContent = fmtPriceNum(price);
  1243. }
  1244. var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
  1245. if (dist != null) {
  1246. var dt = String(dist).trim();
  1247. if (dt) {
  1248. if (!/^距离/.test(dt)) dt = '距离 ' + dt;
  1249. if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
  1250. dt = dt.replace(/\s+$/, '') + 'km';
  1251. }
  1252. var de = document.getElementById('goodsDistance');
  1253. if (de) de.textContent = dt;
  1254. }
  1255. }
  1256. var img =
  1257. pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
  1258. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
  1259. (Array.isArray(d.imageList) && d.imageList[0]);
  1260. if (img) {
  1261. var hi = document.getElementById('goodsHeroImg');
  1262. if (hi) {
  1263. hi.src = String(img);
  1264. hi.alt = '商品图';
  1265. }
  1266. }
  1267. var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
  1268. if (nick) {
  1269. var ne = document.getElementById('goodsUserName');
  1270. if (ne) ne.textContent = String(nick);
  1271. }
  1272. var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
  1273. if (av) {
  1274. var ae = document.getElementById('goodsUserAvatar');
  1275. if (ae) ae.src = String(av);
  1276. }
  1277. var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
  1278. if (tm) {
  1279. var te = document.getElementById('goodsTimeAgo');
  1280. if (te) te.textContent = String(tm);
  1281. }
  1282. var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
  1283. var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
  1284. var wrap = document.getElementById('goodsHeroSloganWrap');
  1285. var e1 = document.getElementById('goodsSlogan1');
  1286. var e2 = document.getElementById('goodsSlogan2');
  1287. if (wrap && e1 && e2) {
  1288. if (s1 || s2) {
  1289. if (s1) e1.textContent = String(s1);
  1290. if (s2) e2.textContent = String(s2);
  1291. wrap.style.display = '';
  1292. } else {
  1293. wrap.style.display = 'none';
  1294. }
  1295. }
  1296. var hotStat = document.getElementById('goodsHotStat');
  1297. var cs = pick(d, ['collectStatus']);
  1298. if (hotStat) {
  1299. var hideHot =
  1300. cs != null &&
  1301. (Number(cs) === 0 || String(cs).trim() === '0');
  1302. hotStat.style.display = hideHot ? 'none' : '';
  1303. }
  1304. var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
  1305. if (hot != null) {
  1306. var he = document.getElementById('goodsHotCount');
  1307. if (he) he.textContent = String(hot);
  1308. }
  1309. var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
  1310. if (fav != null) {
  1311. var fe = document.getElementById('goodsFavCount');
  1312. if (fe) fe.textContent = String(fav);
  1313. }
  1314. var topicStr = d.topic != null ? String(d.topic).trim() : '';
  1315. var labelStr = d.label != null ? String(d.label).trim() : '';
  1316. var hasApiTags = topicStr !== '' || labelStr !== '';
  1317. var mount = document.getElementById('goodsTags');
  1318. if (mount) {
  1319. if (hasApiTags) {
  1320. mount.innerHTML = '';
  1321. if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
  1322. if (labelStr) appendGoodsTag(mount, labelStr, 'label');
  1323. } else {
  1324. var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
  1325. if (tags) {
  1326. mount.innerHTML = '';
  1327. var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
  1328. arr.forEach(function (t) {
  1329. if (t == null || t === '') return;
  1330. var label =
  1331. typeof t === 'object'
  1332. ? (t.tagName || t.name || t.label || '')
  1333. : String(t);
  1334. label = String(label).trim();
  1335. if (!label) return;
  1336. var isTopic = label.indexOf('#') === 0;
  1337. appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
  1338. });
  1339. }
  1340. }
  1341. }
  1342. }
  1343. 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>';
  1344. 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>';
  1345. 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>';
  1346. function cmtAvatarUrl(c) {
  1347. return String(
  1348. pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
  1349. ).trim();
  1350. }
  1351. function cmtUserName(c) {
  1352. var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
  1353. return s || '—';
  1354. }
  1355. function cmtTime(c) {
  1356. return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
  1357. }
  1358. function cmtContent(c) {
  1359. return String(pick(c, ['content', 'commentContent', 'text']) || '');
  1360. }
  1361. function cmtLikeCount(c) {
  1362. var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
  1363. return v != null ? String(v) : '0';
  1364. }
  1365. function cmtReplies(c) {
  1366. if (!c || typeof c !== 'object') return [];
  1367. var sub =
  1368. c.childCommonComments ||
  1369. c.replyList ||
  1370. c.replyVOList ||
  1371. c.children ||
  1372. c.subComments ||
  1373. c.replies;
  1374. if (sub == null) return [];
  1375. return Array.isArray(sub) ? sub.filter(Boolean) : [];
  1376. }
  1377. function appendCmtRow(parentBody, c, showReply) {
  1378. var row = document.createElement('div');
  1379. row.className = 'goods-cmt__row';
  1380. var img = document.createElement('img');
  1381. img.className = 'goods-cmt__avatar';
  1382. img.alt = '';
  1383. var au = cmtAvatarUrl(c);
  1384. img.src = au || 'images/demouser.png';
  1385. var body = document.createElement('div');
  1386. body.className = 'goods-cmt__body';
  1387. var name = document.createElement('span');
  1388. name.className = 'goods-cmt__name';
  1389. name.textContent = cmtUserName(c);
  1390. var time = document.createElement('span');
  1391. time.className = 'goods-cmt__time';
  1392. time.textContent = cmtTime(c);
  1393. var text = document.createElement('p');
  1394. text.className = 'goods-cmt__text';
  1395. text.textContent = cmtContent(c);
  1396. var actions = document.createElement('div');
  1397. actions.className = 'goods-cmt__actions';
  1398. var likeBtn = document.createElement('button');
  1399. likeBtn.type = 'button';
  1400. likeBtn.className = 'goods-cmt__action';
  1401. likeBtn.setAttribute('aria-label', '点赞');
  1402. likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
  1403. actions.appendChild(likeBtn);
  1404. if (showReply) {
  1405. var repBtn = document.createElement('button');
  1406. repBtn.type = 'button';
  1407. repBtn.className = 'goods-cmt__action';
  1408. repBtn.setAttribute('aria-label', '回复');
  1409. repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
  1410. actions.appendChild(repBtn);
  1411. }
  1412. body.appendChild(name);
  1413. body.appendChild(time);
  1414. body.appendChild(text);
  1415. body.appendChild(actions);
  1416. row.appendChild(img);
  1417. row.appendChild(body);
  1418. parentBody.appendChild(row);
  1419. return body;
  1420. }
  1421. function buildNestedCmt(c) {
  1422. var wrap = document.createElement('div');
  1423. wrap.className = 'goods-cmt goods-cmt--nested';
  1424. appendCmtRow(wrap, c, false);
  1425. return wrap;
  1426. }
  1427. function filterTopLevelComments(list) {
  1428. if (!Array.isArray(list) || !list.length) return [];
  1429. var top = list.filter(function (c) {
  1430. if (!c) return false;
  1431. var pid = c.parentId != null ? c.parentId : c.pid;
  1432. if (typeof pid === 'string') pid = pid.trim();
  1433. return pid == null || pid === '' || Number(pid) === 0;
  1434. });
  1435. return top.length ? top : list.slice();
  1436. }
  1437. function countCommentsInApiList(records) {
  1438. if (!Array.isArray(records)) return 0;
  1439. var tops = filterTopLevelComments(records);
  1440. var n = 0;
  1441. for (var i = 0; i < tops.length; i++) {
  1442. var c = tops[i];
  1443. if (!c) continue;
  1444. n += 1 + cmtReplies(c).length;
  1445. }
  1446. return n;
  1447. }
  1448. function normalizeCommentListPayload(d) {
  1449. if (typeof d === 'string') {
  1450. try {
  1451. d = JSON.parse(d);
  1452. } catch (e) {
  1453. return { records: [], total: 0 };
  1454. }
  1455. }
  1456. if (Array.isArray(d)) {
  1457. return { records: d, total: countCommentsInApiList(d) };
  1458. }
  1459. if (d && typeof d === 'object') {
  1460. var arr = d.records || d.list || d.rows;
  1461. if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
  1462. if (!Array.isArray(arr)) arr = [];
  1463. var total =
  1464. d.total != null && !isNaN(Number(d.total))
  1465. ? Number(d.total)
  1466. : countCommentsInApiList(arr);
  1467. return { records: arr, total: total };
  1468. }
  1469. return { records: [], total: 0 };
  1470. }
  1471. function renderCommentsList(rows, total) {
  1472. var mount = document.getElementById('goodsCommentList');
  1473. var totEl = document.getElementById('goodsCommentTotal');
  1474. if (!mount) return;
  1475. mount.innerHTML = '';
  1476. var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
  1477. var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
  1478. if (totEl) totEl.textContent = String(n);
  1479. if (!list.length) {
  1480. var empty = document.createElement('li');
  1481. empty.className = 'goods-comments__empty';
  1482. empty.setAttribute('role', 'status');
  1483. empty.textContent = '暂无留言';
  1484. mount.appendChild(empty);
  1485. return;
  1486. }
  1487. list.forEach(function (c) {
  1488. if (!c) return;
  1489. var li = document.createElement('li');
  1490. li.className = 'goods-cmt';
  1491. appendCmtRow(li, c, true);
  1492. var replies = cmtReplies(c);
  1493. if (replies.length) {
  1494. var thread = document.createElement('div');
  1495. thread.className = 'goods-cmt__thread';
  1496. var inner = document.createElement('div');
  1497. inner.className = 'goods-cmt__replies-inner';
  1498. replies.forEach(function (r) {
  1499. if (r) inner.appendChild(buildNestedCmt(r));
  1500. });
  1501. var bar = document.createElement('button');
  1502. bar.type = 'button';
  1503. bar.className = 'goods-cmt__thread-bar';
  1504. bar.setAttribute('aria-expanded', 'true');
  1505. bar.innerHTML =
  1506. '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
  1507. '<span class="goods-cmt__thread-bar-right">' +
  1508. '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
  1509. thread.appendChild(inner);
  1510. thread.appendChild(bar);
  1511. li.appendChild(thread);
  1512. }
  1513. mount.appendChild(li);
  1514. });
  1515. }
  1516. function bindCommentThreadDelegation() {
  1517. var list = document.getElementById('goodsCommentList');
  1518. if (!list || list.dataset.threadDeleg) return;
  1519. list.dataset.threadDeleg = '1';
  1520. list.addEventListener('click', function (e) {
  1521. var bar = e.target.closest('.goods-cmt__thread-bar');
  1522. if (!bar) return;
  1523. var inner = bar.previousElementSibling;
  1524. if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
  1525. var collapsed = inner.classList.toggle('is-collapsed');
  1526. bar.classList.toggle('is-collapsed', collapsed);
  1527. bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
  1528. var lab = bar.querySelector('.js-thread-label');
  1529. if (lab) lab.textContent = collapsed ? '展开' : '收起';
  1530. });
  1531. }
  1532. function pickGoodsStatusFromStatusApi(res) {
  1533. if (!res || typeof res !== 'object') return null;
  1534. var d = isApiOk(res) ? (res.data != null ? res.data : res.result) : null;
  1535. if (d != null && typeof d === 'object' && d.goodsStatus != null) {
  1536. return d.goodsStatus;
  1537. }
  1538. if (res.goodsStatus != null) return res.goodsStatus;
  1539. return null;
  1540. }
  1541. /** 打开页时先拉取商品状态;query 参数名为 id */
  1542. function fetchGoodsStatusById(id) {
  1543. var sid = String(id != null ? id : '').trim();
  1544. if (!sid) return Promise.resolve(null);
  1545. var path =
  1546. '/secondGoods/getGoodsStatusById?id=' + encodeURIComponent(sid);
  1547. return fetch(API_BASE_SECOND + path, {
  1548. method: 'GET',
  1549. mode: 'cors',
  1550. credentials: 'omit',
  1551. headers: { Accept: 'application/json' }
  1552. }).then(function (res) {
  1553. if (!res.ok) throw new Error('HTTP ' + res.status);
  1554. return res.json();
  1555. });
  1556. }
  1557. function fetchSecondGoodsDetail(goodsId, lon, lat, phoneId) {
  1558. var lonStr =
  1559. lon != null && String(lon).trim() !== ''
  1560. ? String(lon).trim()
  1561. : String(DEFAULT_REQUEST_LONGITUDE);
  1562. var latStr =
  1563. lat != null && String(lat).trim() !== ''
  1564. ? String(lat).trim()
  1565. : String(DEFAULT_REQUEST_LATITUDE);
  1566. var pid =
  1567. phoneId != null && String(phoneId).trim() !== ''
  1568. ? String(phoneId).trim()
  1569. : '';
  1570. /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
  1571. var formBody = {
  1572. goodsId: String(goodsId != null ? goodsId : '').trim(),
  1573. longitude: String(lonStr),
  1574. latitude: String(latStr),
  1575. phoneId: pid
  1576. };
  1577. var form = new URLSearchParams();
  1578. form.set('goodsId', formBody.goodsId);
  1579. form.set('longitude', formBody.longitude);
  1580. form.set('latitude', formBody.latitude);
  1581. form.set('phoneId', formBody.phoneId);
  1582. return fetch(API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT', {
  1583. method: 'POST',
  1584. mode: 'cors',
  1585. credentials: 'omit',
  1586. headers: {
  1587. Accept: 'application/json',
  1588. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  1589. },
  1590. body: form.toString()
  1591. }).then(function (res) {
  1592. if (!res.ok) throw new Error('HTTP ' + res.status);
  1593. return res.json();
  1594. }).then(function (res) {
  1595. var d = isApiOk(res) ? res.data || res.result : null;
  1596. if (d && typeof d === 'object') {
  1597. renderGoodsDetail(d);
  1598. } else if (res && res.msg) {
  1599. console.warn('[querySecondGoodsDetail]', res.msg);
  1600. }
  1601. });
  1602. }
  1603. function fetchCommentList(goodsId, userId, pageNum, pageSize) {
  1604. var st = (q('sourceType') || '').trim();
  1605. var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
  1606. var path = '/commonComment/getListBySourceType?' +
  1607. 'sourceType=' + encodeURIComponent(String(sourceType)) +
  1608. '&sourceId=' + encodeURIComponent(String(goodsId)) +
  1609. '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
  1610. '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
  1611. '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
  1612. return apiGet(path).then(function (res) {
  1613. if (!isApiOk(res)) {
  1614. if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
  1615. renderCommentsList([], 0);
  1616. return;
  1617. }
  1618. var raw = res.data != null ? res.data : res.result;
  1619. var pack = normalizeCommentListPayload(raw);
  1620. renderCommentsList(pack.records, pack.total);
  1621. });
  1622. }
  1623. function run() {
  1624. var goodsId = (q('goodsId') || q('id') || '').trim();
  1625. var userId = (q('userId') || '').trim();
  1626. var phoneId = (q('phoneId') || q('phone_id') || '').trim();
  1627. var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  1628. var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
  1629. var userCity = (q('userCity') || q('city') || '').trim();
  1630. var lonResolved = lon || DEFAULT_REQUEST_LONGITUDE;
  1631. var latResolved = lat || DEFAULT_REQUEST_LATITUDE;
  1632. var pageNum = (q('pageNum') || '1').trim();
  1633. var pageSize = (q('pageSize') || '10').trim();
  1634. bindCommentThreadDelegation();
  1635. if (!goodsId) {
  1636. applyFromUrl();
  1637. return;
  1638. }
  1639. fetchGoodsStatusById(goodsId)
  1640. .catch(function (e) {
  1641. console.warn('[getGoodsStatusById]', e);
  1642. return null;
  1643. })
  1644. .then(function (statusRes) {
  1645. var gs = pickGoodsStatusFromStatusApi(statusRes);
  1646. var gsNum = gs != null ? Number(gs) : NaN;
  1647. var gsStr = gs != null ? String(gs).trim() : '';
  1648. var gsGotoUndefined =
  1649. gs != null &&
  1650. ((!isNaN(gsNum) && (gsNum === 2 || gsNum === 4 || gsNum === 5)) ||
  1651. gsStr === '2' || gsStr === '4' || gsStr === '5');
  1652. if (gsGotoUndefined) {
  1653. var uq = new URLSearchParams();
  1654. uq.set('goodsUnavailable', '1');
  1655. if (gs != null && String(gs).trim() !== '') {
  1656. uq.set('goodsStatus', String(gs).trim());
  1657. }
  1658. if (userId) {
  1659. uq.set('userId', userId);
  1660. }
  1661. uq.set('longitude', lonResolved);
  1662. uq.set('latitude', latResolved);
  1663. if (userCity) {
  1664. uq.set('userCity', userCity);
  1665. }
  1666. window.location.replace('shareUndefined.html?' + uq.toString());
  1667. return { skipRest: true };
  1668. }
  1669. return Promise.all([
  1670. fetchSecondGoodsDetail(goodsId, lon, lat, phoneId).catch(function (e) {
  1671. console.warn('[querySecondGoodsDetail]', e);
  1672. }),
  1673. fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
  1674. console.warn('[getListBySourceType]', e);
  1675. renderCommentsList([], 0);
  1676. })
  1677. ]).then(function () {
  1678. return { skipRest: false };
  1679. });
  1680. })
  1681. .then(function (flag) {
  1682. if (flag && flag.skipRest) return;
  1683. applyFromUrl();
  1684. });
  1685. }
  1686. function applyFromUrl() {
  1687. var heroImg = document.getElementById('goodsHeroImg');
  1688. var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
  1689. imgUrl = tryDecode(imgUrl).trim();
  1690. if (imgUrl) {
  1691. heroImg.src = imgUrl;
  1692. heroImg.alt = '商品图';
  1693. } else {
  1694. heroImg.src = DEFAULT_HERO;
  1695. heroImg.alt = '';
  1696. }
  1697. var av = tryDecode(q('userImage') || q('avatar')).trim();
  1698. document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
  1699. var uname = tryDecode(q('userName') || q('nickname')).trim();
  1700. if (uname) document.getElementById('goodsUserName').textContent = uname;
  1701. var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
  1702. if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
  1703. var s1 = tryDecode(q('slogan1') || q('line1')).trim();
  1704. var s2 = tryDecode(q('slogan2') || q('line2')).trim();
  1705. var elS1 = document.getElementById('goodsSlogan1');
  1706. var elS2 = document.getElementById('goodsSlogan2');
  1707. var elWrap = document.getElementById('goodsHeroSloganWrap');
  1708. if (s1 && elS1) elS1.textContent = s1;
  1709. if (s2 && elS2) elS2.textContent = s2;
  1710. if (elWrap && (s1 || s2)) elWrap.style.display = '';
  1711. var price = tryDecode(q('price')).trim();
  1712. if (price) {
  1713. var pn = parseFloat(price.replace(/[^\d.]/g, ''));
  1714. document.getElementById('goodsPrice').textContent =
  1715. !isNaN(pn) ? pn.toFixed(2) : price;
  1716. }
  1717. var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
  1718. if (dist) {
  1719. if (!/^距离/.test(dist)) dist = '距离 ' + dist;
  1720. if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
  1721. dist = dist.replace(/\s+$/, '') + 'km';
  1722. }
  1723. document.getElementById('goodsDistance').textContent = dist;
  1724. }
  1725. var title = tryDecode(q('title') || q('goodsTitle')).trim();
  1726. if (title) document.getElementById('goodsTitle').textContent = title;
  1727. var hot = tryDecode(q('hotCount') || q('hot')).trim();
  1728. if (hot) document.getElementById('goodsHotCount').textContent = hot;
  1729. var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
  1730. if (fav) document.getElementById('goodsFavCount').textContent = fav;
  1731. var cc = tryDecode(q('commentCount') || q('comments')).trim();
  1732. if (cc) {
  1733. var elTot = document.getElementById('goodsCommentTotal');
  1734. if (elTot) elTot.textContent = cc;
  1735. }
  1736. var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
  1737. var mount = document.getElementById('goodsTags');
  1738. var hasGoodsId = (q('goodsId') || q('id') || '').trim();
  1739. if (mount) {
  1740. if (tagsRaw) {
  1741. mount.innerHTML = '';
  1742. tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
  1743. appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
  1744. });
  1745. } else if (!hasGoodsId) {
  1746. mount.innerHTML = '';
  1747. ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
  1748. appendGoodsTag(mount, t, 'label');
  1749. });
  1750. }
  1751. }
  1752. }
  1753. function sharePage() {
  1754. var title = document.getElementById('goodsTitle').textContent || '商品分享';
  1755. var url = location.href;
  1756. if (navigator.share) {
  1757. navigator.share({ title: title, text: title, url: url }).catch(function () {});
  1758. return;
  1759. }
  1760. if (navigator.clipboard && navigator.clipboard.writeText) {
  1761. navigator.clipboard.writeText(url).then(function () {
  1762. window.alert('链接已复制');
  1763. }).catch(function () {
  1764. window.prompt('复制链接', url);
  1765. });
  1766. } else {
  1767. window.prompt('复制链接', url);
  1768. }
  1769. }
  1770. var shareBtn = document.getElementById('goodsShareBtn');
  1771. if (shareBtn) shareBtn.addEventListener('click', sharePage);
  1772. function boot() {
  1773. var launchTag = document.getElementById('launch-btn');
  1774. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1775. bindWeChatLaunchTagEvents();
  1776. if (shouldInitWeChatJssdkOnLoad()) {
  1777. if (isWeChatInAppBrowser()) document.body.classList.add('is-wechat');
  1778. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1779. document.body.classList.add('wx-pc-debug');
  1780. }
  1781. scheduleWeChatJssdkBootstrap();
  1782. }
  1783. if (isWeChatInAppBrowser()) {
  1784. var openBtnWx = document.getElementById('openApp');
  1785. if (openBtnWx) {
  1786. openBtnWx.addEventListener('click', function () {
  1787. if (!weChatJssdkConfigured) {
  1788. showFabToast(
  1789. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1790. );
  1791. }
  1792. });
  1793. }
  1794. } else {
  1795. var openAppBtn = document.getElementById('openApp');
  1796. if (openAppBtn) {
  1797. openAppBtn.addEventListener('click', tryOpenHBuilderApp);
  1798. }
  1799. }
  1800. run();
  1801. }
  1802. if (document.readyState === 'complete') {
  1803. boot();
  1804. } else {
  1805. window.onload = boot;
  1806. }
  1807. })();
  1808. </script>
  1809. </body>
  1810. </html>