Skip to content

Commit 1ccb293

Browse files
committed
prepare qrcode
1 parent 9e0f8d3 commit 1ccb293

File tree

8 files changed

+76
-10
lines changed

8 files changed

+76
-10
lines changed

app.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var multer = require('multer');
55
var request = require('request')
66
var qsLib = require('qs')
77
var _ = require('lodash')
8+
var session = require('express-session')
9+
var flash = require('connect-flash');
10+
var yaqrcode = require('yaqrcode');
811

912
var authMiddleware = require('./middleware/auth')
1013

@@ -13,11 +16,15 @@ var app = express();
1316
app.set('views', './view')
1417
app.set('view engine', 'ejs');
1518

16-
app.use(bodyParser.urlencoded({extended: true}))
1719

1820
app.use('/static', express.static('./static'))
1921
app.use(authMiddleware.userAuth)
2022

23+
app.use(bodyParser.urlencoded({extended: true}))
24+
app.use(session({
25+
secret: 'project-9',
26+
}))
27+
app.use(flash());
2128

2229
app.use(function (req, res, next) {
2330
res.locals.tabname = res.locals.tabname || '';
@@ -100,7 +107,8 @@ app.get('/showlist', function (req, res) {
100107
res.render('list', {
101108
list: listInfo.list.reverse(),
102109
labels: labels,
103-
tabname: 'showlist'
110+
tabname: 'showlist',
111+
info: req.flash('info')
104112
})
105113
})
106114
})
@@ -113,12 +121,38 @@ app.get('/showpic/:picid', function (req, res) {
113121

114122
var picInfo = _.find(listInfo.list, {_id: req.params.picid})
115123

124+
var picUrl = config.my_main_page + req.originalUrl
125+
116126
res.render('pic_detail', {
117127
picInfo: picInfo,
128+
picUrl: picUrl,
118129
})
119130
})
120131
})
121132

133+
134+
app.post('/delpic', function (req, res) {
135+
var picid = req.body.picid;
136+
137+
var delUrl = config.api_backend + '/delete'
138+
139+
request.post({
140+
url: delUrl,
141+
json: true,
142+
body: {
143+
id: picid
144+
}
145+
}, function (err, response) {
146+
if (err) {
147+
return res.send(err);
148+
}
149+
150+
req.flash('info', '删除成功!')
151+
152+
res.redirect('/showlist')
153+
})
154+
})
155+
122156
app.listen(config.web_app_port, function () {
123157
console.log(`${new Date}, app is listening at ${config.web_app_port}`)
124158
});

config.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var config = {
66
linktang: 'muerqiaohuiche',
77
},
88
api_backend: 'http://119.29.70.101:3000',
9+
10+
my_main_page: 'http://project9.qcourse.net',
911
}
1012

1113

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
"multer": "^1.1.0",
2626
"request": "^2.73.0",
2727
"qs": "^6.2.0",
28-
"lodash": "^4.13.1"
28+
"lodash": "^4.13.1",
29+
"express-session": "^1.14.0",
30+
"connect-flash": "^0.1.1",
31+
"yaqrcode": "^0.2.1"
2932
}
3033
}

readme.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
1. 作为一个授权用户,我可以输入一个关键词来搜索之前上传的图片,支持搜索名称、标签、alt文本
1010
1. 作为一个授权用户,我可以点击搜索结果中的某一张照片,并打开照片详情页,查看图片的所有详细字段
1111
1. 作为一个授权用户,我可以删除一张我之前上传的照片
12-
1. 作为一个授权用户,我可以将某个照片的下载地址制作成短地址,并生成所对应的二维码,显示在图片详情页
13-
1. 我可以用微信扫描生成的二维码,在微信中打开对应的图片
14-
12+
1. 作为一个授权用户,我可以将某个照片的下载地址生成对应的二维码,显示在图片详情页
1513

1614
想要了解项目的完整构建过程,请参考[wiki](https://github.com/qcourse/node-project-9/wiki/)

view/footer.ejs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11

2-
<script src="/static/vendor/jquery-2.2.4.js"></script>
3-
<script src="/static/vendor/bootstrap-3.3.6-dist/js/bootstrap.js"></script>
42
</body>
53
</html>

view/header.ejs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<link rel="stylesheet" href="/static/vendor/bootstrap-3.3.6-dist/css/bootstrap.css">
44
<link rel="stylesheet" href="/static/vendor/bootstrap-3.3.6-dist/css/bootstrap-theme.css">
55
<link rel="stylesheet" href="/static/css/custom.css">
6+
7+
<script src="/static/vendor/jquery-2.2.4.js"></script>
8+
<script src="/static/vendor/bootstrap-3.3.6-dist/js/bootstrap.js"></script>
69
</head>
710
<body>
811

view/list.ejs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<%- include('./header') %>
22

33
<div class="container">
4+
5+
<% if (info.length !== 0) {%>
6+
<div class="alert alert-success" role="alert">
7+
<% info.forEach(function (msg) { %>
8+
<%= msg %>
9+
<% }) %>
10+
</div>
11+
<% } %>
12+
413
<div class="row"><p>共 <%= list.length %> 张</p></div>
514
<div class="row">
615
<p>
@@ -16,7 +25,6 @@
1625
var pic = list[i];
1726
%>
1827
<div class="col-xs-6 col-md-3">
19-
2028
<a href="/showpic/<%- pic._id %>" class="thumbnail">
2129
<img src="<%- pic.url %>" alt="<%- pic.meta.alt %>">
2230
</a>

view/pic_detail.ejs

+21-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,31 @@
99
<h3>名字:<%= picInfo.name %></h3>
1010
<p>alt文本:<%= picInfo.meta.alt %></p>
1111
<p>标签:<%= picInfo.meta.labels %></p>
12+
<p>
13+
<form action="/delpic" method="POST" data-action="delpic">
14+
<input type="hidden" name="picid" value="<%- picInfo._id%>">
15+
<input type="submit" class="btn btn-danger" value="删除">
16+
</form>
17+
</p>
1218
</div>
1319
</div>
1420
</div>
1521

22+
<div class="col-xs-6">
23+
<%- picUrl %>
24+
</div>
25+
1626
</div>
1727
</div>
1828

19-
<%- include('./footer') %>
29+
<script>
30+
$(function () {
31+
$('[data-action="delpic"]').on('submit', function () {
32+
return confirm('确认删除这张照片吗?')
33+
})
34+
})
35+
</script>
36+
37+
38+
<%- include('./footer') %>
39+

0 commit comments

Comments
 (0)