Authored by biao

Merge branch 'release/1.0' of http://git.yoho.cn/fe/yoho-blk into release/1.0

... ... @@ -207,7 +207,7 @@
<p class="title">19. 上传图片接口</p>
<div stlye="width: 200px;height:200px">
<form name="form1" method="post" enctype="multipart/form-data" action="/api/uploadImg">
<form name="form1" method="post" enctype="multipart/form-data" action="/common/uploadImg">
<input type="file" name="filename" style="width:160px;" />
<input type="hidden" name="bucket" value="goodsimg" />
<input type="submit" name="Submit" value="上传" />
... ...
... ... @@ -8,7 +8,7 @@ module.exports = app => {
// 公共服务
app.use('/partial', require('./apps/partial')); // 组件demo
app.use('/api', require('./doraemon/router')); // API
app.use('/common', require('./doraemon')); // API
// 业务模块
app.use('/passport', require('./apps/passport'));
... ...
/**
* common controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/08/03
*/
'use strict';
const common = require('../models/common');
/**
* 获取banner
* @function getBanner
* @return { Object } 银行列表
*/
const getBanner = (req, res, next) => {
const code = req.query.code;
common.getBannerData(code).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
getBanner
};
\ No newline at end of file
... ...
/**
* common model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/08/03
*/
'use strict';
const _ = require('lodash');
const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
/**
* 获取资源数据api
* @function _getResourceData
* @param { string } code 资源码
* @return object
*/
const _getResourceDataAsync = (code) => {
return serviceApi.get('operations/api/v5/resource/get', {
content_code: code
}, {code: 200});
};
const getBannerData = (code) => {
return _getResourceDataAsync(code).then(result => {
let resData = {
code: 404,
message: '获取资源信息失败'
};
if (!_.isEmpty(result.data)) {
resData = Object.assign({code: 200}, result.data[0]);
if (resData.data && resData.data.src) {
resData.data.src = helpers.image(resData.data.src, 330, 390);
}
}
return resData;
});
}
module.exports = {
getBannerData
};
\ No newline at end of file
... ...
... ... @@ -7,8 +7,12 @@
'use strict';
const router = require('express').Router(); // eslint-disable-line
const uploadApi = require('./api/upload');
const cRoot = './controllers';
const uploadApi = require(`${cRoot}/upload`);
const common = require(`${cRoot}/common`);
router.post('/uploadImg', uploadApi.uploadImg);
router.get('/getBanner', common.getBanner);
module.exports = router;
... ...
... ... @@ -64,6 +64,21 @@ function refreshBag() {
});
}
function getNavImg(code, dom) {
$.ajax({
type: 'GET',
url: '/common/getBanner',
data: {
code: code
},
success: function(result) {
if (result.code === 200) {
dom.data('show', true).html('<img src="' + result.data.src + '">');
}
}
});
}
refreshBag();
$('.yoho-group a').hover(function() {
... ... @@ -111,7 +126,16 @@ $bagGoodsList.on('click', '.del-good-btn', function() {
$('.contain-third').on({
mouseenter: function() {
var $thirdWrapper = $(this).children('.third-nav-wrapper');
var $thirdWrapper = $(this).children('.third-nav-wrapper'),
$detail = $thirdWrapper.find('.show-detail');
var data;
if ($detail) {
data = $detail.data();
if (data.code && !data.show) {
getNavImg(data.code, $detail);
}
}
delayer = setTimeout(function() {
$thirdWrapper.show();
... ...
... ... @@ -4,7 +4,7 @@ var $ = require('yoho-jquery'),
var tpl = '<div style="width: 0px; height: 0px; overflow: hidden;">' +
'<iframe id="yoho-upload-result" name="ajaxUpload" style="display:none"></iframe>' +
'<form id="yoho-upload" method="post" enctype="multipart/form-data" ' +
'action="/api/uploadImg" target="ajaxUpload">' +
'action="/common/uploadImg" target="ajaxUpload">' +
'<input type="file" name="filename" class="file-name" />' +
'<input type="hidden" name="bucket" value="goodsimg" />' +
'</form>' +
... ...