2 lines
6.6 KiB
JavaScript
2 lines
6.6 KiB
JavaScript
import{g as R,_,l as i,w as q,W as G,j as A,k as y,m as V,n as f,t as r,p as n,D as j,a6 as v,E as F,F as S,H as J,I as W,an as z,aU as H}from"./vendor/index.CRpmXtWV.js";import{d as X,N as I,R as g,a7 as Y}from"../index.D-NvtsOM.js";import{u as $,a as K,g as Q}from"./neSoftware.CvdsdLsa.js";import{b as T}from"./file.BexoPAcX.js";const ne=R({__name:"EditModal",props:{visible:{type:Boolean,default:!1},editId:{type:String,default:""}},emits:["ok","cancel","update:visible"],setup(N,{emit:x}){const{t}=X(),w=x,b=N;let e=_({visibleByEdit:!1,title:"软件包文件",from:{id:"",neType:"",name:"",path:"",version:"",description:""},confirmLoading:!1,uploadFiles:[],uploadFilesDep:[]});const u=i.Form.useForm(e.from,_({neType:[{required:!0,min:1,max:32,message:t("views.ne.common.neTypePlease")}],version:[{required:!0,min:1,max:64,message:t("views.ne.neSoftware.versionPlease")}],path:[{required:!0,message:t("views.ne.neSoftware.pathPlease")}]}));function L(){e.confirmLoading||u.validate().then(l=>{e.confirmLoading=!0;const o=i.message.loading(t("common.loading"),0),a=z(e.from);if(e.uploadFilesDep.length>0){const s=[];for(const d of e.uploadFilesDep)d.status==="done"&&d.path&&s.push(d.path);s.push(a.path),a.path=s.join(",")}(a.id?$(a):K(a)).then(s=>{s.code===g?(i.message.success({content:t("common.operateOk"),duration:3}),w("ok",JSON.parse(JSON.stringify(a))),h()):i.message.error({content:`${s.msg}`,duration:3}),o(),e.confirmLoading=!1})}).catch(l=>{i.message.error(t("common.errorFields",{num:l.errorFields.length}),3)})}function h(){e.visibleByEdit=!1,e.confirmLoading=!1,u.resetFields(),e.uploadFiles=[],e.uploadFilesDep=[],w("cancel"),w("update:visible",!1)}function E(l){if(e.confirmLoading)return!1;const o=l.name,a=o.substring(o.lastIndexOf("."));if(![".deb",".rpm"].includes(a))return i.message.error(t("views.configManage.softwareManage.onlyAble",{fileText:"(.deb、.rpm)"}),3),i.Upload.LIST_IGNORE;let m="";const s=o.indexOf("-");if(s!==-1&&(m=o.substring(0,s).toUpperCase()),!I.includes(m))return i.notification.warning({message:o,description:t("views.ne.neSoftware.fileCheckType")}),i.Upload.LIST_IGNORE;e.from.neType=m;const d=o.match(/([0-9.]+[0-9x]+)/);return d&&(e.from.version=d[0]),!0}function U(l){const o=e.uploadFiles.find(a=>a.uid===l.file.uid);o&&T(l.file,5,"software").then(a=>{if(a.code===g){o.percent=100,o.status="done",o.path=a.data.fileName;const{fileName:m,originalFileName:s}=a.data;e.from.name=s,e.from.path=m}else i.message.error(a.msg,3)}).catch(a=>{o.percent=0,o.status="error",o.response=a.message}).finally(()=>{e.confirmLoading=!1})}function O(l){if(e.confirmLoading)return!1;const o=l.name,a=o.substring(o.lastIndexOf("."));if(![".deb",".rpm"].includes(a))return i.message.error(t("views.configManage.softwareManage.onlyAble",{fileText:"(.deb、.rpm)"}),3),i.Upload.LIST_IGNORE;if(e.uploadFilesDep.find(c=>c.name===o))return i.notification.warning({message:o,description:t("views.ne.neSoftware.fileNameExists")}),i.Upload.LIST_IGNORE;let s="";const d=o.indexOf("-");return d!==-1&&(s=o.substring(0,d).toUpperCase()),Y.includes(s)?!0:(i.notification.warning({message:o,description:t("views.ne.neSoftware.fileCheckTypeDep")}),i.Upload.LIST_IGNORE)}function D(l){const o=e.uploadFilesDep.find(a=>a.uid===l.file.uid);o&&T(l.file,5,"software").then(a=>{a.code===g?(o.percent=100,o.status="done",o.path=a.data.fileName):i.message.error(a.msg,3)}).catch(a=>{o.percent=0,o.status="error",o.response=a.message}).finally(()=>{e.confirmLoading=!1})}function C(l){if(l){const o=i.message.loading(t("common.loading"),0);Q(l).then(a=>{a.code===g?(Object.assign(e.from,a.data),e.title=t("views.ne.neSoftware.uploadTitle"),e.visibleByEdit=!0):i.message.error(a.msg,3)}).finally(()=>{e.confirmLoading=!1,o()});return}e.title=t("views.ne.neSoftware.uploadTitle"),e.visibleByEdit=!0}return q(()=>b.visible,l=>{l&&C(b.editId)}),G(()=>{}),(l,o)=>{const a=H,m=i.Button,s=i.Upload,d=i.FormItem,c=i.Input,k=i.AutoComplete,B=i.Textarea,P=i.Form,M=A("ProModal");return y(),V(M,{drag:!0,width:650,destroyOnClose:!0,keyboard:!1,"mask-closable":!1,visible:n(e).visibleByEdit,title:n(e).title,"confirm-loading":n(e).confirmLoading,onOk:L,onCancel:h},{default:f(()=>[r(P,{name:"modalStateFrom",layout:"horizontal","wrapper-col":{span:16},"label-col":{span:8},labelWrap:!0},{default:f(()=>[n(e).from.id===""?(y(),j(J,{key:0},[r(d,v({label:n(t)("views.ne.neSoftware.path"),help:n(t)("views.ne.neSoftware.uploadFileName"),name:"file"},n(u).validateInfos.path),{default:f(()=>[r(s,{name:"file","file-list":n(e).uploadFiles,"onUpdate:fileList":o[0]||(o[0]=p=>n(e).uploadFiles=p),accept:".rpm,.deb","list-type":"text","max-count":1,"show-upload-list":{showPreviewIcon:!1,showRemoveIcon:!1,showDownloadIcon:!1},"before-upload":E,"custom-request":U,disabled:n(e).confirmLoading},{default:f(()=>[r(m,{type:"primary"},{icon:f(()=>[r(a)]),default:f(()=>[F(" "+S(n(t)("views.ne.neSoftware.upload")),1)]),_:1})]),_:1},8,["file-list","disabled"])]),_:1},16,["label","help"]),r(d,{name:"dep",label:n(t)("views.ne.neSoftware.dependFile"),help:n(t)("views.ne.neSoftware.dependFileTip")},{default:f(()=>[r(s,{name:"file","file-list":n(e).uploadFilesDep,"onUpdate:fileList":o[1]||(o[1]=p=>n(e).uploadFilesDep=p),accept:".rpm,.deb","list-type":"text",multiple:!0,"max-count":5,"show-upload-list":{showPreviewIcon:!1,showRemoveIcon:!0,showDownloadIcon:!1},"before-upload":O,"custom-request":D,disabled:n(e).confirmLoading},{default:f(()=>[r(m,{type:"dashed"},{icon:f(()=>[r(a)]),default:f(()=>[F(" "+S(n(t)("views.ne.neSoftware.upload")),1)]),_:1})]),_:1},8,["file-list","disabled"])]),_:1},8,["label","help"])],64)):W("",!0),r(d,v({label:n(t)("views.ne.common.neType"),name:"neType"},n(u).validateInfos.neType),{default:f(()=>[r(k,{value:n(e).from.neType,"onUpdate:value":o[2]||(o[2]=p=>n(e).from.neType=p),options:n(I).map(p=>({value:p})),disabled:n(e).from.id!==""},{default:f(()=>[r(c,{"allow-clear":"",placeholder:n(t)("common.inputPlease"),maxlength:32,disabled:n(e).from.id!==""},null,8,["placeholder","disabled"])]),_:1},8,["value","options","disabled"])]),_:1},16,["label"]),r(d,v({label:n(t)("views.ne.neSoftware.version"),name:"version"},n(u).validateInfos.version),{default:f(()=>[r(c,{value:n(e).from.version,"onUpdate:value":o[3]||(o[3]=p=>n(e).from.version=p),"allow-clear":"",placeholder:n(t)("common.inputPlease")},null,8,["value","placeholder"])]),_:1},16,["label"]),r(d,{label:n(t)("common.description"),name:"description"},{default:f(()=>[r(B,{value:n(e).from.description,"onUpdate:value":o[4]||(o[4]=p=>n(e).from.description=p),maxlength:500,"show-count":!0,placeholder:n(t)("common.inputPlease")},null,8,["value","placeholder"])]),_:1},8,["label"])]),_:1})]),_:1},8,["visible","title","confirm-loading"])}}});export{ne as default};
|