2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
import{c as r,I as K,d as ee,o as se,H as te,b as p,e as s,t as k,f as g,m as H,l as A,s as S,R as j,y as L,z as x,g as oe,r as f,J as ne,K as ae,q as le,B as re,L as ce,T as ie,u as de,j as c,N as ue,O as R,P as pe,Q as fe,G as me}from"./index-bPsB4P3d.js";import{u as ve}from"./user-BRXmSDmz.js";import{p as D}from"./product-wgcUL5oj.js";import{s as _e}from"./shop-DXUqoVUd.js";import{f as ge}from"./file-Out0aTUD.js";import{B as he}from"./BellOutlined-Ct1UTp7O.js";var ye={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M880.1 154H143.9c-24.5 0-39.8 26.7-27.5 48L349 597.4V838c0 17.7 14.2 32 31.8 32h262.4c17.6 0 31.8-14.3 31.8-32V597.4L907.7 202c12.2-21.3-3.1-48-27.6-48zM603.4 798H420.6V642h182.9v156zm9.6-236.6l-9.5 16.6h-183l-9.5-16.6L212.7 226h598.6L613 561.4z"}}]},name:"filter",theme:"outlined"};function q(d){for(var n=1;n<arguments.length;n++){var l=arguments[n]!=null?Object(arguments[n]):{},m=Object.keys(l);typeof Object.getOwnPropertySymbols=="function"&&(m=m.concat(Object.getOwnPropertySymbols(l).filter(function(v){return Object.getOwnPropertyDescriptor(l,v).enumerable}))),m.forEach(function(v){be(d,v,l[v])})}return d}function be(d,n,l){return n in d?Object.defineProperty(d,n,{value:l,enumerable:!0,configurable:!0,writable:!0}):d[n]=l,d}var F=function(n,l){var m=q({},n,l.attrs);return r(K,q({},m,{icon:ye}),null)};F.displayName="FilterOutlined";F.inheritAttrs=!1;const ke={class:"mobile-container"},Ce={class:"header"},Ie={class:"avatar"},we={class:"welcome"},Oe={class:"username"},Be={class:"actions"},Se={class:"search-section"},Pe={class:"banner-container"},Ae={class:"banner-carousel"},ze=["src"],He={class:"banner-content"},Le={class:"section"},xe={class:"section-header"},Fe={class:"horizontal-scroll"},Te={class:"product-info"},Ne={class:"name"},Ve={class:"price"},$e={class:"section popular-section"},Ee={class:"section-header"},Me={class:"product-grid"},Ue={class:"product-info"},je={class:"name"},Re={class:"price"},De={key:0,class:"loading-more"},qe={key:1,class:"no-more"},Ge={key:2,class:"no-products"},Qe=ee({__name:"HomeView",setup(d){const n=de(),l=f({id:0,nickname:"",account:"",avatar:"",type:0,status:0,createTime:"",updateTime:""}),m=f(""),v=f([]),T=f([]),C=f([]),I=f(!1),O=f(!0),N=f(1),B=f(10),G=async()=>{try{const t=await ve.getUserInfo();l.value=t||{}}catch(t){console.error("获取用户信息失败:",t)}},Q=async()=>{try{const t=[],e=await _e.getAllShops();for(const i of e){const h=i;if(h.coverImageFileId){const y=h.coverImageFileId.split(",").filter(w=>w.trim());for(const w of y){const P=parseInt(w);if(!isNaN(P)){const o=ge.getSignedUrl(P).then(b=>b).catch(b=>(console.error("获取店铺banner图签名失败:",b),""));t.push(o)}}}}const u=(await Promise.all(t)).filter(i=>i!=="").map(i=>i.replace(/[`]/g,"").trim()),a=[...new Set(u)];v.value=a.slice(0,10)}catch(t){console.error("获取Banner图片失败:",t)}},J=async()=>{try{const e=await D.getProductsByTag("精选")||[],u=(Array.isArray(e)?e:[]).sort(()=>.5-Math.random());T.value=u.slice(0,5).map(a=>({id:a.id,name:a.name,price:a.price,bgColor:z()}))}catch(t){console.error("获取精选作品失败:",t)}},V=async(t=!1)=>{if(!(I.value||!O.value)){I.value=!0;try{const _=await D.getProductsByTag("热门")||[],u=Array.isArray(_)?_:[];if(t){const a=(N.value-1)*B.value,i=a+B.value,h=u.slice(a,i);h.length<B.value&&(O.value=!1),C.value=[...C.value,...h.map(y=>({id:y.id,name:y.name,price:y.price,bgColor:z()}))]}else C.value=u.slice(0,B.value).map(a=>({id:a.id,name:a.name,price:a.price,bgColor:z()})),u.length<=B.value&&(O.value=!1)}catch(e){console.error("获取热门作品失败:",e)}finally{I.value=!1}}},$=()=>{const t=document.documentElement.scrollTop||document.body.scrollTop,e=document.documentElement.scrollHeight||document.body.scrollHeight,_=document.documentElement.clientHeight;t+_>=e-100&&!I.value&&O.value&&(N.value++,V(!0))};se(()=>{G(),Q(),J(),V(),window.addEventListener("scroll",$)}),te(()=>{window.removeEventListener("scroll",$)});const z=()=>{const t=["#ffe4d6","#d6eaff","#e2ffd6","#fff2d6","#d6ffe4","#e4d6ff"];return t[Math.floor(Math.random()*t.length)]},W=()=>{n.push("/profile")},X=()=>{},Y=t=>{},Z=()=>{},E=()=>{},M=t=>{n.push("/products")},U=t=>{n.push(`/product/${t.id}`)};return(t,e)=>{const _=ne,u=ae,a=le,i=re,h=ce,y=ie,w=fe,P=pe;return c(),p("div",ke,[s("header",Ce,[s("div",{class:"user-info",onClick:W},[s("div",Ie,[r(_,{size:40,src:l.value?.avatar||"https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"},null,8,["src"])]),s("div",we,[e[3]||(e[3]=s("p",{class:"greeting"},"Hello!",-1)),s("p",Oe,k(l.value?.nickname||"用户"),1)])]),s("div",Be,[r(u,{count:3,offset:[-5,5]},{default:g(()=>[r(S(he),{class:"notification-icon",onClick:X})]),_:1})])]),s("div",Se,[r(a,{value:m.value,"onUpdate:value":e[0]||(e[0]=o=>m.value=o),placeholder:"搜索作品...",size:"large",onInput:Y},{prefix:g(()=>[r(S(ue),{style:{color:"#999"}})]),_:1},8,["value"]),r(i,{class:"filter-btn",type:"primary",shape:"circle",onClick:Z},{default:g(()=>[r(S(F))]),_:1})]),s("div",Pe,[s("div",Ae,[v.value.length>0?(c(),H(h,{key:0,autoplay:"","autoplay-speed":3e3,effect:"fade"},{default:g(()=>[(c(!0),p(L,null,x(v.value,(o,b)=>(c(),p("div",{key:b,class:"banner-slide",onClick:E},[s("img",{src:o,alt:"Banner",class:"banner-img"},null,8,ze)]))),128))]),_:1})):(c(),p("div",{key:1,class:"banner",onClick:E},[s("div",He,[r(y,{color:"red",class:"banner-tag"},{default:g(()=>[...e[4]||(e[4]=[A("限时优惠",-1)])]),_:1}),e[6]||(e[6]=s("h3",null,"Get Winter Discount",-1)),e[7]||(e[7]=s("h2",null,"20% Off",-1)),e[8]||(e[8]=s("p",null,"For Children",-1)),r(i,{type:"primary",size:"small",class:"banner-btn"},{default:g(()=>[...e[5]||(e[5]=[A("立即购买",-1)])]),_:1})]),e[9]||(e[9]=s("div",{class:"banner-image"},[s("div",{class:"img-placeholder"},"Banner")],-1))]))])]),s("section",Le,[s("div",xe,[e[11]||(e[11]=s("h3",null,"精选作品",-1)),s("a",{class:"see-all",onClick:e[1]||(e[1]=o=>M())},[e[10]||(e[10]=A("查看全部 ",-1)),r(S(j))])]),s("div",Fe,[(c(!0),p(L,null,x(T.value,o=>(c(),H(w,{key:o.id,class:"product-card","body-style":{padding:"12px"},hoverable:"",onClick:b=>U(o)},{default:g(()=>[s("div",{class:"product-img",style:R({backgroundColor:o.bgColor})},[s("span",null,k(o.name[0]),1)],4),s("div",Te,[s("p",Ne,k(o.name),1),s("p",Ve,"$"+k(o.price),1)])]),_:2},1032,["onClick"]))),128))])]),s("section",$e,[s("div",Ee,[e[13]||(e[13]=s("h3",null,"热门作品",-1)),s("a",{class:"see-all",onClick:e[2]||(e[2]=o=>M())},[e[12]||(e[12]=A("查看全部 ",-1)),r(S(j))])]),s("div",Me,[(c(!0),p(L,null,x(C.value,o=>(c(),H(w,{key:o.id,class:"product-card grid-item","body-style":{padding:"12px"},hoverable:"",onClick:b=>U(o)},{default:g(()=>[s("div",{class:"product-img",style:R({backgroundColor:o.bgColor})},[s("span",null,k(o.name[0]),1)],4),s("div",Ue,[s("p",je,k(o.name),1),s("p",Re,"$"+k(o.price),1)])]),_:2},1032,["onClick"]))),128))]),I.value?(c(),p("div",De,[r(P,{size:"small"}),e[14]||(e[14]=s("span",{style:{"margin-left":"8px"}},"加载中...",-1))])):!O.value&&C.value.length>0?(c(),p("div",qe," 暂无更多作品推荐 ")):C.value.length===0&&!I.value?(c(),p("div",Ge," 暂无热门作品 ")):oe("",!0)])])}}}),es=me(Qe,[["__scopeId","data-v-266bf89d"]]);export{es as default};
|