Authored by Aiden Xu

资讯详情

/**
*
* @author: Aiden Xu<aiden.xu@yoho.cn>
* @date: 2016/07/25
*/
'use strict';
// const _ = require('lodash');
// const helpers = global.yoho.helpers;
const model = require('../models/detail');
/**
* 商品详情
*/
const component = {
index(req, res) {
res.render('detail', {
module: 'news',
page: 'detail'
});
},
news(req, res, next) {
let params = {
uid: req.user.uid || 8050378 // TODO: fix this hard coded uid
};
model.product(params).then(result => {
res.json(result);
}).catch(next);
}
};
module.exports = component;
... ...
/**
* sub app
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
const express = require('express');
const path = require('path');
const hbs = require('express-handlebars');
const app = express();
// set view engine
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.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: global.yoho.helpers
}));
// router
app.use(require('./router'));
module.exports = app;
... ...
/**
*
* @author: Aiden Xu<aiden.xu@yoho.cn>
* @date: 2016/07/25
*/
'use strict';
// const _ = require('lodash');
// const helpers = global.yoho.helpers;
const api = global.yoho.API;
/**
* 资讯详情
*/
const model = {
product(params) {
return api.get('', Object.assign({
method: 'h5.product.data'
}, params));
}
};
module.exports = model;
... ...
/**
* router of sub app news
* @author: Aiden Xu<aiden.xu@yoho.cn>
* @date: 2016/07/25
*/
'use strict';
const expressRouter = require('express').Router;
const cRoot = './controllers';
const router = expressRouter();
// 详情controller
const detail = require(`${cRoot}/detail`);
router.get(/\/([\d]+)(.*)/, detail.index); // 详情routers
module.exports = router;
... ...
<div id="app" class="news-page">
Damn news!
<app/>
</div>
... ...
... ... @@ -10,6 +10,7 @@ module.exports = app => {
app.use('/api', require('./apps/api'));
app.use('/product', require('./apps/product'));
app.use('/home', require('./apps/home'));
app.use('/news', require('./apps/news'));
// 组件示例
if (!app.locals.proEnv) {
... ...
const Vue = require('yoho-vue');
const lazyload = require('yoho-vue-lazyload');
const app = require('news/detail.vue');
new Vue({
el: '#app',
components: {
app
}
});
Vue.use(lazyload);
... ...
<template>
<div class="news-box">
<h1>日韩风日韩风日韩风日韩风日韩风日韩风日韩风</h1>
<span class="icon icon-love"></span>
<span class="icon icon-love"></span>
</div>
</template>
<style src="./css/detail.css"></style>
<script src="./js/detail.js"></script>
... ...
module.exports = {
components: {
}
};
... ...