secondShareGoods.html 57 KB

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