Authored by Aiden Xu

资讯详情

  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;
  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;
  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;
  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;
  1 +<div id="app" class="news-page">
  2 + Damn news!
  3 + <app/>
  4 +</div>
@@ -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) {
  1 +const Vue = require('yoho-vue');
  2 +const lazyload = require('yoho-vue-lazyload');
  3 +
  4 +const app = require('news/detail.vue');
  5 +
  6 +new Vue({
  7 + el: '#app',
  8 + components: {
  9 + app
  10 + }
  11 +});
  12 +
  13 +Vue.use(lazyload);
  1 +<template>
  2 + <div class="news-box">
  3 + <h1>日韩风日韩风日韩风日韩风日韩风日韩风日韩风</h1>
  4 + <span class="icon icon-love"></span>
  5 + <span class="icon icon-love"></span>
  6 + </div>
  7 +</template>
  8 +<style src="./css/detail.css"></style>
  9 +<script src="./js/detail.js"></script>
  1 +module.exports = {
  2 + components: {
  3 +
  4 + }
  5 +};