secondShareGoods.html 62 KB

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