Files
qhmes/web-dist/js/JImageUpload-BxXxXpHa.js
2026-06-16 18:19:57 +08:00

2 lines
3.6 KiB
Java

import{useRuleFormItem as z}from"./useFormItem-b_EqFlJz.js";import{as as v,aN as j,bT as H,c0 as R,aO as D,s as W,v as x,di as G,au as J,bV as K,M as Q}from"./index-X7Y8jykP.js";import{U as X}from"./UploadOutlined-D3m-zwOG.js";import{e as Y,h as Z,c as k,r as o,n as ee,C as y,z as r,f as b,A as w,K as U,H as C,y as T,Q as I,G as L,E as te}from"./vue-vendor-DNhG1Cve.js";import"./emoji-mart-vue-fast-R0uJEDq-.js";const{createMessage:_,createErrorModal:me}=W(),ae=Y({name:"JImageUpload",components:{LoadingOutlined:H,UploadOutlined:X},inheritAttrs:!1,props:{value:v.oneOfType([v.string,v.array]),listType:{type:String,required:!1,default:"picture-card"},text:{type:String,required:!1,default:"上传"},bizPath:{type:String,required:!1,default:"temp"},disabled:{type:Boolean,required:!1,default:!1},fileMax:{type:Number,required:!1,default:1},uploadUrl:{type:String,default:j},previewWidth:{type:Number,required:!1,default:520}},emits:["options-change","change","update:value"],setup(e,{emit:i,refs:V}){const O=o([]),M=D(),[c]=z(e,"value","change",O),m=t=>{if(t.lastIndexOf("\\")>=0){let a=new RegExp("\\\\","g");t=t.replace(a,"/")}return t.substring(t.lastIndexOf("/")+1)},p=R(),g=o(!1),d=o(!0);let s=o([]);const u=o(""),h=o(!1),F=k(()=>e.fileMax>1||e.fileMax===0),N=k(()=>e.fileMax===0?!0:s.value.length<e.fileMax);Z(()=>e.value,(t,a)=>{t&&t instanceof Array&&(t=t.join(",")),d.value==!0&&q(t)},{immediate:!0});function q(t){if(!t||t.length==0){s.value=[];return}let a=[];t.split(",").forEach(n=>{let f=x(n);a.push({uid:G(10),name:m(n),status:"done",url:f,response:{status:"history",message:n}})}),s.value=a}function E(t){if(t.type.indexOf("image")<0)return _.info("请上传图片"),!1}function P({file:t,fileList:a,event:A}){if(d.value=!1,t.status==="error"&&_.error(`${t.name} 上传失败.`),t.status==="done"&&t.response.success===!1){const l=s.value.findIndex(B=>B.uid===t.uid);l!=-1&&s.value.splice(l,1),_.warning(t.response.message);return}let n=[],f=0;t.status!="uploading"&&(a.forEach(l=>{l.status==="done"&&n.push(l.response.message),l.status!="uploading"&&f++}),t.status,f==a.length&&(c.value=n.join(","),i("update:value",n.join(",")),ee(()=>{d.value=!0})))}function S(t){u.value=t.url||t.thumbUrl,h.value=!0}function $(){h.value=!1}return{state:c,attrs:M,previewImage:u,previewVisible:h,uploadFileList:s,multiple:F,headers:p,loading:g,beforeUpload:E,uploadVisible:N,handlePreview:S,handleCancel:$,handleChange:P}}}),se={class:"clearfix"},ne={key:0},ie={key:0},le={class:"ant-upload-text"},oe=["src"];function re(e,i,V,O,M,c){const m=U("LoadingOutlined"),p=U("UploadOutlined"),g=U("a-button"),d=K,s=Q;return r(),y("div",se,[b(d,{listType:e.listType,accept:"image/*",multiple:e.multiple,action:e.uploadUrl,headers:e.headers,data:{biz:e.bizPath},fileList:e.uploadFileList,"onUpdate:fileList":i[0]||(i[0]=u=>e.uploadFileList=u),beforeUpload:e.beforeUpload,disabled:e.disabled,onChange:e.handleChange,onPreview:e.handlePreview},{default:w(()=>[e.uploadVisible?(r(),y("div",ne,[e.listType=="picture-card"?(r(),y("div",ie,[e.loading?(r(),T(m,{key:0})):(r(),T(p,{key:1})),I("div",le,L(e.text),1)])):C("",!0),e.listType=="picture"?(r(),T(g,{key:1,disabled:e.disabled},{default:w(()=>[b(p),te(" "+L(e.text),1)]),_:1},8,["disabled"])):C("",!0)])):C("",!0)]),_:1},8,["listType","multiple","action","headers","data","fileList","beforeUpload","disabled","onChange","onPreview"]),b(s,{width:e.previewWidth,open:e.previewVisible,footer:null,onCancel:i[1]||(i[1]=u=>e.handleCancel())},{default:w(()=>[I("img",{alt:"example",style:{width:"100%"},src:e.previewImage},null,8,oe)]),_:1},8,["width","open"])])}const ge=J(ae,[["render",re],["__scopeId","data-v-1aed4071"]]);export{ge as default};