Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
wenbo.dong 2017-08-11 11:05:34 +08:00
commit 5115f9d6e2
38 changed files with 269 additions and 240 deletions

18
.tags
View File

@ -344,11 +344,6 @@ regActions /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/modules/user.js
const.username /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/modules/user.js /^ password,$/;" property line:106
logoutActions /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/modules/user.js /^export function logoutActions() {$/;" function line:115
loginTypeAction /Users/qitmac000445/Desktop/YAPI/yapi/client/reducer/modules/user.js /^export function loginTypeAction(index) {$/;" function line:122
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ constructor(props) {$/;" function line:26
state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ this.state = {$/;" property line:28
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:33
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:45
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:78
const.height /Users/qitmac000445/Desktop/YAPI/yapi/client/components/Header/Header.js /^const headerStyle = {$/;" property line:13
const.lineHeight /Users/qitmac000445/Desktop/YAPI/yapi/client/components/Header/Header.js /^ 'height': '.56rem',$/;" property line:14
const.padding /Users/qitmac000445/Desktop/YAPI/yapi/client/components/Header/Header.js /^ 'lineHeight': '.56rem',$/;" property line:15
@ -457,7 +452,12 @@ static.curUserRole /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/User/
getUserList /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/User/List.js /^ getUserList() {$/;" function line:41
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/User/List.js /^ componentDidMount() {$/;" function line:60
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/User/List.js /^ render() {$/;" function line:85
from.children /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ static propTypes = {$/;" property line:8
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ constructor(props) {$/;" function line:15
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ componentWillMount() {$/;" function line:19
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ render () {$/;" function line:22
from.match /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ static propTypes = {$/;" property line:9
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ constructor(props) {$/;" function line:16
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ componentWillMount() {$/;" function line:20
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ render () {$/;" function line:23
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ constructor(props) {$/;" function line:26
state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ this.state = {$/;" property line:28
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:33
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:45
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:78

9
.tags1
View File

@ -4,7 +4,8 @@
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
from.children /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ static propTypes = {$/;" property line:8
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ constructor(props) {$/;" function line:15
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ componentWillMount() {$/;" function line:19
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Project/Project.js /^ render () {$/;" function line:22
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ constructor(props) {$/;" function line:26
state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ this.state = {$/;" property line:28
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:33
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:45
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:78

View File

@ -1,8 +1,8 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom';
import { Home, Group, Project, News, AddInterface, Follows, AddProject } from './containers/index';
import { Route, BrowserRouter as Router, Redirect, Switch } from 'react-router-dom';
import { Home, Group, Project, Follows, AddProject } from './containers/index';
import User from './containers/User/User.js';
import Header from './components/Header/Header';
import Footer from './components/Footer/Footer';
@ -52,25 +52,24 @@ export default class App extends Component {
return <Loading visible />;
} else {
r = (
<HashRouter>
<Router>
<div className="router-main">
<Header />
<div className="router-container">
<Route path="/" component={Home} exact />
<Switch>
<Redirect exact from='/group' to='/group/1' />
<Route exact path="/group/:groupName" component={requireAuthentication(Group)} />
</Switch>
<Route path="/project" component={requireAuthentication(Project)} />
<Route path="/group/:id" component={requireAuthentication(Group)} />
<Route path="/project/:id" component={requireAuthentication(Project)} />
<Route path="/user" component={requireAuthentication(User)} />
<Route path="/news" component={requireAuthentication(News)} />
<Route path="/add-interface" component={requireAuthentication(AddInterface)} />
<Route path="/follow" component={requireAuthentication(Follows)} />
<Route path="/add-project" component={requireAuthentication(AddProject)} />
{
// <Route path="/news" component={requireAuthentication(News)} />
// <Route path="/add-interface" component={requireAuthentication(AddInterface)} />
}
</div>
<Footer />
</div>
</HashRouter>
</Router>
)
}
return r;

View File

@ -31,7 +31,7 @@ export default class BreadcrumbNavigation extends Component {
type = 'project';
}
const params = { type, id };
axios.get('/user/nav', {params: params}).then( (res) => {
axios.get('/api/user/nav', {params: params}).then( (res) => {
const data = res.data.data;
// 依次填入group/projec/interface
if (data.group_name) {

View File

@ -11,7 +11,7 @@ class Footer extends Component {
}
render () {
const style = {
'background': 'url(./image/footer-bac.jpg)'
'background': 'url(/image/footer-bac.jpg)'
}
return (
<div className = 'footer-wrapper'>

View File

@ -53,7 +53,7 @@ const ToolUser = (props)=> (
</Link>
<Tooltip placement="bottom" title={'使用文档'}>
<li className="toolbar-li">
<a target="_blank" href="./doc/index.html"><Icon className="dropdown-link" style={{ fontSize: 16 }} type="question-circle" /></a>
<a target="_blank" href="/doc/index.html"><Icon className="dropdown-link" style={{ fontSize: 16 }} type="question-circle" /></a>
</li>
</Tooltip>
<li className="toolbar-li">
@ -69,7 +69,9 @@ const ToolUser = (props)=> (
/>
}>
<a className="dropdown-link">
<img style={{width:24,height:24}} src="/user/avatar" /><span className="name">{props.user}</span>
<img style={{width:24,height:24}} src={`/api/user/avatar?uid=${props.uid}`} /><span className="name">{props.user}</span>
</a>
</Dropdown>
</li>
@ -163,6 +165,9 @@ export default class HeaderCom extends Component {
console.log(err);
})
}
render () {
const { login, user, msg, uid } = this.props;
return (
@ -170,7 +175,7 @@ export default class HeaderCom extends Component {
<div className="content g-row">
<div className="logo">
<Link to="/" onClick={this.relieveLink} className="href">
<img className="img" src="./image/logo_header@1x.png" /><span className="logo-name">YAPI<span className="ui-badge"></span></span>
<img className="img" src="/image/logo_header@1x.png" /><span className="logo-name">YAPI<span className="ui-badge"></span></span>
</Link>
</div>
<div className="user-toolbar">

View File

@ -49,7 +49,7 @@ export default class Srch extends Component{
}
handleSearch = (value) => {
axios.get('/project/search?q='+value)
axios.get('/api/project/search?q='+value)
.then((res) => {
if(res.data && res.data.errcode === 0){
const dataSource = [];

View File

@ -147,7 +147,7 @@ class AddInterface extends Component {
getMockURL (project_id, result) {
const params = {id: project_id}
axios.get('/project/get', {params: params}).
axios.get('/api/project/get', {params: params}).
then( data => {
const { prd_host, basepath } = data.data.data
const mockURL = `http://${prd_host}${basepath}${result.path}`

View File

@ -106,7 +106,7 @@ export default class GroupList extends Component {
@autobind
async addGroup() {
const { newGroupName: group_name, newGroupDesc: group_desc } = this.state;
const res = await axios.post('/group/add', { group_name, group_desc })
const res = await axios.post('/api/group/add', { group_name, group_desc })
if (!res.data.errcode) {
this.setState({
addGroupModalVisible: false
@ -120,7 +120,7 @@ export default class GroupList extends Component {
async editGroup() {
const { currGroupName: group_name, currGroupDesc: group_desc } = this.state;
const id = this.props.currGroup._id;
const res = axios.post('/group/up', { group_name, group_desc, id });
const res = axios.post('/api/group/up', { group_name, group_desc, id });
if (res.data.errcode) {
message.error(res.data.errmsg);
} else {
@ -159,7 +159,7 @@ export default class GroupList extends Component {
async deleteGroup() {
const self = this;
const { currGroup } = self.props;
const res = await axios.post('/group/del', {id: currGroup._id})
const res = await axios.post('/api/group/del', {id: currGroup._id})
if (res.data.errcode) {
message.error(res.data.errmsg);
} else {

View File

@ -31,7 +31,7 @@ class InterfaceMode extends Component {
const params = {
id: this.getInterfaceId()
}
axios.get('/project/get_member_list', { params })
axios.get('/api/project/get_member_list', { params })
.then(data => {
this.setState({
'memberList': data.data.data
@ -57,7 +57,7 @@ class InterfaceMode extends Component {
id: this.getInterfaceId()
}
axios.post('/project/del_member', params)
axios.post('/api/project/del_member', params)
.then(() => {
this.getMemberList()
})
@ -70,11 +70,11 @@ class InterfaceMode extends Component {
addNewUser () {
const { userName } = this.state
const params = { q: userName}
axios.get('/user/search', { params })
axios.get('/api/user/search', { params })
.then(data => {
const member_uid = data.data.data[0].uid
const params = {id: this.getInterfaceId(), member_uid}
axios.post('/project/add_member', params)
axios.post('/api/project/add_member', params)
.then( () => {
this.getMemberList()
})
@ -94,7 +94,7 @@ class InterfaceMode extends Component {
})
const params = { q: value}
axios.get('/user/search', { params })
axios.get('/api/user/search', { params })
.then(data => {
const userList = []
data = data.data.data

View File

@ -51,7 +51,7 @@ class InterfaceTable extends Component {
const params = {
id: interfaceId
}
axios.post('/interface/del', params)
axios.post('/api/interface/del', params)
.then(() => {
this.deleteInterfaceData(interfaceId)
})

View File

@ -2,11 +2,12 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Route, Switch, Redirect } from 'react-router-dom';
import { Subnav } from '../../components/index'
import { Interface } from './Interface/Interface.js'
export default class GroupList extends Component {
static propTypes = {
children: PropTypes.element
match: PropTypes.object
}
state = {
@ -20,24 +21,25 @@ export default class GroupList extends Component {
}
render () {
const { match } = this.props;
return (
<div>
<Subnav
default={'接口'}
data={[{
name: '接口',
path: '/project/:id/activity'
path: `/project/${match.params.id}/interface`
}, {
name: '设置',
path: '/project/:id/setting'
path: `/project/${match.params.id}/setting`
}, {
name: '动态',
path: '/project/:id/activity'
path: `/project/${match.params.id}/activity`
}]}/>
<Switch>
<Redirect exact from='/project/:id' to='/project/:id/interface' />
<Redirect exact from='/project/:id' to={`/project/${match.params.id}/interface`} />
<Route path="/project/:id/activity" component={null} />
<Route path="/project/:id/interface" component={null} />
<Route path="/project/:id/interface" component={Interface} />
<Route path="/project/:id/setting" component={null} />
</Switch>
</div>

View File

@ -1,56 +0,0 @@
import './index.scss'
import React, { Component } from 'react'
// import PropTypes from 'prop-types'
import { Upload, Icon, message } from 'antd'
class Avatar extends Component {
constructor(props) {
super(props);
this.state = {
imageUrl:""
}
}
handleChange(info){
if (info.file.status === 'done') {
// Get this url from response in real world.
getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
}
}
render() {
const imageUrl = this.state.imageUrl;
return <div className="avatar-box">
<Upload
className="avatar-uploader"
name="avatar"
showUploadList={true}
action="//jsonplaceholder.typicode.com/posts/"
beforeUpload={beforeUpload}
onChange={this.handleChange.bind(this)} >
{
imageUrl ?
<img src={imageUrl} alt="" className="avatar" /> :
<Icon type="plus" className="avatar-uploader-trigger" />
}
</Upload>
</div>
}
}
function beforeUpload(file) {
const isJPG = file.type === 'image/jpeg';
if (!isJPG) {
message.error('You can only upload JPG file!');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('Image must smaller than 2MB!');
}
return isJPG && isLt2M;
}
function getBase64(img, callback) {
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result));
reader.readAsDataURL(img);
}
export default Avatar;

View File

@ -42,7 +42,7 @@ class LeftMenu extends Component {
this.interval = setInterval(() => {
if (this.searchSign === this._searchSign) {
this.interval = clearInterval(this.interval)
axios.get('/user/search?q=' + value).then((res) => {
axios.get('/api/user/search?q=' + value).then((res) => {
if (res.data.errcode === 0) {
this.setState({
dataSource: res.data.data

View File

@ -39,7 +39,7 @@ class List extends Component {
}
getUserList() {
axios.get('/user/list?page=' + this.state.current).then((res) => {
axios.get('/api/user/list?page=' + this.state.current).then((res) => {
let result = res.data;
if (result.errcode === 0) {
@ -62,7 +62,7 @@ class List extends Component {
}
confirm = (uid) =>{
axios.post('/user/del', {
axios.post('/api/user/del', {
id: uid
}).then( (res)=>{
if(res.data.errcode === 0){

View File

@ -1,10 +1,9 @@
import React, { Component } from 'react'
import { Row, Col, Input, Button, Select, message } from 'antd'
import { Row, Col, Input, Button, Select, message, Upload, Icon } from 'antd'
import axios from 'axios';
import {formatTime} from '../../common.js'
import PropTypes from 'prop-types'
class Profile extends Component {
static propTypes = {
@ -38,7 +37,7 @@ class Profile extends Component {
getUserInfo = (id) => {
var _this = this;
axios.get('/user/find?id=' + id).then((res) => {
axios.get('/api/user/find?id=' + id).then((res) => {
_this.setState({
userinfo: res.data.data,
_userinfo: res.data.data
@ -52,7 +51,7 @@ class Profile extends Component {
let params = {uid: state.userinfo.uid}
params[name] = value;
axios.post('/user/update', params).then( (res)=>{
axios.post('/api/user/update', params).then( (res)=>{
let data = res.data;
if(data.errcode === 0){
let userinfo = this.state.userinfo;
@ -106,7 +105,7 @@ class Profile extends Component {
}
axios.post('/user/change_password', params).then( (res)=>{
axios.post('/api/user/change_password', params).then( (res)=>{
let data = res.data;
if(data.errcode === 0){
this.handleEdit('secureEdit', false)
@ -191,6 +190,7 @@ class Profile extends Component {
return <div className="user-profile">
<Row className="user-item" type="flex" justify="start">
<Col span={24}><Avatar uid={userinfo.uid}>点击上传头像</Avatar></Col>
<Col span={4}>用户id</Col>
<Col span={12}>
{userinfo.uid}
@ -237,4 +237,76 @@ class Profile extends Component {
}
}
class Avatar extends Component {
constructor(props) {
super(props);
this.state = {
imageUrl:""
}
}
static propTypes = {
uid: PropTypes.number
}
uploadAvatar(basecode){
axios.post("/user/upload_avatar",{basecode: basecode}).then(()=>{
this.setState({ imageUrl: basecode })
}).catch((e)=>{
console.log(e);
})
}
handleChange(info){
if (info.file.status === 'done') {
// Get this url from response in real world.
getBase64(info.file.originFileObj, basecode=>{this.uploadAvatar(basecode)});
}
}
render() {
let imageUrl = "";
if(this.props.uid && !this.state.imageUrl){
imageUrl = `/user/avatar?uid=${this.props.uid}`;
}else{
imageUrl = this.state.imageUrl;
}
return <div className="avatar-box">
<Upload
className="avatar-uploader"
name="basecode"
showUploadList={true}
action="/user/upload_avatar"
beforeUpload={beforeUpload}
onChange={this.handleChange.bind(this)} >
{
imageUrl ?
<img src={imageUrl} alt="" className="avatar" /> :
<Icon type="plus" className="avatar-uploader-trigger" />
}
</Upload>
</div>
}
}
function beforeUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isPNG = file.type === 'image/png';
if (!isJPG && !isPNG) {
message.error('图片的格式只能为 jpg、png');
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error('图片必须小于 200kb!');
}
return (isPNG||isJPG) && isLt2M;
}
function getBase64(img, callback) {
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result));
reader.readAsDataURL(img);
}
export default Profile

View File

@ -2,12 +2,12 @@ import './index.scss'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Route } from 'react-router-dom'
import LeftMenu from './LeftMenu.js'
// import LeftMenu from './LeftMenu.js'
import List from './List.js'
import PropTypes from 'prop-types'
import Profile from './Profile.js'
import { Row, Col } from 'antd';
import { Row } from 'antd';
import Subnav from '../../components/Subnav/Subnav.js';
@connect()
class User extends Component {
static propTypes = {
@ -26,16 +26,22 @@ class User extends Component {
return (
<div className="g-doc">
<Row gutter={16} className="user-box">
<Col span={6}>
<LeftMenu />
</Col>
<Col span={18}>
<div>
<Subnav
default={'我的关注'}
data={[{
name: '项目广场',
path: '/group'
}, {
name: '我的关注',
path: '/follow'
}]}/>
<div className="g-doc">
<Row gutter={16} className="user-box">
<Route path={this.props.match.path + '/list'} component={List} />
<Route path={this.props.match.path + '/profile/:uid'} component={Profile} />
</Col>
</Row>
</Row>
</div>
</div>
)
}

View File

@ -161,7 +161,7 @@ export function pushInterfaceMethod (value) {
export function fetchInterfaceProject(id) {
return {
type: FETCH_INTERFACE_PROJECT,
payload: axios.get('/project/get', { params: {id}})
payload: axios.get('/api/project/get', { params: {id}})
}
}

View File

@ -34,7 +34,7 @@ export default (state = initialState, action) => {
export function fetchGroupList() {
return {
type: FETCH_GROUP_LIST,
payload: axios.get('/group/list')
payload: axios.get('/api/group/list')
}
}

View File

@ -46,7 +46,7 @@ export function fetchNewsData (typeid,page,limit) {
}
return {
type: FETCH_NEWS_DATA,
payload: axios.get('/log/list',{
payload: axios.get('/api/log/list',{
params: param
})
};
@ -56,7 +56,7 @@ export function getMockUrl(project_id){
const params = {id: project_id};
return {
type:"",
payload: axios.get('/project/get', {params: params})
payload: axios.get('/api/project/get', {params: params})
}
}

View File

@ -59,7 +59,7 @@ export default (state = initialState, action) => {
export function fetchProjectList(id, pageNum) {
return {
type: FETCH_PROJECT_LIST,
payload: axios.get('/project/list', {
payload: axios.get('/api/project/list', {
params: {
group_id: id,
page: pageNum || 1,
@ -95,7 +95,7 @@ export function addProject(data) {
};
return {
type: PROJECT_ADD,
payload: axios.post('/project/add', param)
payload: axios.post('/api/project/add', param)
};
}
@ -112,7 +112,7 @@ export function updateProject(data) {
};
return {
type: PROJECT_UPDATE,
payload: axios.post('/project/up', param)
payload: axios.post('/api/project/up', param)
};
}
@ -120,6 +120,6 @@ export function delProject(id) {
const param = { id };
return {
type: PROJECT_DEL,
payload: axios.post('/project/del', param)
payload: axios.post('/api/project/del', param)
};
}

View File

@ -81,7 +81,7 @@ export default (state = initialState, action) => {
// Action Creators
export function checkLoginState() {
return(dispatch)=> {
axios.get('/user/status').then((res) => {
axios.get('/api/user/status').then((res) => {
dispatch({
type: GET_LOGIN_STATE,
payload: res
@ -95,7 +95,7 @@ export function checkLoginState() {
export function loginActions(data) {
return {
type: LOGIN,
payload: axios.post('/user/login', data)
payload: axios.post('/api/user/login', data)
};
}
@ -108,14 +108,14 @@ export function regActions(data) {
};
return {
type: REGISTER,
payload: axios.post('/user/reg', param)
payload: axios.post('/api/user/reg', param)
};
}
export function logoutActions() {
return {
type: LOGIN_OUT,
payload: axios.get('./user/logout')
payload: axios.get('/api/user/logout')
}
}

View File

@ -96,7 +96,7 @@ gulp.task('initialBuild', ['removeDist'], () => {
output('success', '初始编译成功!');
waitingSpinner();
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js'], {
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js', 'dev'], {
cwd: __dirname
});

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build-server": "babel server -d server_dist",
"dev-server": "nodemon server_dist/app.js -L",
"dev-server": "nodemon server_dist/app.js dev -L",
"install-server": "node server_dist/install.js",
"dev": "gulp --silent",
"build": "gulp build --silent",

View File

@ -10,13 +10,29 @@ import router from './router.js';
yapi.connect = dbModule.connect();
const app = new Koa();
let indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
app.use(mockServer);
app.use(bodyParser());
app.use(router.routes());
app.use(router.allowedMethods());
app.use( async (ctx, next) => {
if( /^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path) ){
ctx.path = "/"
await next()
}else{
await next()
}
})
app.use(koaStatic(
yapi.path.join(yapi.WEBROOT, 'static')
yapi.path.join(yapi.WEBROOT, 'static'),
{index: indexFile}
));
app.listen(yapi.WEBCONFIG.port);
commons.log(`the server is start at port ${yapi.WEBCONFIG.port}`);

View File

@ -19,7 +19,6 @@ class baseController {
async init(ctx) {
this.$user = null;
console.log(111111)
let ignoreRouter = [
'/user/login_by_token',
'/user/login',

View File

@ -451,7 +451,9 @@ class userController extends baseController {
}
/**
*
* 上传用户头像
* @interface /user/upload_avatar
* @method POST
* @param {*} basecode base64编码通过h5 api传给后端
*/
@ -488,11 +490,19 @@ class userController extends baseController {
}
/**
* 根据用户uid头像
* @interface /user/avatar
* @method GET
* @param {*} uid
*/
async avatar(ctx) {
try{
let uid = ctx.query.uid ? ctx.query.uid: this.getUid();
let avatarInst = yapi.getInst(avatarModel);
let data = await avatarInst.get(this.getUid());
let data = await avatarInst.get(uid);
let dataBuffer, type;
if(!data || !data.basecode){
dataBuffer = yapi.fs.readFileSync(yapi.path.join(yapi.WEBROOT, 'static/image/avatar.png'));

View File

@ -312,7 +312,7 @@ for(let ctrl in routerConfig){
* @param {*} action controller_action_name
*/
function createAction(controller, action, path, method) {
router[method](INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
router[method]("/api" + INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
let inst = new INTERFACE_CONFIG[controller].controller(ctx);
await inst.init(ctx);
@ -325,4 +325,5 @@ function createAction(controller, action, path, method) {
});
}
module.exports = router;

View File

@ -1,5 +1,13 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _yapi = require('./yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
@ -39,11 +47,49 @@ _yapi2.default.commons = _commons2.default;
_yapi2.default.connect = _db2.default.connect();
var app = new _koa2.default();
var indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
app.use(_mockServer2.default);
app.use((0, _koaBodyparser2.default)());
app.use(_router2.default.routes());
app.use(_router2.default.allowedMethods());
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static')));
app.use(function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!/^\/(?!api)[a-zA-Z0-9\/\-]*$/.test(ctx.path)) {
_context.next = 6;
break;
}
ctx.path = "/";
_context.next = 4;
return next();
case 4:
_context.next = 8;
break;
case 6:
_context.next = 8;
return next();
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}());
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static'), { index: indexFile }));
app.listen(_yapi2.default.WEBCONFIG.port);
_commons2.default.log('the server is start at port ' + _yapi2.default.WEBCONFIG.port);

View File

@ -66,23 +66,22 @@ var baseController = function () {
switch (_context.prev = _context.next) {
case 0:
this.$user = null;
console.log(111111);
ignoreRouter = ['/user/login_by_token', '/user/login', '/user/reg', '/user/status', '/user/logout'];
if (!(ignoreRouter.indexOf(ctx.path) > -1)) {
_context.next = 7;
_context.next = 6;
break;
}
this.$auth = true;
_context.next = 9;
_context.next = 8;
break;
case 7:
_context.next = 9;
case 6:
_context.next = 8;
return this.checkLogin(ctx);
case 9:
case 8:
case 'end':
return _context.stop();
}

View File

@ -938,7 +938,9 @@ var userController = function (_baseController) {
}()
/**
*
* 上传用户头像
* @interface /user/upload_avatar
* @method POST
* @param {*} basecode base64编码通过h5 api传给后端
*/
@ -1033,21 +1035,30 @@ var userController = function (_baseController) {
return uploadAvatar;
}()
/**
* 根据用户uid头像
* @interface /user/avatar
* @method GET
* @param {*} uid
*/
}, {
key: 'avatar',
value: function () {
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
var avatarInst, data, dataBuffer, type;
var uid, avatarInst, data, dataBuffer, type;
return _regenerator2.default.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.prev = 0;
uid = ctx.query.uid ? ctx.query.uid : this.getUid();
avatarInst = _yapi2.default.getInst(_avatar2.default);
_context12.next = 4;
return avatarInst.get(this.getUid());
_context12.next = 5;
return avatarInst.get(uid);
case 4:
case 5:
data = _context12.sent;
dataBuffer = void 0, type = void 0;
@ -1061,21 +1072,21 @@ var userController = function (_baseController) {
ctx.set('Content-type', type);
ctx.body = dataBuffer;
_context12.next = 14;
_context12.next = 15;
break;
case 11:
_context12.prev = 11;
case 12:
_context12.prev = 12;
_context12.t0 = _context12['catch'](0);
ctx.body = 'error:' + _context12.t0.message;
case 14:
case 15:
case 'end':
return _context12.stop();
}
}
}, _callee12, this, [[0, 11]]);
}, _callee12, this, [[0, 12]]);
}));
function avatar(_x13) {

View File

@ -1,36 +0,0 @@
"use strict";
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// const jwt = require('jsonwebtoken');
//检查token是否过期
module.exports = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return next();
case 2:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();

View File

@ -1,44 +0,0 @@
"use strict";
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
var path;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
path = ctx.path;
console.log(path); // eslint-disable-line
console.log(ctx.hostname); // eslint-disable-line
if (!next) {
_context.next = 6;
break;
}
_context.next = 6;
return next();
case 6:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();

View File

@ -314,7 +314,7 @@ for (var ctrl in routerConfig) {
function createAction(controller, action, path, method) {
var _this = this;
router[method](INTERFACE_CONFIG[controller].prefix + path, function () {
router[method]("/api" + INTERFACE_CONFIG[controller].prefix + path, function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var inst;
return _regenerator2.default.wrap(function _callee$(_context) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -6,7 +6,6 @@
<title>YAPI-高效、易用、功能强大的api管理平台</title>
<script>
document.write('<script src="prd/assets.js?v=' + Math.random() + '"><\/script>');
console.log(window)
</script>

File diff suppressed because one or more lines are too long