/* 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-94b20c4f.js";/* empty css                          *//* empty css                 */import{u as a}from"./useCreate-9054a19b.js";import{u as l}from"./useShow-b44df7c8.js";import{d as s,f as r,m as t,x as o,O as i,Z 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,ac as y,al as h,s as b,a6 as g,a5 as V,am as j,an as k,W as x,a0 as w,a2 as U,_ as C}from"./index-41bf27b7.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:z,loading:A,submitForm:E,close:K,beforeCreate:R,beforeUpdate:T}=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 W=t(),D=t(),F=t(),I=t(),N=t(!1),O=t("加载中..."),Q=async(e=0)=>{e?y.get("permissions/roles/"+Z(e)).then((e=>{D.value=e.data.data.permissions,X()})):y.get("permissions/permissions",{from:"role"}).then((e=>{D.value=e.data.data,X()}))},X=()=>{h((()=>{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||(O.value="暂无数据")};o((()=>{y.get(q.api,{id:q.primary?q.primary:""}).then((e=>{W.value=e.data.data})),Q(),y.get("permissions/departments").then((e=>{I.value=e.data.data})),K((()=>C("close"))),i(P,(function(e){N.value=2===e.data_range}),{deep:!0})}));const Y=(e,a)=>{P.value.permissions=a.checkedKeys.concat(a.halfCheckedKeys).sort()};R.value=()=>{P.value.parent_id=Z(P.value.parent_id)},T.value=()=>{P.value.parent_id=Z(P.value.parent_id)};const Z=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,K=w,R=U;return d((n(),p(K,{model:r(P),"label-width":"120px",ref_key:"form",ref:z,class:"pr-6"},{default:m((()=>[s.primary?c("",!0):(n(),p(o,{key:0,label:"上级角色",prop:"parent_id"},{default:m((()=>[u(t,{options:W.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:Q,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}),N.value?(n(),p(o,{key:1,label:"自定义权限",prop:"departments",rules:[{required:!0,message:"自定义权限必须选择"}]},{default:m((()=>[u(h,{modelValue:r(P).departments,"onUpdate:modelValue":l[5]||(l[5]=e=>r(P).departments=e),"value-key":"id",class:"w-full",data:I.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:Y,"empty-text":O.value},null,8,["modelValue","data","empty-text"])])),_:1}),_("div",S,[u(q,{type:"primary",onClick:l[7]||(l[7]=e=>r(E)(r(z)))},{default:m((()=>[f(v(a.$t("system.confirm")),1)])),_:1})])])),_:1},8,["model"])),[[R,r(A)]])}}}),[["__scopeId","data-v-f346603d"]]);export{q as default};
