权限控制

master
Caps 6 years ago
parent b8f0ac37bb
commit 706a1fd627

@ -65,6 +65,7 @@ Vue.component('i-switch', Switch);
Vue.component('Modal', Modal); Vue.component('Modal', Modal);
Vue.component('Message', Message); Vue.component('Message', Message);
Vue.prototype.$Modal = Modal; Vue.prototype.$Modal = Modal;
Vue.prototype.$Message = Message;
Vue.component('Radio', Radio); Vue.component('Radio', Radio);
Vue.component('List', List); Vue.component('List', List);
Vue.component('Divider', Divider); Vue.component('Divider', Divider);

@ -8,18 +8,23 @@
<span>拓客营销</span> <span>拓客营销</span>
</div> </div>
<Menu :active-name="selectedItemName" theme="dark" width="auto" :class="menuitemClasses" @on-select="onSelectLister" :accordion="true"> <Menu :active-name="selectedItemName" :open-names="openName" theme="dark" width="auto"
<Submenu :name="item.id" v-for="item in menuList" :key="item.id"> :class="menuitemClasses"
@on-select="onSelectLister" :accordion="true">
<Submenu :name="item.id" v-for="item in onePermissionList" :key="item.id">
<template slot="title"> <template slot="title">
<Icon type="ios-paper" /> <Icon type="ios-paper"/>
{{item.name}} {{item.name}}
</template> </template>
<MenuItem :name="cItem.id" :to="cItem.url" v-for="cItem in item.subMenuList" :key="cItem.id">{{cItem.name}}</MenuItem> <MenuItem :name="cItem.id" :to="cItem.resource" v-for="cItem in item.subMenuList"
:key="cItem.id">
{{cItem.name}}
</MenuItem>
</Submenu> </Submenu>
</Menu> </Menu>
</Sider> </Sider>
<Layout> <Layout>
<!-- <Header :style="{background: '#fff', boxShadow: '0 2px 3px 2px rgba(0,0,0,.1)'}"></Header>--> <!-- <Header :style="{background: '#fff', boxShadow: '0 2px 3px 2px rgba(0,0,0,.1)'}"></Header>-->
<Content :style="{padding: '0 16px 16px'}"> <Content :style="{padding: '0 16px 16px'}">
<Breadcrumb :style="{margin: '16px 0'}"> <Breadcrumb :style="{margin: '16px 0'}">
<BreadcrumbItem>{{selectedMenu}}</BreadcrumbItem> <BreadcrumbItem>{{selectedMenu}}</BreadcrumbItem>
@ -36,89 +41,48 @@
</div> </div>
</template> </template>
<script> <script>
export default { import homeRequest from "../services/home/homeRequest";
provide(){
return{ export default {
checkParamBlank:this.checkParamBlank, provide() {
return {
checkParamBlank: this.checkParamBlank,
}; };
}, },
data() { data() {
return { return {
isCollapsed: false, isCollapsed: false,
mHeight: 600, mHeight: 600,
selectedItemName: '', selectedItemName: 0,
openName: [],
selectedMenu: '', selectedMenu: '',
selectedSubMenu: '', selectedSubMenu: '',
menuList: [ //
{ onePermissionLevel: 1,
id: 1, twoPermissionLevel: 2,
'name': '设置管理', threePermissionLevel: 3,
'url': 'setting', //-1
subMenuList: [ onePermissionList: [],
{ //2
'id': 2, twoPermissionList: [],
'name': '账户管理', //3
'url': '/account/manager' threePermissionList: [],
},
{
'id': 3,
'name': '角色管理',
'url': '/role/manager'
}
]
},
{
id: 4,
'name': '门店推广',
'url': 'shop',
subMenuList: [
{
'id': 5,
'name': '推广管理',
'url': '/shop/increase/manager'
},
{
'id': 6,
'name': '推广数据',
'url': '/shop/increase/data'
}
]
},
{
id: 7,
'name': '数据中心',
'url': 'data',
subMenuList: [
{
'id': 8,
'name': '客户数据',
'url': '/customer/view'
},
{
'id': 9,
'name': '客户数据明细',
'url': '/customer/data/detail'
}
]
}
]
} }
}, },
created() { created() {
this.mHeight = window.screen.availHeight - 22; this.mHeight = window.screen.availHeight - 22;
this.selectedItemName = this.menuList[1].subMenuList[0].id; //
this.selectedMenu = this.menuList[1].name; this.listOnePermission(this.onePermissionLevel);
this.selectedSubMenu = this.menuList[1].subMenuList[0].name;
}, },
computed: { computed: {
rotateIcon () { rotateIcon() {
return [ return [
'menu-icon', 'menu-icon',
this.isCollapsed ? 'rotate-icon' : '' this.isCollapsed ? 'rotate-icon' : ''
]; ];
}, },
menuitemClasses () { menuitemClasses() {
return [ return [
'menu-item', 'menu-item',
this.isCollapsed ? 'collapsed-menu' : '' this.isCollapsed ? 'collapsed-menu' : ''
@ -126,9 +90,9 @@ export default {
} }
}, },
methods: { methods: {
onSelectLister (val) { onSelectLister(val) {
for (let i = 0; i < this.menuList.length; i++) { for (let i = 0; i < this.onePermissionList.length; i++) {
let item = this.menuList[i]; let item = this.onePermissionList[i];
for (let k = 0; k < item.subMenuList.length; k++) { for (let k = 0; k < item.subMenuList.length; k++) {
let cItem = item.subMenuList[k]; let cItem = item.subMenuList[k];
if (cItem.id === val) { if (cItem.id === val) {
@ -139,29 +103,148 @@ export default {
} }
}, },
// //
checkParamBlank: function(obj){ checkParamBlank: function (obj) {
for(let param in obj){ for (let param in obj) {
obj[param] = this.checkBlank(obj[param]); obj[param] = this.checkBlank(obj[param]);
} }
}, },
// //
checkBlank: function(data){ checkBlank: function (data) {
if(!data){ if (!data) {
return "--"; return "--";
}else{ } else {
return data; return data;
} }
},
//
listOnePermission(level) {
let that = this;
let userId = JSON.parse(sessionStorage.getItem("loginInfo")).userId;
let request = {
userId: userId,
level: level
};
homeRequest.listUserLoginPermissionApi(request, function (data) {
data = data.data;
if (data.code === '0001') {
that.$Message.error("查询用户权限出错");
return;
}
if (data.code === '0000') {
data = data.results;
for (let i = 0; i < data.length; i++) {
let row = data[i];
row.class = 'head-permission';
that.onePermissionList.push(row);
}
that.listTwoPermission(that.twoPermissionLevel);
}
})
},
//
listTwoPermission(level) {
let userId = JSON.parse(sessionStorage.getItem("loginInfo")).userId;
let that = this;
that.twoPermissionList = [];
let request = {
userId: userId,
level: level
};
homeRequest.listUserLoginPermissionApi(request, function (data) {
data = data.data;
if (data.code === '0001') {
that.$Message.error("查询用户权限出错");
return;
}
if (data.code === '0000') {
data = data.results;
that.twoPermissionList = [];
for (let i = 0; i < data.length; i++) {
let row = data[i];
that.twoPermissionList.push(row);
}
that.listThreePermission(that.threePermissionLevel);
}
})
},
//
listThreePermission(level) {
let userId = JSON.parse(sessionStorage.getItem("loginInfo")).userId;
let that = this;
that.threePermissionList = [];
let request = {
userId: userId,
level: level
};
homeRequest.listUserLoginPermissionApi(request, function (data) {
data = data.data;
if (data.code === '0001') {
that.$Message.error("查询用户权限出错");
return;
}
if (data.code === '0000') {
data = data.results;
that.threePermissionList = [];
for (let i = 0; i < data.length; i++) {
let row = data[i];
that.threePermissionList.push(row);
}
//
if (data && data.length > 0 && that.refreshFlag) {
let resource = '';
if (that.threePermissionList[0].resource) {
resource = that.threePermissionList[0].resource;
}
that.subMenuClick(0);
that.$router.push({path: resource});
//
that.refreshFlag = false;
}
that.twoPermissionList.forEach(function (two) {
//
let three = that.threePermissionList.filter(function (data) {
return data.pid === two.id
});
two.subMenuList = three;
});
that.onePermissionList.forEach(function (one) {
//
let two = that.twoPermissionList.filter(function (data) {
return data.pid === one.id
});
one.subMenuList = two;
})
//
that.menuInit();
}
})
},
//
menuInit: function () {
let that = this;
that.selectedItemName = that.onePermissionList[0].subMenuList[0].id;
that.openName = ['1'];
},
//-id
subMenuUnfold: function (twoPermissionId) {
},
//-
subMenuClick: function (index) {
},
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.layout-con{ .layout-con {
height: 100%; height: 100%;
width: 100%; width: 100%;
} }
.menu-item span{
.menu-item span {
display: inline-block; display: inline-block;
overflow: hidden; overflow: hidden;
width: 69px; width: 69px;
@ -170,17 +253,20 @@ export default {
vertical-align: bottom; vertical-align: bottom;
transition: width .2s ease .2s; transition: width .2s ease .2s;
} }
.menu-item i{
.menu-item i {
transform: translateX(0px); transform: translateX(0px);
transition: font-size .2s ease, transform .2s ease; transition: font-size .2s ease, transform .2s ease;
vertical-align: middle; vertical-align: middle;
font-size: 16px; font-size: 16px;
} }
.collapsed-menu span{
.collapsed-menu span {
width: 0px; width: 0px;
transition: width .2s ease; transition: width .2s ease;
} }
.collapsed-menu i{
.collapsed-menu i {
transform: translateX(5px); transform: translateX(5px);
transition: font-size .2s ease .2s, transform .2s ease .2s; transition: font-size .2s ease .2s, transform .2s ease .2s;
vertical-align: middle; vertical-align: middle;

@ -0,0 +1,24 @@
/**
* home请求数据
* @author wangyinjia
* @date 2020/2/24
*/
import http from '../CommonHttp'
/**
* 查询用户登录权限
* @param params
* @param call
* @returns {Promise<any | never>}
*/
export function listUserLoginPermissionApi(params, call) {
return http.get('/permission/user/login/list', params).then(call)
}
export default {
listUserLoginPermissionApi,
}
Loading…
Cancel
Save