Showing
9 changed files
with
170 additions
and
8 deletions
@@ -6,7 +6,6 @@ | @@ -6,7 +6,6 @@ | ||
6 | 6 | ||
7 | var express = require('express'), | 7 | var express = require('express'), |
8 | path = require('path'), | 8 | path = require('path'), |
9 | - hbs = require('express-handlebars'), | ||
10 | bodyParser = require('body-parser'), | 9 | bodyParser = require('body-parser'), |
11 | favicon = require('serve-favicon'), | 10 | favicon = require('serve-favicon'), |
12 | cookieParser = require('cookie-parser'); | 11 | cookieParser = require('cookie-parser'); |
apps/product/controllers/detail.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情controller | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/5/6 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const mRoot = '../models'; | ||
10 | + | ||
11 | +// 商品详情model | ||
12 | +const detail = require(`${mRoot}/detail`); | ||
13 | + | ||
14 | +exports.index = (req, res) => { | ||
15 | + var id = req.params.id; | ||
16 | + | ||
17 | + detail({ | ||
18 | + id: id | ||
19 | + }, (data) => { | ||
20 | + res.render('detail'); | ||
21 | + }); | ||
22 | +}; |
apps/product/index.js
0 → 100644
1 | +/** | ||
2 | + * sub app product | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/05/06 | ||
5 | + */ | ||
6 | + | ||
7 | +var express = require('express'), | ||
8 | + path = require('path'), | ||
9 | + hbs = require('express-handlebars'); | ||
10 | + | ||
11 | +var app = express(); | ||
12 | + | ||
13 | +// set view engin | ||
14 | +var doraemon = path.join(__dirname, '../../doraemon/views'); //parent view root | ||
15 | + | ||
16 | +app.set('views', path.join(__dirname, 'views/action')); | ||
17 | +app.engine('.hbs', hbs({ | ||
18 | + extname: '.hbs', | ||
19 | + defaultLayout: 'layout', | ||
20 | + layoutsDir: doraemon, | ||
21 | + partialsDir: ['./views/partial', `${doraemon}/partial`], | ||
22 | + helpers: 'helpers' | ||
23 | +})); | ||
24 | + | ||
25 | +// router | ||
26 | +app.use(require('./router')); | ||
27 | + | ||
28 | +module.exports = app; |
apps/product/models/detail.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情models | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/5/6 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const library = '../../../library'; | ||
10 | +const API = require(`${library}/api`); | ||
11 | +const sign = require(`${library}/sign`); | ||
12 | + | ||
13 | +var api = new API; | ||
14 | + | ||
15 | +/** | ||
16 | + * 详情页数据格式化 | ||
17 | + * @param origin Object 原始数据 | ||
18 | + * @return dest Object 格式化数据 | ||
19 | + */ | ||
20 | +const introDataPkg = (origin) => { | ||
21 | + var dest = {}; | ||
22 | + | ||
23 | + var descBo = origin.productDescBo; | ||
24 | + var sizeBo = origin.sizeInfoBo; | ||
25 | + | ||
26 | + // 商品信息 | ||
27 | + if (descBo) { | ||
28 | + | ||
29 | + // 编号、颜色、性别 | ||
30 | + let sex; | ||
31 | + | ||
32 | + switch (descBo.gender) { | ||
33 | + case 1: | ||
34 | + sex = '男款'; | ||
35 | + break; | ||
36 | + case 2: | ||
37 | + sex = '女款'; | ||
38 | + break; | ||
39 | + default: | ||
40 | + sex = '通用'; | ||
41 | + } | ||
42 | + | ||
43 | + dest.description.table = [ | ||
44 | + `编号:${descBo.erpProductId}`, | ||
45 | + `颜色:${descBo.colorName}`, | ||
46 | + `性别:${sex}` | ||
47 | + ]; | ||
48 | + | ||
49 | + // 其余参数 | ||
50 | + for (let standard of descBo.standardBos) { | ||
51 | + dest.description.table.push(`${standard.standardName}:${standard.standardVal}`); | ||
52 | + } | ||
53 | + | ||
54 | + // 商品详情描述 | ||
55 | + dest.description.desc = descBo.phrase; | ||
56 | + } | ||
57 | + | ||
58 | + // 尺码信息 | ||
59 | + if (sizeBo) { | ||
60 | + let gender = descBo.gender; | ||
61 | + let boyReference = origin.productExtra.boyReference; | ||
62 | + let girlReference = origin.productExtra.girlReference; | ||
63 | + | ||
64 | + let reference = '参考尺码'; | ||
65 | + let showReference = false; | ||
66 | + | ||
67 | + if (gender === 3) { | ||
68 | + if (boyReference) { | ||
69 | + reference = '参考尺码(男)'; | ||
70 | + } else if (girlReference) { | ||
71 | + reference = '参考尺码(女)'; | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + // 是否显示参考尺码 | ||
76 | + showReference = (boyReference && sizeBo.sizeBoList[0].boyReferSize) || | ||
77 | + (girlReference && sizeBo.sizeBoList[0].girlReferSize); | ||
78 | + | ||
79 | + } | ||
80 | +} | ||
81 | + | ||
82 | +module.exports = (data, cb) => { | ||
83 | + | ||
84 | + api.get('', sign.apiSign({ | ||
85 | + productskn: data.id, | ||
86 | + udid: 'f528764d624db129b32c21fbca0cb8d6', | ||
87 | + uid: '11993475', | ||
88 | + method: 'h5.product.intro' | ||
89 | + })).then(data => { | ||
90 | + var dJson = JSON.parse(data); | ||
91 | + | ||
92 | + cb(data); | ||
93 | + }); | ||
94 | +}; |
apps/product/router.js
0 → 100644
1 | +/** | ||
2 | + * router of sub app product | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/05/06 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const router = require('express').Router(); | ||
10 | +const cRoot = './controllers'; | ||
11 | + | ||
12 | +// 商品详情controller | ||
13 | +const detail = require(`${cRoot}/detail`); | ||
14 | + | ||
15 | +// routers | ||
16 | +router.get('/detail/:id', detail.index); | ||
17 | + | ||
18 | +module.exports = router; |
apps/product/views/action/detail.hbs
0 → 100644
1 | +hello, I am product hbs |
@@ -15,7 +15,7 @@ const sourcemaps = require('gulp-sourcemaps'); | @@ -15,7 +15,7 @@ const sourcemaps = require('gulp-sourcemaps'); | ||
15 | const cssnano = require('gulp-cssnano'); | 15 | const cssnano = require('gulp-cssnano'); |
16 | 16 | ||
17 | const webpack = require('webpack'); | 17 | const webpack = require('webpack'); |
18 | -const webpackDevServer = require('webpack-dev-server'); | 18 | +const WebpackDevServer = require('webpack-dev-server'); |
19 | const webpackConfig = require('./webpack.config.js'); | 19 | const webpackConfig = require('./webpack.config.js'); |
20 | 20 | ||
21 | const env = { | 21 | const env = { |
@@ -165,7 +165,7 @@ gulp.task('webpack-dev-server', () => { | @@ -165,7 +165,7 @@ gulp.task('webpack-dev-server', () => { | ||
165 | debug: true | 165 | debug: true |
166 | }); | 166 | }); |
167 | 167 | ||
168 | - new webpackDevServer(webpack(devConfig), { | 168 | + new WebpackDevServer(webpack(devConfig), { |
169 | contentBase: '.', | 169 | contentBase: '.', |
170 | publicPath: '//localhost:8000/', | 170 | publicPath: '//localhost:8000/', |
171 | hot: true, | 171 | hot: true, |
@@ -189,5 +189,6 @@ gulp.task('webpack', () => { | @@ -189,5 +189,6 @@ gulp.task('webpack', () => { | ||
189 | if (err) { | 189 | if (err) { |
190 | throw new gutil.PluginError('webpack', err); | 190 | throw new gutil.PluginError('webpack', err); |
191 | } | 191 | } |
192 | + gutil.log('[webpack compile]:', stats.endTime - stats.startTime, 'ms'); | ||
192 | }); | 193 | }); |
193 | }); | 194 | }); |
@@ -6,17 +6,16 @@ | @@ -6,17 +6,16 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const webpack = require('webpack'); | ||
10 | -const fs = require('fs'); | 9 | +// const webpack = require('webpack'); |
11 | const path = require('path'); | 10 | const path = require('path'); |
12 | const _ = require('lodash'); | 11 | const _ = require('lodash'); |
13 | 12 | ||
14 | -require('shelljs/global'); | 13 | +const shelljs = require('shelljs'); |
15 | 14 | ||
16 | var entries = {}; | 15 | var entries = {}; |
17 | 16 | ||
18 | // 构建各模块子页面JS。生成规则module.page.js | 17 | // 构建各模块子页面JS。生成规则module.page.js |
19 | -ls(__dirname + '/js/**/*.page.js').forEach((f) => { | 18 | +shelljs.ls(path.join(__dirname, 'js/**/*.page.js')).forEach((f) => { |
20 | var dir = _.slice(f.split('/'), -2); // [modulename, xx.page.js] | 19 | var dir = _.slice(f.split('/'), -2); // [modulename, xx.page.js] |
21 | 20 | ||
22 | // Important | 21 | // Important |
-
Please register or login to post a comment