Vue?element實(shí)現(xiàn)權(quán)限管理業(yè)務(wù)流程詳解
添加 編輯 刪除 角色 都與上一篇 用戶類似 只是接口不同
我們只關(guān)注其他不一樣的:
展開(kāi)渲染標(biāo)簽編輯權(quán)限
el-table-column type="expand"設(shè)置了expand
則顯示為一個(gè)可展開(kāi)的按鈕
顯示圖上的效果 使用了 三重for循環(huán) 按照 tree 數(shù)據(jù)結(jié)構(gòu) .children 取得下一級(jí)數(shù)據(jù)
<el-table-column type="expand"> <template slot-scope="scope"> <el-row v-for="(rights1,index) in scope.row.children" class="vertical" :key="index"> <el-col :span="5"> <el-tag class="tag1" disable-transitions closable @close="remRight(scope.row,rights1.id)"> {{rights1.authName}} </el-tag> <i class="el-icon-caret-right"></i> </el-col> <el-col :span="19"> <el-row v-for="(rights2,index2) in rights1.children" class="vertical" :key="index2"> <el-col :span="6"> <el-tag class="tag2" type="success" disable-transitions closable @close="remRight(scope.row,rights2.id)"> {{rights2.authName}} </el-tag> <i class="el-icon-caret-right"></i> </el-col> <el-col :span="18"> <el-tag class="tag3" type="warning" v-for="(rights3,index3) in rights2.children" disable-transitions :key="index3" closable @close="remRight(scope.row,rights3.id)"> {{rights3.authName}} </el-tag> </el-col> </el-row> </el-col> </el-row> pre 標(biāo)簽 整齊的排列 文本 代碼 <!-- <pre>--> <!-- {{scope.row.children}}--> <!-- </pre>--> </template> </el-table-column>
// 關(guān)閉下拉的權(quán)限標(biāo)簽 事件 async remRight(role,rightId){ //彈窗詢問(wèn)用戶是否刪除數(shù)據(jù) const confirmResult = await this.$queding( '確定要為該角色刪除此權(quán)限嗎?', '提示', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning' } ).catch(err => err) // 如果用戶確認(rèn)刪除,則返回值為字符串 confirm // 如果用戶取消刪除,則返回值為字符串 cancel // console.log(confirmResult) if (confirmResult !== 'confirm'){ return this.$Msg.info('已取消刪除') } const {data:res} = await this.$http.delete(`roles/${role.id}/rights/${rightId}`) if (res.meta.status !== 200) return this.$Msg.error('刪除此權(quán)限失?。?) this.$Msg.success('刪除用戶成功!') // 參數(shù)不直接引用role.id 為了給 role.children 重新賦值 動(dòng)態(tài)更新 不用刷新頁(yè)面 再展開(kāi)查看 // 返回的data, 是當(dāng)前角色下最新的權(quán)限數(shù)據(jù) role.children = res.data },
對(duì)話框內(nèi)樹(shù)形組件編輯權(quán)限
顯示樹(shù)形組件的對(duì)話框:
<!-- 編輯角色權(quán)限的對(duì)話框--> <el-dialog title="修改角色權(quán)限" :visible.sync="editNPCRightBox" @close="ERNPCClose" width="45%"> <!-- 樹(shù)形控件組件--> <el-tree 展示數(shù)據(jù)源 :data="RightList" 適用于需要選擇層級(jí)時(shí)使用 show-checkbox 每個(gè)樹(shù)節(jié)點(diǎn)用來(lái)作為唯一標(biāo)識(shí)的屬性,整棵樹(shù)應(yīng)該是唯一的 node-key="id" ref="PushRoleRef" 默認(rèn)全部展開(kāi) default-expand-all 默認(rèn)勾選的節(jié)點(diǎn)的 key 的數(shù)組 :default-checked-keys="defKeys" 配置選項(xiàng) :props="treeProps"> </el-tree> <span slot="footer" class="dialog-footer"> <el-button type="primary" @click="ToEditRightNPC">確 定</el-button> <el-button @click="editNPCRightBox = false">取 消</el-button> </span> </el-dialog> <script> editNPCRightBox:false, RightList:null, // 樹(shù)形配置 根據(jù)哪一個(gè)來(lái)渲染 名字和children屬性 treeProps:{ label:'authName',// 看到的是哪一個(gè)屬性 children:'children'// 父子嵌套的關(guān)系 }, defKeys:[], // 點(diǎn)擊編輯權(quán)限按鈕時(shí) 記錄當(dāng)前ID 供應(yīng)其他方法使用 PushRolesId:null </script>
點(diǎn)擊編輯權(quán)限按鈕 先把要展示的數(shù)據(jù)源 RightList 再使用遞歸把擁有權(quán)限的id push到 defKeys里 之后顯示對(duì)話框
// 點(diǎn)擊表單內(nèi)的編輯按鈕 async editNPCRightBoxShow(role){ this.PushRolesId = role.id const {data:res} = await this.$http.get('rights/tree') if (res.meta.status !==200) return this.$Msg.error('獲取權(quán)限列表失敗') this.RightList = res.data //console.log(role) await this.getThreeKeys(role,this.defKeys) this.editNPCRightBox = true }, // 通過(guò)遞歸的方式 獲取角色下所有的三級(jí)權(quán)限的id 并保存到defKeys 數(shù)組中 getThreeKeys(node,arr){ // 如果當(dāng)前節(jié)點(diǎn)不包含 children 那么他就是三級(jí)節(jié)點(diǎn) if(!node.children){ return arr.push(node.id) } node.children.forEach(item =>{ this.getThreeKeys(item,arr) }) },
點(diǎn)擊體檢按鈕時(shí) 通過(guò)ref調(diào)用
getCheckedKeys(返回目前被選中的節(jié)點(diǎn)所組成的數(shù)組)
getHalfCheckedKeys (返回目前半選中的節(jié)點(diǎn)的 key 所組成的數(shù)組)
把他倆合并 并轉(zhuǎn)成字符串 按照接口約定 向服務(wù)器發(fā)送請(qǐng)求
// 編輯角色權(quán)限的對(duì)話框 內(nèi)的確定按鈕 發(fā)送請(qǐng)求 async ToEditRightNPC(){ const prams = [ ...this.$refs.PushRoleRef.getCheckedKeys(), ...this.$refs.PushRoleRef.getHalfCheckedKeys() ] const xxx = prams.join(',') //console.log(prams) const {data:res} = await this.$http.post(`roles/${this.PushRolesId}/rights`,{rids:xxx}) if (res.meta.status !==200) return this.$Msg.error('為此角色修改權(quán)限失敗') await this.getNPCList() this.editNPCRightBox = false this.$Msg.success('修改角色權(quán)限成功') }, // 編輯角色權(quán)限的對(duì)話框被關(guān)閉時(shí) 清空默認(rèn)選中的值 防止打開(kāi)時(shí)id 重復(fù) ERNPCClose(){ this.defKeys = [] }
展示所有權(quán)限
很簡(jiǎn)單 就是請(qǐng)求數(shù)據(jù) 表格渲染
<template> <div> <!-- 面包屑導(dǎo)航--> <el-breadcrumb separator-class="el-icon-arrow-right"> <el-breadcrumb-item :to="{ path: '/home' }" >首頁(yè)</el-breadcrumb-item> <el-breadcrumb-item>權(quán)限管理</el-breadcrumb-item> <el-breadcrumb-item>權(quán)限列表</el-breadcrumb-item> </el-breadcrumb> <!--卡片區(qū)域--> <el-card> <el-table :data="RightsList" style="width: 100%" stripe border> <el-table-column type="index" label="#"></el-table-column> <el-table-column prop="authName" label="權(quán)限名稱"></el-table-column> <el-table-column prop="path" label="路徑"></el-table-column> <el-table-column label="權(quán)限等級(jí)"> <template slot-scope="scope"> <el-tag v-if="scope.row.level == 0">一級(jí)</el-tag> <el-tag v-else-if="scope.row.level == 1" type="success">二級(jí)</el-tag> <el-tag v-else type="warning">三級(jí)</el-tag> </template> </el-table-column> </el-table> </el-card> </div> </template> <script> export default { name: 'Rights-content', created() { this.getRightsList() }, data(){ return{ RightsList:null } }, methods:{ async getRightsList(){ const {data:res} = await this.$http.get('rights/list') if (res.meta.status !==200) return this.$Msg.error('獲取權(quán)限列表失敗') this.RightsList = res.data } } } </script>
到此這篇關(guān)于Vue element實(shí)現(xiàn)權(quán)限管理業(yè)務(wù)流程詳解的文章就介紹到這了,更多相關(guān)Vue element權(quán)限管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue中實(shí)現(xiàn)權(quán)限管理詳解
- vue登錄路由權(quán)限管理的項(xiàng)目實(shí)踐
- vue實(shí)現(xiàn)前端按鈕組件權(quán)限管理
- 深入解析vue中的權(quán)限管理
- vue?router權(quán)限管理實(shí)現(xiàn)不同角色顯示不同路由
- 淺談vue權(quán)限管理實(shí)現(xiàn)及流程
- Vue 指令實(shí)現(xiàn)按鈕級(jí)別權(quán)限管理功能
- vue權(quán)限管理系統(tǒng)的實(shí)現(xiàn)代碼
- 關(guān)于Vue的路由權(quán)限管理的示例代碼
- vue 權(quán)限管理幾種實(shí)現(xiàn)方法
相關(guān)文章
VueJS組件之間通過(guò)props交互及驗(yàn)證的方式
本篇文章主要介紹了VueJS組件之間通過(guò)props交互及驗(yàn)證的方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-09-09100行代碼理解和分析vue2.0響應(yīng)式架構(gòu)
通過(guò)100行代碼幫助大家理解和分析vue2.0響應(yīng)式架構(gòu)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03解決vue-cli單頁(yè)面手機(jī)應(yīng)用input點(diǎn)擊手機(jī)端虛擬鍵盤彈出蓋住input問(wèn)題
今天小編就為大家分享一篇解決vue-cli單頁(yè)面手機(jī)應(yīng)用input點(diǎn)擊手機(jī)端虛擬鍵盤彈出蓋住input問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Vue中如何對(duì)ElementUI的Dialog組件封裝
這篇文章主要介紹了Vue中如何對(duì)ElementUI的Dialog組件封裝問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03vue深度監(jiān)聽(tīng)(監(jiān)聽(tīng)對(duì)象和數(shù)組的改變)與立即執(zhí)行監(jiān)聽(tīng)實(shí)例
這篇文章主要介紹了vue深度監(jiān)聽(tīng)(監(jiān)聽(tīng)對(duì)象和數(shù)組的改變)與立即執(zhí)行監(jiān)聽(tīng)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09Vue中從template到j(luò)sx語(yǔ)法教程示例
這篇文章主要為大家介紹了Vue中從template到j(luò)sx語(yǔ)法教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10webpack項(xiàng)目中使用vite加速的兼容模式詳解
這篇文章主要為大家介紹了webpack項(xiàng)目中使用vite加速的兼容模式示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07Vue+Element一步步實(shí)現(xiàn)動(dòng)態(tài)添加Input_輸入框案例
這篇文章主要介紹了Vue+Element一步步實(shí)現(xiàn)動(dòng)態(tài)添加Input_輸入框案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09