From deeccfa44eeaa0bfcfb38f22197b0c5d23fb5b18 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Wed, 19 Jul 2017 13:58:12 +0800 Subject: [PATCH] feat: user module in the client --- client/containers/User/LeftMenu.js | 96 ++++++++++++------- client/containers/User/List.js | 2 +- client/containers/User/Profile.js | 15 --- client/containers/User/index.scss | 44 +-------- doc/build/api.html | 17 ++-- .../static/server/controllers/project.js.html | 2 +- .../static/server/controllers/user.js.html | 33 +++++-- exampleCode/api/project/search.json | 2 +- exampleCode/api/user/search.json | 3 +- server/controllers/project.js | 2 +- server/controllers/user.js | 3 +- server_dist/controllers/project.js | 2 +- server_dist/controllers/user.js | 4 +- 13 files changed, 112 insertions(+), 113 deletions(-) diff --git a/client/containers/User/LeftMenu.js b/client/containers/User/LeftMenu.js index 9a2a085b..aed5fe66 100644 --- a/client/containers/User/LeftMenu.js +++ b/client/containers/User/LeftMenu.js @@ -1,68 +1,94 @@ import React, { Component } from 'react' import { Link } from 'react-router-dom' -import { Input, Row, Col } from 'antd' -import { connect } from 'react-redux' -import PropTypes from 'prop-types' +import { Row, Col, Menu, AutoComplete, Input, Icon } from 'antd' +import axios from 'axios' -@connect( - state => { - return { - curUid: state.user.curUid - } - } -) +const Option = AutoComplete.Option; class LeftMenu extends Component { - static propTypes = { - curUid: PropTypes.string - } constructor(props) { super(props) + this.state = { + dataSource: [] + } + this.searchSign = 0; + this._searchSign = 0; + this.interval = null; } - handleActive = () => { - this.setState({ - ______a: 1 //强制刷新 - }) + + //延迟搜索 + handleSearch = (value) => { + if(!value || value.length < 1) return ; + this.searchSign = this.searchSign + 1; + this.interval && clearInterval(this.interval) + this.interval = setInterval(() => { + if (this.searchSign === this._searchSign) { + this.interval = clearInterval(this.interval) + axios.get('/user/search?q=' + value).then((res) => { + if (res.data.errcode === 0) { + this.setState({ + dataSource: res.data.data + }) + } + }) + + } else { + this._searchSign = this.searchSign; + } + }, 600) + + } + + renderOption = (item) => { + return ( + + ) } render() { const menus = [{ title: '个人资料', - path: "/user/profile/" + this.props.curUid + path: "/user/profile/" + 107 }, { title: '用户管理', path: '/user/list' } ] - let content = menus.map((menu, index) => { - if (typeof menu.auth === 'function' && menu.auth('admin') === false) { - return ''; - } + let content = menus.map((menu) => { return ( -
  • + {menu.title} -
  • + ) }) - - const Search = Input.Search; - - return (
    + const { dataSource } = this.state; + return (
    - console.log(value)} - /> +
    + + } /> + +
    -
    -
      + {content} -
    +
    ) } diff --git a/client/containers/User/List.js b/client/containers/User/List.js index 7ffb10cb..be52c3f8 100755 --- a/client/containers/User/List.js +++ b/client/containers/User/List.js @@ -91,7 +91,7 @@ class List extends Component { return ( - {this.confirm(item._id)}} okText="Yes" cancelText="No"> + {this.confirm(item._id)}} okText="Yes" cancelText="No"> diff --git a/client/containers/User/Profile.js b/client/containers/User/Profile.js index 4a759412..c2a0e528 100644 --- a/client/containers/User/Profile.js +++ b/client/containers/User/Profile.js @@ -1,27 +1,13 @@ import React, { Component } from 'react' import { Row, Col, Icon, Input, Button, Select, message } from 'antd' import axios from 'axios'; -import { connect } from 'react-redux' import {formatTime} from '../../common.js' -import { - changeCurUid -} from '../../actions/user.js' import PropTypes from 'prop-types' -@connect( - state => ({ - curUid: state.user.curUid - }), - { - changeCurUid - } -) class Profile extends Component { static propTypes = { - curUid: PropTypes.string, - changeCurUid: PropTypes.func, match: PropTypes.object } @@ -41,7 +27,6 @@ class Profile extends Component { componentDidMount(){ const uid = this.props.match.params.uid; - this.props.changeCurUid(uid) this.getUserInfo(uid) } diff --git a/client/containers/User/index.scss b/client/containers/User/index.scss index 06c4d320..f11301af 100644 --- a/client/containers/User/index.scss +++ b/client/containers/User/index.scss @@ -7,55 +7,21 @@ font-size: 0.14rem; background: #FFF; min-height:500px; - margin-top: 64px; + margin-top: 84px; - .search{ - height: 40px; - padding: 5px; - background: #f9f9f9; - - input{ - background: #f9f9f9; - line-height: 40px; - height: 40px; - border: 0; - font-size: 14px; - } - - input:focus{ - outline:0; - border-color:0; - box-shadow: none - } - - - - } + ul{border:none} .user-list { width: 216px; - line-height: 45px; - background: #f9fafe; - - li { - padding: 0 0 0 30px; - a{ - color: #344562; - } - - &.active,&.active a { - background: #657289; - color: #FFF; - text-decoration: none; - } - + .search{ + margin: 5px; } } .user-table { -webkit-box-flex: 1; padding-right: 15px; - + margin-left: 15px; .ant-table-wrapper table { font-size: .14rem; diff --git a/doc/build/api.html b/doc/build/api.html index 494abfa0..b6c160dd 100644 --- a/doc/build/api.html +++ b/doc/build/api.html @@ -771,7 +771,7 @@

    源码位置: - ./server/controllers/user.js:215 + ./server/controllers/user.js:224

    @@ -868,7 +868,7 @@

    源码位置: - ./server/controllers/user.js:277 + ./server/controllers/user.js:286

    @@ -938,7 +938,7 @@

    源码位置: - ./server/controllers/user.js:309 + ./server/controllers/user.js:315

    @@ -1000,7 +1000,7 @@

    源码位置: - ./server/controllers/user.js:338 + ./server/controllers/user.js:350

    @@ -1062,7 +1062,7 @@

    源码位置: - ./server/controllers/user.js:362 + ./server/controllers/user.js:377

    @@ -1154,7 +1154,7 @@

    源码位置: - ./server/controllers/user.js:408 + ./server/controllers/user.js:426

    @@ -1197,13 +1197,14 @@
    示例:
    {
    -    "errcode": 200,
    +    "errcode": 0,
         "errmsg": "ok",
         "data": [
             {
                 "uid": 101,
                 "email": "admin@admin.com",
                 "role": "admin",
    +            "username": "admin",
                 "addTime": 1499936103,
                 "upTime": 1499936103
             }
    @@ -2086,7 +2087,7 @@
         
         
    示例:
    {
    -    "errcode": 200,
    +    "errcode": 0,
         "errmsg": "ok",
         "data": {
             "project": [
    diff --git a/doc/build/static/server/controllers/project.js.html b/doc/build/static/server/controllers/project.js.html
    index dc659ece..f0376363 100644
    --- a/doc/build/static/server/controllers/project.js.html
    +++ b/doc/build/static/server/controllers/project.js.html
    @@ -410,7 +410,7 @@ class projectController extends baseController {
                 group: groupList
             };
             
    -        return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
    +        return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok')
         }
     }
     
    diff --git a/doc/build/static/server/controllers/user.js.html b/doc/build/static/server/controllers/user.js.html
    index 6d0b49e5..eda9c60c 100644
    --- a/doc/build/static/server/controllers/user.js.html
    +++ b/doc/build/static/server/controllers/user.js.html
    @@ -190,8 +190,17 @@ class userController extends baseController {
         async changePassword(ctx) {
             let params = ctx.request.body;
             let userInst = yapi.getInst(userModel);
    +
    +        if (!params.uid) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
    +        }
    +
    +        if (!params.password) {
    +            return ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空');
    +        }
    +
    +
             if (this.getRole() !== 'admin' && params.uid != this.getUid()) {
    -            console.log(this.getRole(), this.getUid());
                 return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
             }
             if (this.getRole() !== 'admin') {
    @@ -317,10 +326,7 @@ class userController extends baseController {
         async list(ctx){
             let page = ctx.request.query.page || 1,
                 limit = ctx.request.query.limit || 10;
    -
    -        if(this.getRole() !== 'admin'){
    -            return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
    -        }
    +            
             const userInst = yapi.getInst(userModel);
             try {
                 let user = await userInst.listWithPaging(page, limit);
    @@ -349,7 +355,13 @@ class userController extends baseController {
             try {
                 var userInst = yapi.getInst(userModel);
                 let id = ctx.request.query.id;
    +            if (!id) {
    +                return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
    +            }
                 let result = await userInst.findById(id);
    +            if(!result){
    +                return ctx.body = yapi.commons.resReturn(null,402,"不存在的用户");
    +            }
                 return ctx.body = yapi.commons.resReturn({                
                     uid: result._id,
                     username: result.username,
    @@ -374,12 +386,15 @@ class userController extends baseController {
          * @example 
          */
         async del(ctx) {   //根据id删除一个用户
    -        try {
    +        try {            
                 if (this.getRole() !== 'admin') {
                     return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
                 }
                 var userInst = yapi.getInst(userModel);
                 let id = ctx.request.body.id;
    +            if (!id) {
    +                return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
    +            }
                 let result = await userInst.del(id);
                 ctx.body = yapi.commons.resReturn(result);
             } catch (e) {
    @@ -408,6 +423,9 @@ class userController extends baseController {
                 }
                 var userInst = yapi.getInst(userModel);
                 let id = params.uid;
    +            if (!id) {
    +                return ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空');
    +            }
                 let data ={
     
                     up_time: yapi.commons.time()
    @@ -460,6 +478,7 @@ class userController extends baseController {
                     key: '_id',
                     alias: 'uid'
                 },
    +            'username',
                 'email',
                 'role',
                 {
    @@ -475,7 +494,7 @@ class userController extends baseController {
             let filteredRes = common.filterRes(queryList, rules);
             console.log(queryList)
     
    -        return ctx.body = yapi.commons.resReturn(filteredRes, 200, 'ok');
    +        return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok');
         }
     }
     
    diff --git a/exampleCode/api/project/search.json b/exampleCode/api/project/search.json
    index 20590765..72942372 100644
    --- a/exampleCode/api/project/search.json
    +++ b/exampleCode/api/project/search.json
    @@ -1,5 +1,5 @@
     {
    -    "errcode": 200,
    +    "errcode": 0,
         "errmsg": "ok",
         "data": {
             "project": [
    diff --git a/exampleCode/api/user/search.json b/exampleCode/api/user/search.json
    index c6587783..80251848 100644
    --- a/exampleCode/api/user/search.json
    +++ b/exampleCode/api/user/search.json
    @@ -1,11 +1,12 @@
     {
    -    "errcode": 200,
    +    "errcode": 0,
         "errmsg": "ok",
         "data": [
             {
                 "uid": 101,
                 "email": "admin@admin.com",
                 "role": "admin",
    +            "username": "admin",
                 "addTime": 1499936103,
                 "upTime": 1499936103
             }
    diff --git a/server/controllers/project.js b/server/controllers/project.js
    index e8ce28d6..e2c62288 100644
    --- a/server/controllers/project.js
    +++ b/server/controllers/project.js
    @@ -383,7 +383,7 @@ class projectController extends baseController {
                 group: groupList
             };
             
    -        return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
    +        return ctx.body = yapi.commons.resReturn(queryList, 0, 'ok')
         }
     }
     
    diff --git a/server/controllers/user.js b/server/controllers/user.js
    index ab455dc1..a98fe230 100644
    --- a/server/controllers/user.js
    +++ b/server/controllers/user.js
    @@ -451,6 +451,7 @@ class userController extends baseController {
                     key: '_id',
                     alias: 'uid'
                 },
    +            'username',
                 'email',
                 'role',
                 {
    @@ -466,7 +467,7 @@ class userController extends baseController {
             let filteredRes = common.filterRes(queryList, rules);
             console.log(queryList)
     
    -        return ctx.body = yapi.commons.resReturn(filteredRes, 200, 'ok');
    +        return ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok');
         }
     }
     
    diff --git a/server_dist/controllers/project.js b/server_dist/controllers/project.js
    index 004682b9..824b8f84 100644
    --- a/server_dist/controllers/project.js
    +++ b/server_dist/controllers/project.js
    @@ -912,7 +912,7 @@ var projectController = function (_baseController) {
                                         project: projectList,
                                         group: groupList
                                     };
    -                                return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 200, 'ok'));
    +                                return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 0, 'ok'));
     
                                 case 17:
                                 case 'end':
    diff --git a/server_dist/controllers/user.js b/server_dist/controllers/user.js
    index 5c5dee97..ecab6179 100644
    --- a/server_dist/controllers/user.js
    +++ b/server_dist/controllers/user.js
    @@ -989,7 +989,7 @@ var userController = function (_baseController) {
                                     rules = [{
                                         key: '_id',
                                         alias: 'uid'
    -                                }, 'email', 'role', {
    +                                }, 'username', 'email', 'role', {
                                         key: 'add_time',
                                         alias: 'addTime'
                                     }, {
    @@ -1000,7 +1000,7 @@ var userController = function (_baseController) {
     
                                     console.log(queryList);
     
    -                                return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(filteredRes, 200, 'ok'));
    +                                return _context13.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(filteredRes, 0, 'ok'));
     
                                 case 12:
                                 case 'end':