import{_ as e}from"./index.vue_vue_type_script_setup_true_lang-7071596f.js";import{u as a}from"./useCreate-b3492f2b.js";import{u as l}from"./useShow-ca493df3.js";import{d as r,f as s,k as t,p as o,z as d,r as n,K as i,J as p,o as u,j as m,w as c,a as _,s as f,e as v,b as y,t as h,R as b,U as g,_ as V}from"./index-018fb6dd.js";const k={class:"flex justify-end"},x=V(r({__name:"create",props:{primary:String|Number,api:String,hasPermissions:Array},emits:["close"],setup(r,{emit:V}){const x=r,{formData:w,form:U,loading:C,submitForm:j,close:S,beforeCreate:q,beforeUpdate:K}=a(x.api,x.primary);if(x.primary){const{afterShow:e}=l(x.api,x.primary,w);e.value=e=>{const a=s(e);a.parent_id=a.parent_id?[a.parent_id]:0,a.data_range||(a.data_range=null),e.value=a}}const P=t(),E=t(),R=t(),z=t(),A=t(!1),D=t("加载中..."),F=async(e=0)=>{e?b.get("permissions/roles/"+L(e)).then((e=>{E.value=e.data.data.permissions,I()})):b.get("permissions/permissions",{from:"role"}).then((e=>{E.value=e.data.data,I()}))},I=()=>{g((()=>{x.hasPermissions.forEach((e=>{R.value.setChecked(e.id,!0,!1)}));var e=t([]);x.hasPermissions.forEach((a=>{e.value.push(a.id)})),w.value.permissions=e})),E.value.length||(D.value="暂无数据")};o((()=>{b.get(x.api,{id:x.primary?x.primary:""}).then((e=>{P.value=e.data.data})),F(),b.get("permissions/departments").then((e=>{z.value=e.data.data})),S((()=>V("close"))),d(w,(function(e){A.value=2===e.data_range}),{deep:!0})}));const J=(e,a)=>{w.value.permissions=a.checkedKeys.concat(a.halfCheckedKeys).sort()};q.value=()=>{w.value.parent_id=L(w.value.parent_id)},K.value=()=>{w.value.parent_id=L(w.value.parent_id)};const L=e=>void 0===e?0:e[e.length-1];return(a,l)=>{const t=n("el-cascader"),o=n("el-form-item"),d=n("el-input"),b=e,g=n("el-tree-select"),V=n("el-tree"),x=n("el-button"),S=n("el-form"),q=i("loading");return p((u(),m(S,{model:s(w),"label-width":"120px",ref_key:"form",ref:U,class:"pr-6"},{default:c((()=>[r.primary?f("",!0):(u(),m(o,{key:0,label:"上级角色",prop:"parent_id"},{default:c((()=>[_(t,{options:P.value,name:"parent_id",modelValue:s(w).parent_id,"onUpdate:modelValue":l[0]||(l[0]=e=>s(w).parent_id=e),clearable:"","check-strictly":"",class:"w-full",onChange:F,props:{value:"id",label:"role_name",checkStrictly:!0}},null,8,["options","modelValue"])])),_:1})),_(o,{label:"角色名称",prop:"role_name",rules:[{required:!0,message:"角色名称必须填写"}]},{default:c((()=>[_(d,{modelValue:s(w).role_name,"onUpdate:modelValue":l[1]||(l[1]=e=>s(w).role_name=e),name:"role_name",clearable:""},null,8,["modelValue"])])),_:1}),_(o,{label:"角色标识",prop:"identify",rules:[{required:!0,message:"角色标识必须填写"}]},{default:c((()=>[_(d,{modelValue:s(w).identify,"onUpdate:modelValue":l[2]||(l[2]=e=>s(w).identify=e),name:"identify",clearable:""},null,8,["modelValue"])])),_:1}),_(o,{label:"角色描述",prop:"description"},{default:c((()=>[_(d,{modelValue:s(w).description,"onUpdate:modelValue":l[3]||(l[3]=e=>s(w).description=e),name:"description",clearable:"",type:"textarea"},null,8,["modelValue"])])),_:1}),_(o,{label:"数据权限",prop:"data_range"},{default:c((()=>[_(b,{modelValue:s(w).data_range,"onUpdate:modelValue":l[4]||(l[4]=e=>s(w).data_range=e),name:"data_range",clearable:"",api:"dataRange",class:"w-full"},null,8,["modelValue"])])),_:1}),A.value?(u(),m(o,{key:1,label:"自定义权限",prop:"departments",rules:[{required:!0,message:"自定义权限必须选择"}]},{default:c((()=>[_(g,{modelValue:s(w).departments,"onUpdate:modelValue":l[5]||(l[5]=e=>s(w).departments=e),"value-key":"id",class:"w-full",data:z.value,"render-after-expand":!1,"show-checkbox":"",multiple:"",props:{value:"id",label:"department_name"}},null,8,["modelValue","data"])])),_:1})):f("",!0),_(o,{label:"角色权限",prop:"permissions"},{default:c((()=>[_(V,{ref_key:"permissionTree",ref:R,modelValue:s(w).permissions,"onUpdate:modelValue":l[6]||(l[6]=e=>s(w).permissions=e),data:E.value,"node-key":"id",class:"w-full",props:{label:"permission_name",value:"id"},"show-checkbox":"","default-expand-all":!1,onCheck:J,"empty-text":D.value},null,8,["modelValue","data","empty-text"])])),_:1}),v("div",k,[_(x,{type:"primary",onClick:l[7]||(l[7]=e=>s(j)(s(U)))},{default:c((()=>[y(h(a.$t("system.confirm")),1)])),_:1})])])),_:1},8,["model"])),[[q,s(C)]])}}}),[["__scopeId","data-v-f346603d"]]);export{x as default};
