crud.CbIRC3BC.js 5.9 KB

1
  1. import{t as n,V as m,W as p,C as h,h as f}from"./index.BteTc5v8.js";import{a as w}from"./authFunction.u_0onAO2.js";const g="/api/system/articles/";function v(o){return n({url:"/api/system/device-manuals/",method:"get",params:o})}function y(o){return n({url:g+"add-device-manual/",method:"post",data:o})}function q(o){return n({url:"/api/system/device-manuals/"+o.id+"/",method:"put",data:o})}function _(o){return n({url:"/api/system/device-manuals/"+o+"/",method:"delete",data:{id:o}})}const{compute:u}=m(),b=function({crudExpose:o}){return{crudOptions:{request:{pageRequest:async e=>await v(e),addRequest:async({form:e})=>(e.device_id=Number(e.device),e.title=e.article_title,e.content=e.article_content,await y(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 q(e)),delRequest:async({row:e})=>await _(e.id)},actionbar:{buttons:{add:{show:w("area:Create")}}},form:{wrapper:{buttons:{ok:{text:"提交",show:u(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:p({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:u(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,uploader:{type:"form",accept:".pdf",uploadRequest:async e=>{const{action:t,file:r,onProgress:a}=e;let s="";try{s=o.getFormData().device}catch(i){console.warn("获取表单数据失败:",i)}if(!s)throw new Error("请先选择设备");const l=`/api/system/device/${s}/upload_manual/`,c=f.get("token"),d=new FormData;return d.append("file",r),await n({url:l,method:"post",timeout:6e4,headers:{"Content-Type":"multipart/form-data",Authorization:c?`JWT ${c}`:""},data:d,onUploadProgress:i=>{a({percent:Math.round(i.loaded/i.total*100)})}})},successHandle(e){return{url:h(e.data.manual_url),key:e.data.id,...e.data}}}},rules:[{required:!1,message:"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:""}]}}}}}},P=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:b},Symbol.toStringTag,{value:"Module"}));export{v as G,P as a,b as c};