Showing
9 changed files
with
140 additions
and
0 deletions
apps/news/controllers/detail.js
0 → 100644
1 | +/** | ||
2 | + * | ||
3 | + * @author: Aiden Xu<aiden.xu@yoho.cn> | ||
4 | + * @date: 2016/07/25 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | + | ||
8 | +// const _ = require('lodash'); | ||
9 | + | ||
10 | +// const helpers = global.yoho.helpers; | ||
11 | +const model = require('../models/detail'); | ||
12 | + | ||
13 | +/** | ||
14 | + * 商品详情 | ||
15 | + */ | ||
16 | +const component = { | ||
17 | + index(req, res) { | ||
18 | + res.render('detail', { | ||
19 | + module: 'news', | ||
20 | + page: 'detail' | ||
21 | + }); | ||
22 | + }, | ||
23 | + news(req, res, next) { | ||
24 | + let params = { | ||
25 | + uid: req.user.uid || 8050378 // TODO: fix this hard coded uid | ||
26 | + }; | ||
27 | + | ||
28 | + model.product(params).then(result => { | ||
29 | + res.json(result); | ||
30 | + }).catch(next); | ||
31 | + } | ||
32 | +}; | ||
33 | + | ||
34 | +module.exports = component; |
apps/news/index.js
0 → 100644
1 | +/** | ||
2 | + * sub app | ||
3 | + * @author: Bi Kai<kai.bi@yoho.cn> | ||
4 | + * @date: 2016/05/09 | ||
5 | + */ | ||
6 | + | ||
7 | +const express = require('express'); | ||
8 | +const path = require('path'); | ||
9 | +const hbs = require('express-handlebars'); | ||
10 | + | ||
11 | +const app = express(); | ||
12 | + | ||
13 | +// set view engine | ||
14 | +const doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root | ||
15 | + | ||
16 | +app.on('mount', function(parent) { | ||
17 | + delete parent.locals.settings; // 不继承父 App 的设置 | ||
18 | + Object.assign(app.locals, parent.locals); | ||
19 | +}); | ||
20 | + | ||
21 | +app.set('views', path.join(__dirname, 'views/action')); | ||
22 | +app.engine('.hbs', hbs({ | ||
23 | + extname: '.hbs', | ||
24 | + defaultLayout: 'layout', | ||
25 | + layoutsDir: doraemon, | ||
26 | + partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`], | ||
27 | + helpers: global.yoho.helpers | ||
28 | +})); | ||
29 | + | ||
30 | +// router | ||
31 | +app.use(require('./router')); | ||
32 | + | ||
33 | +module.exports = app; |
apps/news/models/detail.js
0 → 100644
1 | +/** | ||
2 | + * | ||
3 | + * @author: Aiden Xu<aiden.xu@yoho.cn> | ||
4 | + * @date: 2016/07/25 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | + | ||
8 | +// const _ = require('lodash'); | ||
9 | + | ||
10 | +// const helpers = global.yoho.helpers; | ||
11 | +const api = global.yoho.API; | ||
12 | + | ||
13 | +/** | ||
14 | + * 资讯详情 | ||
15 | + */ | ||
16 | +const model = { | ||
17 | + product(params) { | ||
18 | + return api.get('', Object.assign({ | ||
19 | + method: 'h5.product.data' | ||
20 | + }, params)); | ||
21 | + } | ||
22 | +}; | ||
23 | + | ||
24 | +module.exports = model; |
apps/news/router.js
0 → 100644
1 | +/** | ||
2 | + * router of sub app news | ||
3 | + * @author: Aiden Xu<aiden.xu@yoho.cn> | ||
4 | + * @date: 2016/07/25 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const expressRouter = require('express').Router; | ||
10 | +const cRoot = './controllers'; | ||
11 | +const router = expressRouter(); | ||
12 | + | ||
13 | +// 详情controller | ||
14 | +const detail = require(`${cRoot}/detail`); | ||
15 | + | ||
16 | +router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers | ||
17 | +module.exports = router; |
apps/news/views/action/detail.hbs
0 → 100644
@@ -10,6 +10,7 @@ module.exports = app => { | @@ -10,6 +10,7 @@ module.exports = app => { | ||
10 | app.use('/api', require('./apps/api')); | 10 | app.use('/api', require('./apps/api')); |
11 | app.use('/product', require('./apps/product')); | 11 | app.use('/product', require('./apps/product')); |
12 | app.use('/home', require('./apps/home')); | 12 | app.use('/home', require('./apps/home')); |
13 | + app.use('/news', require('./apps/news')); | ||
13 | 14 | ||
14 | // 组件示例 | 15 | // 组件示例 |
15 | if (!app.locals.proEnv) { | 16 | if (!app.locals.proEnv) { |
public/js/news/detail.page.js
0 → 100644
public/vue/news/detail.vue
0 → 100644
-
Please register or login to post a comment