crud.Boq5UNsf.js 8.0 KB

1
  1. import{Y as w,W as r,D as a,n as g,G as y,h as b,r as v,s as q}from"./index.CsNe-70m.js";import{D as _,U as W,A as x,G as Y,a as D}from"./api.DOnMNtB7.js";import{a as l}from"./authFunction.BvfKVxRV.js";import{d as F}from"./dictionary.wNMECUDX.js";import{S as c,P as M,aj as R,ai as u}from"./vue.YrNK8sx4.js";const O=function({crudExpose:d}){const m=async e=>await Y(e),p=async({form:e,row:t})=>(e.id=t.id,await W(e)),h=async({row:e})=>await _(e.id),f=async({form:e})=>await x(e);return w.get(),{crudOptions:{request:{pageRequest:m,addRequest:f,editRequest:p,delRequest:h},toolbar:{show:!1},rowHandle:{fixed:"right",width:220,view:{show:!0},edit:{show:!0},remove:{show:!0}},actionbar:{buttons:{add:{show:l("user:Create")},batchimport:{text:"批量导入",title:"导入"},export:{text:"导出",title:"导出",show:l("user:Export")},downloadtemplate:{text:"下载模板",title:"下载模板"},batchdelete:{text:"批量删除",title:"批量删除"}}},columns:{_index:{title:"序号",form:{show:!1},column:{align:"center",width:"70px",columnSetDisabled:!0,formatter:e=>{let t=e.index??1,o=d.crudBinding.value.pagination;return((o.currentPage??1)-1)*o.pageSize+t+1}}},code:{title:"设备编号",search:{show:!0},type:"input",column:{minWidth:120},form:{component:{placeholder:"请输入设备编号"},rules:[{required:!0,message:"请输入设备编号"}]}},category_name:{title:"设备分类",search:{show:!0},type:"dict-select",dict:r({url:"/api/system/device/category/",value:"id",label:"name"}),column:{minWidth:100},form:{show:!1,component:{placeholder:"请选择设备分类"},rules:[{required:!0,message:"请选择设备分类"}]}},name:{title:"设备名称",search:{show:!1},type:"input",column:{minWidth:120},form:{component:{placeholder:"请输入设备名称"},rules:[{required:!0,message:"请输入设备名称"}]}},"inventory.borrowed_quantity":{title:"设备状态",type:"text",search:{show:!1},column:{show:!0,minWidth:100,formatter:({row:e})=>{const t=e.borrowed_quantity>0,o=t?"在借":"空闲",s=t?"#FFA500":"#4CAF50";return u("span",{style:{display:"inline-block",padding:"2px 8px",border:`1px solid ${s}`,borderRadius:"4px",backgroundColor:s,color:"white",fontWeight:"bold"}},o)}},form:{show:!1,component:{placeholder:"请选择设备状态"},rules:[{required:!0,message:"请选择设备状态"}]}},borrowed_quantity:{title:"已借出",type:"input",search:{show:!1},column:{minWidth:100},form:{show:!1,component:{placeholder:"请输入已借出"},rules:[{required:!0,message:"请输入已借出"}]}},brand:{title:"品牌",type:"input",column:{minWidth:100}},specification:{title:"规格型号",search:{show:!1},type:"input",column:{minWidth:100},form:{component:{placeholder:"请输入规格型号"}}},serial_number:{title:"序列号",type:"input",column:{minWidth:100}},total_quantity:{title:"库存数量",type:"input",column:{minWidth:100},addForm:{show:!1},viewForm:{show:!1},editForm:{show:!1},from:{show:!1,component:{placeholder:"请输入库存数量"},rules:[{required:!1,message:"请输入库存数量"}]}},warehouse:{title:"存放仓库",type:"dict-select",column:{minWidth:150},dict:r({url:"/api/system/warehouse/",value:"id",label:"name"}),form:{component:{placeholder:"请选择存放仓库"},rules:[{required:!0,message:"请选择存放仓库"}]}},status:{title:"是否可见",type:"dict-switch",column:{minWidth:90,component:{name:"fs-dict-switch",activeText:"",inactiveText:"",style:"--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6",onChange:g(e=>()=>{D(e.row).then(t=>{q(t.msg)})})}},dict:r({data:F("device_button_status_bool")}),form:{rules:[{required:!0,message:"请选择是否可见"}]}},department:{title:"所属部门",search:{show:!1},type:"input",column:{minWidth:120},form:{component:{placeholder:"请输入所属部门"}}},purchase_date:{title:"采购时间",type:"date",search:{show:!1},column:{minWidth:120,formatter:({value:e})=>e?a(e).format("YYYY-MM-DD"):""},form:{component:{placeholder:"请选择采购时间"},rules:[{required:!1,message:"请选择采购时间"}]},valueResolve({form:e,value:t}){e.purchase_date=t?a(t).format("YYYY-MM-DD"):null},valueBuilder({form:e,value:t}){e.purchase_date=t}},supplier:{title:"供应商",type:"dict-select",search:{show:!1},column:{minWidth:120},dict:r({url:"/api/system/supplier/",value:"id",label:"name"}),form:{component:{placeholder:"请输入供应商"}}},price:{title:"价格",type:"number",search:{show:!1},column:{minWidth:100},form:{component:{placeholder:"请输入设备购入价格"},rules:[{required:!1,message:"请输入设备购入价格"}]}},warranty_expiration:{title:"质保期",type:"date",search:{show:!1},column:{minWidth:120,formatter:({value:e})=>e?a(e).format("YYYY-MM-DD"):""},viewForm:{title:"质保到期",component:{render({value:e}){if(console.log("valuevaluevalue:::",e),!e)return"未设置";const t=a(e).format("YYYY-MM-DD"),o=a(e).isBefore(a(),"day");return u("span",{style:{color:o?"red":"inherit",fontWeight:o?"bold":"normal"}},o?`${t}(已过期)`:t)},showHtml:!0}},form:{component:{placeholder:"请选择质保期"},rules:[{required:!1,message:"请选择质保期"}]},valueResolve({form:e,value:t}){e.warranty_expiration=t?a(t).format("YYYY-MM-DD"):null},valueBuilder({form:e,value:t}){e.warranty_expiration=t}},tenant_id:{title:"租户id",type:"input",value:1,column:{show:!1,minWidth:120},form:{value:1,show:!1,component:{placeholder:"请填租户id"},rules:[{required:!1,message:"请填租户id"}]}},category:{show:!1,title:"设备类别",search:{show:!1},type:"dict-select",column:{show:!1,minWidth:120},dict:r({url:"/api/system/device/category/",value:"id",label:"name"}),form:{component:{placeholder:"请输入设备类别"},rules:[{required:!0,message:"请输入设备类别"}]}},quantity:{show:!1,title:"库存数量",search:{show:!1},type:"input",column:{show:!1,minWidth:120},viewForm:{component:{placeholder:""}},form:{component:{placeholder:"请输入库存数量"},rules:[{required:!0,message:"请输入库存数量"}],valueResolve({form:e,value:t}){e.quantity=Number(t??0)},valueBuilder({form:e,value:t}){e.quantity=e.total_quantity}}},tags:{show:!1,title:"设备标签",search:{show:!1},type:"dict-select",column:{show:!1,minWidth:120},dict:r({url:"/api/system/device_tags/",value:"id",label:"name"}),viewForm:{component:{placeholder:""}},form:{component:{placeholder:"请选择设备标签"},rules:[{required:!0,message:"请选择设备标签"}],valueResolve({form:e,value:t}){e.tags=Array.from(String(t),Number)},valueBuilder({form:e,value:t}){t&&(e.tags=Array.isArray(t)?t.length>0?Number(t[0]):"":Number(t))}}},image:{title:"设备图片",type:"image-uploader",column:{minWidth:120,show:!1},form:{show:l("image:upload"),component:{uploader:{type:"form",limit:1,action:"/api/system/device/upload-image/",accept:".jpg,.png",uploadRequest:async({action:e,file:t,onProgress:o})=>{const s=b.get("token"),i=new FormData;return i.append("image",t),await v({url:e,method:"post",timeout:6e4,headers:{"Content-Type":"multipart/form-data",Authorization:s?`JWT ${s}`:""},data:i,onUploadProgress:n=>{o({percent:Math.round(n.loaded/n.total*100)})}})},successHandle(e){return{url:y(e.data.image_url),key:e.data.id,...e.data}}}}},valueBuilder({row:e,key:t}){return e[t]?[e[t]]:[]},valueResolve({form:e,key:t}){console.log("form[key]:::",e[t]),e[t]=Array.isArray(e[t])?e[t][0]:e[t]}}},form:{row:{gutter:20},group:{groupType:"tabs",accordion:!1,groups:{base:{slots:{label:e=>c("span",{style:{color:e.hasError?"red":"green"}},[c(R("fs-icon"),{icon:"ion:checkmark-circle"},null),M("基础信息")])},icon:"el-icon-goods",columns:["code","category_name","name","status","borrowed_quantity","brand","specification","serial_number","warehouse","is_visible","department","purchase_date","supplier","price","warranty_expiration","tenant_id","category","quantity","tags","image"]},borrow:{label:"借用记录",icon:"el-icon-price-tag",columns:[]},maintenance:{label:"维修记录",collapsed:!0,icon:"el-icon-warning-outline",columns:[""]},maintain:{label:"保养记录",collapsed:!0,icon:"el-icon-warning-outline",columns:[]},datastatis:{label:"数据统计",collapsed:!0,icon:"el-icon-warning-outline",columns:[]}}}}}}};export{O as createCrudOptions};