Merge branch 'release/1.0' of http://git.yoho.cn/fe/yoho-blk into release/1.0
Showing
8 changed files
with
103 additions
and
5 deletions
@@ -207,7 +207,7 @@ | @@ -207,7 +207,7 @@ | ||
207 | 207 | ||
208 | <p class="title">19. 上传图片接口</p> | 208 | <p class="title">19. 上传图片接口</p> |
209 | <div stlye="width: 200px;height:200px"> | 209 | <div stlye="width: 200px;height:200px"> |
210 | - <form name="form1" method="post" enctype="multipart/form-data" action="/api/uploadImg"> | 210 | + <form name="form1" method="post" enctype="multipart/form-data" action="/common/uploadImg"> |
211 | <input type="file" name="filename" style="width:160px;" /> | 211 | <input type="file" name="filename" style="width:160px;" /> |
212 | <input type="hidden" name="bucket" value="goodsimg" /> | 212 | <input type="hidden" name="bucket" value="goodsimg" /> |
213 | <input type="submit" name="Submit" value="上传" /> | 213 | <input type="submit" name="Submit" value="上传" /> |
@@ -8,7 +8,7 @@ module.exports = app => { | @@ -8,7 +8,7 @@ module.exports = app => { | ||
8 | 8 | ||
9 | // 公共服务 | 9 | // 公共服务 |
10 | app.use('/partial', require('./apps/partial')); // 组件demo | 10 | app.use('/partial', require('./apps/partial')); // 组件demo |
11 | - app.use('/api', require('./doraemon/router')); // API | 11 | + app.use('/common', require('./doraemon')); // API |
12 | 12 | ||
13 | // 业务模块 | 13 | // 业务模块 |
14 | app.use('/passport', require('./apps/passport')); | 14 | app.use('/passport', require('./apps/passport')); |
doraemon/controllers/common.js
0 → 100644
1 | +/** | ||
2 | + * common controller | ||
3 | + * @author: yyq<yanqing.yang@yoho.cn> | ||
4 | + * @date: 2016/08/03 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | + | ||
8 | +const common = require('../models/common'); | ||
9 | + | ||
10 | +/** | ||
11 | + * 获取banner | ||
12 | + * @function getBanner | ||
13 | + * @return { Object } 银行列表 | ||
14 | + */ | ||
15 | +const getBanner = (req, res, next) => { | ||
16 | + const code = req.query.code; | ||
17 | + | ||
18 | + common.getBannerData(code).then(result => { | ||
19 | + res.json(result); | ||
20 | + }).catch(next); | ||
21 | +}; | ||
22 | + | ||
23 | +module.exports = { | ||
24 | + getBanner | ||
25 | +}; |
doraemon/models/common.js
0 → 100644
1 | +/** | ||
2 | + * common model | ||
3 | + * @author: yyq<yanqing.yang@yoho.cn> | ||
4 | + * @date: 2016/08/03 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | + | ||
8 | +const _ = require('lodash'); | ||
9 | + | ||
10 | +const serviceApi = global.yoho.ServiceAPI; | ||
11 | +const helpers = global.yoho.helpers; | ||
12 | + | ||
13 | +/** | ||
14 | + * 获取资源数据api | ||
15 | + * @function _getResourceData | ||
16 | + * @param { string } code 资源码 | ||
17 | + * @return object | ||
18 | + */ | ||
19 | +const _getResourceDataAsync = (code) => { | ||
20 | + return serviceApi.get('operations/api/v5/resource/get', { | ||
21 | + content_code: code | ||
22 | + }, {code: 200}); | ||
23 | +}; | ||
24 | + | ||
25 | +const getBannerData = (code) => { | ||
26 | + return _getResourceDataAsync(code).then(result => { | ||
27 | + let resData = { | ||
28 | + code: 404, | ||
29 | + message: '获取资源信息失败' | ||
30 | + }; | ||
31 | + | ||
32 | + if (!_.isEmpty(result.data)) { | ||
33 | + resData = Object.assign({code: 200}, result.data[0]); | ||
34 | + if (resData.data && resData.data.src) { | ||
35 | + resData.data.src = helpers.image(resData.data.src, 330, 390); | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + return resData; | ||
40 | + }); | ||
41 | +} | ||
42 | + | ||
43 | +module.exports = { | ||
44 | + getBannerData | ||
45 | +}; |
@@ -7,8 +7,12 @@ | @@ -7,8 +7,12 @@ | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | const router = require('express').Router(); // eslint-disable-line | 9 | const router = require('express').Router(); // eslint-disable-line |
10 | -const uploadApi = require('./api/upload'); | 10 | +const cRoot = './controllers'; |
11 | + | ||
12 | +const uploadApi = require(`${cRoot}/upload`); | ||
13 | +const common = require(`${cRoot}/common`); | ||
11 | 14 | ||
12 | router.post('/uploadImg', uploadApi.uploadImg); | 15 | router.post('/uploadImg', uploadApi.uploadImg); |
16 | +router.get('/getBanner', common.getBanner); | ||
13 | 17 | ||
14 | module.exports = router; | 18 | module.exports = router; |
@@ -64,6 +64,21 @@ function refreshBag() { | @@ -64,6 +64,21 @@ function refreshBag() { | ||
64 | }); | 64 | }); |
65 | } | 65 | } |
66 | 66 | ||
67 | +function getNavImg(code, dom) { | ||
68 | + $.ajax({ | ||
69 | + type: 'GET', | ||
70 | + url: '/common/getBanner', | ||
71 | + data: { | ||
72 | + code: code | ||
73 | + }, | ||
74 | + success: function(result) { | ||
75 | + if (result.code === 200) { | ||
76 | + dom.data('show', true).html('<img src="' + result.data.src + '">'); | ||
77 | + } | ||
78 | + } | ||
79 | + }); | ||
80 | +} | ||
81 | + | ||
67 | refreshBag(); | 82 | refreshBag(); |
68 | 83 | ||
69 | $('.yoho-group a').hover(function() { | 84 | $('.yoho-group a').hover(function() { |
@@ -111,7 +126,16 @@ $bagGoodsList.on('click', '.del-good-btn', function() { | @@ -111,7 +126,16 @@ $bagGoodsList.on('click', '.del-good-btn', function() { | ||
111 | 126 | ||
112 | $('.contain-third').on({ | 127 | $('.contain-third').on({ |
113 | mouseenter: function() { | 128 | mouseenter: function() { |
114 | - var $thirdWrapper = $(this).children('.third-nav-wrapper'); | 129 | + var $thirdWrapper = $(this).children('.third-nav-wrapper'), |
130 | + $detail = $thirdWrapper.find('.show-detail'); | ||
131 | + var data; | ||
132 | + | ||
133 | + if ($detail) { | ||
134 | + data = $detail.data(); | ||
135 | + if (data.code && !data.show) { | ||
136 | + getNavImg(data.code, $detail); | ||
137 | + } | ||
138 | + } | ||
115 | 139 | ||
116 | delayer = setTimeout(function() { | 140 | delayer = setTimeout(function() { |
117 | $thirdWrapper.show(); | 141 | $thirdWrapper.show(); |
@@ -4,7 +4,7 @@ var $ = require('yoho-jquery'), | @@ -4,7 +4,7 @@ var $ = require('yoho-jquery'), | ||
4 | var tpl = '<div style="width: 0px; height: 0px; overflow: hidden;">' + | 4 | var tpl = '<div style="width: 0px; height: 0px; overflow: hidden;">' + |
5 | '<iframe id="yoho-upload-result" name="ajaxUpload" style="display:none"></iframe>' + | 5 | '<iframe id="yoho-upload-result" name="ajaxUpload" style="display:none"></iframe>' + |
6 | '<form id="yoho-upload" method="post" enctype="multipart/form-data" ' + | 6 | '<form id="yoho-upload" method="post" enctype="multipart/form-data" ' + |
7 | - 'action="/api/uploadImg" target="ajaxUpload">' + | 7 | + 'action="/common/uploadImg" target="ajaxUpload">' + |
8 | '<input type="file" name="filename" class="file-name" />' + | 8 | '<input type="file" name="filename" class="file-name" />' + |
9 | '<input type="hidden" name="bucket" value="goodsimg" />' + | 9 | '<input type="hidden" name="bucket" value="goodsimg" />' + |
10 | '</form>' + | 10 | '</form>' + |
-
Please register or login to post a comment