2 lines
7.0 KiB
JavaScript
2 lines
7.0 KiB
JavaScript
import{d as W,u as X,G as Z,r as w,d1 as ee,a1 as A,o as le,aj as te,y as c,z as v,C as k,A as s,D as b,H as t,ai as B,B as p,S as O,a7 as L,bY as ae,a2 as $,a3 as se,E as U,Q as oe}from"./B565zvD7.js";import{_ as ie}from"./CscEAC8U.js";import{C as V,a as I}from"./CFgyaiyP.js";import{m as a,d as g,o as i,l as ne,c as re}from"./BdYSuaW6.js";import{u as m}from"./50ego_Xv.js";import{i as x}from"./DGz2YCiv.js";import{B as ue}from"./B8tjfeLk.js";import{S as de}from"./DouGH0TO.js";import{a as ce,_ as ve}from"./DGoOYFa5.js";const pe={class:"w-full h-screen bg-black text-white"},me={class:"flex w-full p-4 gap-8 justify-between items-center"},ge={class:"flex gap-8 items-center"},fe=["alt"],he={class:"font-semibold text-lg"},_e={class:"aspect-square flex items-center justify-center"},ke={key:0,class:"relative w-full"},xe=["alt"],ye={class:"flex absolute shadow-black shadow-sm rounded-full bottom-2 mx-3"},be={key:1,class:"empty-state"},we={class:"media-picker"},Ce={class:"media-grid"},Pe={class:"media-preview"},Se={class:"text-sm"},Fe=["onClick"],Le=["src"],Ue=["src"],Ie=["onClick"],Re={class:"text-sm"},Ee={class:"absolute bottom-5 right-5 addStyle"},C=10,ze=W({__name:"index",setup(je){const f=X(),r=Z(),y=w(""),P=w(null),_=w(null),o=w(-2),R=ee();function T(){a.value=[],i.value={},f.push({name:"home"})}A(a,l=>{var e,n,u;((e=a.value)==null?void 0:e.length)===0?g.value="":((n=a.value)==null?void 0:n.length)===1?g.value=a.value[0].url:l&&(g.value=(u=l[(l==null?void 0:l.length)-1])==null?void 0:u.url)},{deep:!0}),A(i,l=>{g.value=l.url,o.value=-1},{deep:!0});function z(){i.value.url?R.name=="edit-product-id-inputProduct"?f.push({name:"edit-product-id-infProduct"}):f.push({name:"add-product-infProduct"}):(console.log(m().originalFile),oe.warn(r.useString("addAtLeastOneMedia")))}function E(l){o.value=l,l===-1?g.value=i.value.url:g.value=a.value[l].url}const q=l=>l.includes(".mp4")||l.includes(".mov")||l.includes("video"),G=async()=>{o.value==-1?await M():await j()},j=async()=>{console.log(o.value,"Media");try{if(V.isNativePlatform())if(o.value==-2)(await I.pickImages({limit:C-a.value.length})).photos.forEach(e=>{m().mediaFiles.push({file:e,index:a.value.length}),a.value.push({url:e.webPath,index:a.value.length})}),o.value=a.value.length-1;else{const l=await I.pickImages({limit:1});l.photos.length>0&&(a.value[o.value].url=l.photos[0].webPath,m().mediaFiles[o.value].file=l.photos[0])}else console.log(o.value,"MediaA"),o.value==-2?P.value.click():_.value.click()}catch(l){console.error("Error selecting media:",l)}},M=async()=>{try{if(V.isNativePlatform()){const l=await I.pickImages({limit:1});l.photos.length>0&&(i.value.url=l.photos[0].webPath,m().originalFile={file:l.photos[0],index:0})}else console.log(o.value,"main"),await _.value.click(),console.log(o.value,"mainA"),_.value.onchange=l=>{const e=l.target.files;console.log(e,8888),e.length>0&&(i.value.url=URL.createObjectURL(e[0]),console.log(e,9999)),setTimeout(()=>{_.value.value=null},10)};console.log("dsacbnkjsdkmc,loskock,sdds",i.value)}catch(l){console.error("Error selecting main media:",l)}},D=l=>{console.log(o.value,4555);const e=l.target.files;e.length!=0&&(console.log(l,45),!i.value.url&&e.length>0||o.value==-1&&e.length>0?(i.value.url=URL.createObjectURL(e[0]),m().originalFile={file:e[0],index:0},console.log(i.value)):o.value==-2?Array.from(e).forEach(n=>{let u=a.value.length;a.value.length<C&&(a.value.push({url:URL.createObjectURL(n),index:u+1}),m().mediaFiles.push({file:n,index:u+1}),o.value=a.value.length-1)}):(a.value[o.value].url=URL.createObjectURL(e[0]),m().mediaFiles.push({file:e[0],index:a.value[o.value].index}),o.value=a.value.length-1),P.value.value="",_.value.value="")},H=l=>{l.preventDefault();const e=l.dataTransfer.files;Array.from(e).forEach(n=>{a.value.length<C&&(m().mediaFiles.push({file:n,index:a.value.length}),a.value.push({url:URL.createObjectURL(n),index:a.value.length}))})},Q=(l,e)=>{const n=m().mediaFiles.findIndex(u=>u.index==e);a.value.splice(l,1),n>=0&&m().mediaFiles.splice(n,1)},Y=()=>{i.value.url=void 0,re.value=void 0};return le(()=>{switch(f.currentRoute.value.name){case"add-product-inputProduct":y.value="product";break;case"add-story-inputStory":y.value="story";break;case"add-product-excel-inputProductExcel":y.value="productExcel";break}}),(l,e)=>{const n=de,u=ce,J=ve,S=te("lazy");return v(),c($,null,[k(n,{spinning:t(ne)},{default:b(()=>{var h,N;return[s("div",pe,[s("div",me,[s("div",ge,[s("img",{src:ie,alt:t(B),class:"w-4",onClick:T},null,8,fe),s("div",he,p(t(R).name=="inputProduct_edit"?t(r).useString("editProduct"):t(r).useString("newProduct")),1)]),s("div",{class:"text-primary text-sm",onClick:z},p(t(r).useString("next")),1)]),s("div",_e,[t(g)?(v(),c("div",ke,[L(s("img",{alt:t(B),class:"w-full object-scale-down aspect-square"},null,8,xe),[[S,{src:t(g),loading:t(x),error:t(x)}]]),s("div",ye,[s("div",{onClick:G,class:"flex bg-primary rounded-full py-1 gap-2 px-2"},[k(ue,{icon:"vuesax-linear:gallery-edit"}),s("span",null,p(t(r).useString("edit")),1)])])])):((h=t(a))==null?void 0:h.length)===0?(v(),c("p",be,p(t(r).useString("tapPlusToAdd")),1)):O("",!0)]),s("div",we,[s("div",{class:"drop-area",onDragover:e[2]||(e[2]=ae(()=>{},["prevent"])),onDrop:H},[s("div",Ce,[t(i).url?(v(),c("div",{key:0,class:"media-container border-1 border-solid border-primary",onClick:e[0]||(e[0]=d=>E(-1))},[L(s("img",Pe,null,512),[[S,{src:t(i).url,loading:t(x),error:t(x)}]]),s("button",{onClick:Y,class:"remove-btn"},"✖")])):(v(),c("div",{key:1,class:"add-media text-black",onClick:M},[s("div",null,p(t(i).url),1),e[9]||(e[9]=s("span",null,"+",-1)),s("div",Se,p(t(r).useString("mainImage")),1)])),(v(!0),c($,null,se(t(a),(d,F)=>(v(),c("div",{key:F,class:"media-container",onClick:K=>E(F)},[q(d.url)?(v(),c("video",{key:0,src:d.url,class:"media-preview",controls:""},null,8,Le)):L((v(),c("img",{key:1,src:d.url,class:"media-preview"},null,8,Ue)),[[S,{src:d.url,loading:t(x),error:t(x)}]]),s("button",{onClick:K=>Q(F,d.index),class:"remove-btn"},"✖",8,Ie)],8,Fe))),128)),((N=t(a))==null?void 0:N.length)<C?(v(),c("div",{key:2,class:"add-media text-black",onClick:e[1]||(e[1]=()=>{o.value=-2,j()})},[e[10]||(e[10]=s("span",null,"+",-1)),s("div",Re,p(t(r).useString("subImage")),1)])):O("",!0)])],32),s("input",{ref_key:"fileInput",ref:P,type:"file",accept:"image/*,video/*",multiple:"",hidden:"",onChange:e[3]||(e[3]=d=>D(d))},null,544),s("input",{ref_key:"fileInputLimited",ref:_,type:"file",accept:"image/*,video/*",hidden:"",onChange:e[4]||(e[4]=d=>D(d))},null,544)])])]}),_:1},8,["spinning"]),s("div",Ee,[k(J,{value:y.value,"onUpdate:value":e[8]||(e[8]=h=>y.value=h),"button-style":"solid"},{default:b(()=>[k(u,{onClick:e[5]||(e[5]=h=>t(f).push({name:"add-product-excel-inputProductExcel"})),value:"productExcel"},{default:b(()=>[U(p(t(r).useString("productExcel")),1)]),_:1}),k(u,{onClick:e[6]||(e[6]=h=>t(f).push({name:"add-product-inputProduct"})),value:"product"},{default:b(()=>[U(p(t(r).useString("product2")),1)]),_:1}),k(u,{onClick:e[7]||(e[7]=h=>t(f).push({name:"add-story-inputStory"})),value:"story"},{default:b(()=>[U(p(t(r).useString("story2")),1)]),_:1})]),_:1},8,["value"])])],64)}}});export{ze as _};
|