Skip to content

Commit 8ffe80c

Browse files
committed
#add 权限管理 35%
1 parent 4968f28 commit 8ffe80c

File tree

16 files changed

+863
-201
lines changed

16 files changed

+863
-201
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = {
6666
'no-caller': 'error',
6767

6868
// disallow empty functions
69-
'no-empty-function': 'error',
69+
//'no-empty-function': 'error',
7070

7171
// disallow unnecessary calls to .bind()
7272
'no-extra-bind': 'error',

config/dev.env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
NODE_ENV: '"development"',
3-
BASE_API: '"https://api-dev"',
3+
BASE_API: '"http://localhost:9527/api"',
44
APP_ORIGIN: '"https://wallstreetcn.com"'
55
}

src/api/permission.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Created by linxiaojie on 2017/8/8.
3+
*/
4+
import fetch from '../utils/fetch_new'
5+
import { cleanArray } from '../utils'
6+
7+
/*
8+
* 获取列表
9+
* */
10+
export const getAll = (query) => {
11+
return fetch({
12+
url: '/permissions',
13+
method: 'get',
14+
params: query
15+
})
16+
}
17+
18+
/*
19+
* 查询详情
20+
* */
21+
export const getDetail = (id) => {
22+
return fetch({
23+
url: '/permissions/' + id,
24+
method: 'get'
25+
})
26+
}
27+
28+
/*
29+
* 更新详情
30+
* */
31+
export const updateDetail = (data = { _id: '' }) => {
32+
if (data._id === '') {
33+
return Promise.reject('id不能为空')
34+
}
35+
return fetch({
36+
url: 'permissions/' + data._id,
37+
method: 'put',
38+
data
39+
})
40+
}
41+
42+
/*
43+
* 删除数据
44+
* */
45+
export const batch = (ids = [], data = null) => {
46+
ids = cleanArray(ids)
47+
if (ids.length === 0) {
48+
return Promise.reject('ids不能为空')
49+
}
50+
const url = 'permissions/batch/' + ids.join(',')
51+
return fetch({
52+
url,
53+
method: 'put',
54+
data
55+
})
56+
}
57+
58+
59+
/*
60+
* 新增
61+
* */
62+
export const create = (data) => {
63+
const url = 'permissions/'
64+
return fetch({
65+
url,
66+
method: 'post',
67+
data
68+
})
69+
}

