2 lines
8.1 KiB
JavaScript
2 lines
8.1 KiB
JavaScript
import{_ as ie,C as V,a as M}from"./C4aRbWEC.js";import{d as ae,u as oe,G as se,r as x,d0 as ne,$ as z,dG as re,o as ue,ai as de,y as d,z as c,A as a,C as h,D as y,J as t,B as g,a5 as D,S as w,bS as ce,a0 as T,a1 as ve,E as N,P as pe}from"./D9_UoUeZ.js";import{_ as me}from"./CscEAC8U.js";import{m as i,e as u,o as v,f as $,r as j,l as ge,D as fe,u as s,i as he,g as q,E as _e}from"./Dxbb2UFv.js";import{i as k}from"./Ddpu7iux.js";import{B as G}from"./iCGCN3gx.js";import"./D72ALlip.js";import{S as xe}from"./CX_9C0QJ.js";import{a as ke,_ as be}from"./C6CENYhF.js";const ye={class:"h-screen bg-black"},we={class:"w-full h-full bg-black text-white"},Ce={class:"sticky bg-black top-0 z-1"},Fe={class:"flex w-full p-4 gap-8 justify-between items-center"},Pe={class:"flex gap-8 items-center"},Se=["alt"],Re={class:"font-semibold text-lg"},Ie={class:"aspect-square flex items-center justify-center"},Ue={key:0,class:"relative w-full"},Ee=["alt"],Le={key:0,class:"flex absolute gap-2 right-5 bottom-5"},Me={key:1,class:"flex absolute left-5 bottom-0"},De={key:1,class:"empty-state"},Ne={class:"media-picker"},$e={class:"media-grid pb-16"},je={class:"media-preview"},Be={class:"text-sm"},Oe=["onClick"],Ae=["src"],Ve=["src"],ze=["onClick"],Te={class:"text-sm"},qe={key:0,class:"fixed bottom-5 right-5 addStyle"},C=10,ll=ae({__name:"index",setup(Ge){const f=oe(),p=se(),b=x(""),F=x(null),_=x(null),o=x(-2),P=ne(),S=x(!1),J=x();function H(){f.push({name:"home"}),j(),s().mediaFiles=[],he.value=[]}function K(){J.value=u.value,q.value=i.value.findIndex(l=>l===u.value),v.value.url===u.value&&(q.value=-2),S.value=!0}z(i,l=>{i.value?.length===0?u.value="":i.value?.length===1?u.value=i.value[0]?.url:l&&(console.log(o.value,l),o.value==-2?u.value=l[l?.length-1]?.url:u.value=l[o.value]?.url)},{deep:!0}),z(v,l=>{u.value=l.url,o.value=-1},{deep:!0});function Q(){v.value.url?P.name=="edit-product-id-inputProduct"?f.push({name:"edit-product-id-infProduct"}):f.push({name:"add-product-infProduct"}):(console.log(s().originalFile,s().mediaFiles),pe.warn(p.useString("addOriginalMedia"))),console.log(s().originalFile,s().mediaFiles)}function R(l){o.value=l,l===-1?u.value=v.value.url:u.value=i.value[l].url}const W=l=>l.includes(".mp4")||l.includes(".mov")||l.includes("video"),X=async()=>{o.value==-1?await O():await B()},B=async()=>{console.log(o.value,"Media");try{if(V.isNativePlatform())if(o.value==-2)(await M.pickImages({limit:C-i.value.length})).photos.forEach(e=>{s().mediaFiles.push({file:e,index:i.value.length}),i.value.push({url:e.webPath,index:i.value.length})}),o.value=i.value.length-1;else{const l=await M.pickImages({limit:1});l.photos.length>0&&(i.value[o.value].url=l.photos[0].webPath,s().mediaFiles[o.value].file=l.photos[0])}else console.log(o.value,"MediaA"),o.value==-2?F.value.click():_.value.click()}catch(l){console.error("Error selecting media:",l)}},O=async()=>{try{if(V.isNativePlatform()){const l=await M.pickImages({limit:1});l.photos.length>0&&(v.value.url=l.photos[0].webPath,s().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&&(v.value.url=URL.createObjectURL(e[0]),console.log(e,9999)),setTimeout(()=>{_.value.value=null},10)}}catch(l){console.error("Error selecting main media:",l)}},A=l=>{console.log(o.value,4555);const e=l.target.files;e.length!=0&&(console.log(l,45),!v.value.url&&e.length>0||o.value==-1&&e.length>0?(v.value.url=URL.createObjectURL(e[0]),s().originalFile={file:e[0],index:0},console.log(v.value)):o.value==-2?Array.from(e).forEach(r=>{let m=i.value.at(-1)?.index??0;i.value.length<C&&(i.value.push({url:URL.createObjectURL(r),index:m+1}),s().mediaFiles.push({file:r,index:m+1}),s().mediaFiles.sort((I,U)=>I.index-U.index),o.value=i.value.length-1)}):(i.value[o.value].url=URL.createObjectURL(e[0]),s().mediaFiles.length>0?s().mediaFiles.some((r,m)=>{if(r.index==i.value[o.value].index)return r.file=e[0],!0})||(s().mediaFiles.push({file:e[0],index:i.value[o.value].index}),console.log(s().mediaFiles)):s().mediaFiles.push({file:e[0],index:i.value[o.value].index}),s().mediaFiles.sort((r,m)=>r.index-m.index)),F.value.value="",_.value.value="",console.log(s().mediaFiles))},Y=l=>{l.preventDefault();const e=l.dataTransfer.files;Array.from(e).forEach(r=>{i.value.length<C&&(s().mediaFiles.push({file:r,index:i.value.length}),i.value.push({url:URL.createObjectURL(r),index:i.value.length}))})},Z=(l,e)=>{const r=s().mediaFiles.findIndex(m=>m.index==e);i.value.splice(l,1),r>=0&&s().mediaFiles.splice(r,1),console.log(s().mediaFiles,i.value)},ee=()=>{v.value.url=void 0,_e.value=void 0},le=re();return ue(()=>{switch(!$(f.currentRoute.value.name)&&le.previousRoute.name!="add-product-infProduct"&&j(),f.currentRoute.value.name){case"add-product-inputProduct":b.value="product";break;case"add-story-inputStory":b.value="story";break;case"add-product-excel-inputProductExcel":b.value="productExcel";break}R(-1)}),(l,e)=>{const r=xe,m=ke,I=be,U=ie,E=de("lazy");return d(),c(T,null,[a("div",ye,[h(r,{spinning:t(ge)},{default:y(()=>[a("div",we,[a("div",Ce,[a("div",Fe,[a("div",Pe,[a("img",{src:me,alt:t(p).appName.en,class:"w-4",onClick:H},null,8,Se),a("div",Re,g(t($)(t(P).name)?t(p).useString("editProduct"):t(p).useString("newProduct")),1)]),a("div",{class:"text-primary text-sm",onClick:Q},g(t(p).useString("next")),1)]),a("div",Ie,[t(u)?(d(),c("div",Ue,[D(a("img",{alt:t(p).appName.en,class:"w-full object-scale-down aspect-square"},null,8,Ee),[[E,{src:t(u),loading:t(k),error:t(k)}]]),t(u)?(d(),c("div",Le,[a("div",{onClick:K,class:"flex bg-black/80 items-center rounded gap-2 p-2"},[h(G,{icon:"vuesax-linear:crop"})]),a("div",{onClick:X,class:"flex bg-black/80 items-center rounded gap-2 p-2"},[h(G,{icon:"vuesax-linear:gallery-edit"})])])):w("",!0),t(u)?(d(),c("div",Me)):w("",!0)])):t(i)?.length===0?(d(),c("p",De,g(t(p).useString("tapPlusToAdd")),1)):w("",!0)])]),a("div",Ne,[a("div",{class:"drop-area overflow-y-auto",onDragover:e[2]||(e[2]=ce(()=>{},["prevent"])),onDrop:Y},[a("div",$e,[t(v).url?(d(),c("div",{key:0,class:"media-container border-1 border-solid border-primary",onClick:e[0]||(e[0]=n=>R(-1))},[D(a("img",je,null,512),[[E,{src:t(v).url,loading:t(k),error:t(k)}]]),a("button",{onClick:ee,class:"remove-btn"},"✖")])):(d(),c("div",{key:1,class:"add-media text-black",onClick:O},[a("div",null,g(t(v).url),1),e[11]||(e[11]=a("span",null,"+",-1)),a("div",Be,g(t(p).useString("mainImage")),1)])),(d(!0),c(T,null,ve(t(i),(n,L)=>(d(),c("div",{key:L,class:"media-container",onClick:te=>R(L)},[W(n.url)?(d(),c("video",{key:0,src:n.url,class:"media-preview",controls:""},null,8,Ae)):D((d(),c("img",{key:1,src:n.url,class:"media-preview"},null,8,Ve)),[[E,{src:n.url,loading:t(k),error:t(k)}]]),a("button",{onClick:te=>Z(L,n.index),class:"remove-btn"},"✖",8,ze)],8,Oe))),128)),t(i)?.length<C?(d(),c("div",{key:2,class:"add-media text-black",onClick:e[1]||(e[1]=()=>{o.value=-2,B()})},[e[12]||(e[12]=a("span",null,"+",-1)),a("div",Te,g(t(p).useString("subImage")),1)])):w("",!0)])],32),a("input",{ref_key:"fileInput",ref:F,type:"file",accept:"image/*,video/*",multiple:"",hidden:"",onChange:e[3]||(e[3]=n=>A(n))},null,544),a("input",{ref_key:"fileInputLimited",ref:_,type:"file",accept:"image/*,video/*",hidden:"",onChange:e[4]||(e[4]=n=>A(n))},null,544)])])]),_:1},8,["spinning"]),t($)(t(P).name)?w("",!0):(d(),c("div",qe,[h(I,{value:b.value,"onUpdate:value":e[8]||(e[8]=n=>b.value=n),onChange:e[9]||(e[9]=n=>t(j)()),"button-style":"solid"},{default:y(()=>[h(m,{onClick:e[5]||(e[5]=n=>t(f).push({name:"add-product-excel-inputProductExcel"})),value:"productExcel"},{default:y(()=>[N(g(t(p).useString("productExcel")),1)]),_:1}),h(m,{onClick:e[6]||(e[6]=n=>t(f).push({name:"add-product-inputProduct"})),value:"product"},{default:y(()=>[N(g(t(p).useString("product2")),1)]),_:1}),h(m,{onClick:e[7]||(e[7]=n=>t(f).push({name:"add-story-inputStory"})),value:"story"},{default:y(()=>[N(g(t(p).useString("story2")),1)]),_:1})]),_:1},8,["value"])]))]),h(U,{visible:S.value,"onUpdate:visible":e[10]||(e[10]=n=>S.value=n),img:t(u),mode:"free",aspectRatio:4/4,resizable:!0,onCropped:t(fe)},null,8,["visible","img","onCropped"])],64)}}});export{ll as _};
|