import{r as l,W as q}from"./index.iT2mHWns.js";import{G as j,a as W,A as F,D as R,U as O,b as E}from"./api.PytcanJG.js";import"./vue.D1BjjNmv.js";let c=[];const N=async()=>{try{const a=await j();if(a&&(a.code===200||a.code===2e3||!a.code)){const o=a.data||a.results||a;Array.isArray(o)&&(c=o)}}catch(a){console.error("获取组织架构数据失败:",a),c=[]}};function x(a,o){if(!(!a||!o)){for(const g of o)if(Array.isArray(g.children)){for(const m of g.children)if(m.name===a)return m}}}const S=function({crudExpose:a}){return N(),{crudOptions:{request:{pageRequest:async e=>await E(e),editRequest:async({form:e,row:r})=>(e.id=r.id,await O(e)),delRequest:async({row:e})=>await R(e.id),addRequest:async({form:e})=>await F(e),getDetail:async({row:e})=>await W(e.id)},toolbar:{show:!1},actionbar:{buttons:{add:{show:!1}}},form:{wrapper:{buttons:{ok:{text:"提交",show:l(e=>e.mode!=="view")}}}},pagination:{show:!0},columns:{_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:"请输入姓名"}},viewForm:{component:{placeholder:""}}},password:{title:"密码",type:"password",column:{minWidth:120,show:!1},form:{component:{placeholder:"请填写密码"}},addForm:{component:{placeholder:"请填写密码"},rules:[{required:!0,message:"请填写密码"},{validator:(e,r,t)=>{if(!r){t();return}if(r.length<8){t(new Error("密码长度不能少于8位"));return}const n=/[a-zA-Z]/.test(r),s=/[0-9]/.test(r),d=/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?`~]/.test(r);if(!n||!s||!d){t(new Error("密码必须包含字母、数字和特殊符号"));return}t()},trigger:"blur"}]},editForm:{show:!0,component:{placeholder:"留空则不修改密码",type:"password",showPassword:!0},rules:[{validator:(e,r,t)=>{if(!r||r.trim()===""){t();return}const n=8,s=/[a-zA-Z]/.test(r),d=/\d/.test(r),p=/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(r);if(r.length=4?(e._college_id=(n=i[1])==null?void 0:n.id,e._major_id=(s=i[2])==null?void 0:s.id,e._grade_id=t==null?void 0:t.id):i.length===3?(e._college_id=(d=i[1])==null?void 0:d.id,e._major_id=(p=i[2])==null?void 0:p.id,e._grade_id=t==null?void 0:t.id):i.length===2?(e._college_id=(f=i[0])==null?void 0:f.id,e._major_id=(y=i[1])==null?void 0:y.id,e._grade_id=t==null?void 0:t.id):i.length===1?(e._college_id=(z=i[0])==null?void 0:z.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&&c.length>0){const i=e.organization,w=e.sub_organization,b=e.grade_or_level||e.class_or_group;if(i){const _=x(i,c);if(_&&(e._college_id=_.id,w&&Array.isArray(_.children))){const h=_.children.find(u=>u.name===w);if(h&&(e._major_id=h.id,b&&Array.isArray(h.children))){const u=h.children.find(A=>A.name===b);u&&(e._grade_id=u.id,e.organization_ref=u.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:{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!==0)return e.organization_detail&&e.organization_detail.name?e.organization_detail.name:t(r)?r:"";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:l(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:l(({row:e})=>e&&e.user_type===0),minWidth:120,formatter:({row:e,value:r})=>{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:l(({form:e})=>e&&e.user_type==0),component:{placeholder:"请填写专业"},rules:[{required:!1,message:"请填写专业"}]},viewForm:{component:{placeholder:""}}},grade_or_level:{title:"班级",type:"input",search:{show:!1},column:{show:l(({row:e})=>e&&e.user_type===0),minWidth:120,formatter:({row:e,value:r})=>{const t=n=>n!=null&&n!==""&&n!=="nan"&&!Number.isNaN(n);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:l(({form:e})=>e&&e.user_type==0),component:{placeholder:"请填写年级"},rules:[{required:!1,message:"请填写年级"}]},viewForm:{component:{placeholder:""}}}}}}};export{S as createCrudOptions};