import{t as u,r as w,W as F,X as s}from"./index.Du9xfTeB.js";import{r as R,t as C}from"./vue.D1BjjNmv.js";const h="/api/system/app_user/";function P(i){return u({url:h,method:"get",params:i})}function V(i){return u({url:h+i+"/",method:"get"})}function G(i){return u({url:h,method:"post",data:i})}function L(i){return u({url:h+i.id+"/",method:"put",data:i})}function v(i){return u({url:h+i+"/",method:"delete",data:{id:i}})}function Z(){return u({url:h,method:"get"})}function I(){return u({url:"/api/system/organization/tree/",method:"get"})}let g=[];const D=async()=>{try{const i=await I();if(i&&(i.code===200||i.code===2e3||!i.code)){const l=i.data||i.results||i;Array.isArray(l)&&(g=l)}}catch(i){console.error("获取组织架构数据失败:",i),g=[]}};function $(i,l){if(!(!i||!l)){for(const m of l)if(Array.isArray(m.children)){for(const f of m.children)if(f.name===i)return f}}}const B=function({crudExpose:i}){D();const l=async e=>await P(e),m=async({row:e})=>await V(e.id),f=async({form:e,row:r})=>(e.id=r.id,await L(e)),E=async({row:e})=>await v(e.id),O=async({form:e})=>await G(e),d=R([]),b=R([]),S=e=>{const t=i.getTableData().filter(n=>!e.includes(n));s.arrayEach(e,n=>{s.pluck(d.value,"id").includes(n.id)||(d.value=s.union(d.value,[n]))}),s.arrayEach(t,n=>{d.value=s.remove(d.value,o=>o.id!==n.id)}),b.value=s.pluck(d.value,"id")},T=()=>{const e=i.getBaseTableRef(),r=i.getTableData(),t=s.filter(r,n=>s.pluck(d.value,"id").includes(n.id));C(()=>{s.arrayEach(t,n=>{e.toggleRowSelection(n,!0)})})};return i.selectedIds=b,{crudOptions:{request:{pageRequest:l,editRequest:f,delRequest:E,addRequest:O,getDetail:m},toolbar:{show:!1},actionbar:{buttons:{add:{show:!0}}},form:{wrapper:{buttons:{ok:{text:"提交",show:w(e=>e.mode!=="view")}}}},pagination:{show:!0},table:{rowKey:"id",rowSelection:{show:!0,multiple:!0},onSelectionChange:S,onRefreshed:()=>T()},columns:{$checked:{title:"选择",form:{show:!1},column:{type:"selection",align:"center",width:"55px",columnSetDisabled:!0,selectable(e,r){return e.id}}},_index:{title:"序号",form:{show:!1},column:{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}},user_code:{title:"学号/工号",type:"input",column:{minWidth:120},form:{component:{placeholder:"请填写学号/工号"},rules:[{required:!0,message:"请填写学号/工号"}]},viewForm:{component:{placeholder:""}}},username:{title:"用户名",type:"input",column:{show:!1,minWidth:120},form:{component:{placeholder:"请填写用户名"},rules:[{required:!0,message:"请填写用户名"}]},viewForm:{component:{placeholder:""}}},name:{title:"姓名",search:{show:!1},treeNode:!0,type:"input",column:{minWidth:120},form:{rules:[{required:!0,message:"姓名必填项"}],component:{placeholder:"请输入姓名"}}},password:{title:"密码",type:"input",column:{minWidth:120,show:!1},form:{component:{placeholder:"请填写密码",type:"password",showPassword:!0}},addForm:{component:{placeholder:"请填写密码",type:"password",showPassword:!0},rules:[{required:!0,message:"请填写密码"},{validator:(e,r,t)=>{if(!r||r.trim()===""){t(new Error("请填写密码"));return}const n=8,o=/[a-zA-Z]/.test(r),c=/\d/.test(r),p=/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(r);if(r.length{if(!r||r.trim()===""){t();return}const n=8,o=/[a-zA-Z]/.test(r),c=/\d/.test(r),p=/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(r);if(r.length=4?(e._college_id=(n=a[1])==null?void 0:n.id,e._major_id=(o=a[2])==null?void 0:o.id,e._grade_id=t==null?void 0:t.id):a.length===3?(e._college_id=(c=a[1])==null?void 0:c.id,e._major_id=(p=a[2])==null?void 0:p.id,e._grade_id=t==null?void 0:t.id):a.length===2?(e._college_id=(q=a[0])==null?void 0:q.id,e._major_id=(N=a[1])==null?void 0:N.id,e._grade_id=t==null?void 0:t.id):a.length===1?(e._college_id=(W=a[0])==null?void 0:W.id,e._major_id=void 0,e._grade_id=t==null?void 0:t.id):(e._college_id=void 0,e._major_id=void 0,e._grade_id=t==null?void 0:t.id)}else if(e.user_type===1||e.user_type===3)t&&t.id&&(e.organization_ref=t.id);else if(e.user_type===0&&!t&&g.length>0){const a=e.organization,j=e.sub_organization,A=e.grade_or_level||e.class_or_group;if(a){const y=$(a,g);if(y&&(e._college_id=y.id,j&&Array.isArray(y.children))){const z=y.children.find(_=>_.name===j);if(z&&(e._major_id=z.id,A&&Array.isArray(z.children))){const _=z.children.find(x=>x.name===A);_&&(e._grade_id=_.id,e.organization_ref=_.id)}}}}},valueResolve({form:e,value:r}){if(e.user_type!==0){e.organization_ref=r??e.organization_ref;return}if(e._grade_id){e.organization_ref=e._grade_id;return}}},organization_detail:{title:"组织架构",type:"dict-cascader",column:{show:!1,minWidth:200,formatter:({row:e,value:r})=>e.organization_detail&&e.organization_detail.full_path?e.organization_detail.full_path:r||""},form:{show:!1,component:{placeholder:"请填写组织架构"},rules:[{required:!1,message:"请填写组织架构"}]},viewForm:{component:{placeholder:""}}},organization:{title:"学院",type:"input",search:{show:!1},column:{show:!0,minWidth:200,formatter:({row:e,value:r})=>{const t=n=>n!=null&&n!==""&&n!=="nan"&&!Number.isNaN(n);if(e.user_type===2)return t(r)?r:e.organization_detail&&e.organization_detail.name?e.organization_detail.name:"";if(e.user_type!==0)return e.organization_detail&&e.organization_detail.name?e.organization_detail.name:t(r)?r:t(e.class_or_group)?e.class_or_group:"";if(e.organization_detail&&e.organization_detail.parent_chain&&e.organization_detail.parent_chain.length>=2){if(!e.organization_detail.parent_chain[1])return;const n=e.organization_detail.parent_chain[1];return n.name||n.code||""}return t(r)?r:t(e.sub_organization)?e.sub_organization:""}},form:{show:w(e=>e.user_type===0||e.user_type===1||e.user_type===3),component:{placeholder:"请选择学院"},rules:[{required:!1,message:"请选择学院"}]},viewForm:{component:{placeholder:""}}},sub_organization:{title:"专业",type:"input",search:{show:!1},column:{show:!0,minWidth:120,formatter:({row:e,value:r})=>{if(e&&e.user_type!==0)return"";const t=n=>n!=null&&n!==""&&n!=="nan"&&!Number.isNaN(n);if(e.organization_detail&&e.organization_detail.parent_chain&&e.organization_detail.parent_chain.length>=2){if(!e.organization_detail.parent_chain[2])return;const n=e.organization_detail.parent_chain[2];return n.name||n.code||""}return t(r)?r:t(e.sub_organization)?e.sub_organization:""}},form:{show:w(({form:e})=>e&&e.user_type==0),component:{placeholder:"请填写专业"},rules:[{required:!1,message:"请填写专业"}]}},grade_or_level:{title:"班级",type:"input",search:{show:!1},column:{show:!0,minWidth:120,formatter:({row:e,value:r})=>{const t=n=>n!=null&&n!==""&&n!=="nan"&&!Number.isNaN(n);if(e.user_type===0)return e.organization_detail&&e.organization_detail.name?e.organization_detail.name:t(r)?r:t(e.class_or_group)?e.class_or_group:""}},form:{show:w(({form:e})=>e&&e.user_type==0),component:{placeholder:"请选择班级"},rules:[{required:!1,message:"请选择班级"}]},viewForm:{component:{placeholder:""}}},class_or_group:{title:"班级",type:"input",search:{show:!1},column:{show:!1,minWidth:120,formatter:({row:e,value:r})=>e.organization_detail&&e.organization_detail.name?e.organization_detail.name:r||e.class_or_group},form:{show:!1,component:{placeholder:"请填写班级"},rules:[{required:!1,message:"请填写班级"}]},viewForm:{component:{placeholder:""}}}}}}},K=Object.freeze(Object.defineProperty({__proto__:null,createCrudOptions:B},Symbol.toStringTag,{value:"Module"}));export{Z as G,K as a,B as c};