import{r as n,m as g,v as w,x as o,s as i,E as c,w as x,I as y,S as v}from"./index.lP_uh0LI.js";import{C as b,g as S}from"./vue.BxlDVA1H.js";const s=`${g.knowledge}course/category/manage/`;function C(r){return n({url:s,method:"get",params:r})}function _(r){return n({url:s,method:"post",data:r})}function l(r){return n({url:s+r.uuid+"/",method:"patch",data:r})}function u(r){return n({url:s+r+"/",method:"delete",data:{uuid:r}})}const P=function({crudExpose:r}){const d=async e=>(e.ordering="-created_time",await C(e)),m=async({form:e,row:t})=>(e.uuid=t.uuid,await l(e)),f=async({row:e})=>await u(e.uuid),h=async({form:e})=>await _(e),p=b();return{crudOptions:{request:{pageRequest:d,addRequest:h,editRequest:m,delRequest:f,transformQuery:({page:e,form:t})=>{const a=(e==null?void 0:e.pageSize)||10;return{offset:(((e==null?void 0:e.currentPage)||1)-1)*a,limit:a,...t}},transformRes:({res:e,query:t})=>{const a=e;return a.success?{records:a.data.results||[],currentPage:t.offset/t.limit+1,pageSize:t.limit,total:a.data.count}:{records:[],currentPage:t.offset/t.limit+1,pageSize:t.limit,total:0}}},actionbar:{buttons:{add:{show:!0,text:"新增分类"}}},toolbar:{buttons:{export:{show:!1}}},search:{autoSearch:!1},rowHandle:{fixed:"right",width:200,buttons:{view:{show:!1},edit:{show:!0,link:!0,type:"primary"},remove:{show:o(({row:e})=>!e.is_active),link:!0,click:async({row:e})=>{if(e.course_count&&e.course_count>0){x("该分类下有关联课程，请先检查");return}await c.confirm("删除后不可撤销，请谨慎操作！","确认删除数据？",{distinguishCancelAndClose:!0,confirmButtonText:"确定",cancelButtonText:"取消",closeOnClickModal:!1}),(await u(e.uuid)).success?(i("删除成功"),r.doRefresh()):y("删除失败")}}}},table:{rowKey:"uuid",remove:{async confirmFn(){await c.confirm("删除后不可撤销，请谨慎操作！","确认删除数据？",{distinguishCancelAndClose:!0,confirmButtonText:"确定",cancelButtonText:"取消",closeOnClickModal:!1})}}},columns:{_index:{title:"序号",form:{show:!1},column:{align:"center",width:"70px",columnSetDisabled:!0,formatter:e=>{let t=e.index??1,a=r.crudBinding.value.pagination;return((a.currentPage??1)-1)*a.pageSize+t+1}}},name:{title:"分类名称",search:{show:!0,col:{span:6},component:{placeholder:"请输入分类名称",minlength:0,maxlength:99999}},type:["text","colspan"],column:{minWidth:120,align:"left"},form:{show:!0,rules:[{required:!0,message:"请输入分类名称"}],component:{placeholder:"请输入分类名称",minlength:1,maxlength:6}}},sort:{title:"排序",search:{show:!1},type:["number","colspan"],column:{minWidth:120,align:"left"},form:{show:!0,rules:[{required:!0,message:"请输入分类排序"}],title:"分类排序",component:{placeholder:"请输入分类排序",min:0,max:99999,precision:0}}},course_count:{title:"关联课程",search:{show:!1},type:["text","colspan"],column:{minWidth:120,align:"left",formatter:({row:e})=>e.course_count?S("div",{style:"color: #409EFF;cursor: pointer;",onClick:()=>{const t=JSON.stringify({label:e.name,value:e.uuid});window.localStorage.setItem("category",t);const a=v.get("sessionId");a?window.parent.postMessage({sessionId:a,data:{operation:"curriculumManage"}},"*"):p.push({name:"curriculumManage"})}},[e.course_count]):""},form:{show:!1}},is_active:{title:"状态",search:{show:!0,col:{span:6},component:{placeholder:"请选择状态"}},type:"dict-radio",column:{minWidth:90,align:"left",component:{name:"fs-dict-switch",activeText:"",inactiveText:"",style:"--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6",onChange:o(({row:e})=>async()=>{l(e).then(t=>{i(t.msg)})})}},form:{show:!1},dict:w({data:[{label:"启用",value:!0},{label:"禁用",value:!1}]})},created_time:{title:"创建时间",type:"daterange",search:{show:!1},form:{show:!1},column:{minWidth:120,align:"left",formatter:e=>e.value}}},form:{wrapper:{width:"600px"}},editForm:{wrapper:{title:"编辑分类"}},addForm:{wrapper:{title:"新建分类"}}}}};export{P as createCrudOptions};
