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