docs: 文档更新

This commit is contained in:
wenbo.dong 2017-08-11 16:16:16 +08:00
parent fcba2f35fe
commit 1479728ffd
5 changed files with 205 additions and 48 deletions

View File

@ -138,12 +138,20 @@
<a href="#-user-update">/user/update</a>
</li>
<li >
<a href="#-user-upload_avatar">/user/upload_avatar</a>
</li>
<li >
<a href="#-user-avatar">/user/avatar</a>
</li>
<li >
<a href="#-user-search">/user/search</a>
</li>
<li >
<a href="#-user-nav">/user/nav</a>
<a href="#-user-project">/user/project</a>
</li>
</ul>
@ -1242,6 +1250,130 @@
</div>
<div class="con-list-item">
<blockquote class="api">
<h3 id="-user-upload_avatar" class="page-header subject">
/user/upload_avatar
<span class="ui-badge">POST</span>
<a class="hashlink" href="#-user-upload_avatar">#</a>
</h3>
</blockquote>
<p>
<small class="text-muted">描述:</small>
上传用户头像
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#452" target="_blank">./server/controllers/user.js:452</a>
</p>
<p>
<small class="text-muted">参数:</small>
</p>
<div class="docs-table">
<table class="yo-table yo-table-border">
<colgroup>
<col class="c1">
<col class="c2">
<col class="c3">
<col class="c4">
</colgroup>
<thead>
<tr class="active">
<th>参数名</th>
<th>类型</th>
<th>描述</th>
<th>必选</th>
<th>支持版本</th>
</tr>
</thead>
<tr>
<td>basecode</td>
<td>*</td>
<td>base64编码通过h5 api传给后端</td>
<td>
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
</td>
<td></td>
</tr>
</table>
</div>
</div>
<div class="con-list-item">
<blockquote class="api">
<h3 id="-user-avatar" class="page-header subject">
/user/avatar
<span class="ui-badge">GET</span>
<a class="hashlink" href="#-user-avatar">#</a>
</h3>
</blockquote>
<p>
<small class="text-muted">描述:</small>
根据用户uid头像
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#495" target="_blank">./server/controllers/user.js:495</a>
</p>
<p>
<small class="text-muted">参数:</small>
</p>
<div class="docs-table">
<table class="yo-table yo-table-border">
<colgroup>
<col class="c1">
<col class="c2">
<col class="c3">
<col class="c4">
</colgroup>
<thead>
<tr class="active">
<th>参数名</th>
<th>类型</th>
<th>描述</th>
<th>必选</th>
<th>支持版本</th>
</tr>
</thead>
<tr>
<td>uid</td>
<td>*</td>
<td></td>
<td>
<i class="yo-ico glyphicon glyphicon-ok text-success"></i>
</td>
<td></td>
</tr>
</table>
</div>
</div>
<div class="con-list-item">
@ -1262,7 +1394,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#511" target="_blank">./server/controllers/user.js:511</a>
<a href="./static/server/controllers/user.js.html#527" target="_blank">./server/controllers/user.js:527</a>
</p>
@ -1324,23 +1456,23 @@
<div class="con-list-item">
<blockquote class="api">
<h3 id="-user-nav" class="page-header subject">
/user/nav
<h3 id="-user-project" class="page-header subject">
/user/project
<span class="ui-badge">GET</span>
<a class="hashlink" href="#-user-nav">#</a>
<a class="hashlink" href="#-user-project">#</a>
</h3>
</blockquote>
<p>
<small class="text-muted">描述:</small>
根据路由id获取面包屑数据
根据路由id初始化项目数据
</p>
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#556" target="_blank">./server/controllers/user.js:556</a>
<a href="./static/server/controllers/user.js.html#572" target="_blank">./server/controllers/user.js:572</a>
</p>
@ -1393,20 +1525,6 @@
</div>
<div>示例:</div>
<pre class="ydoc-example" data-foldnumber=10><code class="js-code"><span class="token punctuation">{</span>
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"success"</span><span class="token punctuation">,</span>
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"interface_id"</span><span class="token punctuation">:</span> <span class="token number">2746</span><span class="token punctuation">,</span>
<span class="token string">"interface_name"</span><span class="token punctuation">:</span> <span class="token string">"/a/c"</span><span class="token punctuation">,</span>
<span class="token string">"project_id"</span><span class="token punctuation">:</span> <span class="token number">2481</span><span class="token punctuation">,</span>
<span class="token string">"project_name"</span><span class="token punctuation">:</span> <span class="token string">"www.xxx.com/api"</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">181</span><span class="token punctuation">,</span>
<span class="token string">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"YMFE"</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
</div>

View File

@ -47,11 +47,11 @@ class baseController {
async init(ctx) {
this.$user = null;
let ignoreRouter = [
'/user/login_by_token',
'/user/login',
'/user/reg',
'/user/status',
'/user/logout'
'/api/user/login_by_token',
'/api/user/login',
'/api/user/reg',
'/api/user/status',
'/api/user/logout'
];
if (ignoreRouter.indexOf(ctx.path) > -1) {
this.$auth = true;
@ -88,10 +88,14 @@ class baseController {
}
}
/**
*
* @param {*} ctx
*/
async getLoginStatus(ctx) {
if (await this.checkLogin(ctx) === true) {
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time', 'role']);
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time', 'role', 'type']);
result.server_ip = yapi.WEBCONFIG.server_ip;
return ctx.body = yapi.commons.resReturn(result);
}

View File

@ -603,7 +603,7 @@ class projectController extends baseController {
}, 500);
});
}
module.exports = run;`;
module.exports = run;`
.trim();
return ctx.body = res;
}