src/api/role.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,41 @@ export const getDetail = (id) => {
2828
/*
2929
* 更新详情
3030
* */
31-
export const updateDetail = (data = { id: '' }) => {
32-
if (data.id === '') {
31+
export const updateDetail = (data = { _id: '' }) => {
32+
if (data._id === '') {
3333
return Promise.reject('id不能为空')
3434
}
3535
return fetch({
36-
url: 'roles/' + data.id,
37-
method: 'post',
36+
url: 'roles/' + data._id,
37+
method: 'put',
3838
data
3939
})
4040
}
4141

4242
/*
43-
* 删除数据
43+
* 批量操作数据
4444
* */
45-
export const del = (ids = []) => {
45+
export const batch = (ids = [], data = null) => {
4646
ids = cleanArray(ids)
4747
if (ids.length === 0) {
4848
return Promise.reject('ids不能为空')
4949
}
50-
const url = 'roles/' + (ids.length > 1 ? '/batch/' + ids.join(',') : ids[0]) + id
50+
const url = 'roles/batch/' + ids.join(',')
51+
return fetch({
52+
url,
53+
method: 'put',
54+
data
55+
})
56+
}
57+
58+
/*
59+
* 新增
60+
* */
61+
export const create = (data) => {
62+
const url = 'roles/'
5163
return fetch({
5264
url,
5365
method: 'post',
5466
data
5567
})
56-
}
68+
}

src/router/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import Vue from 'vue';
2-
import Router from 'vue-router';
3-
const _import = require('./_import_' + process.env.NODE_ENV);
1+
import Vue from 'vue'
2+
import Router from 'vue-router'
3+
const _import = require('./_import_' + process.env.NODE_ENV)
44
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading
55

6-
Vue.use(Router);
6+
Vue.use(Router)
77

88
/* layout */
9-
import Layout from '../views/layout/Layout';
9+
import Layout from '../views/layout/Layout'
1010

1111
/* view */
1212
import Login from '../views/login'
1313
import Role from '../views/role'
14+
import Permission from '../views/permission'
15+
1416
/**
1517
* icon : the icon show in the sidebar
1618
* hidden : if `hidden:true` will not show in the sidebar
@@ -45,7 +47,7 @@ export default new Router({
4547
// mode: 'history', //后端支持可开
4648
scrollBehavior: () => ({ y: 0 }),
4749
routes: constantRouterMap
48-
});
50+
})
4951

5052
export const asyncRouterMap = [
5153
{
@@ -56,7 +58,8 @@ export const asyncRouterMap = [
5658
icon: 'quanxian',
5759
// meta: { role: ['admin'] },
5860
children: [
59-
{ path: 'roles', component: Role, name: '角色管理' }
61+
{ path: 'roles', component: Role, name: '角色管理' },
62+
{ path: 'permissions', component: Permission, name: '权限管理' }
6063
]
6164
},
6265
{
@@ -162,4 +165,4 @@ export const asyncRouterMap = [
162165
},
163166

164167
{ path: '*', redirect: '/404', hidden: true }
165-
];
168+
]

src/store/getters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const getters = {
1010
setting: state => state.user.setting,
1111
permission_routers: state => state.permission.routers,
1212
addRouters: state => state.permission.addRouters,
13-
crpRoles: state => state.role
13+
crpRoles: state => state.role,
14+
crpPermissions: state => state.permission
1415
};
1516
export default getters

src/store/modules/permission.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { asyncRouterMap, constantRouterMap } from 'src/router'
2+
import { each, has } from '../../utils'
3+
import { getAll, getDetail, updateDetail, batch, create } from '../../api/permission'
4+
import * as TYPES from '../types'
25

36
/**
47
* 通过meta.role判断是否与当前用户权限匹配
@@ -34,12 +37,35 @@ function filterAsyncRouter(asyncRouterMap, roles) {
3437
const permission = {
3538
state: {
3639
routers: constantRouterMap,
37-
addRouters: []
40+
addRouters: [],
41+
records: [],
42+
pageInfo: {
43+
currentPage: 1,
44+
totalRow: 0,
45+
totalPage: 0
46+
}
3847
},
3948
mutations: {
4049
SET_ROUTERS: (state, routers) => {
4150
state.addRouters = routers
4251
state.routers = constantRouterMap.concat(routers)
52+
},
53+
[TYPES.SET_PERMISSIONS_LIST] (state, data) {
54+
each(data, (val, key) => {
55+
if (has(state, key)) {
56+
state[key] = val
57+
}
58+
})
59+
},
60+
[TYPES.SET_PERMISSIONS_SELECTED] (state, item) {
61+
each(item, (val, key) => {
62+
if (state.current.has(key)) {
63+
state.current[key] = val
64+
}
65+
})
66+
},
67+
[TYPES.SET_PERMISSIONS_PERMISSIONS] (state, permissions) {
68+
state.current.permissions = permissions
4369
}
4470
},
4571
actions: {
@@ -55,6 +81,51 @@ const permission = {
5581
commit('SET_ROUTERS', accessedRouters);
5682
resolve();
5783
})
84+
},
85+
GetAllPermissions ({ commit }, query) {
86+
return new Promise((resolve, reject) => {
87+
getAll(query).then(({ data }) => {
88+
commit(TYPES.SET_PERMISSIONS_LIST, data)
89+
resolve()
90+
}).catch(error => {
91+
reject(error)
92+
})
93+
})
94+
},
95+
GetPermissionDetail ({ commit }, id) {
96+
return new Promise((resolve, reject) => {
97+
getDetail(id).then(({ data: { permission } }) => {
98+
resolve(permission)
99+
}).catch(error => {
100+
reject(error)
101+
})
102+
})
103+
},
104+
UpdatePermissionDetail ({ commit, state }, detail) {
105+
return new Promise((resolve, reject) => {
106+
updateDetail(detail).then(() => resolve()).catch(error => {
107+
reject(error)
108+
})
109+
})
110+
},
111+
DelPermissions ({ dispatch }, { ids, data }) {
112+
return new Promise((resolve, reject) => {
113+
batch(ids, data).then(() => {
114+
dispatch('GetAllPermissions').then(resolve, reject)
115+
resolve()
116+
}).catch(error => {
117+
reject(error)
118+
})
119+
})
120+
},
121+
CreatePermission (store, detail) {
122+
return new Promise((resolve, reject) => {
123+
create(detail).then(() => {
124+
resolve()
125+
}).catch(error => {
126+
reject(error)
127+
})
128+
})
58129
}
59130
}
60131
};

src/store/modules/role.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { each, has } from '../../utils'
55
import * as TYPES from '../types'
6-
import { getAll, getDetail, updateDetail, del } from '../../api/role'
6+
import { getAll, getDetail, updateDetail, batch, create } from '../../api/role'
77

88
const role = {
99
state: {
@@ -12,13 +12,6 @@ const role = {
1212
currentPage: 1,
1313
totalRow: 0,
1414
totalPage: 0
15-
},
16-
current: {
17-
_id: '',
18-
name: '',
19-
description: '',
20-
status: '',
21-
permissions: []
2215
}
2316
},
2417
mutations: {
@@ -44,40 +37,48 @@ const role = {
4437
GetAllRoles ({ commit }, query) {
4538
return new Promise((resolve, reject) => {
4639
getAll(query).then(({ data }) => {
47-
commit(TYPES.SET_ROLES_LIST, data);
48-
resolve();
40+
commit(TYPES.SET_ROLES_LIST, data)
41+
resolve()
4942
}).catch(error => {
50-
reject(error);
51-
});
52-
});
43+
reject(error)
44+
})
45+
})
5346
},
5447
GetRoleDetail ({ commit }, id) {
5548
return new Promise((resolve, reject) => {
5649
getDetail(id).then(({ data: { role } }) => {
57-
commit(TYPES.SET_ROLES_SELECTED, role);
58-
resolve();
50+
resolve(role)
5951
}).catch(error => {
60-
reject(error);
61-
});
62-
});
52+
reject(error)
53+
})
54+
})
6355
},
64-
UpdateRoleDetail ({ commit, state }, id, detail) {
56+
UpdateRoleDetail ({ commit, state }, detail) {
6557
return new Promise((resolve, reject) => {
6658
updateDetail(detail).then(() => resolve()).catch(error => {
67-
reject(error);
68-
});
69-
});
59+
reject(error)
60+
})
61+
})
7062
},
71-
DelRoles ({ dispatch }, ids) {
63+
DelRoles ({ dispatch }, {ids, data}) {
7264
return new Promise((resolve, reject) => {
73-
del(ids).then(() => {
74-
dispatch('GetAllRoles').then(resolve, reject)
65+
batch(ids, data).then(() => {
66+
resolve()
7567
}).catch(error => {
76-
reject(error);
77-
});
78-
});
68+
reject(error)
69+
})
70+
})
71+
},
72+
CreateRole (store, detail) {
73+
return new Promise((resolve, reject) => {
74+
create(detail).then(() => {
75+
resolve()
76+
}).catch(error => {
77+
reject(error)
78+
})
79+
})
7980
}
8081
}
8182
}
8283

83-
export default role
84+
export default role

src/store/types.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ export const LOGOUT_USER = 'LOGOUT_USER'
2121
* */
2222
export const SET_ROLES_LIST = 'SET_ROLES_LIST'
2323
export const SET_ROLES_SELECTED = 'SET_ROLES_SELECTED'
24-
export const SET_ROLES_PERMISSIONS = 'SET_ROLE_PERMISSIONS'
24+
export const SET_ROLES_PERMISSIONS = 'SET_ROLE_PERMISSIONS'
25+
26+
/*
27+
* 权限管理
28+
* */
29+
export const SET_PERMISSIONS_LIST = 'SET_PERMISSIONS_LIST'
30+
export const SET_PERMISSIONS_SELECTED = 'SET_PERMISSIONS_SELECTED'
31+
export const SET_PERMISSIONS_PERMISSIONS = 'SET_PERMISSION_PERMISSIONS'

0 commit comments

Comments
 (0)