secondShareGoods.html 62 KB

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