Files
CoreInject/frontend/dist/assets/D0Zic1w3.js
2025-11-14 04:00:32 +08:00

21 lines
3.2 KiB
JavaScript

import{d as t,r as e,w as a,o as n,k as i,F as o,z as s,b as c,m as r,t as l,g as u,x as m,e as h}from"./CD7TqNEc.js"
import{_ as f,A as g,a as v}from"./DTEPVF5R.js"
function d(t){const e=new Date(t),a=(new Date).getTime()-e.getTime(),n=Math.floor(a/6e4),i=Math.floor(a/36e5),o=Math.floor(a/864e5)
return n<1?"刚刚":n<60?`${n}分钟前`:i<24?`${i}小时前`:o<7?`${o}天前`:e.toLocaleDateString("zh-CN")}function p(t){return"object"==typeof t.author&&null!==t.author?t.author.id||"":"string"==typeof t.author?t.author:""}function y(t){if("object"==typeof t.author&&null!==t.author){const e=t.author
return e.nickName||e.username||""}return"string"==typeof t.author?t.author:""}function k(t){if("object"==typeof t.author&&null!==t.author)return t.author.username}function b(t){return t.filter(t=>"image"===t.type)}function w(t){return t.filter(t=>"image"!==t.type)}function C(t){var e,a
return"string"==typeof t?t:t&&"object"==typeof t?(null==(e=t._id)?void 0:e.toString())||(null==(a=t.id)?void 0:a.toString())||t.toString():String(t)}function I(t){return b(t).map(t=>C(t))}const j={class:"edit-attachments-list"},_=["onClick"],A=["src","alt"],M={key:1,class:"image-loading"},S=["onClick"],z={class:"attachment-name"},E=["onClick"],P=v(t({__name:"EditAttachmentPreview",props:{attachments:{}},emits:["remove","imageClick"],setup(t,{emit:v}){const d=t,p=v,y=e({}),k=async()=>{const t=d.attachments.filter(t=>"image"===t.type)
await Promise.all(t.map(t=>(async t=>{if(!y.value[t])try{const e=await g.getAttachmentImage(t)
e&&(y.value[t]=e)}catch(e){}})(t.id)))}
a(()=>d.attachments,()=>{y.value={},k()},{immediate:!0}),n(()=>{k()})
const b=t=>{t.target.style.display="none"}
return(e,a)=>(h(),i("div",j,[(h(!0),i(o,null,s(t.attachments,t=>(h(),i("div",{key:t.id,class:c(["edit-attachment-item",{"image-preview":"image"===t.type}])},["image"===t.type?(h(),i("div",{key:0,class:"edit-attachment-preview",onClick:()=>p("imageClick",t.id)},[y.value[t.id]?(h(),i("img",{key:0,src:y.value[t.id]||"",alt:t.name,onError:b,class:"clickable-image"},null,40,A)):(h(),i("div",M,[...a[0]||(a[0]=[r("div",{class:"spinner"},null,-1)])])),r("button",{class:"remove-attachment-btn",onClick:l(e=>p("remove",t.id),["stop"])},[u(f,{icon:"mdi:close"})],8,S)],8,_)):(h(),i(o,{key:1},[u(f,{icon:"mdi:file",class:"attachment-icon"}),r("span",z,m(t.name),1),r("button",{class:"remove-attachment-btn",onClick:a=>e.$emit("remove",t.id)},[u(f,{icon:"mdi:close"})],8,E)],64))],2))),128))]))}}),[["__scopeId","data-v-b3def6f7"]])
function $(){const t=e(!1),a=e([]),n=e(0),i=e(new Map)
return{previewVisible:t,previewImagesInfo:a,previewIndex:n,imageCache:i,preloadPostImages:async t=>{const e=b(t)
for(const n of e){const t=C(n)
if(!i.value.has(t))try{const e=await g.getAttachmentImage(t)
e&&i.value.set(t,e)}catch(a){}}},handleImageClick:async(e,o)=>{const s=b(e),c=[]
for(const t of s){const e=C(t)
let a=i.value.get(e)
if(!a)try{const t=await g.getAttachmentImage(e)
t&&(a=t,i.value.set(e,t))}catch(r){continue}a&&c.push({url:a,size:t.size})}c.length>0&&(a.value=c,n.value=Math.min(o,c.length-1),t.value=!0)},closePreview:()=>{t.value=!1,a.value=[],n.value=0},clearImageCache:()=>{i.value.forEach(t=>{t.startsWith("blob:")&&URL.revokeObjectURL(t)}),i.value.clear()}}}export{P as E,w as a,I as b,y as c,p as d,k as e,d as f,b as g,$ as u}