From e4a2adab1162f9a3f77c228017dfec692755dc29 Mon Sep 17 00:00:00 2001 From: "yhui.yang" Date: Thu, 27 Jul 2017 14:08:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E6=9C=80=E5=B0=8F=E5=AE=BD=E5=BA=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Footer/Footer.scss | 2 +- client/components/Header/Header.js | 7 +++++-- client/components/Header/Header.scss | 2 +- client/components/Intro/Intro.scss | 2 ++ client/containers/Home/Home.scss | 7 +++++-- client/styles/mixin.scss | 4 ++++ 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/components/Footer/Footer.scss b/client/components/Footer/Footer.scss index 60c8cf6b..17e34b76 100644 --- a/client/components/Footer/Footer.scss +++ b/client/components/Footer/Footer.scss @@ -2,7 +2,7 @@ @import '../../styles/mixin.scss'; .footer{ - // max-width: 12rem; + @include wrap-width-limit; margin: 0px auto; clear: both; font-size: 12px; diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index baf46932..9055657c 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -150,8 +150,11 @@ export default class HeaderCom extends Component { 'background': 'url(./image/header-bg-img.jpg) no-repeat', 'backgroundSize':'100% 100%' }; - const headerShadeStyle = login?{}:{ - 'background': 'linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0.5))' + const headerShadeStyle = login? { + 'padding':'0' + }: { + 'background': 'linear-gradient(to bottom,rgba(0,0,0,0.6),rgba(0,0,0,0.5))', + 'padding':'0' }; return ( diff --git a/client/components/Header/Header.scss b/client/components/Header/Header.scss index 510d199d..b05bb82f 100644 --- a/client/components/Header/Header.scss +++ b/client/components/Header/Header.scss @@ -11,7 +11,7 @@ $color-black-light : #404040; display: block; font-size: 0.14rem; z-index: 99; - // 内容宽度 + @include wrap-width-limit; .content { @include row-width-limit; margin: 0 auto; diff --git a/client/components/Intro/Intro.scss b/client/components/Intro/Intro.scss index a4c3d334..204f2e38 100644 --- a/client/components/Intro/Intro.scss +++ b/client/components/Intro/Intro.scss @@ -52,6 +52,8 @@ $color-white: #fff; } } .img-container{ + height: 100%; + width: 100%; padding-right: .15rem; //background-image: url("#{$imgUrl}demo-img.png"); img{ diff --git a/client/containers/Home/Home.scss b/client/containers/Home/Home.scss index f62eb0f6..5ad5c9d9 100644 --- a/client/containers/Home/Home.scss +++ b/client/containers/Home/Home.scss @@ -12,9 +12,10 @@ $color-black-lighter: #404040; display: -webkit-box; -webkit-box-orient: vertical; .main-one{ + @include wrap-width-limit; .home-des{ color: $color-blue-grey-lighter; - padding: .5rem 0 0; + padding: .4rem 0 0; .title{ font-size: .6rem; } @@ -26,7 +27,7 @@ $color-black-lighter: #404040; color: $color-white; } .img-container{ - margin-bottom: -.2rem; + margin-bottom: -.3rem; img{ width: 100%; height: 100%; @@ -75,6 +76,7 @@ $color-black-lighter: #404040; .main-part{ padding: .9rem .5rem; height: 5.8rem; + @include wrap-width-limit; &:nth-child(odd){ background-color: $color-blue-lighter; } @@ -83,6 +85,7 @@ $color-black-lighter: #404040; } } .feat-part{ + @include wrap-width-limit; padding: .9rem .5rem; background-color: $color-white; p{ diff --git a/client/styles/mixin.scss b/client/styles/mixin.scss index 0489cf44..c94c2eb9 100644 --- a/client/styles/mixin.scss +++ b/client/styles/mixin.scss @@ -2,3 +2,7 @@ max-width: 11.7rem; min-width: 9.7rem; } + +@mixin wrap-width-limit { + min-width: 10.7rem; +} From 4fe4bf3334152aaa7bc77fb8a239e22bedcb4eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9D=E9=91=AB=E5=A5=94?= Date: Thu, 27 Jul 2017 14:12:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?opti:=20=E4=BF=AE=E5=A4=8D=E7=BC=A9?= =?UTF-8?q?=E8=BF=9B=E5=92=8C=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpfile.js | 32 +++++++--- server/controllers/base.js | 97 ++++++++++++++++------------ server/controllers/group.js | 123 +++++++++++++++++++----------------- 3 files changed, 145 insertions(+), 107 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 7f79ee0e..196cc5c6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,14 +12,14 @@ const SRC = 'server/**/*.js'; function generateBabel(status) { const babelProcess = babel({ - presets: ['es2015', "stage-3"], + presets: ['es2015', 'stage-3'], plugins: ['transform-runtime'] }); babelProcess.on('error', function (e) { const restart = status ? status.count < 2 : true; - console.error(e); + console.error(e); // eslint-disable-line output('error', 'babel 编译失败!', restart); if (status) { @@ -39,7 +39,13 @@ function excuteCmd(cmd, args, opts) { }); command.stderr.on('data', data => { - output('log', `${NAME} ${data.toString()}`, true); + const message = data.toString(); + + output('log', `${NAME} ${message}`, true); + + if (~message.indexOf('building complete')) { + waitingSpinner(); + } }); return command; @@ -50,12 +56,12 @@ function output(type, message, restart = false) { if (type === 'success') { message = '✔ ' + message; - console.log(chalk.green(message)); + console.log(chalk.green(message)); // eslint-disable-line } else if (type === 'error') { message = '✖ ' + message; - console.log(chalk.red(message)); + console.log(chalk.red(message)); // eslint-disable-line } else { - console.log(message); + console.log(message); // eslint-disable-line } if (restart) { spinner.start(); @@ -63,6 +69,7 @@ function output(type, message, restart = false) { } function waitingSpinner() { + spinner.stop(); spinner = ora({ text: '等待文件变更...', spinner: 'circleQuarters', @@ -71,7 +78,7 @@ function waitingSpinner() { } gulp.task('removeDist', [], function () { - return fs.removeSync(DIST) + return fs.removeSync(DIST); }); gulp.task('initialBuild', ['removeDist'], () => { @@ -95,9 +102,14 @@ gulp.task('initialBuild', ['removeDist'], () => { }); gulp.task('default', ['initialBuild'], () => { - gulp.watch(SRC, (event) => { - let originFilePath = path.relative(path.join(__dirname, 'server'), event.path) - let distPath = path.resolve(DIST, path.join(originFilePath)) + gulp.watch('client/**/*', event => { + spinner.stop(); + spinner = ora(`正在编译 ${event.path}`).start(); + }); + + gulp.watch(SRC, event => { + let originFilePath = path.relative(path.join(__dirname, 'server'), event.path); + let distPath = path.resolve(DIST, path.join(originFilePath)); spinner.text = `正在编译 ${event.path}...`; gulp.src(event.path).pipe(generateBabel()) diff --git a/server/controllers/base.js b/server/controllers/base.js index b8b2b3d2..876eee35 100644 --- a/server/controllers/base.js +++ b/server/controllers/base.js @@ -1,20 +1,19 @@ -import yapi from '../yapi.js' -import projectModel from '../models/project.js' -import userModel from '../models/user.js' +import yapi from '../yapi.js'; +import projectModel from '../models/project.js'; +import userModel from '../models/user.js'; const jwt = require('jsonwebtoken'); - -class baseController{ - constructor(ctx){ +class baseController { + constructor(ctx) { this.ctx = ctx; //网站上线后,role对象key是不能修改的,value可以修改 this.roles = { admin: 'Admin', member: '网站会员' - } + }; } - async init(ctx){ + async init(ctx) { this.$user = null; let ignoreRouter = [ '/user/login_by_token', @@ -22,73 +21,93 @@ class baseController{ '/user/reg', '/user/status', '/user/logout' - ] - if(ignoreRouter.indexOf(ctx.path) > -1){ + ]; + if (ignoreRouter.indexOf(ctx.path) > -1) { this.$auth = true; - }else{ - await this.checkLogin(ctx) + } else { + await this.checkLogin(ctx); } - + } - getUid(ctx){ + getUid() { return parseInt(this.$uid, 10); } - async checkLogin(ctx){ + async checkLogin(ctx) { let token = ctx.cookies.get('_yapi_token'); - let uid = ctx.cookies.get('_yapi_uid'); - try{ - if(!token || !uid) return false; + let uid = ctx.cookies.get('_yapi_uid'); + + try { + if (!token || !uid) return false; let userInst = yapi.getInst(userModel); //创建user实体 let result = await userInst.findById(uid); - let decoded = jwt.verify(token, result.passsalt) - if(decoded.uid == uid){ + let decoded = jwt.verify(token, result.passsalt); + + if (decoded.uid == uid) { this.$uid = uid; this.$auth = true; - this.$user = result; + this.$user = result; return true; } + return false; - }catch(e){ + } catch (e) { return false; } } - async getLoginStatus(ctx){ - if(await this.checkLogin(ctx) === true){ - return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user,['_id','username','email', 'up_time', 'add_time'])); + async getLoginStatus(ctx) { + if (await this.checkLogin(ctx) === true) { + return ctx.body = yapi.commons.resReturn(yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time'])); } - return ctx.body = yapi.commons.resReturn(null, 300 , 'Please login.'); - + return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.'); } - getRole(){ + getRole() { return this.$user.role; } - async jungeProjectAuth(id){ + async jungeProjectAuth(id) { let model = yapi.getInst(projectModel); - if(this.getRole() === 'admin') return true; - if(!id) return false; - let result = await model.get(id); - if(result.uid === this.getUid()){ + + if (this.getRole() === 'admin') { return true; } + + if (!id) { + return false; + } + + let result = await model.get(id); + + if (result.uid === this.getUid()) { + return true; + } + return false; } - async jungeMemberAuth(id, member_uid){ + async jungeMemberAuth(id, member_uid) { let model = yapi.getInst(projectModel); - if(this.getRole() === 'admin') return true; - if(!id || !member_uid) return false; - let result = await model.checkMemberRepeat(id, member_uid); - if(result > 0){ + + if (this.getRole() === 'admin') { return true; } + + if (!id || !member_uid) { + return false; + } + + let result = await model.checkMemberRepeat(id, member_uid); + + if (result > 0) { + return true; + } + return false; } } -module.exports = baseController \ No newline at end of file +module.exports = baseController; \ No newline at end of file diff --git a/server/controllers/group.js b/server/controllers/group.js index 9dbb7db0..47aac602 100644 --- a/server/controllers/group.js +++ b/server/controllers/group.js @@ -1,14 +1,12 @@ -import groupModel from '../models/group.js' -import yapi from '../yapi.js' -import baseController from './base.js' -import projectModel from '../models/project.js' +import groupModel from '../models/group.js'; +import yapi from '../yapi.js'; +import baseController from './base.js'; +import projectModel from '../models/project.js'; -// -class groupController extends baseController{ - constructor(ctx){ - super(ctx) +class groupController extends baseController { + constructor(ctx) { + super(ctx); } - /** * 添加项目分组 @@ -23,37 +21,45 @@ class groupController extends baseController{ */ async add(ctx) { let params = ctx.request.body; + params = yapi.commons.handleParams(params, { group_name: 'string', group_desc: 'string' - }) - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); + }); + + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); } - if(!params.group_name){ + + if (!params.group_name) { return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空'); } - var groupInst = yapi.getInst(groupModel); - - var checkRepeat = await groupInst.checkRepeat(params.group_name); - if(checkRepeat > 0){ - return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在'); + + let groupInst = yapi.getInst(groupModel); + + let checkRepeat = await groupInst.checkRepeat(params.group_name); + + if (checkRepeat > 0) { + return ctx.body = yapi.commons.resReturn(null, 401, '项目分组名已存在'); } + let data = { group_name: params.group_name, group_desc: params.group_desc, uid: this.getUid(), add_time: yapi.commons.time(), up_time: yapi.commons.time() - } - try{ + }; + + try { let result = await groupInst.save(data); + result = yapi.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']); ctx.body = yapi.commons.resReturn(result); - }catch(e){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); } - + } /** @@ -65,14 +71,13 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/list.json */ - async list(ctx) { - try{ + try { var groupInst = yapi.getInst(groupModel); let result = await groupInst.list(); - ctx.body = yapi.commons.resReturn(result) - }catch(e){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (e) { + ctx.body = yapi.commons.resReturn(null, 402, e.message); } } @@ -86,27 +91,30 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/del.json */ + async del(ctx) { + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); + } - async del(ctx){ - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); - } - try{ - var groupInst = yapi.getInst(groupModel); - var projectInst = yapi.getInst(projectModel); - let id = ctx.request.body.id; - if(!id){ + try { + let groupInst = yapi.getInst(groupModel); + let projectInst = yapi.getInst(projectModel); + let id = ctx.request.body.id; + + if (!id) { return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空'); } - let count = await projectInst.countByGroupId(id); - if(count > 0){ + + let count = await projectInst.countByGroupId(id); + + if (count > 0) { return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目'); } let result = await groupInst.del(id); - ctx.body = yapi.commons.resReturn(result) - }catch(err){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); } } @@ -122,33 +130,32 @@ class groupController extends baseController{ * @returns {Object} * @example ./api/group/up.json */ - - async up(ctx){ - if(this.getRole() !== 'admin'){ - return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); + async up(ctx) { + if (this.getRole() !== 'admin') { + return ctx.body = yapi.commons.resReturn(null, 401, '没有权限'); } - try{ - + + try { + ctx.request.body = yapi.commons.handleParams(ctx.request.body, { id: 'number', group_name: 'string', group_desc: 'string' - }) - var groupInst = yapi.getInst(groupModel); + }); + let groupInst = yapi.getInst(groupModel); let id = ctx.request.body.id; let data = {}; - ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name) - ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc) - if(Object.keys(data).length === 0 ){ + ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name); + ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc); + if (Object.keys(data).length === 0) { ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空'); } let result = await groupInst.up(id, data); - ctx.body = yapi.commons.resReturn(result) - }catch(err){ - ctx.body = yapi.commons.resReturn(null, 402, e.message) + ctx.body = yapi.commons.resReturn(result); + } catch (err) { + ctx.body = yapi.commons.resReturn(null, 402, err.message); } } } - -module.exports = groupController +module.exports = groupController; \ No newline at end of file