roleManageAdd-BfNnv9D9.js 7.6 KB

1
  1. import{d as se,r as m,a as K,o as de,I as ce,f as h,i as t,w as a,n as ie,l as g,m as ue,q as f,s as A,F as L,t as P,K as pe,E as S,Z as q,v as F,y as D,h as Z,_ as he}from"./index-JAEh4X-P.js";import{b as fe,c as _e,e as ve}from"./auth-DdGlAz8q.js";import{g as me}from"./menus-8pwyf4HB.js";import{c as ge}from"./setting-CO6n2wVB.js";const ke={class:"permission-container"},be={key:0,class:"el-icon-arrow-down"},ye={key:0,class:"role-dropdown__list"},Ve={class:"role-dropdown__label"},Ce={key:0,class:"el-icon-arrow-right"},we={key:0,class:"role-dropdown__list"},Ae={class:"role-dropdown__label"},xe=se({__name:"roleManageAdd",setup(Ee){const x=ie(),J=ue(),Q={label:"name",value:"id",emitPath:!1,multiple:!0,checkStrictly:!0};m(!0);const y=m([]),N=m([]),s=K({data_scope:"ALL",role_name:"",dept_ids:[],role_describe:""}),W=K({role_name:[{required:!0,message:"请输入角色名称!",trigger:"blur"},{min:1,max:10,message:"长度在 1 到 10 个字符",trigger:"blur"}]}),i=m([]),I=m(!1),M=m(!1),_=m(!1),V=m(x.query.id);console.log("role_id:",x.query);const X=()=>{let n=-1;return s.dept_ids.forEach((e,l)=>{e.length===1&&(n=l)}),n},Y=n=>{n?y.value.unshift({id:"全选",name:"全选",value:"全选"}):y.value.shift()},ee=async(n=[])=>{const e=n.filter(r=>r!=="全选").length,l=n.some(r=>r==="全选");let o=[...s.dept_ids];if(l&&_.value)o=o.filter(r=>r!=="全选"),o.splice(X(),1),s.dept_ids=o,_.value=!1;else if(l&&!_.value){_.value=!0;const r=y.value,d=[],C=w=>{w.forEach(b=>{d.push(b.id),b.children&&b.children.length>0&&C(b.children)})};C(r),s.dept_ids=d}else!l&&_.value?(_.value=!1,s.dept_ids=[]):e===N.value.length&&(_.value=!0,o.unshift("全选"),s.dept_ids=o);pe(()=>{})};let le=function n(e,l){const o=[];for(let r=0;r<e.length;r++)if(e[r].parent_id===l){const d={id:e[r].id,parent_id:e[r].parent_id,name:e[r].name,create_time:e[r].create_time,remark:e[r].remark,sn:e[r].sn,sort:e[r].sort,type:e[r].type,region_ids:e[r].region_ids,children:n(e,e[r].id)};o.push(d)}return o};const $=()=>{ge({page_no:1,page_size:1e3}).then(n=>{y.value=le(n,"0");const e=[],l=o=>{o.forEach(r=>{e.push(r),r.children&&r.children.length>0&&l(r.children)})};l(n),N.value=e,s.dept_ids.length===e.length&&(s.dept_ids.push("全选"),_.value=!0)})},k=n=>Array.isArray(n.children)&&n.children.length!==0,ne=n=>{M.value=!1,i.value=T(i.value,n)},E=(n,e)=>{n.children&&n.children.length&&(n.children=T(n.children,n.checked)),U(i.value),B(i.value)},T=(n,e)=>{const l=[...n];return l.map(o=>{o.checked=e,o.children&&o.children.length&&(o.children=T(o.children,e))}),l},R=n=>{if(!Array.isArray(n))return!1;const e=n.length,l=n.filter(o=>o.checked).length;return l!==0&&e!==l},U=n=>{const e=n||i.value;if(!Array.isArray(e))return console.warn("permissions is not an array:",e),[];const l=[];e.forEach(d=>{l.push(d),d.children&&l.push(...U(d.children))});const o=l.length,r=l.filter(d=>d.checked).length;return I.value=o===r,M.value=r!==0&&o!==r,l},B=n=>{(n||i.value).forEach(l=>{if(l.children&&l.children.length){B(l.children),l.children.length;const o=l.children.filter(r=>r.checked).length;l.checked=!!o}})},j=m(),oe=()=>{j.value.validate(n=>{if(n){let e={...s,menus:i.value};if(!e.dept_ids){S.error("请选择数据范围!");return}e.dept_ids=e.dept_ids.filter(o=>o!=="全选"),e.dept_ids&&(_.value?(e.data_scope="ALL",e.dept_ids=e.dept_ids.join(",")):(e.data_scope="DEPT_CUSTOM",e.dept_ids=e.dept_ids.join(",")));const l=()=>{S.success("保存成功!"),J.push({name:"roleManage"})};V.value==="0"?_e(e).then(()=>l()):ve(V.value,e).then(()=>l())}else return S.error("表单填写有误,请检查!"),!1})},z=()=>{me().then(n=>{V.value!=="0"?fe(V.value).then(e=>{const l=G(e.menus);i.value=O(n,l),Array.isArray(i.value)?U():console.warn("Invalid permissions data:",i.value),$()}):(i.value=n,Array.isArray(i.value)?U():console.warn("Invalid permissions data:",i.value),$())})},G=n=>{const e=[];return n.forEach(l=>{l.checked&&e.push(l.identifier),l.children&&l.children.length&&e.push(...G(l.children))}),e},O=(n,e)=>{const l=[];return n.forEach(o=>{e.includes(o.identifier)||o.hidden?o.checked=!0:o.checked=!1,o.children&&(o.children=O(o.children,e)),l.push(o)}),l};return de(()=>{z()}),ce(()=>x.query.id,()=>{V.value=x.query.id,z()}),(n,e)=>{const l=g("el-input"),o=g("el-form-item"),r=g("el-cascader"),d=g("el-checkbox"),C=g("el-col"),w=g("el-popover"),b=g("el-row"),re=g("el-button"),te=g("el-form");return f(),h("div",ke,[t(te,{model:s,rules:W,ref_key:"permissionFormRef",ref:j,"label-width":"200px",class:"demo-ruleForm"},{default:a(()=>[t(o,{label:"角色名称",prop:"role_name"},{default:a(()=>[t(l,{modelValue:s.role_name,"onUpdate:modelValue":e[0]||(e[0]=c=>s.role_name=c)},null,8,["modelValue"])]),_:1}),t(o,{label:"数据范围",prop:"dept_ids"},{default:a(()=>[t(r,{onVisibleChange:Y,ref:"cascader",clearable:!0,modelValue:s.dept_ids,"onUpdate:modelValue":e[1]||(e[1]=c=>s.dept_ids=c),options:y.value,onChange:ee,props:Q},null,8,["modelValue","options"])]),_:1}),t(o,{label:"角色描述",prop:"role_describe"},{default:a(()=>[t(l,{modelValue:s.role_describe,"onUpdate:modelValue":e[2]||(e[2]=c=>s.role_describe=c)},null,8,["modelValue"])]),_:1}),t(o,{label:"角色权限",prop:"permission"},{default:a(()=>[t(d,{indeterminate:M.value,modelValue:I.value,"onUpdate:modelValue":e[3]||(e[3]=c=>I.value=c),onChange:ne},{default:a(()=>[A("全部选择")]),_:1},8,["indeterminate","modelValue"]),(f(!0),h(L,null,P(i.value,c=>(f(),h("div",{key:c.identifier,class:"level_1"},[t(b,{gutter:20},{default:a(()=>[t(C,{span:4},{default:a(()=>[t(d,{modelValue:c.checked,"onUpdate:modelValue":u=>c.checked=u,label:c.title,indeterminate:R(c.children),onChange:u=>E(c,"")},null,8,["modelValue","onUpdate:modelValue","label","indeterminate","onChange"])]),_:2},1024),t(C,{span:20},{default:a(()=>[(f(!0),h(L,null,P(c.children,u=>(f(),h("div",{key:u.identifier,class:"checkbox-dropdown"},[t(w,{placement:"bottom",trigger:"hover","open-delay":300,disabled:!k(u),"append-to-body":!1},{reference:a(()=>[t(d,{modelValue:u.checked,"onUpdate:modelValue":p=>u.checked=p,indeterminate:R(u.children),onClick:e[4]||(e[4]=q(()=>{},["stop"])),onChange:p=>E(u,c)},{default:a(()=>[A(F(u.title)+" ",1),k(u)?(f(),h("i",be)):D("",!0)]),_:2},1032,["modelValue","onUpdate:modelValue","indeterminate","onChange"])]),default:a(()=>[k(u)?(f(),h("div",ye,[(f(!0),h(L,null,P(u.children,p=>(f(),h("div",{class:"role-dropdown",key:p.identifier},[t(w,{placement:"right",trigger:"hover","open-delay":200,disabled:!k(p),"append-to-body":!1},{reference:a(()=>[Z("div",Ve,[t(d,{modelValue:p.checked,"onUpdate:modelValue":v=>p.checked=v,indeterminate:R(p.children),onClick:e[5]||(e[5]=q(()=>{},["stop"])),onChange:v=>E(p,u)},{default:a(()=>[A(F(p.title)+" ",1),k(p)?(f(),h("i",Ce)):D("",!0)]),_:2},1032,["modelValue","onUpdate:modelValue","indeterminate","onChange"])])]),default:a(()=>[k(p)?(f(),h("div",we,[(f(!0),h(L,null,P(p.children,(v,ae)=>(f(),h("div",{class:"role-dropdown",key:ae},[t(w,{placement:"right",trigger:"hover","open-delay":200,disabled:!k(v),"append-to-body":!1},{reference:a(()=>[Z("div",Ae,[t(d,{modelValue:v.checked,"onUpdate:modelValue":H=>v.checked=H,indeterminate:R(v.children),onClick:e[6]||(e[6]=q(()=>{},["stop"])),onChange:H=>E(v,p)},{default:a(()=>[A(F(v.title),1)]),_:2},1032,["modelValue","onUpdate:modelValue","indeterminate","onChange"])])]),_:2},1032,["disabled"])]))),128))])):D("",!0)]),_:2},1032,["disabled"])]))),128))])):D("",!0)]),_:2},1032,["disabled"])]))),128))]),_:2},1024)]),_:2},1024)]))),128))]),_:1}),t(o,{label:""},{default:a(()=>[t(re,{type:"primary",size:"small",style:{"margin-top":"15px"},onClick:oe},{default:a(()=>[A("保存设置")]),_:1})]),_:1})]),_:1},8,["model","rules"])])}}}),De=he(xe,[["__scopeId","data-v-48e0d71f"]]);export{De as default};