crud.BvX2U6tK.js 6.5 KB

1
  1. import{t as n,V as p,W as h,E as i,C as f,h as w}from"./index.BGBj-4PV.js";import{a as g}from"./authFunction.DC0n_p4g.js";const v="/api/system/articles/";function y(o){return n({url:"/api/system/device-manuals/",method:"get",params:o})}function q(o){return n({url:v+"add-device-manual/",method:"post",data:o})}function _(o){return n({url:"/api/system/device-manuals/"+o.id+"/",method:"put",data:o})}function D(o){return n({url:"/api/system/device-manuals/"+o+"/",method:"delete",data:{id:o}})}const{compute:m}=p(),F=function({crudExpose:o}){return{crudOptions:{request:{pageRequest:async e=>await y(e),addRequest:async({form:e})=>(e.device_id=Number(e.device),e.title=e.article_title,e.content=e.article_content,await q(e)),editRequest:async({form:e,row:t})=>(e.id=t.id,e.device_id=Number(e.device),e.title=e.article_title,e.content=e.article_content,await _(e)),delRequest:async({row:e})=>await D(e.id)},actionbar:{buttons:{add:{show:g("area:Create")}}},form:{wrapper:{buttons:{ok:{text:"提交",show:m(e=>e.mode!=="view")}}}},toolbar:{show:!1},rowHandle:{buttons:{remove:{show:!0},edit:{show:!0}}},pagination:{show:!0},columns:{_index:{title:"序号",form:{show:!1},column:{show:!1,type:"index",align:"center",width:"70px",columnSetDisabled:!0}},search:{title:"关键字搜索",search:{show:!0,type:"input"},type:"input",form:{component:{placeholder:"请输入"},show:!1},column:{show:!1}},device_code:{title:"设备编号",type:"input",column:{show:!0,minWidth:120},form:{show:!0,component:{placeholder:"请填写设备编号",onBlur:async e=>{var r;const t=(r=e.target.value)==null?void 0:r.trim();if(console.log("onBlur deviceCode:",t),!!t)try{const a=await n({url:`/api/system/device/?code=${encodeURIComponent(t)}`,method:"get"});if(console.log("设备搜索响应:",a),a.code===2e3&&a.data&&a.data.length>0){const s=a.data[0];console.log("找到设备:",s);const l=o.getFormData();l.device=s.id,l.device_code=s.code,l.device_name=s.name,o.setFormData(l)}else console.log("未找到匹配的设备")}catch(a){console.error("搜索设备信息失败:",a)}}},rules:[{required:!0,message:"请填写设备编号"}]},editForm:{component:{disabled:!0}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},device:{title:"设备名称",search:{show:!1},treeNode:!0,type:"dict-select",column:{show:!1,minWidth:120},dict:h({url:"/api/system/device/?page=1&limit=100&has_inventory=1",value:"id",label:"name"}),form:{show:!0,component:{placeholder:"请选择设备名称",filterable:!0,onChange:async e=>{console.log("onChange context:",e);const t=e;if(t)try{const r=await n({url:`/api/system/device/${t}/`,method:"get"});if(console.log("response::::",r),r.code==2e3){const a=r.data;console.log("设备数据:",a);const s=o.getFormData();s.device_code=a.code,s.device_name=a.name,o.setFormData(s)}}catch(r){console.error("获取设备信息失败:",r)}}},rules:[{required:!0,message:"请选择设备名称"}]}},article:{title:"文章id",search:{show:!1},type:"input",column:{show:!1,minWidth:120},form:{show:!1}},device_name:{title:"设备名称",type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请填设备名称"},rules:[{required:!1,message:"请填写设备名称"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},article_title:{title:"手册标题",search:{show:!1},treeNode:!0,type:"input",column:{minWidth:120},form:{show:!0,rules:[{required:!0,message:"手册标题必填项"}],component:{placeholder:"请输入手册标题"}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},article_content:{title:"内容",type:"editor-wang5",column:{show:!1,minWidth:120,formatter:({row:e,value:t})=>{if(!t)return"";const r=t.replace(/<[^>]*>/g,"").trim();return console.log("原始内容:",t),console.log("处理后内容:",r),r}},form:{show:!0,col:{span:24},rules:[{required:!0,message:"内容为必填项"}],component:{disabled:!1,id:"1",editorConfig:{readOnly:m(e=>{const{mode:t}=e;return t!=="add"})},uploader:{type:"form",buildUrl(e){return console.log("res::::",e),e.url}}}},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},device_operation_manual:{title:"PDF手册",type:"file-uploader",column:{show:!1,minWidth:120,formatter:({row:e,value:t})=>t?t.split("/").pop()||"PDF文件":"无"},form:{show:!0,component:{limit:1,helpMessage:"请先选择设备名称或填写设备编号后再上传PDF",uploader:{type:"form",accept:"application/pdf,.pdf",beforeUpload:e=>{try{const r=o.getFormData();if(!r||!r.device)return i.warning("请先选择设备或填写设备编号"),!1}catch{return i.error("无法获取表单数据,请重试"),!1}return e.type==="application/pdf"||/\.pdf$/i.test(e.name)?!0:(i.error("仅支持上传 PDF 文件"),!1)},uploadRequest:async e=>{const{action:t,file:r,onProgress:a}=e;let s="";try{s=o.getFormData().device}catch(c){console.warn("获取表单数据失败:",c)}if(!s)throw i.warning("请先选择设备或填写设备编号"),new Error("请先选择设备");const l=`/api/system/device/${s}/upload_manual/`,d=w.get("token"),u=new FormData;return u.append("file",r),await n({url:l,method:"post",timeout:6e4,headers:{"Content-Type":"multipart/form-data",Authorization:d?`JWT ${d}`:""},data:u,onUploadProgress:c=>{a({percent:Math.round(c.loaded/c.total*100)})}})},successHandle(e){return{url:f(e.data.manual_url),key:e.data.id,...e.data}},onError:e=>{i.error("PDF 上传失败,请重试"),console.error("PDF上传失败:",e)},onExceed:()=>{i.warning("只允许上传 1 个文件")}}},rules:[{required:!1,message:"PDF手册为可选项"}],helper:{text:"请先选择设备名称或填写设备编号后再上传PDF"}},viewForm:{component:{placeholder:"",disabled:!0},rules:[{required:!1,message:""}]}},publisher_name:{title:"发布人",type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请填写发布人"},rules:[{required:!1,message:"请填写发布人"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},create_datetime:{title:"发布时间",type:"input",column:{minWidth:120},form:{show:!1,component:{placeholder:"请填写发布时间"},rules:[{required:!1,message:"请填写发布时间"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}},is_default:{title:"状态",type:"input",column:{show:!1,minWidth:120},form:{value:!0,show:!1,component:{placeholder:"请填写状态"},rules:[{required:!1,message:"请填写状态"}]},viewForm:{component:{placeholder:""},rules:[{required:!0,message:""}]}}}}}},U=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:F},Symbol.toStringTag,{value:"Module"}));export{y as G,U as a,F as c};