1
0
Files
build.ems/build/usr/local/omc/htdocs/front/js/index.DEnkYk_r.js
2024-10-25 14:59:47 +08:00

2 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{g as C,_ as L,k as v,m as b,n,t as l,p as u,E as m,ak as N,l as t,au as _}from"./vendor/index.CRpmXtWV.js";import{d as U,c as B,a as D,b as O}from"./file.BexoPAcX.js";import{d as I}from"../index.D-NvtsOM.js";const q=C({__name:"index",setup(M){const{t:c}=I();let o=L({loading:!1,uploadFilePath:"",downloadFilePath:"",fileList:[]});function h(){const i="downloadFile";t.message.loading({content:c("common.loading"),key:i});const a=o.downloadFilePath;a&&U(a).then(e=>{if(e.code===200){t.message.success({content:"已完成下载",key:i,duration:2});const s=a.substring(a.lastIndexOf("/")+1);_(e.data,s)}else t.message.error({content:`${e.msg}`,key:i,duration:2})})}function w(){const i="downloadFileChunk";t.message.loading({content:c("common.loading"),key:i});const a=o.downloadFilePath;B(a,5).then(e=>{if(console.log(e),e.size===0)t.message.error({content:"文件读取失败",key:i,duration:2});else{t.message.success({content:"已完成下载",key:i,duration:2});const s=a.substring(a.lastIndexOf("/")+1);_(e,s)}})}function F(i){if(o.loading)return!1;const a=["image/jpeg","image/png"].includes(i.type);a||t.message.error("只支持上传图片格式jpg、png",3);const e=i.size/1024/1024<2;return e||t.message.error("图片文件大小必须小于 2MB",3),a&&e}function x(i){t.Modal.confirm({title:c("common.tipTitle"),content:"确认要上传文件吗?",onOk(){const a=t.message.loading(c("common.loading"),0);o.loading=!0;let e=new FormData;e.append("file",i.file),e.append("subPath","default"),D(e).then(s=>{o.loading=!1,a(),s.code===200?(t.message.success("文件上传成功",3),o.uploadFilePath=s.data.url,o.downloadFilePath=s.data.fileName):t.message.error(s.msg,3)})}})}function y(i){const a=i.file,e=o.fileList.find(s=>s.name===a.name);t.Modal.confirm({title:c("common.tipTitle"),content:"确认要上传文件吗?",onOk(){const s=t.message.loading(c("common.loading"),0);O(a,4,"default").then(d=>{s(),d.code===200?(t.message.success("文件上传成功",3),e&&(e.url=d.data.url,e.name=d.data.newFileName,e.percent=100,e.status="done")):(t.message.error(d.msg,3),o.fileList.splice(o.fileList.length-1,1))})},onCancel(){e&&o.fileList.splice(o.fileList.length-1,1)}})}return(i,a)=>{const e=t.Button,s=t.Input,d=t.Col,r=t.Upload,k=t.Image,P=t.Space,p=t.Row,g=t.Card;return v(),b(u(N),{title:"上传示例"},{default:n(()=>[l(p,{gutter:16},{default:n(()=>[l(d,{lg:12,md:12,xs:24},{default:n(()=>[l(g,{title:"普通文件",style:{"margin-bottom":"16px"}},{default:n(()=>[l(p,{gutter:8},{default:n(()=>[l(d,{span:24,style:{"margin-bottom":"16px"}},{default:n(()=>[l(s,{style:{"margin-bottom":"16px"},type:"text",placeholder:"输入资源文件地址",value:u(o).downloadFilePath,"onUpdate:value":a[0]||(a[0]=f=>u(o).downloadFilePath=f)},{suffix:n(()=>[l(e,{type:"primary",onClick:h},{default:n(()=>[m(" 普通下载 ")]),_:1})]),_:1},8,["value"]),l(s,{type:"text",placeholder:"输入资源文件地址",value:u(o).downloadFilePath,"onUpdate:value":a[1]||(a[1]=f=>u(o).downloadFilePath=f)},{suffix:n(()=>[l(e,{type:"primary",onClick:w},{default:n(()=>[m(" 分片下载 ")]),_:1})]),_:1},8,["value"])]),_:1}),l(d,{span:24},{default:n(()=>[l(P,{direction:"vertical",size:16},{default:n(()=>[l(r,{name:"file","list-type":"picture","max-count":1,"show-upload-list":!1,"before-upload":F,"custom-request":x},{default:n(()=>[l(e,{type:"default",loading:u(o).loading},{default:n(()=>[m(" 选择文件 ")]),_:1},8,["loading"])]),_:1}),l(k,{width:128,height:128,src:u(o).uploadFilePath},null,8,["src"])]),_:1})]),_:1})]),_:1})]),_:1})]),_:1}),l(d,{lg:12,md:12,xs:24},{default:n(()=>[l(g,{title:"大文件分片上传",style:{"margin-bottom":"16px"}},{default:n(()=>[l(r,{"file-list":u(o).fileList,"onUpdate:fileList":a[2]||(a[2]=f=>u(o).fileList=f),name:"file","list-type":"picture","custom-request":y},{default:n(()=>[l(e,null,{default:n(()=>[m(" 选择文件 ")]),_:1})]),_:1},8,["file-list"])]),_:1})]),_:1})]),_:1})]),_:1})}}});export{q as default};