From aa42de21e92b2ea36236738edd87701e08606bea Mon Sep 17 00:00:00 2001 From: zhenxianyimeng <1920405993@qq.com> Date: Sat, 6 Jul 2019 11:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/config/router.config.js | 5 ++ admin-web/package.json | 2 +- admin-web/src/locales/zh-CN/menu.js | 1 + admin-web/src/models/admin/deptmentList.js | 61 +++++++++++++ admin-web/src/pages/Admin/DeptmentList.js | 86 +++++++++++++++++++ admin-web/src/pages/Admin/DeptmentList.less | 11 +++ admin-web/src/services/admin.js | 7 ++ .../controller/admins/DeptmentController.java | 4 +- .../api/dto/depetment/DeptmentPageDTO.java | 4 + 9 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 admin-web/src/models/admin/deptmentList.js create mode 100644 admin-web/src/pages/Admin/DeptmentList.js create mode 100644 admin-web/src/pages/Admin/DeptmentList.less diff --git a/admin-web/config/router.config.js b/admin-web/config/router.config.js index c4225a313..a058ce557 100644 --- a/admin-web/config/router.config.js +++ b/admin-web/config/router.config.js @@ -51,6 +51,11 @@ export default [ name: 'role-list', component: './Admin/RoleList', }, + { + path: '/admin/dept-list', + name: 'deptment-list', + component: './Admin/DeptmentList', + }, { path: '/admin/dictionary-list', name: 'dictionary-list', diff --git a/admin-web/package.json b/admin-web/package.json index 11be4d07f..72bc06f68 100644 --- a/admin-web/package.json +++ b/admin-web/package.json @@ -118,7 +118,7 @@ "node ./scripts/lint-prettier.js", "git add" ], - "**/*.{js,jsx}": "npm run lint-staged:js", + "**/*.{js}": "npm run lint-staged:js", "**/*.less": "stylelint --syntax less" }, "engines": { diff --git a/admin-web/src/locales/zh-CN/menu.js b/admin-web/src/locales/zh-CN/menu.js index cfc3478a3..2dcf49161 100644 --- a/admin-web/src/locales/zh-CN/menu.js +++ b/admin-web/src/locales/zh-CN/menu.js @@ -44,6 +44,7 @@ export default { 'menu.admin.resource-list': '权限列表', 'menu.admin.role-list': '角色列表', 'menu.admin.dictionary-list': '数据字典', + 'menu.admin.deptment-list': '部门列表', // 商品相关 'menu.product': '商品管理', 'menu.product.product-spu-list': '商品管理', diff --git a/admin-web/src/models/admin/deptmentList.js b/admin-web/src/models/admin/deptmentList.js new file mode 100644 index 000000000..5b393718c --- /dev/null +++ b/admin-web/src/models/admin/deptmentList.js @@ -0,0 +1,61 @@ +import { message } from 'antd'; +import { deptTreePage } from '../../services/admin'; + +export default { + namespace: 'deptmentList', + + state: { + list: [], + selectTree: [], + deptmentData: { + list: [], + }, + }, + + effects: { + *getDeptmentList({ payload }, { call, put }) { + const result = yield call(deptTreePage, payload); + let deptmentData = {}; + if (result.code === 0) { + deptmentData = result.data; + } + yield put({ + type: 'save', + payload: { + deptmentData, + }, + }); + }, + }, + + reducers: { + save(state, action) { + return { + ...state, + ...action.payload, + }; + }, + + treeSuccess(state, { payload }) { + const resultData = payload; + const treeData = buildSelectTree(resultData); + + // value 要保护 displayName 不然,搜索会失效 + const rootNode = [ + { + title: '根节点', + value: `根节点-0`, + key: 0, + children: [], + }, + ]; + + const selectTree = rootNode.concat(treeData); + return { + ...state, + list: resultData, + selectTree, + }; + }, + }, +}; diff --git a/admin-web/src/pages/Admin/DeptmentList.js b/admin-web/src/pages/Admin/DeptmentList.js new file mode 100644 index 000000000..ad38eea3c --- /dev/null +++ b/admin-web/src/pages/Admin/DeptmentList.js @@ -0,0 +1,86 @@ +import React, { PureComponent, Fragment } from 'react'; +import { Button, Card, Table, Form, Divider } from 'antd'; +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; +import { connect } from 'dva'; +import styles from './DeptmentList.less'; +import PaginationHelper from '../../../helpers/PaginationHelper'; +import moment from 'moment'; + +@connect(({ deptmentList, loading }) => ({ + deptmentList, + deptmentData: deptmentList.deptmentData, + loading: loading.models.deptmentList, +})) +@Form.create() +export default class DepetmentList extends PureComponent { + componentDidMount() { + const { dispatch } = this.props; + dispatch({ + type: 'deptmentList/getDeptmentList', + payload: { + ...PaginationHelper.defaultPayload, + }, + }); + } + + render() { + const { deptmentData, deptmentList } = this.props; + const columns = [ + { + title: '部门名称', + dataIndex: 'name', + }, + { + title: '排序', + dataIndex: 'sort', + }, + { + title: '创建时间', + dataIndex: 'createTime', + sorter: true, + render: val => {moment(val).format('YYYY-MM-DD')}, + }, + { + title: '操作', + render: (text, record) => ( + + this.handleModalVisible(true, 'update', record)}>编辑 + + this.handleDelete(record)}> + 删除 + + + ), + }, + ]; + + // const { + // deptmentList: {deptmentData}, + // loading, + // } = this.props; + + return ( + + +
+
+ +
+
+ + + + ); + } +} diff --git a/admin-web/src/pages/Admin/DeptmentList.less b/admin-web/src/pages/Admin/DeptmentList.less new file mode 100644 index 000000000..22e257421 --- /dev/null +++ b/admin-web/src/pages/Admin/DeptmentList.less @@ -0,0 +1,11 @@ +@import '~antd/lib/style/themes/default.less'; +@import '~@/utils/utils.less'; + +.tableList { + .tableListOperator { + margin-bottom: 16px; + button { + margin-right: 8px; + } + } +} diff --git a/admin-web/src/services/admin.js b/admin-web/src/services/admin.js index 8f58db491..913773f17 100644 --- a/admin-web/src/services/admin.js +++ b/admin-web/src/services/admin.js @@ -55,6 +55,13 @@ export async function adminRoleAssign(params) { }); } +// deptment +export async function deptTreePage(params) { + return request(`/admin-api/admins/dept/tree/page?${stringify(params)}`, { + method: 'GET', + }); +} + // resource export async function addResource(params) { diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java index 75da64dc4..f91493a2a 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java @@ -16,8 +16,10 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -42,7 +44,7 @@ public class DeptmentController { @GetMapping("tree/page") @ApiOperation(value = "根部门分页的部门树") - public CommonResult> treePage(DeptmentPageDTO deptmentPageDTO){ + public CommonResult> treePage(@Validated DeptmentPageDTO deptmentPageDTO){ PageResult pageResult = deptmentService.getPageRootDeptment(deptmentPageDTO); PageResult voPageResult = DeptmentConvert.INSTANCE.convert(pageResult); List list = deptmentService.getAllDeptments(); diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentPageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentPageDTO.java index cb12e1549..5522c79d4 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentPageDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentPageDTO.java @@ -1,8 +1,10 @@ package cn.iocoder.mall.admin.api.dto.depetment; import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.experimental.Accessors; /** @@ -12,7 +14,9 @@ import lombok.Data; * @date: 2019-06-21 * @time: 00:22 */ +@ApiModel(value = "部门分页 DTO") @Data +@Accessors(chain = true) public class DeptmentPageDTO extends PageParam { @ApiModelProperty(value = "根部门名字", example = "研发部") private String name;