secondShareGoods.html 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  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: 198px;
  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: 198px;
  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="198" 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. * 进入页先校验商品是否存在:
  595. * POST {API_BASE_SECOND}/recommend/querySecondGoodsDetailWithOutJWT
  596. * body(x-www-form-urlencoded):goodsId、longitude、latitude、phoneId(均为字符串)
  597. * 无有效 data 或已下架/删除 → shareUndefined.html;有 data → renderGoodsDetail 再拉留言
  598. * 留言:GET {API_BASE}/commonComment/getListBySourceType
  599. * URL:goodsId、userId、phoneId、longitude/lon/jingdu、latitude/lat/weidu、alienSecondBase(可选覆盖二手接口前缀)
  600. */
  601. /**
  602. * 唤起 App 落地:二手商品详情(与 pages.json 路径一致)
  603. */
  604. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  605. var APP_IOS_URL_SCHEME = 'shopro://';
  606. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  607. var API_BASE = 'https://test.ailien.shop/alienStore';
  608. /**
  609. * 微信 JSSDK — 与 shareIndex.html 一致
  610. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  611. */
  612. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  613. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  614. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  615. var H5_PAGE_BASE_FALLBACK = 'https://test.ailien.shop/h5/HBuilderProjects/';
  616. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'secondShareGoods.html';
  617. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'test.ailien.shop'];
  618. var weChatJssdkConfigured = false;
  619. var wxConfigSignRetriedBaseUrl = false;
  620. var wxInitLastError = '';
  621. var wxJssdkInitPromise = null;
  622. function showDownloadTip() {
  623. var msg = '请到应用商店下载';
  624. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  625. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  626. } else {
  627. window.alert(msg);
  628. }
  629. }
  630. function mergeSearchAndHashParams() {
  631. var params = new URLSearchParams();
  632. function ingestAppend(querySlice) {
  633. if (!querySlice) return;
  634. var p = new URLSearchParams(querySlice);
  635. p.forEach(function (val, key) {
  636. params.append(key, val);
  637. });
  638. }
  639. function ingestSet(querySlice) {
  640. if (!querySlice) return;
  641. var p = new URLSearchParams(querySlice);
  642. p.forEach(function (val, key) {
  643. params.set(key, val);
  644. });
  645. }
  646. if (location.search && location.search.length > 1) {
  647. ingestAppend(location.search.slice(1));
  648. }
  649. var hash = location.hash || '';
  650. var qi = hash.indexOf('?');
  651. if (qi >= 0) {
  652. ingestSet(hash.slice(qi + 1));
  653. }
  654. return params;
  655. }
  656. function q(name) {
  657. var v = mergeSearchAndHashParams().get(name);
  658. return v == null ? '' : String(v);
  659. }
  660. function buildAppOpenQueryStringMerged() {
  661. var params = mergeSearchAndHashParams();
  662. var gid = params.get('goodsId') || params.get('id') || '';
  663. if (gid && !params.has('goodsId')) {
  664. params.set('goodsId', gid);
  665. }
  666. var sid = params.get('storeId') || params.get('id') || '';
  667. if (sid && !params.has('storeId')) {
  668. params.set('storeId', sid);
  669. }
  670. var qsOut = params.toString();
  671. return qsOut ? ('?' + qsOut) : '';
  672. }
  673. function getSecondGoodsAppUniPath() {
  674. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  675. /^\//,
  676. ''
  677. );
  678. }
  679. function buildAppDeepLink() {
  680. var path = getSecondGoodsAppUniPath();
  681. var s = buildAppOpenQueryStringMerged();
  682. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  683. if (!s) {
  684. return root + '/' + path;
  685. }
  686. return root + '/' + path + s;
  687. }
  688. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  689. function buildAppUniPageLaunchUrl() {
  690. var path = getSecondGoodsAppUniPath();
  691. var qs = buildAppOpenQueryStringMerged().replace(/^\?/, '');
  692. return qs ? path + '?' + qs : path;
  693. }
  694. /**
  695. * wx-open-launch-app extinfo:pages/secondHandTransactions/pages/detail/index?goodsId=…
  696. */
  697. function buildWeChatLaunchExtinfo() {
  698. var uniPage = buildAppUniPageLaunchUrl();
  699. if (uniPage.length <= 1024) return uniPage;
  700. var params = mergeSearchAndHashParams();
  701. var mini = new URLSearchParams();
  702. var goodsId = params.get('goodsId') || params.get('id') || '';
  703. if (goodsId) mini.set('goodsId', goodsId);
  704. var path = getSecondGoodsAppUniPath();
  705. var shortPage = path + '?' + mini.toString();
  706. if (shortPage.length <= 1024) return shortPage;
  707. return shortPage.slice(0, 1024);
  708. }
  709. function isWeChatInAppBrowser() {
  710. return /MicroMessenger/i.test(navigator.userAgent || '');
  711. }
  712. /**
  713. * 复制链接进入常无 from=;与点击分享卡片对齐,在拉 getWxConfig 前补 from=singlemessage(不刷新页面)。
  714. */
  715. function ensureWxShareFromQueryBeforeConfig() {
  716. if (!isWeChatInAppBrowser()) return;
  717. var from = String(q('from') || '').trim();
  718. if (from) return;
  719. try {
  720. var u = new URL(location.href);
  721. u.searchParams.set('from', 'singlemessage');
  722. history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
  723. } catch (eFrom) {
  724. var sep = location.search && location.search.length > 1 ? '&' : '?';
  725. history.replaceState(
  726. null,
  727. '',
  728. location.pathname +
  729. (location.search || '') +
  730. sep +
  731. 'from=singlemessage' +
  732. (location.hash || '')
  733. );
  734. }
  735. }
  736. function logWxEntryDiagnostics() {
  737. if (!isWeChatInAppBrowser()) return;
  738. console.log('[wx-entry]', {
  739. entryFrom: q('from') || '(无)',
  740. signUrl: getWxConfigSignUrl()
  741. });
  742. }
  743. function readQueryParam(name) {
  744. return q(name);
  745. }
  746. function isWxDebugOn() {
  747. return readQueryParam('wxDebug') === '1';
  748. }
  749. function isWxForceDebug() {
  750. return readQueryParam('wxForce') === '1';
  751. }
  752. function isWxConfigOnClickDebug() {
  753. return readQueryParam('wxConfigOnClick') === '1';
  754. }
  755. function isWxPcAutoDebugHost() {
  756. var h = (location.hostname || '').toLowerCase();
  757. if (h === 'localhost' || h === '127.0.0.1') return true;
  758. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  759. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  760. }
  761. return false;
  762. }
  763. function isWxPcBrowser() {
  764. return !isWeChatInAppBrowser();
  765. }
  766. function shouldInitWeChatJssdkOnLoad() {
  767. if (isWeChatInAppBrowser()) return true;
  768. return isWxForceDebug() || isWxPcAutoDebugHost();
  769. }
  770. function shouldFetchWxConfig(fromUserClick) {
  771. if (isWeChatInAppBrowser()) return true;
  772. if (fromUserClick) return true;
  773. return isWxForceDebug() || isWxPcAutoDebugHost();
  774. }
  775. function getWxHtmlUrl() {
  776. var forced = String(q('wxSignUrl') || '').trim();
  777. if (forced) return forced.split('#')[0];
  778. return String(location.href || '').split('#')[0];
  779. }
  780. function getWxSignPageUrlForApi() {
  781. var htmlUrl = getWxHtmlUrl();
  782. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  783. return WX_GET_CONFIG_SIGN_URL;
  784. }
  785. function getWxHtmlUrlBase() {
  786. var htmlUrl = getWxSignPageUrlForApi();
  787. try {
  788. var u = new URL(htmlUrl);
  789. return u.origin + u.pathname;
  790. } catch (eU) {
  791. return WX_GET_CONFIG_SIGN_URL;
  792. }
  793. }
  794. function getWxConfigSignUrl() {
  795. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  796. return getWxSignPageUrlForApi();
  797. }
  798. function getWxGetConfigApiUrl() {
  799. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  800. }
  801. function buildWxGetConfigRequestBody(htmlUrl) {
  802. return {
  803. url: String(htmlUrl || '').split('#')[0].trim()
  804. };
  805. }
  806. function resolveWxConfigAppIdFromSignData(d) {
  807. if (!d || typeof d !== 'object') return '';
  808. var mp =
  809. d.mpAppId ||
  810. d.mpAppid ||
  811. d.officialAppId ||
  812. d.gzhAppId ||
  813. d.serviceAppId;
  814. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  815. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  816. if (fromQuery) return fromQuery;
  817. var raw = d.appId || d.appid || d.wxAppId;
  818. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  819. }
  820. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  821. if (!res || typeof res !== 'object') return null;
  822. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  823. if (!d || typeof d !== 'object') return null;
  824. var appId = resolveWxConfigAppIdFromSignData(d);
  825. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  826. var nonceStr =
  827. d.nonceStr != null && String(d.nonceStr) !== ''
  828. ? d.nonceStr
  829. : d.noncestr != null && String(d.noncestr) !== ''
  830. ? d.noncestr
  831. : d.nonce;
  832. var signature = d.signature || d.sign;
  833. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  834. return null;
  835. }
  836. return {
  837. appId: String(appId),
  838. timestamp: Number(timestamp),
  839. nonceStr: String(nonceStr),
  840. signature: String(signature),
  841. signUrl: String(signUrlUsed || '')
  842. .split('#')[0]
  843. .trim()
  844. };
  845. }
  846. function getWxErrMsg(err) {
  847. if (!err) return '';
  848. if (err.errMsg) return String(err.errMsg);
  849. if (typeof err === 'string') return err;
  850. try {
  851. return JSON.stringify(err);
  852. } catch (e) {
  853. return String(err);
  854. }
  855. }
  856. function formatWxConfigErrorTip(err, signPageUrl) {
  857. var errMsg = getWxErrMsg(err);
  858. var tip = '微信 JSSDK 配置失败';
  859. if (/invalid signature/i.test(errMsg)) {
  860. return (
  861. tip +
  862. ':签名无效。url=' +
  863. (signPageUrl || getWxHtmlUrl()) +
  864. ';appId=' +
  865. WECHAT_MP_APP_ID
  866. );
  867. }
  868. if (/require\s*subscribe/i.test(errMsg)) {
  869. return tip + ':' + errMsg + '(服务号需用户已关注)';
  870. }
  871. return errMsg ? tip + ':' + errMsg : tip;
  872. }
  873. function setWxInitError(msg) {
  874. wxInitLastError = String(msg || '').trim();
  875. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  876. }
  877. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  878. var htmlUrl = String(
  879. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  880. )
  881. .split('#')[0]
  882. .trim();
  883. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  884. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  885. }
  886. if (isWxDebugOn()) {
  887. try {
  888. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  889. } catch (eDbg) {}
  890. }
  891. var requestUrl = getWxGetConfigApiUrl();
  892. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  893. console.log('[wx] htmlUrl=', htmlUrl);
  894. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  895. return fetch(requestUrl, {
  896. method: 'POST',
  897. mode: 'cors',
  898. credentials: 'omit',
  899. headers: {
  900. Accept: 'application/json',
  901. 'Content-Type': 'application/json;charset=UTF-8'
  902. },
  903. body: JSON.stringify(requestBody)
  904. })
  905. .then(function (r) {
  906. if (r.ok) return r.json();
  907. return r
  908. .text()
  909. .catch(function () {
  910. return '';
  911. })
  912. .then(function (text) {
  913. var hint = '';
  914. try {
  915. var j = JSON.parse(text);
  916. hint = j.msg || j.message || '';
  917. } catch (eP) {
  918. if (text) hint = text.slice(0, 120);
  919. }
  920. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  921. });
  922. })
  923. .then(function (res) {
  924. if (res && res.code != null) {
  925. var c = Number(res.code);
  926. if (c !== 200 && c !== 0 && res.success !== true) {
  927. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  928. }
  929. }
  930. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  931. if (!sign) {
  932. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  933. throw new Error(
  934. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  935. );
  936. }
  937. if (sign.appId !== WECHAT_MP_APP_ID) {
  938. console.warn(
  939. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  940. );
  941. }
  942. if (typeof wx === 'undefined') {
  943. if (isWxPcBrowser()) {
  944. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  945. return true;
  946. }
  947. setWxInitError('jweixin.js 未加载');
  948. return false;
  949. }
  950. return applyWxConfigFromSign(sign, htmlUrl);
  951. });
  952. }
  953. function applyWxConfigFromSign(sign, htmlUrl) {
  954. var wxConfigParams = {
  955. debug: isWxDebugOn(),
  956. appId: String(sign.appId),
  957. timestamp: sign.timestamp,
  958. nonceStr: String(sign.nonceStr),
  959. signature: String(sign.signature),
  960. jsApiList: [],
  961. openTagList: ['wx-open-launch-app']
  962. };
  963. return new Promise(function (resolve) {
  964. wx.config(wxConfigParams);
  965. wx.ready(function () {
  966. weChatJssdkConfigured = true;
  967. document.body.classList.add('wx-jssdk-ready');
  968. refreshWxLaunchTagAttrs();
  969. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  970. resolve(true);
  971. });
  972. wx.error(function (err) {
  973. weChatJssdkConfigured = false;
  974. document.body.classList.remove('wx-jssdk-ready');
  975. wxJssdkInitPromise = null;
  976. var errMsg = getWxErrMsg(err);
  977. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  978. if (isWxDebugOn()) window.alert(wxInitLastError);
  979. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  980. var baseUrl = getWxHtmlUrlBase();
  981. var fullUrl = getWxSignPageUrlForApi();
  982. if (
  983. !/invalid signature/i.test(errMsg) ||
  984. wxConfigSignRetriedBaseUrl ||
  985. baseUrl === fullUrl ||
  986. htmlUrl === baseUrl
  987. ) {
  988. resolve(false);
  989. return;
  990. }
  991. wxConfigSignRetriedBaseUrl = true;
  992. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  993. });
  994. });
  995. }
  996. function refreshWxLaunchTagAttrs() {
  997. var tag = document.getElementById('launch-btn');
  998. if (!tag) return;
  999. try {
  1000. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1001. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
  1002. } catch (eA) {}
  1003. }
  1004. function bindWeChatLaunchTagEvents() {
  1005. var tag = document.getElementById('launch-btn');
  1006. if (!tag || tag._wxLaunchBound) return;
  1007. tag._wxLaunchBound = true;
  1008. refreshWxLaunchTagAttrs();
  1009. tag.addEventListener('launch', function () {
  1010. console.log('[wx-open-launch-app] launch ok');
  1011. // showFabToast('正在打开 U店在哪…');
  1012. });
  1013. tag.addEventListener('error', function (e) {
  1014. var detail = e && e.detail;
  1015. var errMsg =
  1016. detail && detail.errMsg
  1017. ? String(detail.errMsg)
  1018. : detail && detail.errmsg
  1019. ? String(detail.errmsg)
  1020. : '';
  1021. console.warn('[wx-open-launch-app]', detail);
  1022. showAppOpenFailTip(
  1023. '请确复制链接进入U店在哪'
  1024. );
  1025. });
  1026. }
  1027. function initWeChatOpenLaunchApp(fromUserClick) {
  1028. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1029. return Promise.resolve(false);
  1030. }
  1031. ensureWxShareFromQueryBeforeConfig();
  1032. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1033. wxConfigSignRetriedBaseUrl = false;
  1034. wxInitLastError = '';
  1035. var htmlUrl = getWxConfigSignUrl();
  1036. bindWeChatLaunchTagEvents();
  1037. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1038. .then(function (ok) {
  1039. if (ok === true) return true;
  1040. if (!wxInitLastError) {
  1041. setWxInitError('wx.config 失败,可加 ?wxDebug=1');
  1042. }
  1043. return false;
  1044. })
  1045. .catch(function (e) {
  1046. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  1047. setWxInitError(msg);
  1048. console.warn('[wx] init failed', msg, 'htmlUrl=', htmlUrl);
  1049. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1050. return false;
  1051. })
  1052. .finally(function () {
  1053. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1054. });
  1055. return wxJssdkInitPromise;
  1056. }
  1057. function scheduleWeChatJssdkBootstrap() {
  1058. if (!shouldInitWeChatJssdkOnLoad()) return;
  1059. var attempts = 0;
  1060. function tick() {
  1061. attempts += 1;
  1062. if (weChatJssdkConfigured) return;
  1063. initWeChatOpenLaunchApp();
  1064. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
  1065. setTimeout(tick, 400);
  1066. }
  1067. }
  1068. tick();
  1069. }
  1070. function showFabToast(msg, ms) {
  1071. var tip = String(msg || '').trim();
  1072. if (!tip) return;
  1073. var el = document.getElementById('openAppToast');
  1074. if (el) {
  1075. el.textContent = tip;
  1076. el.style.display = 'block';
  1077. if (showFabToast._t) clearTimeout(showFabToast._t);
  1078. showFabToast._t = setTimeout(function () {
  1079. el.style.display = 'none';
  1080. }, ms || 2800);
  1081. }
  1082. console.log('[openApp]', tip);
  1083. }
  1084. function showAppOpenFailTip(msg) {
  1085. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  1086. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  1087. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  1088. } else if (isWeChatInAppBrowser()) {
  1089. window.alert(tip);
  1090. } else {
  1091. console.warn('[openApp]', tip);
  1092. }
  1093. }
  1094. function tryFetchWxConfigOnPcClick() {
  1095. if (!isWxPcBrowser()) return Promise.resolve(false);
  1096. showFabToast('正在请求 getWxConfig…');
  1097. wxJssdkInitPromise = null;
  1098. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1099. if (ok) {
  1100. showFabToast(
  1101. weChatJssdkConfigured
  1102. ? 'getWxConfig 成功,wx.config 已就绪'
  1103. : 'getWxConfig 成功'
  1104. );
  1105. } else {
  1106. showFabToast(wxInitLastError || 'getWxConfig 失败');
  1107. }
  1108. return ok;
  1109. });
  1110. }
  1111. function launchAppDeepLink(deepLink) {
  1112. try {
  1113. var a = document.createElement('a');
  1114. a.href = deepLink;
  1115. a.setAttribute('target', '_self');
  1116. document.body.appendChild(a);
  1117. a.click();
  1118. document.body.removeChild(a);
  1119. } catch (e1) {}
  1120. try {
  1121. window.location.href = deepLink;
  1122. } catch (e2) {}
  1123. }
  1124. function tryOpenHBuilderApp() {
  1125. if (isWeChatInAppBrowser()) return;
  1126. tryFetchWxConfigOnPcClick().then(function () {
  1127. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1128. return;
  1129. }
  1130. tryOpenHBuilderAppViaScheme();
  1131. });
  1132. }
  1133. function tryOpenHBuilderAppViaScheme() {
  1134. // showFabToast('正在打开 U店在哪…');
  1135. var deepLink = buildAppDeepLink();
  1136. if (typeof plus !== 'undefined' && plus.runtime) {
  1137. var installed = null;
  1138. try {
  1139. if (typeof plus.runtime.isApplicationExist === 'function') {
  1140. installed = plus.runtime.isApplicationExist({
  1141. pname: APP_ANDROID_PACKAGE,
  1142. action: APP_IOS_URL_SCHEME
  1143. });
  1144. }
  1145. } catch (e) {
  1146. console.warn(e);
  1147. }
  1148. if (installed === false) {
  1149. showDownloadTip();
  1150. return;
  1151. }
  1152. try {
  1153. plus.runtime.openURL(deepLink);
  1154. } catch (e2) {
  1155. console.warn(e2);
  1156. showDownloadTip();
  1157. }
  1158. return;
  1159. }
  1160. var t0 = Date.now();
  1161. var done = false;
  1162. function finish() {
  1163. if (done) return;
  1164. done = true;
  1165. document.removeEventListener('visibilitychange', onVis);
  1166. window.removeEventListener('pagehide', onHide);
  1167. }
  1168. function onVis() {
  1169. if (document.visibilityState === 'hidden') finish();
  1170. }
  1171. function onHide() {
  1172. finish();
  1173. }
  1174. document.addEventListener('visibilitychange', onVis);
  1175. window.addEventListener('pagehide', onHide);
  1176. try {
  1177. launchAppDeepLink(deepLink);
  1178. } catch (e3) {
  1179. finish();
  1180. showDownloadTip();
  1181. return;
  1182. }
  1183. window.setTimeout(function () {
  1184. finish();
  1185. }, 2600);
  1186. }
  1187. function tryDecode(s) {
  1188. s = String(s || '');
  1189. if (!s) return '';
  1190. try {
  1191. return decodeURIComponent(s.replace(/\+/g, ' '));
  1192. } catch (e) {
  1193. return s;
  1194. }
  1195. }
  1196. var DEFAULT_HERO = '';
  1197. /** 二手商品接口前缀;可用 URL 参数 alienSecondBase / secondApiBase 覆盖 */
  1198. function resolveSecondApiBase() {
  1199. var custom = (q('alienSecondBase') || q('secondApiBase') || '').trim();
  1200. if (custom) {
  1201. return custom.replace(/\/+$/, '');
  1202. }
  1203. return 'http://120.26.186.130:8000/alienSecond';
  1204. }
  1205. var API_BASE_SECOND = resolveSecondApiBase();
  1206. /** 与 querySecondGoodsDetailWithOutJWT 表单一致;优先地址栏,否则默认坐标 */
  1207. var DEFAULT_REQUEST_LONGITUDE =
  1208. (q('longitude') || q('lon') || q('jingdu') || '').trim() || '121.662527';
  1209. var DEFAULT_REQUEST_LATITUDE =
  1210. (q('latitude') || q('lat') || q('weidu') || '').trim() || '38.925754';
  1211. var COMMENT_SOURCE_TYPE = 4;
  1212. function apiGet(path) {
  1213. return fetch(API_BASE + path, {
  1214. method: 'GET',
  1215. mode: 'cors',
  1216. credentials: 'omit',
  1217. headers: { Accept: 'application/json' }
  1218. }).then(function (res) {
  1219. if (!res.ok) throw new Error('HTTP ' + res.status);
  1220. return res.json();
  1221. });
  1222. }
  1223. function apiPostJson(path, body) {
  1224. return fetch(API_BASE + path, {
  1225. method: 'POST',
  1226. mode: 'cors',
  1227. credentials: 'omit',
  1228. headers: {
  1229. Accept: 'application/json',
  1230. 'Content-Type': 'application/json'
  1231. },
  1232. body: JSON.stringify(body || {})
  1233. }).then(function (res) {
  1234. if (!res.ok) throw new Error('HTTP ' + res.status);
  1235. return res.json();
  1236. });
  1237. }
  1238. function pick(d, keys) {
  1239. if (!d || typeof d !== 'object') return null;
  1240. for (var i = 0; i < keys.length; i++) {
  1241. var k = keys[i];
  1242. if (d[k] != null && d[k] !== '') return d[k];
  1243. }
  1244. return null;
  1245. }
  1246. function isApiOk(res) {
  1247. if (!res || typeof res !== 'object') return false;
  1248. if (res.success === false) return false;
  1249. var c = res.code;
  1250. return c === 200 || c === '200' || Number(c) === 200;
  1251. }
  1252. function fmtPriceNum(v) {
  1253. var n = v != null ? Number(v) : NaN;
  1254. return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
  1255. }
  1256. /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
  1257. function appendGoodsTag(mount, raw, kind) {
  1258. if (!mount || raw == null) return;
  1259. var s = String(raw).trim();
  1260. if (!s) return;
  1261. var span = document.createElement('span');
  1262. span.className =
  1263. 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
  1264. if (kind === 'label') {
  1265. span.textContent = s.replace(/^#+/, '');
  1266. } else {
  1267. span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
  1268. }
  1269. mount.appendChild(span);
  1270. }
  1271. function renderGoodsDetail(d) {
  1272. if (!d || typeof d !== 'object') return;
  1273. var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
  1274. if (title) {
  1275. var el = document.getElementById('goodsTitle');
  1276. if (el) el.textContent = String(title);
  1277. }
  1278. var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
  1279. if (price != null) {
  1280. var pe = document.getElementById('goodsPrice');
  1281. if (pe) pe.textContent = fmtPriceNum(price);
  1282. }
  1283. var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
  1284. if (dist != null) {
  1285. var dt = String(dist).trim();
  1286. if (dt) {
  1287. if (!/^距离/.test(dt)) dt = '距离 ' + dt;
  1288. if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
  1289. dt = dt.replace(/\s+$/, '') + 'km';
  1290. }
  1291. var de = document.getElementById('goodsDistance');
  1292. if (de) de.textContent = dt;
  1293. }
  1294. }
  1295. var img =
  1296. pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
  1297. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
  1298. (Array.isArray(d.imageList) && d.imageList[0]);
  1299. if (img) {
  1300. var hi = document.getElementById('goodsHeroImg');
  1301. if (hi) {
  1302. hi.src = String(img);
  1303. hi.alt = '商品图';
  1304. }
  1305. }
  1306. var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
  1307. if (nick) {
  1308. var ne = document.getElementById('goodsUserName');
  1309. if (ne) ne.textContent = String(nick);
  1310. }
  1311. var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
  1312. if (av) {
  1313. var ae = document.getElementById('goodsUserAvatar');
  1314. if (ae) ae.src = String(av);
  1315. }
  1316. var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
  1317. if (tm) {
  1318. var te = document.getElementById('goodsTimeAgo');
  1319. if (te) te.textContent = String(tm);
  1320. }
  1321. var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
  1322. var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
  1323. var wrap = document.getElementById('goodsHeroSloganWrap');
  1324. var e1 = document.getElementById('goodsSlogan1');
  1325. var e2 = document.getElementById('goodsSlogan2');
  1326. if (wrap && e1 && e2) {
  1327. if (s1 || s2) {
  1328. if (s1) e1.textContent = String(s1);
  1329. if (s2) e2.textContent = String(s2);
  1330. wrap.style.display = '';
  1331. } else {
  1332. wrap.style.display = 'none';
  1333. }
  1334. }
  1335. var hotStat = document.getElementById('goodsHotStat');
  1336. var cs = pick(d, ['collectStatus']);
  1337. if (hotStat) {
  1338. var hideHot =
  1339. cs != null &&
  1340. (Number(cs) === 0 || String(cs).trim() === '0');
  1341. hotStat.style.display = hideHot ? 'none' : '';
  1342. }
  1343. var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
  1344. if (hot != null) {
  1345. var he = document.getElementById('goodsHotCount');
  1346. if (he) he.textContent = String(hot);
  1347. }
  1348. var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
  1349. if (fav != null) {
  1350. var fe = document.getElementById('goodsFavCount');
  1351. if (fe) fe.textContent = String(fav);
  1352. }
  1353. var topicStr = d.topic != null ? String(d.topic).trim() : '';
  1354. var labelStr = d.label != null ? String(d.label).trim() : '';
  1355. var hasApiTags = topicStr !== '' || labelStr !== '';
  1356. var mount = document.getElementById('goodsTags');
  1357. if (mount) {
  1358. if (hasApiTags) {
  1359. mount.innerHTML = '';
  1360. if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
  1361. if (labelStr) appendGoodsTag(mount, labelStr, 'label');
  1362. } else {
  1363. var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
  1364. if (tags) {
  1365. mount.innerHTML = '';
  1366. var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
  1367. arr.forEach(function (t) {
  1368. if (t == null || t === '') return;
  1369. var label =
  1370. typeof t === 'object'
  1371. ? (t.tagName || t.name || t.label || '')
  1372. : String(t);
  1373. label = String(label).trim();
  1374. if (!label) return;
  1375. var isTopic = label.indexOf('#') === 0;
  1376. appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
  1377. });
  1378. }
  1379. }
  1380. }
  1381. }
  1382. 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>';
  1383. 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>';
  1384. 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>';
  1385. function cmtAvatarUrl(c) {
  1386. return String(
  1387. pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
  1388. ).trim();
  1389. }
  1390. function cmtUserName(c) {
  1391. var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
  1392. return s || '—';
  1393. }
  1394. function cmtTime(c) {
  1395. return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
  1396. }
  1397. function cmtContent(c) {
  1398. return String(pick(c, ['content', 'commentContent', 'text']) || '');
  1399. }
  1400. function cmtLikeCount(c) {
  1401. var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
  1402. return v != null ? String(v) : '0';
  1403. }
  1404. function cmtReplies(c) {
  1405. if (!c || typeof c !== 'object') return [];
  1406. var sub =
  1407. c.childCommonComments ||
  1408. c.replyList ||
  1409. c.replyVOList ||
  1410. c.children ||
  1411. c.subComments ||
  1412. c.replies;
  1413. if (sub == null) return [];
  1414. return Array.isArray(sub) ? sub.filter(Boolean) : [];
  1415. }
  1416. function appendCmtRow(parentBody, c, showReply) {
  1417. var row = document.createElement('div');
  1418. row.className = 'goods-cmt__row';
  1419. var img = document.createElement('img');
  1420. img.className = 'goods-cmt__avatar';
  1421. img.alt = '';
  1422. var au = cmtAvatarUrl(c);
  1423. img.src = au || 'images/demouser.png';
  1424. var body = document.createElement('div');
  1425. body.className = 'goods-cmt__body';
  1426. var name = document.createElement('span');
  1427. name.className = 'goods-cmt__name';
  1428. name.textContent = cmtUserName(c);
  1429. var time = document.createElement('span');
  1430. time.className = 'goods-cmt__time';
  1431. time.textContent = cmtTime(c);
  1432. var text = document.createElement('p');
  1433. text.className = 'goods-cmt__text';
  1434. text.textContent = cmtContent(c);
  1435. var actions = document.createElement('div');
  1436. actions.className = 'goods-cmt__actions';
  1437. var likeBtn = document.createElement('button');
  1438. likeBtn.type = 'button';
  1439. likeBtn.className = 'goods-cmt__action';
  1440. likeBtn.setAttribute('aria-label', '点赞');
  1441. likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
  1442. actions.appendChild(likeBtn);
  1443. if (showReply) {
  1444. var repBtn = document.createElement('button');
  1445. repBtn.type = 'button';
  1446. repBtn.className = 'goods-cmt__action';
  1447. repBtn.setAttribute('aria-label', '回复');
  1448. repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
  1449. actions.appendChild(repBtn);
  1450. }
  1451. body.appendChild(name);
  1452. body.appendChild(time);
  1453. body.appendChild(text);
  1454. body.appendChild(actions);
  1455. row.appendChild(img);
  1456. row.appendChild(body);
  1457. parentBody.appendChild(row);
  1458. return body;
  1459. }
  1460. function buildNestedCmt(c) {
  1461. var wrap = document.createElement('div');
  1462. wrap.className = 'goods-cmt goods-cmt--nested';
  1463. appendCmtRow(wrap, c, false);
  1464. return wrap;
  1465. }
  1466. function filterTopLevelComments(list) {
  1467. if (!Array.isArray(list) || !list.length) return [];
  1468. var top = list.filter(function (c) {
  1469. if (!c) return false;
  1470. var pid = c.parentId != null ? c.parentId : c.pid;
  1471. if (typeof pid === 'string') pid = pid.trim();
  1472. return pid == null || pid === '' || Number(pid) === 0;
  1473. });
  1474. return top.length ? top : list.slice();
  1475. }
  1476. function countCommentsInApiList(records) {
  1477. if (!Array.isArray(records)) return 0;
  1478. var tops = filterTopLevelComments(records);
  1479. var n = 0;
  1480. for (var i = 0; i < tops.length; i++) {
  1481. var c = tops[i];
  1482. if (!c) continue;
  1483. n += 1 + cmtReplies(c).length;
  1484. }
  1485. return n;
  1486. }
  1487. function normalizeCommentListPayload(d) {
  1488. if (typeof d === 'string') {
  1489. try {
  1490. d = JSON.parse(d);
  1491. } catch (e) {
  1492. return { records: [], total: 0 };
  1493. }
  1494. }
  1495. if (Array.isArray(d)) {
  1496. return { records: d, total: countCommentsInApiList(d) };
  1497. }
  1498. if (d && typeof d === 'object') {
  1499. var arr = d.records || d.list || d.rows;
  1500. if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
  1501. if (!Array.isArray(arr)) arr = [];
  1502. var total =
  1503. d.total != null && !isNaN(Number(d.total))
  1504. ? Number(d.total)
  1505. : countCommentsInApiList(arr);
  1506. return { records: arr, total: total };
  1507. }
  1508. return { records: [], total: 0 };
  1509. }
  1510. function renderCommentsList(rows, total) {
  1511. var mount = document.getElementById('goodsCommentList');
  1512. var totEl = document.getElementById('goodsCommentTotal');
  1513. if (!mount) return;
  1514. mount.innerHTML = '';
  1515. var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
  1516. var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
  1517. if (totEl) totEl.textContent = String(n);
  1518. if (!list.length) {
  1519. var empty = document.createElement('li');
  1520. empty.className = 'goods-comments__empty';
  1521. empty.setAttribute('role', 'status');
  1522. empty.textContent = '暂无留言';
  1523. mount.appendChild(empty);
  1524. return;
  1525. }
  1526. list.forEach(function (c) {
  1527. if (!c) return;
  1528. var li = document.createElement('li');
  1529. li.className = 'goods-cmt';
  1530. appendCmtRow(li, c, true);
  1531. var replies = cmtReplies(c);
  1532. if (replies.length) {
  1533. var thread = document.createElement('div');
  1534. thread.className = 'goods-cmt__thread';
  1535. var inner = document.createElement('div');
  1536. inner.className = 'goods-cmt__replies-inner';
  1537. replies.forEach(function (r) {
  1538. if (r) inner.appendChild(buildNestedCmt(r));
  1539. });
  1540. var bar = document.createElement('button');
  1541. bar.type = 'button';
  1542. bar.className = 'goods-cmt__thread-bar';
  1543. bar.setAttribute('aria-expanded', 'true');
  1544. bar.innerHTML =
  1545. '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
  1546. '<span class="goods-cmt__thread-bar-right">' +
  1547. '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
  1548. thread.appendChild(inner);
  1549. thread.appendChild(bar);
  1550. li.appendChild(thread);
  1551. }
  1552. mount.appendChild(li);
  1553. });
  1554. }
  1555. function bindCommentThreadDelegation() {
  1556. var list = document.getElementById('goodsCommentList');
  1557. if (!list || list.dataset.threadDeleg) return;
  1558. list.dataset.threadDeleg = '1';
  1559. list.addEventListener('click', function (e) {
  1560. var bar = e.target.closest('.goods-cmt__thread-bar');
  1561. if (!bar) return;
  1562. var inner = bar.previousElementSibling;
  1563. if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
  1564. var collapsed = inner.classList.toggle('is-collapsed');
  1565. bar.classList.toggle('is-collapsed', collapsed);
  1566. bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
  1567. var lab = bar.querySelector('.js-thread-label');
  1568. if (lab) lab.textContent = collapsed ? '展开' : '收起';
  1569. });
  1570. }
  1571. /** 2=已卖出 3/4/5=下架或删除等不可用态 */
  1572. function isGoodsStatusUnavailable(gs) {
  1573. if (gs == null) return false;
  1574. var n = Number(gs);
  1575. if (!isNaN(n) && (n === 2 || n === 3 || n === 4 || n === 5)) return true;
  1576. var s = String(gs).trim();
  1577. return s === '2' || s === '3' || s === '4' || s === '5';
  1578. }
  1579. function buildShareUndefinedRedirectQuery(gs, ctx) {
  1580. ctx = ctx || {};
  1581. var uq = new URLSearchParams();
  1582. uq.set('goodsUnavailable', '1');
  1583. if (gs != null && String(gs).trim() !== '') {
  1584. uq.set('goodsStatus', String(gs).trim());
  1585. }
  1586. if (ctx.userId) uq.set('userId', String(ctx.userId));
  1587. if (ctx.longitude) uq.set('longitude', String(ctx.longitude));
  1588. if (ctx.latitude) uq.set('latitude', String(ctx.latitude));
  1589. if (ctx.userCity) uq.set('userCity', String(ctx.userCity));
  1590. var gid = ctx.goodsId || '';
  1591. if (gid) {
  1592. uq.set('goodsId', String(gid));
  1593. uq.set('id', String(gid));
  1594. }
  1595. return uq;
  1596. }
  1597. function redirectToShareUndefined(gs, ctx) {
  1598. window.location.replace(
  1599. 'shareUndefined.html?' + buildShareUndefinedRedirectQuery(gs, ctx).toString()
  1600. );
  1601. }
  1602. function isDetailResponseGoodsUnavailable(res) {
  1603. if (!res || typeof res !== 'object') return true;
  1604. var d = res.data != null ? res.data : res.result;
  1605. if (d && typeof d === 'object' && d.goodsStatus != null) {
  1606. return isGoodsStatusUnavailable(d.goodsStatus);
  1607. }
  1608. var msg = res.msg != null ? String(res.msg) : '';
  1609. if (/已删除|已下架|已卖出|不存在|不可用|下架|卖出|删除/.test(msg)) {
  1610. return true;
  1611. }
  1612. if (!isApiOk(res)) {
  1613. return !d || (typeof d === 'object' && !Object.keys(d).length);
  1614. }
  1615. return !d || (typeof d !== 'object');
  1616. }
  1617. /**
  1618. * 载入时校验商品是否存在(querySecondGoodsDetailWithOutJWT)
  1619. * @returns {Promise<{redirected:boolean, exists:boolean}>}
  1620. */
  1621. function fetchSecondGoodsDetail(goodsId, lon, lat, phoneId, redirectCtx) {
  1622. var lonStr =
  1623. lon != null && String(lon).trim() !== ''
  1624. ? String(lon).trim()
  1625. : String(DEFAULT_REQUEST_LONGITUDE);
  1626. var latStr =
  1627. lat != null && String(lat).trim() !== ''
  1628. ? String(lat).trim()
  1629. : String(DEFAULT_REQUEST_LATITUDE);
  1630. var pid =
  1631. phoneId != null && String(phoneId).trim() !== ''
  1632. ? String(phoneId).trim()
  1633. : '';
  1634. /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
  1635. var formBody = {
  1636. goodsId: String(goodsId != null ? goodsId : '').trim(),
  1637. longitude: String(lonStr),
  1638. latitude: String(latStr),
  1639. phoneId: pid
  1640. };
  1641. var form = new URLSearchParams();
  1642. form.set('goodsId', formBody.goodsId);
  1643. form.set('longitude', formBody.longitude);
  1644. form.set('latitude', formBody.latitude);
  1645. form.set('phoneId', formBody.phoneId);
  1646. return fetch(API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT', {
  1647. method: 'POST',
  1648. mode: 'cors',
  1649. credentials: 'omit',
  1650. headers: {
  1651. Accept: 'application/json',
  1652. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  1653. },
  1654. body: form.toString()
  1655. })
  1656. .then(function (res) {
  1657. if (!res.ok) throw new Error('HTTP ' + res.status);
  1658. return res.json();
  1659. })
  1660. .then(function (res) {
  1661. redirectCtx = redirectCtx || {};
  1662. if (isDetailResponseGoodsUnavailable(res)) {
  1663. var gsPick =
  1664. res && res.data && res.data.goodsStatus != null
  1665. ? res.data.goodsStatus
  1666. : null;
  1667. redirectToShareUndefined(gsPick, redirectCtx);
  1668. return { redirected: true, exists: false };
  1669. }
  1670. var d = isApiOk(res) ? res.data || res.result : null;
  1671. if (d && typeof d === 'object') {
  1672. renderGoodsDetail(d);
  1673. return { redirected: false, exists: true };
  1674. }
  1675. if (res && res.msg) {
  1676. console.warn('[querySecondGoodsDetailWithOutJWT]', res.msg);
  1677. }
  1678. redirectToShareUndefined(null, redirectCtx);
  1679. return { redirected: true, exists: false };
  1680. });
  1681. }
  1682. function fetchCommentList(goodsId, userId, pageNum, pageSize) {
  1683. var st = (q('sourceType') || '').trim();
  1684. var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
  1685. var path = '/commonComment/getListBySourceType?' +
  1686. 'sourceType=' + encodeURIComponent(String(sourceType)) +
  1687. '&sourceId=' + encodeURIComponent(String(goodsId)) +
  1688. '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
  1689. '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
  1690. '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
  1691. return apiGet(path).then(function (res) {
  1692. if (!isApiOk(res)) {
  1693. if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
  1694. renderCommentsList([], 0);
  1695. return;
  1696. }
  1697. var raw = res.data != null ? res.data : res.result;
  1698. var pack = normalizeCommentListPayload(raw);
  1699. renderCommentsList(pack.records, pack.total);
  1700. });
  1701. }
  1702. function run() {
  1703. var goodsId = (q('goodsId') || q('id') || '').trim();
  1704. var userId = (q('userId') || '').trim();
  1705. var phoneId = (q('phoneId') || q('phone_id') || '').trim();
  1706. var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  1707. var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
  1708. var userCity = (q('userCity') || q('city') || '').trim();
  1709. var lonResolved = lon || DEFAULT_REQUEST_LONGITUDE;
  1710. var latResolved = lat || DEFAULT_REQUEST_LATITUDE;
  1711. var pageNum = (q('pageNum') || '1').trim();
  1712. var pageSize = (q('pageSize') || '10').trim();
  1713. var redirectCtx = {
  1714. goodsId: goodsId,
  1715. userId: userId,
  1716. longitude: lonResolved,
  1717. latitude: latResolved,
  1718. userCity: userCity
  1719. };
  1720. bindCommentThreadDelegation();
  1721. if (String(q('goodsUnavailable') || '').trim() === '1') {
  1722. redirectToShareUndefined(q('goodsStatus'), redirectCtx);
  1723. return;
  1724. }
  1725. if (!goodsId) {
  1726. applyFromUrl();
  1727. return;
  1728. }
  1729. fetchSecondGoodsDetail(goodsId, lon, lat, phoneId, redirectCtx)
  1730. .catch(function (e) {
  1731. console.warn('[querySecondGoodsDetailWithOutJWT]', e);
  1732. redirectToShareUndefined(null, redirectCtx);
  1733. return { redirected: true, exists: false };
  1734. })
  1735. .then(function (detailResult) {
  1736. if (!detailResult || detailResult.redirected) {
  1737. return;
  1738. }
  1739. return fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
  1740. console.warn('[getListBySourceType]', e);
  1741. renderCommentsList([], 0);
  1742. });
  1743. });
  1744. }
  1745. function applyFromUrl() {
  1746. var heroImg = document.getElementById('goodsHeroImg');
  1747. var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
  1748. imgUrl = tryDecode(imgUrl).trim();
  1749. if (imgUrl) {
  1750. heroImg.src = imgUrl;
  1751. heroImg.alt = '商品图';
  1752. } else {
  1753. heroImg.src = DEFAULT_HERO;
  1754. heroImg.alt = '';
  1755. }
  1756. var av = tryDecode(q('userImage') || q('avatar')).trim();
  1757. document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
  1758. var uname = tryDecode(q('userName') || q('nickname')).trim();
  1759. if (uname) document.getElementById('goodsUserName').textContent = uname;
  1760. var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
  1761. if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
  1762. var s1 = tryDecode(q('slogan1') || q('line1')).trim();
  1763. var s2 = tryDecode(q('slogan2') || q('line2')).trim();
  1764. var elS1 = document.getElementById('goodsSlogan1');
  1765. var elS2 = document.getElementById('goodsSlogan2');
  1766. var elWrap = document.getElementById('goodsHeroSloganWrap');
  1767. if (s1 && elS1) elS1.textContent = s1;
  1768. if (s2 && elS2) elS2.textContent = s2;
  1769. if (elWrap && (s1 || s2)) elWrap.style.display = '';
  1770. var price = tryDecode(q('price')).trim();
  1771. if (price) {
  1772. var pn = parseFloat(price.replace(/[^\d.]/g, ''));
  1773. document.getElementById('goodsPrice').textContent =
  1774. !isNaN(pn) ? pn.toFixed(2) : price;
  1775. }
  1776. var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
  1777. if (dist) {
  1778. if (!/^距离/.test(dist)) dist = '距离 ' + dist;
  1779. if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
  1780. dist = dist.replace(/\s+$/, '') + 'km';
  1781. }
  1782. document.getElementById('goodsDistance').textContent = dist;
  1783. }
  1784. var title = tryDecode(q('title') || q('goodsTitle')).trim();
  1785. if (title) document.getElementById('goodsTitle').textContent = title;
  1786. var hot = tryDecode(q('hotCount') || q('hot')).trim();
  1787. if (hot) document.getElementById('goodsHotCount').textContent = hot;
  1788. var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
  1789. if (fav) document.getElementById('goodsFavCount').textContent = fav;
  1790. var cc = tryDecode(q('commentCount') || q('comments')).trim();
  1791. if (cc) {
  1792. var elTot = document.getElementById('goodsCommentTotal');
  1793. if (elTot) elTot.textContent = cc;
  1794. }
  1795. var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
  1796. var mount = document.getElementById('goodsTags');
  1797. var hasGoodsId = (q('goodsId') || q('id') || '').trim();
  1798. if (mount) {
  1799. if (tagsRaw) {
  1800. mount.innerHTML = '';
  1801. tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
  1802. appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
  1803. });
  1804. } else if (!hasGoodsId) {
  1805. mount.innerHTML = '';
  1806. ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
  1807. appendGoodsTag(mount, t, 'label');
  1808. });
  1809. }
  1810. }
  1811. }
  1812. function sharePage() {
  1813. var title = document.getElementById('goodsTitle').textContent || '商品分享';
  1814. var url = location.href;
  1815. if (navigator.share) {
  1816. navigator.share({ title: title, text: title, url: url }).catch(function () {});
  1817. return;
  1818. }
  1819. if (navigator.clipboard && navigator.clipboard.writeText) {
  1820. navigator.clipboard.writeText(url).then(function () {
  1821. window.alert('链接已复制');
  1822. }).catch(function () {
  1823. window.prompt('复制链接', url);
  1824. });
  1825. } else {
  1826. window.prompt('复制链接', url);
  1827. }
  1828. }
  1829. var shareBtn = document.getElementById('goodsShareBtn');
  1830. if (shareBtn) shareBtn.addEventListener('click', sharePage);
  1831. function boot() {
  1832. var launchTag = document.getElementById('launch-btn');
  1833. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1834. bindWeChatLaunchTagEvents();
  1835. if (isWeChatInAppBrowser()) {
  1836. document.body.classList.add('is-wechat');
  1837. ensureWxShareFromQueryBeforeConfig();
  1838. logWxEntryDiagnostics();
  1839. }
  1840. if (shouldInitWeChatJssdkOnLoad()) {
  1841. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1842. document.body.classList.add('wx-pc-debug');
  1843. }
  1844. scheduleWeChatJssdkBootstrap();
  1845. }
  1846. document.addEventListener('WeixinOpenTagsError', function (e) {
  1847. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1848. });
  1849. if (isWeChatInAppBrowser()) {
  1850. var openBtnWx = document.getElementById('openApp');
  1851. if (openBtnWx) {
  1852. openBtnWx.addEventListener('click', function () {
  1853. if (!weChatJssdkConfigured) {
  1854. showFabToast(
  1855. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1856. );
  1857. }
  1858. });
  1859. }
  1860. } else {
  1861. var openAppBtn = document.getElementById('openApp');
  1862. if (openAppBtn) {
  1863. openAppBtn.addEventListener('click', tryOpenHBuilderApp);
  1864. }
  1865. }
  1866. run();
  1867. }
  1868. if (document.readyState === 'complete') {
  1869. boot();
  1870. } else {
  1871. window.onload = boot;
  1872. }
  1873. })();
  1874. </script>
  1875. </body>
  1876. </html>