diff --git a/admin-web/config/router.config.js b/admin-web/config/router.config.js index 484bb4261..fc9ef3f55 100644 --- a/admin-web/config/router.config.js +++ b/admin-web/config/router.config.js @@ -46,6 +46,11 @@ export default [ name: 'resource-list', component: './Admin/ResourceList', }, + { + path: '/admin/role-list', + name: 'role-list', + component: './Admin/RoleList', + }, ], }, { diff --git a/admin-web/mock/admin.js b/admin-web/mock/admin.js index 1945f0162..f5c359a7c 100644 --- a/admin-web/mock/admin.js +++ b/admin-web/mock/admin.js @@ -2,6 +2,7 @@ import adminMenu from './geographic/admin-menu.json'; import adminMenuAll from './geographic/admin-menu-all.json'; import adminUrls from './geographic/admin-urls'; import resourceTree from './geographic/resource-tree.json'; +import roleQuery from './geographic/role-query.json'; /* eslint-disable */ function getAdminMenu(req, res) { @@ -20,8 +21,13 @@ function getResourceTree(req, res) { return res.json(resourceTree); } +function getQueryRole(req, res) { + return res.json(roleQuery); +} + export default { 'GET /admin-api/admin/resource/admin_menu_tree': getAdminMenuAll, 'GET /admin-api/admin/resource/admin_url_list': getAdminUrls, 'GET /admin-api/admin/resource/tree': getResourceTree, + 'GET /admin-api/admin/role/page': getQueryRole, }; diff --git a/admin-web/mock/geographic/role-query.json b/admin-web/mock/geographic/role-query.json new file mode 100644 index 000000000..2dc6442d4 --- /dev/null +++ b/admin-web/mock/geographic/role-query.json @@ -0,0 +1,19 @@ +{ + "code": 0, + "data": { + "count": 2, + "roles": [ + { + "id": 1, + "name": "系统管理员", + "createTime": 1551332076000 + }, + { + "id": 2, + "name": "系统管理员", + "createTime": 1551332076000 + } + ] + }, + "message": "string" +} diff --git a/admin-web/src/locales/zh-CN/menu.js b/admin-web/src/locales/zh-CN/menu.js index 3e39dade5..1b846e53e 100644 --- a/admin-web/src/locales/zh-CN/menu.js +++ b/admin-web/src/locales/zh-CN/menu.js @@ -3,6 +3,7 @@ export default { 'menu.admin': 'Admin管理', 'menu.admin.admin-list': '管理员列表', 'menu.admin.resource-list': '资源列表', + 'menu.admin.role-list': '角色列表', 'menu.home': '首页', 'menu.login': '登录', 'menu.register': '注册', diff --git a/admin-web/src/models/resourceList.js b/admin-web/src/models/admin/resourceList.js similarity index 97% rename from admin-web/src/models/resourceList.js rename to admin-web/src/models/admin/resourceList.js index 3fc3e4596..ae83e92c0 100644 --- a/admin-web/src/models/resourceList.js +++ b/admin-web/src/models/admin/resourceList.js @@ -1,5 +1,5 @@ import { message } from 'antd'; -import { addResource, updateResource, deleteResource, resourceTree } from '@/services/resource'; +import { addResource, updateResource, deleteResource, resourceTree } from '../../services/admin'; export default { namespace: 'resourceList', diff --git a/admin-web/src/models/admin/roleList.js b/admin-web/src/models/admin/roleList.js new file mode 100644 index 000000000..591a6cf5e --- /dev/null +++ b/admin-web/src/models/admin/roleList.js @@ -0,0 +1,74 @@ +import { message } from 'antd'; +import { addRole, updateRole, deleteRole, queryRole } from '../../services/admin'; + +export default { + namespace: 'roleList', + + state: { + list: [], + count: 0, + pageNo: 0, + pageSize: 10, + }, + + effects: { + *add({ payload }, { call, put }) { + const { callback, body, queryParams } = payload; + const response = yield call(addRole, body); + if (callback) { + callback(response); + } + yield put({ + type: 'query', + payload: { + ...queryParams, + }, + }); + }, + *update({ payload }, { call, put }) { + const { callback, body, queryParams } = payload; + const response = yield call(updateRole, body); + if (callback) { + callback(response); + } + yield put({ + type: 'query', + payload: { + ...queryParams, + }, + }); + }, + *delete({ payload }, { call, put }) { + const { queryParams, body } = payload; + yield call(deleteRole, body); + message.info('删除成功!'); + yield put({ + type: 'query', + payload: { + ...queryParams, + }, + }); + }, + *query({ payload }, { call, put }) { + const response = yield call(queryRole, payload); + message.info('查询成功!'); + const { count, roles } = response.data; + yield put({ + type: 'querySuccess', + payload: { + list: roles, + count, + }, + }); + }, + }, + + reducers: { + querySuccess(state, { payload }) { + return { + ...state, + ...payload, + }; + }, + }, +}; diff --git a/admin-web/src/pages/Admin/ResourceList.js b/admin-web/src/pages/Admin/ResourceList.js index b44dc3be7..433a54b4a 100644 --- a/admin-web/src/pages/Admin/ResourceList.js +++ b/admin-web/src/pages/Admin/ResourceList.js @@ -89,6 +89,7 @@ const CreateForm = Form.create()(props => { @connect(({ resourceList, loading }) => ({ resourceList, + list: resourceList.list, loading: loading.models.resourceList, })) @Form.create() @@ -103,7 +104,7 @@ class ResourceList extends PureComponent { componentDidMount() { const { dispatch } = this.props; dispatch({ - type: 'resourceList/tree', + type: 'roleList/tree', payload: {}, }); } @@ -172,9 +173,7 @@ class ResourceList extends PureComponent { } render() { - const { - resourceList: { list }, - } = this.props; + const { list } = this.props; const { modalVisible, modalType, initValues, defaultExpandAllRows } = this.state; const parentMethods = { handleAdd: this.handleAdd, @@ -253,6 +252,7 @@ class ResourceList extends PureComponent { + TODO 展开没效果,需要研究下