secondShareGoods.html 62 KB

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