feat: user module

This commit is contained in:
suxiaoxin 2017-07-18 17:15:29 +08:00
parent 6a889422ee
commit 5576cd7284
7 changed files with 72 additions and 33 deletions

5
client/common.js Normal file
View File

@ -0,0 +1,5 @@
import moment from 'moment'
exports.formatTime = (timestamp) => {
return moment.unix(timestamp).format("YYYY-MM-DD:HH:mm:ss")
}

View File

@ -29,7 +29,7 @@ class LeftMenu extends Component {
render() {
const menus = [{
title: '个人资料',
path: "/user/profile/107"
path: "/user/profile/" + this.props.curUid
}, {
title: '用户管理',
path: '/user/list',

View File

@ -1,4 +1,6 @@
import React, { Component } from 'react'
import {formatTime} from '../../common.js'
import { Link } from 'react-router-dom'
//import PropTypes from 'prop-types'
import {
Table,
@ -7,10 +9,11 @@ import {
import axios from 'axios';
const columns = [{
title: 'UID',
dataIndex: 'uid',
key: 'uid'
dataIndex: '_id',
key: '_id'
}, {
title: '用户名',
dataIndex: 'username',
@ -30,10 +33,10 @@ const columns = [{
}, {
title: '功能',
key: 'action',
render: () => {
render: (item) => {
return (
<span>
<Button type="primary">查看</Button>
<Button type="primary"><Link to={"/user/profile/"+item._id} > 查看 </Link></Button>
<Button type="danger">删除</Button>
</span>
)
@ -51,9 +54,17 @@ class List extends Component {
getUserList() {
axios.get('/user/list').then((res) => {
let data = res.data;
if (res.errno === 0) {
this.setState('data', data.data);
let result = res.data;
if (result.errcode === 0) {
let list = result.data.list;
list.map( (item, index) => {
item.key = index;
item.up_time = formatTime(item.up_time)
} )
this.setState({
data: list
});
}
})
}

View File

@ -2,7 +2,7 @@ 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'
@ -202,12 +202,17 @@ class Profile extends Component {
return <div className="user-profile">
<Row className="user-item" type="flex" justify="start">
<Col span={4}>用户id</Col>
<Col span={12}>
{userinfo.uid}
</Col>
</Row>
<Row className="user-item" type="flex" justify="start">
<Col span={4}>用户名</Col>
<Col span={12}>
{userNameEditHtml}
</Col>
</Row>
<Row className="user-item" type="flex" justify="start">
<Col span={4}>Email</Col>
@ -221,6 +226,19 @@ class Profile extends Component {
{roleEditHtml}
</Col>
</Row>
<Row className="user-item" type="flex" justify="start">
<Col span={4}>创建账号时间</Col>
<Col span={12}>
{formatTime(userinfo.add_time)}
</Col>
</Row>
<Row className="user-item" type="flex" justify="start">
<Col span={4}>更新账号时间</Col>
<Col span={12}>
{formatTime(userinfo.up_time)}
</Col>
</Row>
<Row className="user-item" type="flex" justify="start">
<Col span={4}>安全</Col>
<Col span={12}>

View File

@ -7,6 +7,7 @@
font-size: 0.14rem;
background: #FFF;
min-height:500px;
margin-top: 64px;
.search{
height: 40px;
@ -53,7 +54,7 @@
.user-table {
-webkit-box-flex: 1;
margin: 0 0 0 20px;
padding-right: 15px;
.ant-table-wrapper table {
font-size: .14rem;

View File

@ -31,6 +31,7 @@
"koa-static": "^3.0.0",
"koa-views": "^5.2.0",
"mockjs": "^1.0.1-beta3",
"moment": "^2.18.1",
"mongoose": "4.10.8",
"mongoose-auto-increment": "^5.0.1",
"node-sass-china": "^4.5.0",
@ -89,26 +90,26 @@
"webpack-node-externals": "^1.6.0"
},
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg"
},
"validate-commit-msg": {
"types": [
"feat",
"fix",
"docs",
"test",
"chore",
"refactor",
"opti"
],
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "请输入message信息!",
"helpMessage": "Commit message 格式错误, \n请查看规范: http://wiki.corp.qunar.com/pages/viewpage.action?pageId=159698767"
}
"ghooks": {
"commit-msg": "validate-commit-msg"
},
"validate-commit-msg": {
"types": [
"feat",
"fix",
"docs",
"test",
"chore",
"refactor",
"opti"
],
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "请输入message信息!",
"helpMessage": "Commit message 格式错误, \n请查看规范: http://wiki.corp.qunar.com/pages/viewpage.action?pageId=159698767"
}
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"

View File

@ -291,9 +291,9 @@ class userController extends baseController {
let pageNo = ctx.request.query.pageNo || 1,
pageSize = ctx.request.query.pageSize || 10;
if(this.getRole() !== 'admin'){
return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
}
// if(this.getRole() !== 'admin'){
// return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
// }
var userInst = yapi.getInst(userModel);
try{
let user = await userInst.list();
@ -329,6 +329,9 @@ class userController extends baseController {
var userInst = yapi.getInst(userModel);
let id = ctx.request.query.id;
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,