/* 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-872e1028.js";/* empty css                          *//* empty css                 */import{u as a}from"./useCreate-d1a919fb.js";import{u as l}from"./useShow-5d0f85e9.js";import{d as s,f as r,m as t,x as o,O as i,W as d,o as n,l as p,w as m,a as u,z as c,e as _,b as f,t as v,a9 as y,ak as b,s as h,a3 as g,a2 as V,al as j,am as k,S as x,Y as w,$ as U,_ as C}from"./index-2b50ecca.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:P,form:E,loading:I,submitForm:K,close:Y,beforeCreate:$,beforeUpdate:z}=a(q.api,q.primary);if(q.primary){const{afterShow:e}=l(q.api,q.primary,P);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 A=t(),D=t(),F=t(),G=t(),J=t(!1),N=t("加载中..."),O=async(e=0)=>{e?y.get("permissions/roles/"+W(e)).then((e=>{D.value=e.data.data.permissions,R()})):y.get("permissions/permissions",{from:"role"}).then((e=>{D.value=e.data.data,R()}))},R=()=>{b((()=>{q.hasPermissions.forEach((e=>{F.value.setChecked(e.id,!0,!1)}));var e=t([]);q.hasPermissions.forEach((a=>{e.value.push(a.id)})),P.value.permissions=e})),D.value.length||(N.value="暂无数据")};o((()=>{y.get(q.api,{id:q.primary?q.primary:""}).then((e=>{A.value=e.data.data})),O(),y.get("permissions/departments").then((e=>{G.value=e.data.data})),Y((()=>C("close"))),i(P,(function(e){J.value=2===e.data_range}),{deep:!0})}));const T=(e,a)=>{P.value.permissions=a.checkedKeys.concat(a.halfCheckedKeys).sort()};$.value=()=>{P.value.parent_id=W(P.value.parent_id)},z.value=()=>{P.value.parent_id=W(P.value.parent_id)};const W=e=>void 0===e?0:e[e.length-1];return(a,l)=>{const t=h,o=g,i=V,y=e,b=j,C=k,q=x,Y=w,$=U;return d((n(),p(Y,{model:r(P),"label-width":"120px",ref_key:"form",ref:E,class:"pr-6"},{default:m((()=>[s.primary?c("",!0):(n(),p(o,{key:0,label:"上级角色",prop:"parent_id"},{default:m((()=>[u(t,{options:A.value,name:"parent_id",modelValue:r(P).parent_id,"onUpdate:modelValue":l[0]||(l[0]=e=>r(P).parent_id=e),clearable:"","check-strictly":"",class:"w-full",onChange:O,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(P).role_name,"onUpdate:modelValue":l[1]||(l[1]=e=>r(P).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(P).identify,"onUpdate:modelValue":l[2]||(l[2]=e=>r(P).identify=e),name:"identify",clearable:""},null,8,["modelValue"])])),_:1}),u(o,{label:"角色描述",prop:"description"},{default:m((()=>[u(i,{modelValue:r(P).description,"onUpdate:modelValue":l[3]||(l[3]=e=>r(P).description=e),name:"description",clearable:"",type:"textarea"},null,8,["modelValue"])])),_:1}),u(o,{label:"数据权限",prop:"data_range"},{default:m((()=>[u(y,{modelValue:r(P).data_range,"onUpdate:modelValue":l[4]||(l[4]=e=>r(P).data_range=e),name:"data_range",clearable:"",api:"dataRange",class:"w-full"},null,8,["modelValue"])])),_:1}),J.value?(n(),p(o,{key:1,label:"自定义权限",prop:"departments",rules:[{required:!0,message:"自定义权限必须选择"}]},{default:m((()=>[u(b,{modelValue:r(P).departments,"onUpdate:modelValue":l[5]||(l[5]=e=>r(P).departments=e),"value-key":"id",class:"w-full",data:G.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:F,modelValue:r(P).permissions,"onUpdate:modelValue":l[6]||(l[6]=e=>r(P).permissions=e),data:D.value,"node-key":"id",class:"w-full",props:{label:"permission_name",value:"id"},"show-checkbox":"","default-expand-all":!1,onCheck:T,"empty-text":N.value},null,8,["modelValue","data","empty-text"])])),_:1}),_("div",S,[u(q,{type:"primary",onClick:l[7]||(l[7]=e=>r(K)(r(E)))},{default:m((()=>[f(v(a.$t("system.confirm")),1)])),_:1})])])),_:1},8,["model"])),[[$,r(I)]])}}}),[["__scopeId","data-v-be2c8881"]]);export{q as default};
