antd許可權管理 ANTDPRO許可權如何設定?

2021-10-12 15:02:20 字數 964 閱讀 2327

腳手架預設有乙個使用localstorage的demo。位於src/utils/authority.js中有getauthority與setauthority方法。setauthority方法會在使用者進行登入時觸發。具體流程為:login頁面輸入使用者名稱密碼->dispatchuserlogin/login->呼叫登入介面拿到返回值(其中包含使用者許可權資訊)->dispatchuserlogin/changeloginstatus且進行重定向跳轉到登陸後的頁面->setauthority(user_authority)。該方法只是簡單的將使用者許可權寫入到localstorage裡面,一般不會用作生產環境。而重定向會先判斷是否有redirectiveurl,有則跳轉至該url,無則跳轉至主頁。此時basiclayout還會獲取當前使用者的資訊,同時獲取路由資訊並在路由陣列中使用map+authorized.check方法進行許可權判斷,返回合法路由。而authorized實際上位於utils/authorized.js,其中的定義為letauthorized=renderauthorize(getauthority())。而renderauthorize實際上是定義為renderauthorize(authorized),該函式又接受了getauthority()的返回值,即當前使用者存放於localstorage的許可權資訊,並返回乙個authorized,該物件有若干方法,上文提到的check方法也在其中,用於許可權判斷。

check方法定義於/src/components/authorized/checkpermissions.jsx。該方法會接受單個路由資訊的許可權資訊,路由對應的元件資訊,exception資訊,checkpermissions方法自帶current引數用於引入當前使用者的許可權資訊,該引數來自renderauthorize,即上文提及的呼叫getauthority方法所在的函式定義中,處理使用者許可權資訊時將其儲存與current變數中並暴露出去。

回到basiclayout元件的路由許可權判斷中,menudatarender產出了合法路由資訊並進行渲染。

antd pro框架使用者許可權的簡單配置和使用

這裡只介紹antd pro框架authorized的最簡單的使用 高階些的用法參考以下文章 ant design pro 鑑權 許可權管理 ant design pro 配置動態選單 許可權 對許可權的寫入 一般來說,我們對於許可權的寫入都是在登入成功之後進行呼叫 所以現在登入頁面匯入setauth...

Antd開發後台管理筆記一

安裝antdyarn add antd axios設定antd 按需載入,需要安裝依賴庫 yarn add babel plugin import安裝狀態管理工具redux和除錯工具 yarn add redux react redux redux thunk除錯工具安裝比較麻煩文件在github的...

許可權管理 chattr許可權

1 chattr 許可權 對包括root在內的所有使用者都起作用 新增chattr許可權 chattr i abc 檢視chattr許可權 lsattr abc 取消chattr許可權 chattr i abc i 針對檔案 則完全不能修改該檔案,針對目錄 只能修改目錄下檔案的資料,但不允許建立和刪...