| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
- <meta name="format-detection" content="telephone=no">
- <title>商品分享</title>
- <style>
- :root {
- --orange: #F58220;
- --price-red: #E62E2E;
- --tag-bg: #fff5e9;
- --tag-text: #b05b28;
- --text: #1a1a1a;
- --text-secondary: #999999;
- --safe-bottom: env(safe-area-inset-bottom, 0px);
- }
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- html {
- font-size: 16px;
- -webkit-tap-highlight-color: transparent;
- overflow-x: hidden;
- }
- body {
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
- background: #fff;
- color: var(--text);
- min-height: 100vh;
- padding-bottom: calc(100px + var(--safe-bottom));
- }
- .fab-wrap {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 200;
- padding: 12px 24px calc(12px + var(--safe-bottom));
- background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
- pointer-events: none;
- }
- .fab-dock__slot {
- width: 100%;
- max-width: 198px;
- height: 48px;
- margin: 0 auto;
- pointer-events: auto;
- }
- #openApp.fab {
- padding: 0 10px;
- -webkit-font-smoothing: antialiased;
- text-rendering: optimizeLegibility;
- }
- .fab__brand-clip {
- display: block;
- flex-shrink: 0;
- line-height: 0;
- }
- .fab__brand-img {
- display: block;
- height: 26px;
- width: auto;
- max-width: none;
- pointer-events: none;
- -webkit-user-drag: none;
- }
- .fab__label {
- font-size: 15px;
- line-height: 1;
- letter-spacing: 0.04em;
- white-space: nowrap;
- }
- #launch-btn {
- display: none;
- width: 100%;
- height: 48px;
- min-height: 48px;
- border-radius: 24px;
- overflow: hidden;
- opacity: 1;
- }
- body.is-wechat.wx-jssdk-ready #launch-btn {
- display: block;
- }
- body.is-wechat.wx-jssdk-ready #openApp {
- display: none !important;
- }
- .fab-wrap .fab {
- pointer-events: auto;
- }
- #openAppToast {
- display: none;
- position: fixed;
- left: 16px;
- right: 16px;
- bottom: calc(72px + var(--safe-bottom));
- z-index: 10001;
- padding: 10px 14px;
- font-size: 13px;
- line-height: 1.45;
- color: #fff;
- text-align: center;
- background: rgba(0, 0, 0, 0.78);
- border-radius: 8px;
- pointer-events: none;
- word-break: break-all;
- }
- #openApp {
- touch-action: manipulation;
- }
- .fab {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 4px;
- width: 100%;
- max-width: 198px;
- margin: 0 auto;
- height: 48px;
- border: none;
- border-radius: 24px;
- background: #F47D1F;
- color: #fff;
- font-size: 16px;
- font-weight: 600;
- box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
- cursor: pointer;
- }
- .fab__logo {
- width: 28px;
- height: 28px;
- flex-shrink: 0;
- }
- .home-indicator {
- height: 5px;
- background: #000;
- border-radius: 3px;
- width: 134px;
- margin: 8px auto 4px;
- opacity: 0.2;
- }
- /* 顶部大图 + 叠字 */
- .goods-hero {
- position: relative;
- width: 100%;
- min-height: 58vh;
- max-height: 520px;
- background: #e8e8e8 center / cover no-repeat;
- overflow: hidden;
- }
- .goods-hero__img {
- position: absolute;
- inset: 0;
- width: 100%;
- height: 100%;
- object-fit: cover;
- display: block;
- }
- .goods-hero__shade {
- position: absolute;
- inset: 0;
- background: linear-gradient(
- 180deg,
- rgba(0, 0, 0, 0.35) 0%,
- rgba(0, 0, 0, 0.1) 38%,
- rgba(0, 0, 0, 0.45) 100%
- );
- pointer-events: none;
- }
- .goods-hero__inner {
- position: relative;
- z-index: 1;
- min-height: 58vh;
- max-height: 520px;
- padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 28px;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- align-items: flex-start;
- }
- .goods-hero__user {
- display: flex;
- align-items: center;
- gap: 10px;
- }
- .goods-hero__avatar {
- width: 40px;
- height: 40px;
- border-radius: 50%;
- object-fit: cover;
- flex-shrink: 0;
- background: rgba(255, 255, 255, 0.3);
- }
- .goods-hero__user-meta {
- display: flex;
- flex-direction: column;
- gap: 2px;
- }
- .goods-hero__name {
- font-size: 15px;
- font-weight: 600;
- color: #fff;
- text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
- }
- .goods-hero__time {
- font-size: 12px;
- color: rgba(255, 255, 255, 0.82);
- text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
- }
- .goods-hero__slogan {
- margin-top: auto;
- padding-bottom: 4px;
- }
- .goods-hero__slogan-line {
- font-size: 26px;
- font-weight: 800;
- line-height: 1.25;
- color: #fff;
- letter-spacing: 0.02em;
- text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
- }
- /* 白色内容区 */
- .goods-panel {
- background: #fff;
- border-radius: 16px 16px 0 0;
- margin-top: -16px;
- position: relative;
- z-index: 2;
- padding: 20px 16px 24px;
- box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
- }
- .goods-panel__row-price {
- display: flex;
- align-items: flex-end;
- justify-content: space-between;
- gap: 12px;
- margin-bottom: 14px;
- }
- .goods-panel__price {
- display: flex;
- align-items: baseline;
- gap: 2px;
- color: var(--price-red);
- font-weight: 800;
- line-height: 1;
- }
- .goods-panel__price-yen {
- font-size: 18px;
- }
- .goods-panel__price-num {
- font-size: 28px;
- letter-spacing: -0.02em;
- }
- .goods-panel__dist {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- font-size: 12px;
- color: var(--text-secondary);
- flex-shrink: 0;
- padding-bottom: 2px;
- }
- .goods-panel__dist svg,
- .goods-panel__dist img {
- width: 14px;
- height: 14px;
- opacity: 0.85;
- display: block;
- flex-shrink: 0;
- object-fit: contain;
- }
- .goods-panel__title {
- font-size: 17px;
- font-weight: 700;
- line-height: 1.45;
- color: var(--text);
- margin-bottom: 16px;
- }
- .goods-panel__row-stats {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 12px;
- margin-bottom: 16px;
- }
- .goods-panel__stats {
- display: flex;
- align-items: center;
- gap: 18px;
- }
- .goods-panel__stat {
- display: inline-flex;
- align-items: center;
- gap: 5px;
- font-size: 14px;
- color: var(--text-secondary);
- }
- .goods-panel__stat svg {
- width: 16px;
- height: 16px;
- flex-shrink: 0;
- }
- .goods-panel__stat img {
- width: 16px;
- height: 16px;
- flex-shrink: 0;
- display: block;
- object-fit: contain;
- }
- .goods-panel__share {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- padding: 0;
- border: none;
- background: none;
- font-size: 14px;
- color: var(--text-secondary);
- cursor: pointer;
- -webkit-tap-highlight-color: transparent;
- }
- .goods-panel__share svg {
- width: 18px;
- height: 18px;
- }
- .goods-panel__tags {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- gap: 8px;
- }
- .goods-tag {
- display: inline-block;
- padding: 2px 8px;
- border-radius: 4px;
- font-size: 12px;
- font-weight: 400;
- line-height: 1.35;
- background: #fff5e9;
- }
- .goods-tag--topic {
- color: #b05b28;
- }
- .goods-tag--label {
- color: #333333;
- }
- /* 留言 */
- .goods-comments {
- margin-top: 20px;
- padding-top: 20px;
- border-top: 1px solid #eee;
- }
- .goods-comments__head {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 18px;
- }
- .goods-comments__title {
- font-size: 17px;
- font-weight: 700;
- color: var(--text);
- }
- .goods-comments__total {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- font-size: 14px;
- color: #151515;
- }
- .goods-comments__total svg {
- width: 18px;
- height: 18px;
- opacity: 0.85;
- }
- .goods-comments__list {
- list-style: none;
- }
- .goods-comments__empty {
- list-style: none;
- padding: 24px 12px;
- text-align: center;
- font-size: 14px;
- color: var(--text-secondary);
- }
- .goods-cmt {
- padding-bottom: 18px;
- margin-bottom: 18px;
- border-bottom: 1px solid #eee;
- }
- .goods-cmt:last-child {
- margin-bottom: 0;
- padding-bottom: 0;
- border-bottom: none;
- }
- .goods-cmt__row {
- display: flex;
- align-items: flex-start;
- gap: 12px;
- }
- .goods-cmt__avatar {
- width: 40px;
- height: 40px;
- border-radius: 50%;
- object-fit: cover;
- background: #e8e8e8;
- flex-shrink: 0;
- }
- .goods-cmt--nested .goods-cmt__avatar {
- width: 32px;
- height: 32px;
- }
- .goods-cmt__body {
- flex: 1;
- min-width: 0;
- }
- .goods-cmt__name {
- font-size: 15px;
- font-weight: 700;
- color: var(--text);
- line-height: 1.3;
- }
- .goods-cmt__time {
- display: block;
- margin-top: 2px;
- font-size: 12px;
- color: var(--text-secondary);
- line-height: 1.35;
- }
- .goods-cmt__text {
- margin-top: 10px;
- font-size: 15px;
- line-height: 1.5;
- color: var(--text);
- word-break: break-word;
- }
- .goods-cmt__actions {
- display: flex;
- align-items: center;
- gap: 20px;
- margin-top: 12px;
- }
- .goods-cmt__action {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- padding: 0;
- border: none;
- background: none;
- font-size: 13px;
- color: var(--text-secondary);
- cursor: pointer;
- -webkit-tap-highlight-color: transparent;
- }
- .goods-cmt__action svg {
- width: 16px;
- height: 16px;
- flex-shrink: 0;
- opacity: 0.88;
- }
- .goods-cmt__thread {
- margin-top: 14px;
- padding-left: 52px;
- }
- .goods-cmt__replies-inner.is-collapsed {
- display: none;
- }
- .goods-cmt__thread-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- margin-top: 10px;
- padding: 10px 12px;
- border: none;
- border-radius: 8px;
- background: #f5f5f5;
- font-size: 13px;
- color: #888;
- cursor: pointer;
- -webkit-tap-highlight-color: transparent;
- }
- .goods-cmt__thread-bar-right {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- color: var(--text-secondary);
- }
- .goods-cmt__thread-chevron {
- width: 14px;
- height: 14px;
- transition: transform 0.2s ease;
- flex-shrink: 0;
- }
- .goods-cmt__thread-bar.is-collapsed .goods-cmt__thread-chevron {
- transform: rotate(180deg);
- }
- .goods-cmt--nested {
- padding-bottom: 0;
- margin-bottom: 0;
- border-bottom: none;
- }
- .goods-cmt--nested .goods-cmt__text {
- margin-top: 8px;
- }
- </style>
- </head>
- <body>
- <section class="goods-hero" id="goodsHero" aria-label="商品配图">
- <img class="goods-hero__img" id="goodsHeroImg" src="" alt="">
- <div class="goods-hero__shade" aria-hidden="true"></div>
- <div class="goods-hero__inner">
- <div class="goods-hero__user">
- <img class="goods-hero__avatar" id="goodsUserAvatar" src="images/demouser.png" alt="">
- <div class="goods-hero__user-meta">
- <span class="goods-hero__name" id="goodsUserName">维尼</span>
- <span class="goods-hero__time" id="goodsTimeAgo">11小时前</span>
- </div>
- </div>
- <div class="goods-hero__slogan" id="goodsHeroSloganWrap" style="display:none;">
- <div class="goods-hero__slogan-line" id="goodsSlogan1"></div>
- <div class="goods-hero__slogan-line" id="goodsSlogan2"></div>
- </div>
- </div>
- </section>
- <div class="goods-panel">
- <div class="goods-panel__row-price">
- <div class="goods-panel__price">
- <span class="goods-panel__price-yen">¥</span>
- <span class="goods-panel__price-num" id="goodsPrice">690.00</span>
- </div>
- <div class="goods-panel__dist">
- <img src="images/juli.svg" alt="" width="14" height="14" decoding="async" aria-hidden="true">
- <span id="goodsDistance">距离 2.5km</span>
- </div>
- </div>
- <h1 class="goods-panel__title" id="goodsTitle">HCK哈士奇BC-330RDE烤漆复古冰箱家用大容量单门冰柜高颜值网红</h1>
- <div class="goods-panel__row-stats">
- <div class="goods-panel__stats">
- <span class="goods-panel__stat goods-panel__stat--hot" id="goodsHotStat">
- <img src="images/huo.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
- <span id="goodsHotCount" style="color:#151515;">510</span>
- </span>
- <span class="goods-panel__stat">
- <img src="images/xing.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
- <span id="goodsFavCount" style="color:#151515;">260</span>
- </span>
- </div>
- </div>
- <div class="goods-panel__tags" id="goodsTags"></div>
- <section class="goods-comments" id="goodsComments" aria-label="留言">
- <div class="goods-comments__head">
- <h2 class="goods-comments__title">留言</h2>
- <div class="goods-comments__total">
- <img src="images/liuyan.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
- <span id="goodsCommentTotal">24</span>
- </div>
- </div>
- <ul class="goods-comments__list" id="goodsCommentList"></ul>
- </section>
- </div>
- <div id="openAppToast" role="status" aria-live="polite"></div>
- <div class="fab-wrap">
- <div class="fab-dock__slot">
- <button type="button" class="fab" id="openApp" aria-label="APP内打开">
- <span class="fab__brand-clip" aria-hidden="true">
- <img class="fab__brand-img" src="images/uBtn.svg" alt="" decoding="async">
- </span>
- <span class="fab__label">APP内打开</span>
- </button>
- <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
- <script type="text/wxtag-template">
- <style>
- .wx-open-app-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 4px;
- width: 100%;
- height: 48px;
- margin: 0;
- padding: 0 10px;
- border: none;
- border-radius: 24px;
- background: #F47D1F;
- box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
- color: #fff;
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
- -webkit-font-smoothing: antialiased;
- cursor: pointer;
- overflow: hidden;
- -webkit-tap-highlight-color: transparent;
- box-sizing: border-box;
- }
- .wx-open-app-btn .fab__brand-clip {
- display: block;
- flex-shrink: 0;
- line-height: 0;
- }
- .wx-open-app-btn .fab__brand-img {
- display: block;
- height: 26px;
- width: auto;
- max-width: none;
- pointer-events: none;
- -webkit-user-drag: none;
- }
- .wx-open-app-btn .fab__label {
- font-size: 15px;
- line-height: 1;
- letter-spacing: 0.04em;
- white-space: nowrap;
- }
- </style>
- <button class="wx-open-app-btn" aria-label="APP内打开">
- <span class="fab__brand-clip" aria-hidden="true">
- <img class="fab__brand-img" src="https://prod.ailien.shop/h5/HBuilderProjects/images/uBtn.svg" alt="" decoding="async">
- </span>
- <span class="fab__label">APP内打开</span>
- </button>
- </script>
- </wx-open-launch-app>
- </div>
- <div class="home-indicator" aria-hidden="true"></div>
- </div>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <script>
- (function () {
- 'use strict';
- /**
- * 进入页仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在(不用其 data 渲染页面):
- * POST {API_BASE_SECOND}/recommend/querySecondGoodsDetailWithOutJWT
- * body:goodsId、longitude、latitude、phoneId
- * goodsStatus 不为 3 → shareUndefined;goodsStatus 为 3 → applyFromUrl + 留言
- */
- /**
- * 唤起 App 落地:二手商品详情(与 pages.json 路径一致)
- */
- var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
- var APP_IOS_URL_SCHEME = 'shopro://';
- var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
- var API_BASE = 'https://prod.ailien.shop/alienStore';
- /**
- * 微信 JSSDK — 与 shareIndex.html 一致
- * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
- */
- var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
- var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
- var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
- var H5_PAGE_BASE_FALLBACK = 'https://prod.ailien.shop/h5/HBuilderProjects/';
- var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'secondShareGoods.html';
- var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'prod.ailien.shop'];
- var weChatJssdkConfigured = false;
- var wxConfigSignRetriedBaseUrl = false;
- var wxInitLastError = '';
- var wxJssdkInitPromise = null;
- function showDownloadTip() {
- var msg = '请到应用商店下载';
- if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
- uni.showToast({ title: msg, icon: 'none', duration: 2500 });
- } else {
- window.alert(msg);
- }
- }
- function mergeSearchAndHashParams() {
- var params = new URLSearchParams();
- function ingestAppend(querySlice) {
- if (!querySlice) return;
- var p = new URLSearchParams(querySlice);
- p.forEach(function (val, key) {
- params.append(key, val);
- });
- }
- function ingestSet(querySlice) {
- if (!querySlice) return;
- var p = new URLSearchParams(querySlice);
- p.forEach(function (val, key) {
- params.set(key, val);
- });
- }
- if (location.search && location.search.length > 1) {
- ingestAppend(location.search.slice(1));
- }
- var hash = location.hash || '';
- var qi = hash.indexOf('?');
- if (qi >= 0) {
- ingestSet(hash.slice(qi + 1));
- }
- return params;
- }
- function q(name) {
- var v = mergeSearchAndHashParams().get(name);
- return v == null ? '' : String(v);
- }
- function buildAppOpenQueryStringMerged() {
- var params = mergeSearchAndHashParams();
- var gid = params.get('goodsId') || params.get('id') || '';
- if (gid && !params.has('goodsId')) {
- params.set('goodsId', gid);
- }
- var sid = params.get('storeId') || params.get('id') || '';
- if (sid && !params.has('storeId')) {
- params.set('storeId', sid);
- }
- var qsOut = params.toString();
- return qsOut ? ('?' + qsOut) : '';
- }
- function getSecondGoodsAppUniPath() {
- return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
- /^\//,
- ''
- );
- }
- function buildAppDeepLink() {
- var path = getSecondGoodsAppUniPath();
- var s = buildAppOpenQueryStringMerged();
- var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
- if (!s) {
- return root + '/' + path;
- }
- return root + '/' + path + s;
- }
- /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
- function buildAppUniPageLaunchUrl() {
- var path = getSecondGoodsAppUniPath();
- var qs = buildAppOpenQueryStringMerged().replace(/^\?/, '');
- return qs ? path + '?' + qs : path;
- }
- /**
- * wx-open-launch-app extinfo:pages/secondHandTransactions/pages/detail/index?goodsId=…
- */
- function buildWeChatLaunchExtinfo() {
- var uniPage = buildAppUniPageLaunchUrl();
- if (uniPage.length <= 1024) return uniPage;
- var params = mergeSearchAndHashParams();
- var mini = new URLSearchParams();
- var goodsId = params.get('goodsId') || params.get('id') || '';
- if (goodsId) mini.set('goodsId', goodsId);
- var path = getSecondGoodsAppUniPath();
- var shortPage = path + '?' + mini.toString();
- if (shortPage.length <= 1024) return shortPage;
- return shortPage.slice(0, 1024);
- }
- function isWeChatInAppBrowser() {
- return /MicroMessenger/i.test(navigator.userAgent || '');
- }
- function getWxShareEntryFrom() {
- var from = q('from');
- if (from) return String(from).trim().toLowerCase();
- try {
- var h = location.hash || '';
- var qi = h.indexOf('?');
- if (qi >= 0) {
- var hf = new URLSearchParams(h.slice(qi + 1)).get('from');
- if (hf) return String(hf).trim().toLowerCase();
- }
- } catch (eH) {}
- try {
- var sf = new URLSearchParams(location.search || '').get('from');
- if (sf) return String(sf).trim().toLowerCase();
- } catch (eS) {}
- return '';
- }
- function logWxEntryDiagnostics() {
- if (!isWeChatInAppBrowser()) return;
- console.log('[wx-entry]', {
- entryFrom: getWxShareEntryFrom() || '(无)',
- wxJssdkReady: weChatJssdkConfigured,
- signUrl: getWxConfigSignUrl()
- });
- }
- function isIOSWeChatBrowser() {
- var ua = navigator.userAgent || '';
- return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
- }
- function readQueryParam(name) {
- return q(name);
- }
- function isWxDebugOn() {
- return readQueryParam('wxDebug') === '1';
- }
- function isWxForceDebug() {
- return readQueryParam('wxForce') === '1';
- }
- function isWxConfigOnClickDebug() {
- return readQueryParam('wxConfigOnClick') === '1';
- }
- function isWxPcAutoDebugHost() {
- var h = (location.hostname || '').toLowerCase();
- if (h === 'localhost' || h === '127.0.0.1') return true;
- for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
- if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
- }
- return false;
- }
- function isWxPcBrowser() {
- return !isWeChatInAppBrowser();
- }
- function shouldInitWeChatJssdkOnLoad() {
- if (isWeChatInAppBrowser()) return true;
- return isWxForceDebug() || isWxPcAutoDebugHost();
- }
- function shouldFetchWxConfig(fromUserClick) {
- if (isWeChatInAppBrowser()) return true;
- if (fromUserClick) return true;
- return isWxForceDebug() || isWxPcAutoDebugHost();
- }
- function getWxHtmlUrl() {
- var forced = String(q('wxSignUrl') || '').trim();
- if (forced) return forced.split('#')[0];
- return String(location.href || '').split('#')[0];
- }
- function getWxSignPageUrlForApi() {
- var htmlUrl = getWxHtmlUrl();
- if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
- return WX_GET_CONFIG_SIGN_URL;
- }
- function getWxHtmlUrlBase() {
- var htmlUrl = getWxSignPageUrlForApi();
- try {
- var u = new URL(htmlUrl);
- return u.origin + u.pathname;
- } catch (eU) {
- return WX_GET_CONFIG_SIGN_URL;
- }
- }
- function getWxConfigSignUrl() {
- if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
- return getWxSignPageUrlForApi();
- }
- function getWxGetConfigApiUrl() {
- return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
- }
- function buildWxGetConfigRequestBody(htmlUrl) {
- return {
- url: String(htmlUrl || '').split('#')[0].trim()
- };
- }
- function resolveWxConfigAppIdFromSignData(d) {
- if (!d || typeof d !== 'object') return '';
- var mp =
- d.mpAppId ||
- d.mpAppid ||
- d.officialAppId ||
- d.gzhAppId ||
- d.serviceAppId;
- if (mp != null && String(mp).trim() !== '') return String(mp).trim();
- var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
- if (fromQuery) return fromQuery;
- var raw = d.appId || d.appid || d.wxAppId;
- return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
- }
- function normalizeWxJssdkSignPayload(res, signUrlUsed) {
- if (!res || typeof res !== 'object') return null;
- var d = res.data != null && typeof res.data === 'object' ? res.data : res;
- if (!d || typeof d !== 'object') return null;
- var appId = resolveWxConfigAppIdFromSignData(d);
- var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
- var nonceStr =
- d.nonceStr != null && String(d.nonceStr) !== ''
- ? d.nonceStr
- : d.noncestr != null && String(d.noncestr) !== ''
- ? d.noncestr
- : d.nonce;
- var signature = d.signature || d.sign;
- if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
- return null;
- }
- return {
- appId: String(appId),
- timestamp: Number(timestamp),
- nonceStr: String(nonceStr),
- signature: String(signature),
- signUrl: String(signUrlUsed || '')
- .split('#')[0]
- .trim()
- };
- }
- function getWxErrMsg(err) {
- if (!err) return '';
- if (err.errMsg) return String(err.errMsg);
- if (typeof err === 'string') return err;
- try {
- return JSON.stringify(err);
- } catch (e) {
- return String(err);
- }
- }
- function formatWxConfigErrorTip(err, signPageUrl) {
- var errMsg = getWxErrMsg(err);
- var tip = '微信 JSSDK 配置失败';
- if (/invalid signature/i.test(errMsg)) {
- return (
- tip +
- ':签名无效。url=' +
- (signPageUrl || getWxHtmlUrl()) +
- ';appId=' +
- WECHAT_MP_APP_ID
- );
- }
- if (/require\s*subscribe/i.test(errMsg)) {
- return tip + ':' + errMsg + '(服务号需用户已关注)';
- }
- return errMsg ? tip + ':' + errMsg : tip;
- }
- function setWxInitError(msg) {
- wxInitLastError = String(msg || '').trim();
- if (wxInitLastError) console.warn('[wx]', wxInitLastError);
- }
- function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
- var htmlUrl = String(
- htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
- )
- .split('#')[0]
- .trim();
- if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
- htmlUrl = WX_GET_CONFIG_SIGN_URL;
- }
- if (isWxDebugOn()) {
- try {
- window.alert('htmlUrl(签名用):\n' + htmlUrl);
- } catch (eDbg) {}
- }
- var requestUrl = getWxGetConfigApiUrl();
- var requestBody = buildWxGetConfigRequestBody(htmlUrl);
- console.log('[wx] htmlUrl=', htmlUrl);
- console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
- return fetch(requestUrl, {
- method: 'POST',
- mode: 'cors',
- credentials: 'omit',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json;charset=UTF-8'
- },
- body: JSON.stringify(requestBody)
- })
- .then(function (r) {
- if (r.ok) return r.json();
- return r
- .text()
- .catch(function () {
- return '';
- })
- .then(function (text) {
- var hint = '';
- try {
- var j = JSON.parse(text);
- hint = j.msg || j.message || '';
- } catch (eP) {
- if (text) hint = text.slice(0, 120);
- }
- throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
- });
- })
- .then(function (res) {
- if (res && res.code != null) {
- var c = Number(res.code);
- if (c !== 200 && c !== 0 && res.success !== true) {
- throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
- }
- }
- var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
- if (!sign) {
- console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
- throw new Error(
- 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
- );
- }
- if (sign.appId !== WECHAT_MP_APP_ID) {
- console.warn(
- '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
- );
- }
- if (typeof wx === 'undefined') {
- if (isWxPcBrowser()) {
- console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
- return true;
- }
- setWxInitError('jweixin.js 未加载');
- return false;
- }
- return applyWxConfigFromSign(sign, htmlUrl);
- });
- }
- function applyWxConfigFromSign(sign, htmlUrl) {
- var wxConfigParams = {
- debug: isWxDebugOn(),
- appId: String(sign.appId),
- timestamp: sign.timestamp,
- nonceStr: String(sign.nonceStr),
- signature: String(sign.signature),
- jsApiList: [],
- openTagList: ['wx-open-launch-app']
- };
- return new Promise(function (resolve) {
- wx.config(wxConfigParams);
- wx.ready(function () {
- weChatJssdkConfigured = true;
- document.body.classList.add('wx-jssdk-ready');
- refreshWxLaunchTagAttrs();
- console.log('[wx.config] ready, htmlUrl=', htmlUrl);
- resolve(true);
- });
- wx.error(function (err) {
- weChatJssdkConfigured = false;
- document.body.classList.remove('wx-jssdk-ready');
- wxJssdkInitPromise = null;
- var errMsg = getWxErrMsg(err);
- setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
- if (isWxDebugOn()) window.alert(wxInitLastError);
- console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
- var baseUrl = getWxHtmlUrlBase();
- var fullUrl = getWxSignPageUrlForApi();
- if (
- !/invalid signature/i.test(errMsg) ||
- wxConfigSignRetriedBaseUrl ||
- baseUrl === fullUrl ||
- htmlUrl === baseUrl
- ) {
- resolve(false);
- return;
- }
- wxConfigSignRetriedBaseUrl = true;
- requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
- });
- });
- }
- function refreshWxLaunchTagAttrs() {
- var tag = document.getElementById('launch-btn');
- if (!tag) return;
- try {
- tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
- tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
- } catch (eA) {}
- }
- function bindWeChatLaunchTagEvents() {
- var tag = document.getElementById('launch-btn');
- if (!tag || tag._wxLaunchBound) return;
- tag._wxLaunchBound = true;
- refreshWxLaunchTagAttrs();
- tag.addEventListener('launch', function () {
- console.log('[wx-open-launch-app] launch ok');
- // showFabToast('正在打开 U店在哪…');
- });
- tag.addEventListener('error', function (e) {
- var detail = e && e.detail;
- var errMsg =
- detail && detail.errMsg
- ? String(detail.errMsg)
- : detail && detail.errmsg
- ? String(detail.errmsg)
- : '';
- console.warn('[wx-open-launch-app]', detail);
- if (/launch:fail/i.test(errMsg) && !getWxShareEntryFrom()) {
- showAppOpenFailTip(
- '请前往应用商店下载U店在哪app'
- );
- } else {
- showAppOpenFailTip(
- errMsg
- ? '未能打开 App:' + errMsg
- : '未能打开 App,请确认已安装最新版「U店在哪」'
- );
- }
- });
- }
- function initWeChatOpenLaunchApp(fromUserClick) {
- if (!shouldFetchWxConfig(!!fromUserClick)) {
- return Promise.resolve(false);
- }
- if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
- wxConfigSignRetriedBaseUrl = false;
- wxInitLastError = '';
- var htmlUrl = getWxConfigSignUrl();
- bindWeChatLaunchTagEvents();
- wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
- .then(function (ok) {
- if (ok === true) return true;
- if (!wxInitLastError) {
- setWxInitError('wx.config 失败,可加 ?wxDebug=1');
- }
- return false;
- })
- .catch(function (e) {
- var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
- setWxInitError(msg);
- console.warn('[wx] init failed', msg, 'htmlUrl=', htmlUrl);
- if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
- return false;
- })
- .finally(function () {
- if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
- });
- return wxJssdkInitPromise;
- }
- function scheduleWeChatJssdkBootstrap() {
- if (!shouldInitWeChatJssdkOnLoad()) return;
- var attempts = 0;
- function tick() {
- attempts += 1;
- if (weChatJssdkConfigured) return;
- initWeChatOpenLaunchApp();
- if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
- setTimeout(tick, 400);
- }
- }
- /* iOS 微信分享卡片可能稍后才写入 from 等参数,过早验签会 invalid signature */
- if (isIOSWeChatBrowser()) {
- setTimeout(tick, 350);
- } else {
- tick();
- }
- }
- function showFabToast(msg, ms) {
- var tip = String(msg || '').trim();
- if (!tip) return;
- var el = document.getElementById('openAppToast');
- if (el) {
- el.textContent = tip;
- el.style.display = 'block';
- if (showFabToast._t) clearTimeout(showFabToast._t);
- showFabToast._t = setTimeout(function () {
- el.style.display = 'none';
- }, ms || 2800);
- }
- console.log('[openApp]', tip);
- }
- function showAppOpenFailTip(msg) {
- var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
- if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
- uni.showToast({ title: tip, icon: 'none', duration: 2800 });
- } else if (isWeChatInAppBrowser()) {
- window.alert(tip);
- } else {
- console.warn('[openApp]', tip);
- }
- }
- function tryFetchWxConfigOnPcClick() {
- if (!isWxPcBrowser()) return Promise.resolve(false);
- showFabToast('正在请求 getWxConfig…');
- wxJssdkInitPromise = null;
- return initWeChatOpenLaunchApp(true).then(function (ok) {
- if (ok) {
- showFabToast(
- weChatJssdkConfigured
- ? 'getWxConfig 成功,wx.config 已就绪'
- : 'getWxConfig 成功'
- );
- } else {
- showFabToast(wxInitLastError || 'getWxConfig 失败');
- }
- return ok;
- });
- }
- function launchAppDeepLink(deepLink) {
- try {
- var a = document.createElement('a');
- a.href = deepLink;
- a.setAttribute('target', '_self');
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- } catch (e1) {}
- try {
- window.location.href = deepLink;
- } catch (e2) {}
- }
- function tryOpenHBuilderApp() {
- if (isWeChatInAppBrowser()) return;
- tryFetchWxConfigOnPcClick().then(function () {
- if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
- return;
- }
- tryOpenHBuilderAppViaScheme();
- });
- }
- function tryOpenHBuilderAppViaScheme() {
- // showFabToast('正在打开 U店在哪…');
- var deepLink = buildAppDeepLink();
- if (typeof plus !== 'undefined' && plus.runtime) {
- var installed = null;
- try {
- if (typeof plus.runtime.isApplicationExist === 'function') {
- installed = plus.runtime.isApplicationExist({
- pname: APP_ANDROID_PACKAGE,
- action: APP_IOS_URL_SCHEME
- });
- }
- } catch (e) {
- console.warn(e);
- }
- if (installed === false) {
- showDownloadTip();
- return;
- }
- try {
- plus.runtime.openURL(deepLink);
- } catch (e2) {
- console.warn(e2);
- showDownloadTip();
- }
- return;
- }
- var t0 = Date.now();
- var done = false;
- function finish() {
- if (done) return;
- done = true;
- document.removeEventListener('visibilitychange', onVis);
- window.removeEventListener('pagehide', onHide);
- }
- function onVis() {
- if (document.visibilityState === 'hidden') finish();
- }
- function onHide() {
- finish();
- }
- document.addEventListener('visibilitychange', onVis);
- window.addEventListener('pagehide', onHide);
- try {
- launchAppDeepLink(deepLink);
- } catch (e3) {
- finish();
- showDownloadTip();
- return;
- }
- window.setTimeout(function () {
- finish();
- }, 2600);
- }
- function tryDecode(s) {
- s = String(s || '');
- if (!s) return '';
- try {
- return decodeURIComponent(s.replace(/\+/g, ' '));
- } catch (e) {
- return s;
- }
- }
- var DEFAULT_HERO = '';
- /** 二手商品接口前缀;可用 URL 参数 alienSecondBase / secondApiBase 覆盖 */
- function resolveSecondApiBase() {
- var custom = (q('alienSecondBase') || q('secondApiBase') || '').trim();
- if (custom) {
- return custom.replace(/\/+$/, '');
- }
- var host = (location.hostname || '').toLowerCase();
- if (host === 'prod.ailien.shop' || host === 'uat.ailien.shop') {
- return 'https://prod.ailien.shop/alienSecond';
- }
- return 'http://120.26.186.130:8000/alienSecond';
- }
- var API_BASE_SECOND = resolveSecondApiBase();
- /** 与 querySecondGoodsDetailWithOutJWT 表单一致;优先地址栏,否则默认坐标 */
- var DEFAULT_REQUEST_LONGITUDE =
- (q('longitude') || q('lon') || q('jingdu') || '').trim() || '121.662527';
- var DEFAULT_REQUEST_LATITUDE =
- (q('latitude') || q('lat') || q('weidu') || '').trim() || '38.925754';
- var COMMENT_SOURCE_TYPE = 4;
- function apiGet(path) {
- return fetch(API_BASE + path, {
- method: 'GET',
- mode: 'cors',
- credentials: 'omit',
- headers: { Accept: 'application/json' }
- }).then(function (res) {
- if (!res.ok) throw new Error('HTTP ' + res.status);
- return res.json();
- });
- }
- function apiPostJson(path, body) {
- return fetch(API_BASE + path, {
- method: 'POST',
- mode: 'cors',
- credentials: 'omit',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(body || {})
- }).then(function (res) {
- if (!res.ok) throw new Error('HTTP ' + res.status);
- return res.json();
- });
- }
- function pick(d, keys) {
- if (!d || typeof d !== 'object') return null;
- for (var i = 0; i < keys.length; i++) {
- var k = keys[i];
- if (d[k] != null && d[k] !== '') return d[k];
- }
- return null;
- }
- function isApiOk(res) {
- if (!res || typeof res !== 'object') return false;
- if (res.success === false) return false;
- var c = res.code;
- return c === 200 || c === '200' || Number(c) === 200;
- }
- /** 二手详情存在性接口:兼容 code 0 / success:true(与 alienSecond 常见返回一致) */
- function isSecondGoodsExistOk(res) {
- if (!res || typeof res !== 'object') return false;
- if (res.success === false) return false;
- if (res.success === true) return true;
- var c = res.code;
- if (c === 200 || c === '200' || Number(c) === 200) return true;
- if (c === 0 || c === '0' || Number(c) === 0) return true;
- return false;
- }
- function pickSecondGoodsDetailData(res) {
- if (!res || typeof res !== 'object') return null;
- var d = res.data != null ? res.data : res.result;
- if (d == null) return null;
- if (Array.isArray(d)) {
- return d.length && typeof d[0] === 'object' ? d[0] : null;
- }
- if (typeof d !== 'object') return null;
- var inner =
- d.secondGoodsDetail ||
- d.goodsDetail ||
- d.goodsInfo ||
- d.detail ||
- d.record;
- if (inner && typeof inner === 'object' && !Array.isArray(inner)) {
- return inner;
- }
- return d;
- }
- /** 详情里是否有可识别的商品实体(有则视为存在,不依赖 goodsStatus 数值) */
- function hasSecondGoodsDetailPayload(d) {
- if (!d || typeof d !== 'object') return false;
- var id = d.goodsId != null ? d.goodsId : d.id;
- if (id != null && String(id).trim() !== '' && String(id).trim() !== '0') {
- return true;
- }
- var name = d.goodsName || d.title || d.secondGoodsTitle || d.name;
- if (name != null && String(name).trim() !== '') return true;
- var img =
- d.coverUrl ||
- d.mainImage ||
- d.goodsImage ||
- d.firstImage ||
- (Array.isArray(d.goodsImageList) && d.goodsImageList[0]);
- if (img != null && String(img).trim() !== '') return true;
- return Object.keys(d).length > 0;
- }
- function isDetailDataExplicitlyDeleted(d) {
- if (!d || typeof d !== 'object') return false;
- if (d.deleteFlag === 1 || d.deleteFlag === '1' || Number(d.deleteFlag) === 1) {
- return true;
- }
- if (d.deleted === true || d.isDelete === 1 || d.isDelete === '1') {
- return true;
- }
- return false;
- }
- /** 与店铺 getClientStoreDetail 一致:无商品时 code 仍可能为 200 */
- function isNoCarryingDataMsg(res) {
- if (!res || typeof res !== 'object') return false;
- var msg = res.msg != null ? String(res.msg).trim() : '';
- return msg === '暂无承载数据';
- }
- function isMsgIndicateGoodsGone(msg) {
- msg = String(msg || '').trim();
- if (!msg) return false;
- if (msg === '暂无承载数据') return true;
- return /已删除|已下架|已卖出|商品不存在|不存在该|查无此商品|找不到该商品|商品不可用/.test(
- msg
- );
- }
- function fmtPriceNum(v) {
- var n = v != null ? Number(v) : NaN;
- return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
- }
- /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
- function appendGoodsTag(mount, raw, kind) {
- if (!mount || raw == null) return;
- var s = String(raw).trim();
- if (!s) return;
- var span = document.createElement('span');
- span.className =
- 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
- if (kind === 'label') {
- span.textContent = s.replace(/^#+/, '');
- } else {
- span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
- }
- mount.appendChild(span);
- }
- function renderGoodsDetail(d) {
- if (!d || typeof d !== 'object') return;
- var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
- if (title) {
- var el = document.getElementById('goodsTitle');
- if (el) el.textContent = String(title);
- }
- var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
- if (price != null) {
- var pe = document.getElementById('goodsPrice');
- if (pe) pe.textContent = fmtPriceNum(price);
- }
- var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
- if (dist != null) {
- var dt = String(dist).trim();
- if (dt) {
- if (!/^距离/.test(dt)) dt = '距离 ' + dt;
- if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
- dt = dt.replace(/\s+$/, '') + 'km';
- }
- var de = document.getElementById('goodsDistance');
- if (de) de.textContent = dt;
- }
- }
- var img =
- pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
- (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
- (Array.isArray(d.imageList) && d.imageList[0]);
- if (img) {
- var hi = document.getElementById('goodsHeroImg');
- if (hi) {
- hi.src = String(img);
- hi.alt = '商品图';
- }
- }
- var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
- if (nick) {
- var ne = document.getElementById('goodsUserName');
- if (ne) ne.textContent = String(nick);
- }
- var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
- if (av) {
- var ae = document.getElementById('goodsUserAvatar');
- if (ae) ae.src = String(av);
- }
- var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
- if (tm) {
- var te = document.getElementById('goodsTimeAgo');
- if (te) te.textContent = String(tm);
- }
- var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
- var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
- var wrap = document.getElementById('goodsHeroSloganWrap');
- var e1 = document.getElementById('goodsSlogan1');
- var e2 = document.getElementById('goodsSlogan2');
- if (wrap && e1 && e2) {
- if (s1 || s2) {
- if (s1) e1.textContent = String(s1);
- if (s2) e2.textContent = String(s2);
- wrap.style.display = '';
- } else {
- wrap.style.display = 'none';
- }
- }
- var hotStat = document.getElementById('goodsHotStat');
- var cs = pick(d, ['collectStatus']);
- if (hotStat) {
- var hideHot =
- cs != null &&
- (Number(cs) === 0 || String(cs).trim() === '0');
- hotStat.style.display = hideHot ? 'none' : '';
- }
- var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
- if (hot != null) {
- var he = document.getElementById('goodsHotCount');
- if (he) he.textContent = String(hot);
- }
- var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
- if (fav != null) {
- var fe = document.getElementById('goodsFavCount');
- if (fe) fe.textContent = String(fav);
- }
- var topicStr = d.topic != null ? String(d.topic).trim() : '';
- var labelStr = d.label != null ? String(d.label).trim() : '';
- var hasApiTags = topicStr !== '' || labelStr !== '';
- var mount = document.getElementById('goodsTags');
- if (mount) {
- if (hasApiTags) {
- mount.innerHTML = '';
- if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
- if (labelStr) appendGoodsTag(mount, labelStr, 'label');
- } else {
- var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
- if (tags) {
- mount.innerHTML = '';
- var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
- arr.forEach(function (t) {
- if (t == null || t === '') return;
- var label =
- typeof t === 'object'
- ? (t.tagName || t.name || t.label || '')
- : String(t);
- label = String(label).trim();
- if (!label) return;
- var isTopic = label.indexOf('#') === 0;
- appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
- });
- }
- }
- }
- }
- 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>';
- 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>';
- 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>';
- function cmtAvatarUrl(c) {
- return String(
- pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
- ).trim();
- }
- function cmtUserName(c) {
- var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
- return s || '—';
- }
- function cmtTime(c) {
- return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
- }
- function cmtContent(c) {
- return String(pick(c, ['content', 'commentContent', 'text']) || '');
- }
- function cmtLikeCount(c) {
- var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
- return v != null ? String(v) : '0';
- }
- function cmtReplies(c) {
- if (!c || typeof c !== 'object') return [];
- var sub =
- c.childCommonComments ||
- c.replyList ||
- c.replyVOList ||
- c.children ||
- c.subComments ||
- c.replies;
- if (sub == null) return [];
- return Array.isArray(sub) ? sub.filter(Boolean) : [];
- }
- function appendCmtRow(parentBody, c, showReply) {
- var row = document.createElement('div');
- row.className = 'goods-cmt__row';
- var img = document.createElement('img');
- img.className = 'goods-cmt__avatar';
- img.alt = '';
- var au = cmtAvatarUrl(c);
- img.src = au || 'images/demouser.png';
- var body = document.createElement('div');
- body.className = 'goods-cmt__body';
- var name = document.createElement('span');
- name.className = 'goods-cmt__name';
- name.textContent = cmtUserName(c);
- var time = document.createElement('span');
- time.className = 'goods-cmt__time';
- time.textContent = cmtTime(c);
- var text = document.createElement('p');
- text.className = 'goods-cmt__text';
- text.textContent = cmtContent(c);
- var actions = document.createElement('div');
- actions.className = 'goods-cmt__actions';
- var likeBtn = document.createElement('button');
- likeBtn.type = 'button';
- likeBtn.className = 'goods-cmt__action';
- likeBtn.setAttribute('aria-label', '点赞');
- likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
- actions.appendChild(likeBtn);
- if (showReply) {
- var repBtn = document.createElement('button');
- repBtn.type = 'button';
- repBtn.className = 'goods-cmt__action';
- repBtn.setAttribute('aria-label', '回复');
- repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
- actions.appendChild(repBtn);
- }
- body.appendChild(name);
- body.appendChild(time);
- body.appendChild(text);
- body.appendChild(actions);
- row.appendChild(img);
- row.appendChild(body);
- parentBody.appendChild(row);
- return body;
- }
- function buildNestedCmt(c) {
- var wrap = document.createElement('div');
- wrap.className = 'goods-cmt goods-cmt--nested';
- appendCmtRow(wrap, c, false);
- return wrap;
- }
- function filterTopLevelComments(list) {
- if (!Array.isArray(list) || !list.length) return [];
- var top = list.filter(function (c) {
- if (!c) return false;
- var pid = c.parentId != null ? c.parentId : c.pid;
- if (typeof pid === 'string') pid = pid.trim();
- return pid == null || pid === '' || Number(pid) === 0;
- });
- return top.length ? top : list.slice();
- }
- function countCommentsInApiList(records) {
- if (!Array.isArray(records)) return 0;
- var tops = filterTopLevelComments(records);
- var n = 0;
- for (var i = 0; i < tops.length; i++) {
- var c = tops[i];
- if (!c) continue;
- n += 1 + cmtReplies(c).length;
- }
- return n;
- }
- function normalizeCommentListPayload(d) {
- if (typeof d === 'string') {
- try {
- d = JSON.parse(d);
- } catch (e) {
- return { records: [], total: 0 };
- }
- }
- if (Array.isArray(d)) {
- return { records: d, total: countCommentsInApiList(d) };
- }
- if (d && typeof d === 'object') {
- var arr = d.records || d.list || d.rows;
- if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
- if (!Array.isArray(arr)) arr = [];
- var total =
- d.total != null && !isNaN(Number(d.total))
- ? Number(d.total)
- : countCommentsInApiList(arr);
- return { records: arr, total: total };
- }
- return { records: [], total: 0 };
- }
- function renderCommentsList(rows, total) {
- var mount = document.getElementById('goodsCommentList');
- var totEl = document.getElementById('goodsCommentTotal');
- if (!mount) return;
- mount.innerHTML = '';
- var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
- var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
- if (totEl) totEl.textContent = String(n);
- if (!list.length) {
- var empty = document.createElement('li');
- empty.className = 'goods-comments__empty';
- empty.setAttribute('role', 'status');
- empty.textContent = '暂无留言';
- mount.appendChild(empty);
- return;
- }
- list.forEach(function (c) {
- if (!c) return;
- var li = document.createElement('li');
- li.className = 'goods-cmt';
- appendCmtRow(li, c, true);
- var replies = cmtReplies(c);
- if (replies.length) {
- var thread = document.createElement('div');
- thread.className = 'goods-cmt__thread';
- var inner = document.createElement('div');
- inner.className = 'goods-cmt__replies-inner';
- replies.forEach(function (r) {
- if (r) inner.appendChild(buildNestedCmt(r));
- });
- var bar = document.createElement('button');
- bar.type = 'button';
- bar.className = 'goods-cmt__thread-bar';
- bar.setAttribute('aria-expanded', 'true');
- bar.innerHTML =
- '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
- '<span class="goods-cmt__thread-bar-right">' +
- '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
- thread.appendChild(inner);
- thread.appendChild(bar);
- li.appendChild(thread);
- }
- mount.appendChild(li);
- });
- }
- function bindCommentThreadDelegation() {
- var list = document.getElementById('goodsCommentList');
- if (!list || list.dataset.threadDeleg) return;
- list.dataset.threadDeleg = '1';
- list.addEventListener('click', function (e) {
- var bar = e.target.closest('.goods-cmt__thread-bar');
- if (!bar) return;
- var inner = bar.previousElementSibling;
- if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
- var collapsed = inner.classList.toggle('is-collapsed');
- bar.classList.toggle('is-collapsed', collapsed);
- bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
- var lab = bar.querySelector('.js-thread-label');
- if (lab) lab.textContent = collapsed ? '展开' : '收起';
- });
- }
- function buildShareUndefinedRedirectQuery(gs, ctx) {
- ctx = ctx || {};
- var uq = new URLSearchParams();
- uq.set('goodsUnavailable', '1');
- if (gs != null && String(gs).trim() !== '') {
- uq.set('goodsStatus', String(gs).trim());
- }
- if (ctx.userId) uq.set('userId', String(ctx.userId));
- if (ctx.longitude) uq.set('longitude', String(ctx.longitude));
- if (ctx.latitude) uq.set('latitude', String(ctx.latitude));
- if (ctx.userCity) uq.set('userCity', String(ctx.userCity));
- var gid = ctx.goodsId || '';
- if (gid) {
- uq.set('goodsId', String(gid));
- uq.set('id', String(gid));
- }
- return uq;
- }
- function redirectToShareUndefined(gs, ctx) {
- window.location.replace(
- 'shareUndefined.html?' + buildShareUndefinedRedirectQuery(gs, ctx).toString()
- );
- }
- /** 从 querySecondGoodsDetailWithOutJWT 返回中解析 goodsStatus(兼容 data 嵌套) */
- function pickGoodsStatusFromDetailResponse(res) {
- if (!res || typeof res !== 'object') return null;
- var d = pickSecondGoodsDetailData(res);
- var candidates = [];
- if (d && d.goodsStatus != null) candidates.push(d.goodsStatus);
- if (res.goodsStatus != null) candidates.push(res.goodsStatus);
- var raw = res.data != null ? res.data : res.result;
- if (raw && typeof raw === 'object' && !Array.isArray(raw) && raw.goodsStatus != null) {
- candidates.push(raw.goodsStatus);
- }
- var i;
- for (i = 0; i < candidates.length; i++) {
- var v = candidates[i];
- if (v != null && String(v).trim() !== '') return v;
- }
- return null;
- }
- /** 仅 goodsStatus === 3 视为可展示;缺省或其它值均进不可用页 */
- function isGoodsStatusAvailable(gs) {
- if (gs == null || String(gs).trim() === '') return false;
- return Number(gs) === 3 || String(gs).trim() === '3';
- }
- /**
- * 存在性接口:以 goodsStatus 为准,不为 3(含缺失)→ 跳转 shareUndefined。
- */
- function isDetailResponseGoodsUnavailable(res) {
- if (!res || typeof res !== 'object') return true;
- if (!isSecondGoodsExistOk(res)) return true;
- return !isGoodsStatusAvailable(pickGoodsStatusFromDetailResponse(res));
- }
- /**
- * 仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在,不渲染接口返回的详情字段
- * @returns {Promise<{redirected:boolean, exists:boolean}>}
- */
- function checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx) {
- var lonStr =
- lon != null && String(lon).trim() !== ''
- ? String(lon).trim()
- : String(DEFAULT_REQUEST_LONGITUDE);
- var latStr =
- lat != null && String(lat).trim() !== ''
- ? String(lat).trim()
- : String(DEFAULT_REQUEST_LATITUDE);
- var pid =
- phoneId != null && String(phoneId).trim() !== ''
- ? String(phoneId).trim()
- : '';
- /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
- var formBody = {
- goodsId: String(goodsId != null ? goodsId : '').trim(),
- longitude: String(lonStr),
- latitude: String(latStr),
- phoneId: pid
- };
- var form = new URLSearchParams();
- form.set('goodsId', formBody.goodsId);
- form.set('longitude', formBody.longitude);
- form.set('latitude', formBody.latitude);
- form.set('phoneId', formBody.phoneId);
- var detailUrl =
- API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT';
- var formStr = form.toString();
- return fetch(detailUrl, {
- method: 'POST',
- mode: 'cors',
- credentials: 'omit',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
- },
- body: formStr
- })
- .then(function (res) {
- if (!res.ok) throw new Error('HTTP ' + res.status);
- return res.json();
- })
- .then(function (res) {
- redirectCtx = redirectCtx || {};
- var d = pickSecondGoodsDetailData(res);
- if (isDetailResponseGoodsUnavailable(res)) {
- var gs = pickGoodsStatusFromDetailResponse(res);
- console.warn(
- '[querySecondGoodsDetailWithOutJWT] unavailable goodsStatus=',
- gs,
- res && res.code,
- res && res.msg,
- d
- );
- redirectToShareUndefined(gs, redirectCtx);
- return { redirected: true, exists: false };
- }
- return { redirected: false, exists: true };
- });
- }
- function fetchCommentList(goodsId, userId, pageNum, pageSize) {
- var st = (q('sourceType') || '').trim();
- var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
- var path = '/commonComment/getListBySourceType?' +
- 'sourceType=' + encodeURIComponent(String(sourceType)) +
- '&sourceId=' + encodeURIComponent(String(goodsId)) +
- '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
- '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
- '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
- return apiGet(path).then(function (res) {
- if (!isApiOk(res)) {
- if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
- renderCommentsList([], 0);
- return;
- }
- var raw = res.data != null ? res.data : res.result;
- var pack = normalizeCommentListPayload(raw);
- renderCommentsList(pack.records, pack.total);
- });
- }
- /** 分享卡片常用 sourceId;与留言 sourceId 一致 */
- function getShareGoodsId() {
- return (q('goodsId') || q('id') || q('sourceId') || '').trim();
- }
- function run() {
- var goodsId = getShareGoodsId();
- var userId = (q('userId') || '').trim();
- var phoneId = (q('phoneId') || q('phone_id') || '').trim();
- var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
- var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
- var userCity = (q('userCity') || q('city') || '').trim();
- var lonResolved = lon || DEFAULT_REQUEST_LONGITUDE;
- var latResolved = lat || DEFAULT_REQUEST_LATITUDE;
- var pageNum = (q('pageNum') || '1').trim();
- var pageSize = (q('pageSize') || '10').trim();
- var redirectCtx = {
- goodsId: goodsId,
- userId: userId,
- longitude: lonResolved,
- latitude: latResolved,
- userCity: userCity
- };
- bindCommentThreadDelegation();
- /* 分享卡片应带 goodsId;勿因 URL 残留 goodsUnavailable=1 跳过存在性校验直接进不可用页 */
- if (
- !goodsId &&
- String(q('goodsUnavailable') || '').trim() === '1'
- ) {
- redirectToShareUndefined(q('goodsStatus'), redirectCtx);
- return;
- }
- if (!goodsId) {
- applyFromUrl();
- return;
- }
- checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx)
- .catch(function (e) {
- console.warn('[querySecondGoodsDetailWithOutJWT]', e);
- return { redirected: false, exists: null, checkFailed: true };
- })
- .then(function (checkResult) {
- if (checkResult && checkResult.redirected) {
- return;
- }
- applyFromUrl();
- return fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
- console.warn('[getListBySourceType]', e);
- renderCommentsList([], 0);
- });
- });
- }
- function applyFromUrl() {
- var heroImg = document.getElementById('goodsHeroImg');
- var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
- imgUrl = tryDecode(imgUrl).trim();
- if (imgUrl) {
- heroImg.src = imgUrl;
- heroImg.alt = '商品图';
- } else {
- heroImg.src = DEFAULT_HERO;
- heroImg.alt = '';
- }
- var av = tryDecode(q('userImage') || q('avatar')).trim();
- document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
- var uname = tryDecode(q('userName') || q('nickname')).trim();
- if (uname) document.getElementById('goodsUserName').textContent = uname;
- var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
- if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
- var s1 = tryDecode(q('slogan1') || q('line1')).trim();
- var s2 = tryDecode(q('slogan2') || q('line2')).trim();
- var elS1 = document.getElementById('goodsSlogan1');
- var elS2 = document.getElementById('goodsSlogan2');
- var elWrap = document.getElementById('goodsHeroSloganWrap');
- if (s1 && elS1) elS1.textContent = s1;
- if (s2 && elS2) elS2.textContent = s2;
- if (elWrap && (s1 || s2)) elWrap.style.display = '';
- var price = tryDecode(q('price')).trim();
- if (price) {
- var pn = parseFloat(price.replace(/[^\d.]/g, ''));
- document.getElementById('goodsPrice').textContent =
- !isNaN(pn) ? pn.toFixed(2) : price;
- }
- var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
- if (dist) {
- if (!/^距离/.test(dist)) dist = '距离 ' + dist;
- if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
- dist = dist.replace(/\s+$/, '') + 'km';
- }
- document.getElementById('goodsDistance').textContent = dist;
- }
- var title = tryDecode(q('title') || q('goodsTitle')).trim();
- if (title) document.getElementById('goodsTitle').textContent = title;
- var hot = tryDecode(q('hotCount') || q('hot')).trim();
- if (hot) document.getElementById('goodsHotCount').textContent = hot;
- var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
- if (fav) document.getElementById('goodsFavCount').textContent = fav;
- var cc = tryDecode(q('commentCount') || q('comments')).trim();
- if (cc) {
- var elTot = document.getElementById('goodsCommentTotal');
- if (elTot) elTot.textContent = cc;
- }
- var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
- var mount = document.getElementById('goodsTags');
- var hasGoodsId = (q('goodsId') || q('id') || '').trim();
- if (mount) {
- if (tagsRaw) {
- mount.innerHTML = '';
- tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
- appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
- });
- } else if (!hasGoodsId) {
- mount.innerHTML = '';
- ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
- appendGoodsTag(mount, t, 'label');
- });
- }
- }
- }
- function sharePage() {
- var title = document.getElementById('goodsTitle').textContent || '商品分享';
- var url = location.href;
- if (navigator.share) {
- navigator.share({ title: title, text: title, url: url }).catch(function () {});
- return;
- }
- if (navigator.clipboard && navigator.clipboard.writeText) {
- navigator.clipboard.writeText(url).then(function () {
- window.alert('链接已复制');
- }).catch(function () {
- window.prompt('复制链接', url);
- });
- } else {
- window.prompt('复制链接', url);
- }
- }
- var shareBtn = document.getElementById('goodsShareBtn');
- if (shareBtn) shareBtn.addEventListener('click', sharePage);
- function boot() {
- var launchTag = document.getElementById('launch-btn');
- if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
- bindWeChatLaunchTagEvents();
- if (isWeChatInAppBrowser()) {
- document.body.classList.add('is-wechat');
- logWxEntryDiagnostics();
- }
- if (shouldInitWeChatJssdkOnLoad()) {
- if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
- document.body.classList.add('wx-pc-debug');
- }
- scheduleWeChatJssdkBootstrap();
- }
- document.addEventListener('WeixinOpenTagsError', function (e) {
- console.warn('[WeixinOpenTagsError]', e && e.detail);
- });
- if (isWeChatInAppBrowser()) {
- var openBtnWx = document.getElementById('openApp');
- if (openBtnWx) {
- openBtnWx.addEventListener('click', function () {
- if (!weChatJssdkConfigured) {
- showFabToast(
- wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
- );
- }
- });
- }
- } else {
- var openAppBtn = document.getElementById('openApp');
- if (openAppBtn) {
- openAppBtn.addEventListener('click', tryOpenHBuilderApp);
- }
- }
- run();
- }
- if (document.readyState === 'complete') {
- boot();
- } else {
- window.onload = boot;
- }
- })();
- </script>
- </body>
- </html>
|