crud.C5POyNQY.js 4.8 KB

1
  1. import{x as n,V as u,W as d}from"./index.DHn9b8nY.js";import{a as m}from"./authFunction.CL7rDwVJ.js";const i="/api/system/articles/";function p(t){return n({url:i+"device-manuals/",method:"get",params:t})}function h(t){return n({url:i+"add-device-manual/",method:"post",data:t})}function w(t){return n({url:"/api/system/device-manuals/"+t.id+"/",method:"put",data:t})}function g(t){return n({url:i+t+"/",method:"delete",data:{id:t}})}const{compute:c}=u(),f=function({crudExpose:t}){return{crudOptions:{request:{pageRequest:async e=>await p(e),addRequest:async({form:e})=>(e.device_id=Number(e.device),e.title=e.article_title,e.content=e.article_content,await h(e)),editRequest:async({form:e,row:o})=>(e.id=o.id,e.device_id=Number(e.device),e.title=e.article_title,e.content=e.article_content,await w(e)),delRequest:async({row:e})=>await g(e.id)},actionbar:{buttons:{add:{show:m("area:Create")}}},form:{wrapper:{buttons:{ok:{text:"提交",show:c(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 o=(r=e.target.value)==null?void 0:r.trim();if(console.log("onBlur deviceCode:",o),!!o)try{const s=await n({url:`/api/system/device/?code=${encodeURIComponent(o)}`,method:"get"});if(console.log("设备搜索响应:",s),s.code===2e3&&s.data&&s.data.length>0){const a=s.data[0];console.log("找到设备:",a);const l=t.getFormData();l.device=a.id,l.device_code=a.code,l.device_name=a.name,t.setFormData(l)}else console.log("未找到匹配的设备")}catch(s){console.error("搜索设备信息失败:",s)}}},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:d({url:"/api/system/device/?has_inventory=1",value:"id",label:"name"}),form:{show:!0,component:{placeholder:"请选择设备名称",onChange:async e=>{console.log("onChange context:",e);const o=e;if(o)try{const r=await n({url:`/api/system/device/${o}/`,method:"get"});if(console.log("response::::",r),r.code==2e3){const s=r.data;console.log("设备数据:",s);const a=t.getFormData();a.device_code=s.code,a.device_name=s.name,t.setFormData(a)}}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:!0},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:!0,minWidth:120,formatter:({row:e,value:o})=>{if(!o)return"";const r=o.replace(/<[^>]*>/g,"").trim();return console.log("原始内容:",o),console.log("处理后内容:",r),r}},form:{show:!0,col:{span:24},rules:[{required:!0,message:"内容为必填项"}],component:{disabled:!1,id:"1",editorConfig:{readOnly:c(e=>{const{mode:o}=e;return o!=="add"})},uploader:{type:"form",buildUrl(e){return console.log("res::::",e),e.url}}}},viewForm:{component:{placeholder:""},rules:[{required:!0,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:""}]}}}}}},D=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:f},Symbol.toStringTag,{value:"Module"}));export{p as G,D as a,f as c};