secondShareGoods.html 62 KB

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