From a15d669a8b84e23bf0b1ed56b32ec6ccd3220113 Mon Sep 17 00:00:00 2001 From: zhangyanpeng <bob.zhang@highdatas.com> Date: 星期三, 22 一月 2020 11:13:48 +0800 Subject: [PATCH] 角色设置 --- src/views/Home.vue | 69 ++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index 7ae0bac..0befde0 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -43,6 +43,7 @@ <el-header style="text-align: right; font-size: 15px;padding-right: 40px;"> <i class="el-icon-user-solid"></i> <span>admin</span> + <el-button size="small" type="primary" @click="Cancel">閫� 鍑�</el-button> </el-header> <el-main style="background-color: #f7f8f9;"> @@ -86,16 +87,84 @@ }, created() { let userId_ = localStorage.getItem('userId'); + let userType = localStorage.getItem('userType'); if (!userId_) { this.$router.push('/login'); } else { this.defaultActive = "mine"; this.$router.push('/mine'); + + this.getMenu(userType); } }, methods: { + getMenu(userType) { + let DayDatas = { + all: [ + {'id': "110", 'title': "棣栭〉", 'path': "mine"}, //杩斿洖鐨勬暟缁勫瓧娈� + {'id': "111", 'title': "椤圭洰绠$悊", 'path': "0_111"}, //杩斿洖鐨勬暟缁勫瓧娈� + {'id': "112", 'title': "浠诲姟绠$悊", 'path': "0_112"}, + {'id': "111_1", 'title': "淇℃伅骞垮満", 'path': 'project2', 'parentId': "111"}, // + {'id': "111_2", 'title': "椤圭洰鎬昏", 'path': 'Overview', 'parentId': "111"}, // + {'id': "111_3", 'title': "椤圭洰鍒嗘瀽", 'path': 'project3', 'parentId': "111"}, // + {'id': "111_4", 'title': "褰掓。鎶ュ憡", 'path': 'project4', 'parentId': "111"}, // + {'id': "112_1", 'title': "浠诲姟鍒楄〃", 'path': 'calendarTask', 'parentId': "112"}, // + ], + role1: [ + {'id': "110", 'title': "棣栭〉", 'path': "mine"}, //杩斿洖鐨勬暟缁勫瓧娈� + {'id': "111", 'title': "椤圭洰绠$悊", 'path': "0_111"}, //杩斿洖鐨勬暟缁勫瓧娈� + {'id': "111_1", 'title': "淇℃伅骞垮満", 'path': 'project2', 'parentId': "111"}, // + {'id': "111_2", 'title': "椤圭洰鎬昏", 'path': 'Overview', 'parentId': "111"}, // + {'id': "111_3", 'title': "椤圭洰鍒嗘瀽", 'path': 'project3', 'parentId': "111"}, // + {'id': "111_4", 'title': "褰掓。鎶ュ憡", 'path': 'project4', 'parentId': "111"}, // + ], + role2: [ + {'id': "110", 'title': "棣栭〉", 'path': "mine"}, //杩斿洖鐨勬暟缁勫瓧娈� + {'id': "112", 'title': "浠诲姟绠$悊", 'path': "0_112"}, + {'id': "112_1", 'title': "浠诲姟鍒楄〃", 'path': 'calendarTask', 'parentId': "112"}, // + ], + }; + + let list = []; + if (!userType) { + list = DayDatas['all']; + } + else { + list = DayDatas[userType]; + } + + let parId = ""; + let obj = {}; + let result = []; + + list.map(el => { + obj[el.id] = el; + }) + for(let i=0, len = list.length; i < len; i++) { + let id = list[i].parentId; + //璁剧疆鏄剧ず瀛楁 + list[i].title = list[i].title; + if(id == parId || !id) { + if(!obj[list[i].id].children) { + obj[list[i].id].children = []; + } + result.push(list[i]); + continue; + } + if(obj[id].children) { + obj[id].children.push(list[i]); + } else { + obj[id].children = [list[i]]; + } + } + this.navList = result; + }, + + Cancel() { + this.$router.push('/login'); + }, menuSelect(index, a){ let isPage = index.substring(0,2); if (isPage != "0_") { -- Gitblit v1.8.0