Authored by 李奇

活动管理修改

... ... @@ -15,6 +15,7 @@ const bodyParser = require('body-parser');
const compression = require('compression');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const favicon = require('serve-favicon');
const moment = require('moment');
const _ = require('lodash');
const pkg = require('./package.json');
... ... @@ -36,13 +37,14 @@ global.yoho.utils = {
mysqlCli: new SqlHelper(config.mysql.database)
};
app.use(express.static('public'));
app.use(cookieSession({
name: 'yoho_activity',
secret: 'activity@yoho',
maxAge: 24 * 60 * 60 * 1000
}));
app.use(compression());
app.use(favicon(path.join(__dirname, '/favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
... ...
... ... @@ -4,6 +4,7 @@
* @date: 23/06/2017
*/
const _ = require('lodash');
const moment = require('moment');
const AdminModel = require('../models/admin');
const POST_SUCCESS = '操作成功';
... ... @@ -110,11 +111,27 @@ const article = {
* @param next
*/
activityListPage(req, res, next) {
const _timeFormat = (time) => {
if (_.isNumber(time)) {
time = moment.unix(time);
}
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
req.ctx(AdminModel).activityList()
.then(result => {
_.each(result, item => {
item.endTime = _timeFormat(item.endTime);
item.startTime = _timeFormat(item.startTime);
item.createTime = _timeFormat(item.createTime);
});
res.render('activity/list', {
bodyClass: 'nav-md',
activityList: result
activityList: result,
module: 'admin',
page: 'activity'
});
})
.catch(next);
... ... @@ -165,6 +182,32 @@ const article = {
module: 'admin',
page: 'activity'
});
},
/**
* 活动删除
* @param req
* @param res
* @param next
*/
deleteActivity(req, res, next) {
const id = req.body.id;
if (!id) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
req.ctx(AdminModel).deleteActivity(id)
.then(() => {
return res.json({
code: 200,
message: POST_SUCCESS
});
})
.catch(next);
}
};
... ...
/**
* 文章model
* 管理model
* @author: leo <qi.li@yoho.cn>
* @date: 28/06/2017
*/
... ... @@ -37,7 +37,21 @@ class AdminModel extends global.yoho.BaseModel {
*/
activityList() {
return mysqlCli.query(
`select title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};`
`select id, title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};`
);
}
/**
* 删除活动
* @param actId 活动ID
* @returns {*}
*/
deleteActivity(actId) {
return mysqlCli.delete(
`delete from ${TABLE_ACTIVITY} where id = :actId;`,
{
actId
}
);
}
}
... ...
... ... @@ -19,5 +19,6 @@ router.post('/api/login', admin.login);
router.post('/api/logout', admin.logout);
router.post('/api/activity/list', admin.activityList);
router.post('/api/activity/create', admin.createActivity);
router.post('/api/activity/delete', admin.deleteActivity);
module.exports = router;
... ...
... ... @@ -17,31 +17,28 @@
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="actName" class="form-control col-md-7 col-xs-12"
data-validate-length-range="6" data-validate-words="2" name="actName"
type="text">
type="text" maxlength="50">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="startTime">开始时间<span
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="activityTime">活动时间<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="datetime" id="startTime" name="startTime" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="endTime">结束时间<span
class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="datetime" id="endTime" name="endTime" required="required"
class="form-control col-md-7 col-xs-12">
<div class="input-prepend input-group">
<span class="add-on input-group-addon"><i
class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>
<input type="text" name="activityTime" id="activityTime"
class="form-control col-md-7 col-xs-12"
placeholder="开始时间 - 结束时间"/>
</div>
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button class="btn btn-success create-btn">创建活动</button>
<a class="btn btn-success create-btn">创建活动</a>
</div>
</div>
</form>
... ...
... ... @@ -19,6 +19,7 @@
<th class="column-title">结束时间</th>
<th class="column-title">创建时间</th>
<th class="column-title">活动状态</th>
<th class="column-title">操作</th>
</tr>
</thead>
... ... @@ -30,6 +31,11 @@
<td class=" ">{{endTime}}</td>
<td class=" ">{{createTime}}</td>
<td class=" ">未开始</td>
<td class=" ">
<button class="btn btn-info">活动文章</button>
<button class="btn btn-primary">编辑</button>
<button class="btn btn-danger btn-delete" data-id="{{id}}">删除</button>
</td>
</tr>
{{/each}}
</tbody>
... ...
... ... @@ -37,7 +37,7 @@
<div class="clearfix"></div>
<br/>
<div>
<p>©2017-2020 All Rights Reserved.</p>
<p>YOHO! Activity Platform ©2017-2020 All Rights Reserved.</p>
</div>
</div>
</form>
... ...
... ... @@ -47,7 +47,7 @@ const cssLoader = (env, type) => {
const getEntries = () => {
const entries = {
libs: ['yoho-jquery', path.join(__dirname, '../public/js/global.js')],
libs: ['jquery', path.join(__dirname, '../public/js/global.js')],
common: path.join(__dirname, '../public/scss/common.css'),
};
... ... @@ -114,11 +114,11 @@ module.exports = (env) => {
filename: 'libs.js'
}),
new webpack.ProvidePlugin({
$: 'yoho-jquery',
jQuery: 'yoho-jquery',
'window.jQuery': 'yoho-jquery'
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
// new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
]
};
};
\ No newline at end of file
};
... ...
... ... @@ -20,5 +20,4 @@ module.exports = app => {
// 文章
app.use('/article', article);
};
... ...
... ... @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>YOHO!Activity Admin</title>
<title>YOHO!活动平台</title>
{{#if devEnv}}
<link rel="stylesheet" media="all" href="//{{devHost}}:5001/common.css?t={{startTime}}">
... ... @@ -31,7 +31,7 @@
<!-- menu profile quick info -->
<div class="profile clearfix">
<div class="profile_pic">
<img src="/img/admin/admin_avatar.png" alt="..." class="img-circle profile_img">
<img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="..." class="img-circle profile_img">
</div>
<div class="profile_info">
<span>Welcome,</span>
... ... @@ -47,13 +47,6 @@
<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
<div class="menu_section">
<ul class="nav side-menu">
<li><a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li><a href="index.html">Dashboard</a></li>
<li><a href="index2.html">Dashboard2</a></li>
<li><a href="index3.html">Dashboard3</a></li>
</ul>
</li>
<li><a><i class="fa fa-edit"></i> 活动管理 <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li><a href="/admin/activity/list">活动列表</a></li>
... ... @@ -96,7 +89,7 @@
<li class="">
<a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown"
aria-expanded="false">
<img src="/img/admin/admin_avatar.png" alt="">John Doe
<img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="">John Doe
<span class=" fa fa-angle-down"></span>
</a>
<ul class="dropdown-menu dropdown-usermenu pull-right">
... ... @@ -121,7 +114,7 @@
<ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">
<li>
<a>
<span class="image"><img src="/img/admin/admin_avatar.png" alt="Profile Image"/></span>
<span class="image"><img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="Profile Image"/></span>
<span>
<span>John Smith</span>
<span class="time">3 mins ago</span>
... ... @@ -133,7 +126,7 @@
</li>
<li>
<a>
<span class="image"><img src="/img/admin/admin_avatar.png" alt="Profile Image"/></span>
<span class="image"><img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="Profile Image"/></span>
<span>
<span>John Smith</span>
<span class="time">3 mins ago</span>
... ... @@ -145,7 +138,7 @@
</li>
<li>
<a>
<span class="image"><img src="/img/admin/admin_avatar.png" alt="Profile Image"/></span>
<span class="image"><img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="Profile Image"/></span>
<span>
<span>John Smith</span>
<span class="time">3 mins ago</span>
... ... @@ -157,7 +150,7 @@
</li>
<li>
<a>
<span class="image"><img src="/img/admin/admin_avatar.png" alt="Profile Image"/></span>
<span class="image"><img src="{{imgSrc 'img/admin/admin_avatar.png'}}" alt="Profile Image"/></span>
<span>
<span>John Smith</span>
<span class="time">3 mins ago</span>
... ...
No preview for this file type
... ... @@ -48,7 +48,6 @@
"fast-safe-stringify": "^1.2.0",
"feed": "^1.1.0",
"geetest": "^4.1.2",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"memory-cache": "^0.1.6",
"moment": "^2.18.1",
... ... @@ -63,6 +62,7 @@
"request": "^2.81.0",
"request-promise": "^4.2.1",
"semver": "^5.3.0",
"serve-favicon": "^2.4.3",
"sitemap": "^1.12.0",
"uuid": "^3.0.1",
"yoho-md5": "^2.0.0",
... ... @@ -82,6 +82,7 @@
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.22.0",
"bootstrap": "^3.3.7",
"bootstrap-daterangepicker": "^2.1.25",
"css-loader": "^0.28.4",
"eslint": "^3.19.0",
"eslint-config-yoho": "^1.0.1",
... ... @@ -101,6 +102,8 @@
"happypack": "^3.1.0",
"husky": "^0.13.4",
"install": "^0.10.1",
"jquery": "^3.2.1",
"moment": "^2.18.1",
"nodemon": "^1.11.0",
"npm": "^5.0.4",
"nprogress": "^0.2.0",
... ... @@ -137,7 +140,6 @@
"yoho-fastclick": "^1.0.6",
"yoho-hammer": "^2.0.7",
"yoho-iscroll": "^5.2.0",
"yoho-jquery": "^2.2.4",
"yoho-jquery-lazyload": "^1.9.12",
"yoho-jquery-qrcode": "^0.14.0",
"yoho-lint": "^1.0.1",
... ...
require('admin/activity.page.css');
let $ = require('yoho-jquery');
const createFn = function() {
const $form = $('#createForm');
const actName = $form.find('#actName').val();
const startTime = $form.find('#startTime').val();
const endTime = $form.find('#endTime').val();
$.ajax({
method: 'post',
url: '/admin/api/activity/create',
data: {
startTime,
endTime,
title: actName
}
})
.then(result => {
if (result.code !== 200) {
return;
}
require('bootstrap-daterangepicker');
location.href = '/admin/activity/list';
});
const moment = require('moment');
const toUnixTimestamp = function(time) {
return moment(time).format('X');
};
$('.create-btn').on('click', createFn);
function bind_date_picker() {
if (typeof ($.fn.daterangepicker) === 'undefined') {
return;
}
$('#activityTime').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
});
}
function bind_create_act() {
const createFn = function() {
const $form = $('#createForm');
const actName = $form.find('#actName').val();
const actTime = $form.find('#activityTime').val();
const timeArray = actTime.split(' - ');
const startTime = toUnixTimestamp(timeArray[0]);
const endTime = toUnixTimestamp(timeArray[1]);
$.ajax({
method: 'post',
url: '/admin/api/activity/create',
data: {
startTime,
endTime,
title: actName
}
})
.then(result => {
if (result.code !== 200) {
return;
}
location.href = '/admin/activity/list';
});
};
$('.create-btn').on('click', createFn);
}
function bind_delete_act() {
const deleteFn = function() {
const id = $(this).data('id');
$.ajax({
method: 'post',
url: '/admin/api/activity/delete',
data: {
id
}
})
.then(() => {
location.href = '/admin/activity/list';
});
};
$('.btn-delete').on('click', deleteFn);
}
(function() {
bind_date_picker();
bind_create_act();
bind_delete_act();
}());
... ...
require('admin/login.page.css');
let $ = require('yoho-jquery');
const loginFn = function() {
const $form = $('#loginForm');
... ...
This diff could not be displayed because it is too large.
@import 'login/login';
@import '~bootstrap-daterangepicker';
... ...