secondShareGoods.html 60 KB

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