Authored by 李奇

文章列表导出添加

... ... @@ -5,6 +5,7 @@
*/
const _ = require('lodash');
const moment = require('moment');
const excelExport = require('excel-export');
const AdminModel = require('../models/admin');
const POST_SUCCESS = '操作成功';
... ... @@ -240,6 +241,7 @@ const article = {
item.createTime = timeFormat(item.createTime);
});
res.render('activity/article-list', {
actId,
bodyClass: 'nav-md',
articleList: result,
module: 'admin',
... ... @@ -276,6 +278,73 @@ const article = {
},
/**
* 文章列表导出
* @param req
* @param res
* @param next
*/
exportArticleList(req, res, next) {
const actId = req.query.actId;
if (!actId) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
let conf = {
name: 'mysheet',
cols: [
{
caption: '文章ID',
type: 'string'
},
{
caption: '赞数',
type: 'number'
},
{
caption: '发布者',
type: 'string'
},
{
caption: '手机号',
type: 'string'
},
{
caption: '创建时间',
type: 'string'
}
],
rows: []
};
req.ctx(AdminModel).actArticleList(actId)
.then(result => {
let temp = [];
_.each(result, item => {
temp = [];
temp.push(item.id);
temp.push(item.goodCount);
temp.push(item.userName);
temp.push(item.phone);
temp.push(timeFormat(item.createTime));
conf.rows.push(temp);
});
let exportFile = excelExport.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', 'attachment; filename=articleList.xlsx');
res.end(exportFile, 'binary');
})
.catch(next);
},
/**
* 活动参与用户列表
* @param req
* @param res
... ...
... ... @@ -23,5 +23,6 @@ router.post('/api/activity/list', admin.activityList);
router.post('/api/activity/create', admin.createActivity);
router.post('/api/activity/delete', admin.deleteActivity);
router.post('/api/activity/deleteArticle', admin.deleteArticle);
router.get('/api/activity/exportArticleList', admin.exportArticleList);
module.exports = router;
... ...
... ... @@ -8,7 +8,7 @@
<h2>文章列表</h2>
<div class="clearfix"></div>
</div>
<button class="btn btn-primary btn-export-article" data-id="{{actId}}">列表导出</button>
<div class="x_content">
<div class="table-responsive">
<table class="table table-striped jambo_table bulk_action">
... ...
... ... @@ -9,7 +9,7 @@
<div class="clearfix"></div>
</div>
<div class="x_content">
<form id="createForm" class="form-horizontal form-label-left" novalidate>
<form id="createForm" class="form-horizontal form-label-left">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">活动名称<span
class="required">*</span>
... ... @@ -38,7 +38,7 @@
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<a class="btn btn-success create-btn">创建活动</a>
<button type="button" class="btn btn-success create-btn">创建活动</button>
</div>
</div>
</form>
... ...
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>用户列表</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<div class="table-responsive">
<table class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">活动ID</th>
<th class="column-title">活动名称</th>
<th class="column-title">开始时间</th>
<th class="column-title">结束时间</th>
<th class="column-title">创建时间</th>
<th class="column-title">操作</th>
</tr>
</thead>
<tbody>
{{#each activityList}}
<tr class="even pointer">
<td class="">{{id}}</td>
<td class="">{{title}}</td>
<td class="">{{startTime}}</td>
<td class="">{{endTime}}</td>
<td class="">{{createTime}}</td>
<td class="">
<a class="btn btn-info" href="/admin/activity/article?actId={{id}}">活动文章</a>
<button class="btn btn-danger btn-delete" data-id="{{id}}">删除活动</button>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /page content -->
... ...
/**
* 管理员app
* @author: leo <qi.li@yoho.cn>
* @date: 23/06/2017
*/
const path = require('path');
const express = require('express');
const app = express();
const doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'error',
layoutsDir: doraemon,
partialsDir: path.join(__dirname, 'views/partial'),
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
app.locals.layout = 'error';
app.use(require('./router'));
module.exports = app;
... ...
... ... @@ -53,6 +53,11 @@
<li><a href="/admin/activity/create">活动创建</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/user/list">用户列表</a></li>
</ul>
</li>
</ul>
</div>
</div>
... ...
... ... @@ -44,6 +44,7 @@
"cookie-session": "^2.0.0-beta.2",
"cors": "^2.8.3",
"cssnano": "^3.10.0",
"excel-export": "^0.5.1",
"express": "^4.15.3",
"fast-safe-stringify": "^1.2.0",
"feed": "^1.1.0",
... ...
... ... @@ -88,11 +88,22 @@ function bind_delete_article() {
$('.btn-delete-article').on('click', deleteFn);
}
function bind_export_article_list() {
const deleteFn = function() {
const actId = $(this).data('id');
window.open(`/admin/api/activity/exportArticleList?actId=${actId}`, '_blank');
};
$('.btn-export-article').on('click', deleteFn);
}
(function() {
bind_date_picker();
bind_create_act();
bind_delete_act();
bind_delete_article();
bind_export_article_list();
}());
... ...
... ... @@ -112,6 +112,10 @@ amdefine@>=0.0.4:
version "1.0.1"
resolved "http://npm.yoho.cn/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
animate.css@^3.5.2:
version "3.5.2"
resolved "http://npm.yoho.cn/animate.css/-/animate.css-3.5.2.tgz#91e668dc069a808e5e499514867b97aae0166c36"
ansi-align@^2.0.0:
version "2.0.0"
resolved "http://npm.yoho.cn/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f"
... ... @@ -985,6 +989,13 @@ boom@2.x.x:
dependencies:
hoek "2.x.x"
bootstrap-daterangepicker@^2.1.25:
version "2.1.25"
resolved "http://npm.yoho.cn/bootstrap-daterangepicker/-/bootstrap-daterangepicker-2.1.25.tgz#fcd8ba0b755a054d330d7a3b7c4dd8bb855cffb7"
dependencies:
jquery ">=1.10"
moment "^2.9.0"
bootstrap@^3.3.7:
version "3.3.7"
resolved "http://npm.yoho.cn/bootstrap/-/bootstrap-3.3.7.tgz#5a389394549f23330875a3b150656574f8a9eb71"
... ... @@ -1418,6 +1429,12 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "http://npm.yoho.cn/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
collections@^3.0.0:
version "3.0.0"
resolved "http://npm.yoho.cn/collections/-/collections-3.0.0.tgz#27e3894df1b24cedfc55a1bbb0c0da12f68bab31"
dependencies:
weak-map "~1.0.x"
color-convert@^1.3.0:
version "1.9.0"
resolved "http://npm.yoho.cn/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a"
... ... @@ -2649,6 +2666,13 @@ evp_bytestokey@^1.0.0:
dependencies:
create-hash "^1.1.1"
excel-export@^0.5.1:
version "0.5.1"
resolved "http://npm.yoho.cn/excel-export/-/excel-export-0.5.1.tgz#6d08787f98b2ec931e4b3dcff18cc9083bbb8b77"
dependencies:
collections "^3.0.0"
node-zip "1.x"
execa@^0.4.0:
version "0.4.0"
resolved "http://npm.yoho.cn/execa/-/execa-0.4.0.tgz#4eb6467a36a095fabb2970ff9d5e3fb7bce6ebc3"
... ... @@ -2951,6 +2975,10 @@ flush-write-stream@^1.0.0:
inherits "^2.0.1"
readable-stream "^2.0.4"
font-awesome@^4.7.0:
version "4.7.0"
resolved "http://npm.yoho.cn/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133"
for-in@^1.0.1:
version "1.0.2"
resolved "http://npm.yoho.cn/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
... ... @@ -4233,7 +4261,7 @@ jpeg-js@^0.1.1:
version "0.1.2"
resolved "http://npm.yoho.cn/jpeg-js/-/jpeg-js-0.1.2.tgz#135b992c0575c985cfa0f494a3227ed238583ece"
jquery@^3.2.1:
jquery@>=1.10, jquery@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.2.1.tgz#5c4d9de652af6cd0a770154a631bba12b015c787"
... ... @@ -4356,6 +4384,12 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"
jszip@2.5.0:
version "2.5.0"
resolved "http://npm.yoho.cn/jszip/-/jszip-2.5.0.tgz#7444fd8551ddf3e5da7198fea0c91bc8308cc274"
dependencies:
pako "~0.2.5"
kew@~0.7.0:
version "0.7.0"
resolved "http://npm.yoho.cn/kew/-/kew-0.7.0.tgz#79d93d2d33363d6fdd2970b335d9141ad591d79b"
... ... @@ -5093,7 +5127,7 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdi
dependencies:
minimist "0.0.8"
moment@^2.13.0, moment@^2.18.1:
moment@^2.13.0, moment@^2.18.1, moment@^2.9.0:
version "2.18.1"
resolved "http://npm.yoho.cn/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
... ... @@ -5311,6 +5345,12 @@ node-sass@^4.2.0:
sass-graph "^2.1.1"
stdout-stream "^1.4.0"
node-zip@1.x:
version "1.1.1"
resolved "http://npm.yoho.cn/node-zip/-/node-zip-1.1.1.tgz#94d1ad674a3cd46a1588dd736f4a9a78c757eb62"
dependencies:
jszip "2.5.0"
node-zookeeper-client@^0.2.2:
version "0.2.2"
resolved "http://npm.yoho.cn/node-zookeeper-client/-/node-zookeeper-client-0.2.2.tgz#097bda01999eef8f602ce068b632600069dbf685"
... ... @@ -5546,6 +5586,10 @@ npm@^5.0.4:
gauge "~2.7.3"
set-blocking "~2.0.0"
nprogress@^0.2.0:
version "0.2.0"
resolved "http://npm.yoho.cn/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
nth-check@~1.0.1:
version "1.0.1"
resolved "http://npm.yoho.cn/nth-check/-/nth-check-1.0.1.tgz#9929acdf628fc2c41098deab82ac580cf149aae4"
... ... @@ -5820,7 +5864,7 @@ pacote@~2.7.34:
unique-filename "^1.1.0"
which "^1.2.12"
pako@~0.2.0:
pako@~0.2.0, pako@~0.2.5:
version "0.2.9"
resolved "http://npm.yoho.cn/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
... ... @@ -7537,6 +7581,16 @@ serialize-error@^2.1.0:
version "2.1.0"
resolved "http://npm.yoho.cn/serialize-error/-/serialize-error-2.1.0.tgz#50b679d5635cdf84667bdc8e59af4e5b81d5f60a"
serve-favicon@^2.4.3:
version "2.4.3"
resolved "http://npm.yoho.cn/serve-favicon/-/serve-favicon-2.4.3.tgz#5986b17b0502642b641c21f818b1acce32025d23"
dependencies:
etag "~1.8.0"
fresh "0.5.0"
ms "2.0.0"
parseurl "~1.3.1"
safe-buffer "5.0.1"
serve-index@^1.7.2:
version "1.9.0"
resolved "http://npm.yoho.cn/serve-index/-/serve-index-1.9.0.tgz#d2b280fc560d616ee81b48bf0fa82abed2485ce7"
... ... @@ -8793,6 +8847,10 @@ wcwidth@^1.0.0:
dependencies:
defaults "^1.0.3"
weak-map@~1.0.x:
version "1.0.5"
resolved "http://npm.yoho.cn/weak-map/-/weak-map-1.0.5.tgz#79691584d98607f5070bd3b70a40e6bb22e401eb"
webpack-bundle-analyzer@^2.8.2:
version "2.8.2"
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-2.8.2.tgz#8b6240c29a9d63bc72f09d920fb050adbcce9fe8"
... ... @@ -9178,10 +9236,6 @@ yoho-jquery-qrcode@^0.14.0:
version "0.14.0"
resolved "http://npm.yoho.cn/yoho-jquery-qrcode/-/yoho-jquery-qrcode-0.14.0.tgz#e583c2d6a51a96e31cf60b982afb6445b2b80b39"
yoho-jquery@^2.2.4:
version "2.2.4"
resolved "http://npm.yoho.cn/yoho-jquery/-/yoho-jquery-2.2.4.tgz#8115e8320fa75feaba0527d186443f2884c78b36"
yoho-lint@^1.0.1:
version "1.0.1"
resolved "http://npm.yoho.cn/yoho-lint/-/yoho-lint-1.0.1.tgz#91c033d198b2144c05433f0b17446a1fa3c4012a"
... ...