View File

@ -81,8 +81,8 @@ class userController extends baseController {
email: result.email,
add_time: result.add_time,
up_time: result.up_time,
server_ip: yapi.WEBCONFIG.server_ip
server_ip: yapi.WEBCONFIG.server_ip,
type: 'site'
}, 0, 'logout success...');
} else {
return ctx.body = yapi.commons.resReturn(null, 405, '密码错误');
@ -478,8 +478,13 @@ class userController extends baseController {
}
/**
*
* 上传用户头像
* @interface /user/upload_avatar
* @method POST
* @param {*} basecode base64编码通过h5 api传给后端
* @category user
* @returns {Object}
* @example
*/
async uploadAvatar(ctx) {
@ -515,11 +520,22 @@ class userController extends baseController {
}
/**
* 根据用户uid头像
* @interface /user/avatar
* @method GET
* @param {*} uid
* @category user
* @returns {Object}
* @example
*/
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'));
@ -582,26 +598,24 @@ class userController extends baseController {
}
/**
* 根据路由id获取面包屑数据
* @interface /user/nav
* 根据路由id初始化项目数据
* @interface /user/project
* @method GET
* @category user
* @foldnumber 10
* @param {String} type 可选group|interface|project
* @param {Number} id
* @return {Object}
* @example ./api/user/nav.json
* @example
*/
async nav(ctx) {
async project(ctx) {
let { id, type } = ctx.request.query;
let result = {};
try {
if (type === 'interface') {
let interfaceInst = yapi.getInst(interfaceModel);
let interfaceData = await interfaceInst.get(id)
result["interface_id"] = interfaceData._id;
result["interface_name"] = interfaceData.path;
result.interface = interfaceData;
type = 'project';
id = interfaceData.project_id;
}
@ -609,17 +623,38 @@ class userController extends baseController {
if (type === 'project') {
let projectInst = yapi.getInst(projectModel);
let projectData = await projectInst.get(id);
result["project_id"] = projectData._id;
result["project_name"] = projectData.prd_host + projectData.basepath;
result.project = projectData.toObject();
let ownerAuth = await this.checkAuth(id, 'project', 'danger'), devAuth;
if(ownerAuth){
result.project.role = 'owner'
}else{
devAuth = await this.checkAuth(id, 'project', 'site');
if(devAuth){
result.project.role = 'dev'
}else{
result.project.role = 'member'
}
}
type = 'group';
id = projectData.group_id
id = projectData.group_id;
}
if (type === 'group') {
let groupInst = yapi.getInst(groupModel);
let groupData = await groupInst.get(id);
result["group_id"] = groupData._id;
result["group_name"] = groupData.group_name;
result.group = groupData.toObject();
let ownerAuth = await this.checkAuth(id, 'group', 'danger'), devAuth;
if(ownerAuth){
result.group.role = 'owner'
}else{
devAuth = await this.checkAuth(id, 'group', 'site');
if(devAuth){
result.group.role = 'dev'
}else{
result.group.role = 'member'
}
}
}
return ctx.body = yapi.commons.resReturn(result)

View File

@ -85,7 +85,7 @@
"options": {
"type": "interface", // component lib component
"source": true, // false
"categories":["group","user","project", "interface"]
"categories":["group","user","project", "interface","follow"]
}
}]