Files
JayuCloud/docs/product/Frontend/assets/WishlistView-BVXvURB3.js
T

2 lines
3.2 KiB
JavaScript

import{d as V,o as W,b as c,e as o,c as a,f as u,y as F,z as R,g as T,r as v,a6 as p,a7 as U,a9 as $,u as z,j as n,s as y,ab as D,O as L,t as g,l as w,aA as S,ac as Z,a1 as j,a2 as O,G}from"./index-DVh2g0kp.js";/* empty css */import{w as b}from"./wishlist-CzQIXbfE.js";import{f as H}from"./file-CYuTQo5B.js";const q={class:"mobile-container"},J={class:"header"},K={class:"wishlist-items"},Q=["onClick"],X=["src","alt"],Y={class:"item-details"},tt=["onClick"],et={class:"item-price"},st={class:"item-actions"},ot={key:0,class:"empty-wishlist"},C="data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg==",at=V({__name:"WishlistView",setup(rt){const m=z(),I=j("updateCartCount",async()=>{}),i=v([]),f=v({}),_=v({}),A=()=>{m.back()},P=async()=>{try{const s=await b.getWishlist();i.value=s,await B(s)}catch(s){console.error("获取收藏列表失败:",s),p.error("获取收藏列表失败")}},B=async s=>{for(const t of s)if(t.product.imageFileIds){const d=t.product.imageFileIds.split(","),l=[];for(const e of d)if(e)try{if(!f.value[e]){const r=await H.getSignedUrl(Number(e));f.value[e]=r}f.value[e]&&l.push(f.value[e])}catch(r){console.error("获取签名链接失败:",r),l.push(C)}_.value[t.product.id]=l}else _.value[t.product.id]=[C]},h=s=>_.value[s.id]||[C],N=async s=>{try{await O.addToCart({productId:s,quantity:1}),await I(),p.success("已添加到购物车")}catch(t){console.error("添加到购物车失败:",t),p.error("添加到购物车失败")}},x=async s=>{try{await b.removeFromWishlist(s),i.value=i.value.filter(t=>t.productId!==s),p.success("已从收藏中移除")}catch(t){console.error("移除收藏失败:",t),p.error("移除收藏失败")}},E=()=>{m.push("/products")},k=s=>{m.push(`/product/${s}`)},M=()=>{const s=["#ffe4d6","#d6eaff","#e2ffd6","#fff2d6","#d6ffe4","#e4d6ff"];return s[Math.floor(Math.random()*s.length)]};return W(()=>{P()}),(s,t)=>{const d=U,l=$;return n(),c("div",q,[o("header",J,[o("div",{class:"back-btn",onClick:A},[a(d,null,{default:u(()=>[a(y(D))]),_:1})]),t[0]||(t[0]=o("h1",null,"我的收藏",-1)),t[1]||(t[1]=o("div",{class:"empty"},null,-1))]),o("div",K,[(n(!0),c(F,null,R(i.value,e=>(n(),c("div",{key:e.id,class:"wishlist-item"},[o("div",{class:"item-image",onClick:r=>k(e.product.id)},[h(e.product)&&h(e.product).length>0?(n(),c("img",{key:0,src:h(e.product)[0],alt:e.product.title},null,8,X)):(n(),c("div",{key:1,class:"image-placeholder",style:L({backgroundColor:M()})},[o("span",null,g(e.product.title?e.product.title[0]:"商"),1)],4))],8,Q),o("div",Y,[o("h3",{class:"item-name",onClick:r=>k(e.product.id)},g(e.product.title),9,tt),o("p",et,"¥"+g(e.product.price),1),o("div",st,[a(l,{size:"small",type:"primary",onClick:r=>N(e.product.id)},{default:u(()=>[...t[2]||(t[2]=[w(" 添加到购物车 ",-1)])]),_:1},8,["onClick"]),a(d,{class:"delete-icon",onClick:r=>x(e.product.id)},{default:u(()=>[a(y(S))]),_:1},8,["onClick"])])])]))),128))]),i.value.length===0?(n(),c("div",ot,[a(d,{size:60,style:{color:"#fadb14"}},{default:u(()=>[a(y(Z))]),_:1}),t[4]||(t[4]=o("p",null,"收藏列表为空",-1)),a(l,{type:"primary",onClick:E},{default:u(()=>[...t[3]||(t[3]=[w(" 浏览作品 ",-1)])]),_:1})])):T("",!0)])}}}),dt=G(at,[["__scopeId","data-v-0d6f3390"]]);export{dt as default};