Authored by xuqi

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

... ... @@ -20,6 +20,7 @@ const favicon = require('serve-favicon');
const session = require('express-session');
const memcached = require('connect-memcached');
const hbs = require('express-handlebars');
const multer = require('connect-multiparty');
const pkg = require('./package.json');
const yohoLib = require('yoho-node-lib');
... ... @@ -52,6 +53,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(multer());
app.use(session({
proxy: true,
... ...
/**
* 公共接口 controller
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/21
*/
'use strict';
var requestPromise = require('request-promise');
var fs = require('fs');
const uploadImg = (req, res) => {
console.log('-----uploadImg:');
let files, fileIndex;
let ret, imgs, datas;
let flag;
let i = 0;
if (req.user.uid) {
console.log('req.files...', JSON.stringify(req.files));
console.log('req.body.bucket:', req.body.bucket);
files = [req.files.filename];
// 判断是单张传还是多张传
flag = Object.prototype.toString.call(files) === '[object Array]';
console.log('files...', files);
// 如果是单张,则数组化
if (!flag) {
files = [req.files.filename];
}
console.log('upload files....', files);
req.body.files = [];
req.body.fileNames = [];
for (fileIndex = 0; fileIndex < files.length; fileIndex++) {
req.body.files[fileIndex] = fs.createReadStream(files[fileIndex].path);
req.body.fileNames[fileIndex] = files[fileIndex].name;
}
console.log('upload files path:', JSON.stringify(req.body.files));
console.log('upload files names:', JSON.stringify(req.body.fileNames));
if (req.body.bucket === 'goodsimg') {
requestPromise({
url: 'http://upload.static.yohobuy.com',
method: 'POST',
body: {
fileData: req.body.files,
project: req.body.bucket
}
}).then((error, httpResponse, rebody) => {
if (!error && httpResponse.statusCode === 200) {
ret = JSON.parse(rebody);
imgs = ret.data.imagesList || [];
datas = [];
for (i = 0; i < imgs.length; i++) {
// datas.push(Utils.joinImg(imgs[i]));
}
}
res.json({
code: 200,
data: datas[0],
datas: datas,
names: req.body.fileNames,
message: '上传成功',
status: true
});
});
} else {
res.json({
code: 500,
message: '上传图片失败, 请稍后重试!'
});
}
} else {
res.json({
code: 401,
message: '用户失效,请重新登录'
});
}
};
module.exports = {
uploadImg
};
... ...
/**
* sub app api
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/21
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var app = express();
// set view engin
var 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: ['./views/partial', `${doraemon}/partial`],
helpers: 'helpers'
}));
console.log('api.............');
// router
app.use(require('./router'));
module.exports = app;
... ...
/**
* router of sub app api
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/21
*/
'use strict';
const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const apiCtrl = require(`${cRoot}/api`);
router.post('/uploadImg', apiCtrl.uploadImg);
module.exports = router;
... ...
... ... @@ -204,6 +204,15 @@
</pre>
</div>
</div>
<p class="title">19. 上传图片接口</p>
<div stlye="width: 200px;height:200px">
<form name="form1" method="post" enctype="multipart/form-data" action="/api/uploadImg">
<input type="file" name="filename" style="width:160px;" />
<input type="hidden" name="bucket" value="goodsimg" />
<input type="submit" name="Submit" value="上传" />
</form>
</div>
{{/ content}}
</div>
... ...
{{> layout/header}}
<div class="passport-page yoho-page clearfix">
{{# passport}}
{{> passport/cover}}
<div class="content">
{{> passport/register}}
</div>
{{/ passport}}
<div class="page-tip clearfix">为了给您更好的购物体验, 建议您创建YOHO!Family账号</div>
</div>
{{> layout/footer}}
\ No newline at end of file
... ... @@ -18,4 +18,5 @@ module.exports = app => {
app.use('/editorial', require('./apps/editorial')); // 资讯
app.use('/product', require('./apps/product'));
app.use('/brand', require('./apps/brand')); // 品牌
app.use('/api', require('./apps/api')); // API
};
... ...
... ... @@ -35,6 +35,7 @@
"body-parser": "^1.15.0",
"captchapng": "0.0.1",
"connect-memcached": "^0.2.0",
"connect-multiparty": "^2.0.0",
"cookie-parser": "^1.4.3",
"express": "^4.13.1",
"express-handlebars": "^3.0.0",
... ...
... ... @@ -45,14 +45,16 @@ function disableSMSBtn() {
second = 60;
$smsCaptchaCtrl.text('获取短信验证码');
$smsCaptchaCtrl.removeClass('disable');
$smsCaptchaCtrl.removeClass('second-progress');
} else {
$smsCaptchaCtrl.addClass('second-progress');
$smsCaptchaCtrl.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
}
$smsCaptchaCtrl.click(function() {
if ($smsCaptchaCtrl.hasClass('disable')) {
if ($smsCaptchaCtrl.hasClass('disable') || $smsCaptchaCtrl.hasClass('second-progress')) {
return;
}
... ...
... ... @@ -48,8 +48,9 @@ function disableSMSBtn() {
second = 60;
$smsCaptchaCtrl.text('获取短信验证码');
$smsCaptchaCtrl.removeClass('disable');
$smsCaptchaCtrl.removeClass('progress');
$smsCaptchaCtrl.removeClass('second-progress');
} else {
$smsCaptchaCtrl.addClass('second-progress');
$smsCaptchaCtrl.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
... ... @@ -113,7 +114,7 @@ $('#region').change(function() {
});
ep.tail('phoneNum', 'img-captcha', function(phoneAuth, imgAuth) {
if (phoneAuth && imgAuth && !$smsCaptchaCtrl.hasClass('progress')) {
if (phoneAuth && imgAuth && !$smsCaptchaCtrl.hasClass('second-progress')) {
$smsCaptchaCtrl.removeClass('disable');
} else {
$smsCaptchaCtrl.addClass('disable');
... ... @@ -210,12 +211,11 @@ $smsCaptchaInput.on('blur', function() {
});
$smsCaptchaCtrl.on('click', function() {
if ($smsCaptchaCtrl.hasClass('disable')) {
if ($smsCaptchaCtrl.hasClass('disable') || $smsCaptchaCtrl.hasClass('second-progress')) {
return;
}
$smsCaptchaCtrl.addClass('disable');
$smsCaptchaCtrl.addClass('progress');
disableSMSBtn();
sendSMSCaptcha();
... ...
... ... @@ -13,9 +13,9 @@ function computeComplex(password) {
if (length === 0) {
lengthS = 0;
} else if (length <= 6 && length > 0) {
} else if (length < 6 && length > 0) {
lengthS = 0 + isAllNumberOrAlph(password);
} else if (length > 6 && length <= 16) {
} else if (length >= 6 && length <= 16) {
lengthS = 1 + isAllNumberOrAlph(password);
} else {
lengthS = 2 + isAllNumberOrAlph(password);
... ...
... ... @@ -423,9 +423,9 @@ function disableSMSBtn() {
second = 60;
$smsCaptchaCtrl.text('获取短信验证码');
$smsCaptchaCtrl.removeClass('disable');
$smsCaptchaCtrl.removeClass('progress');
$smsCaptchaCtrl.removeClass('second-progress');
} else {
$smsCaptchaCtrl.add('progress');
$smsCaptchaCtrl.addClass('second-progress');
$smsCaptchaCtrl.text(second + '秒后可重新操作');
window.setTimeout(disableSMSBtn, 1000);
}
... ... @@ -459,7 +459,7 @@ exports.init = function() {
// 图形验证通过时,发送短信按钮可点击
ep.tail('captcha-img', 'phone-num', function(captchaAuth, phoneAuth) {
if (captchaAuth && phoneAuth && !$smsCaptchaCtrl.hasClass('progress')) {
if (captchaAuth && phoneAuth && !$smsCaptchaCtrl.hasClass('second-progress')) {
$smsCaptchaCtrl.removeClass('disable');
} else {
$smsCaptchaCtrl.addClass('disable');
... ... @@ -505,7 +505,7 @@ exports.init = function() {
// 点击发送验证码
$smsCaptchaCtrl.on('click', function() {
if ($(this).hasClass('disable')) {
if ($smsCaptchaCtrl.hasClass('disable') || $smsCaptchaCtrl.hasClass('second-progress')) {
return;
}
... ...
... ... @@ -23,7 +23,7 @@ var settings = {
resources: 'areas',
names: ['province', 'city', 'district'],
indicators: ['请选择省份', '请选择城市', '请选择区/县'],
defaultDes: '加载中...',
defaultDes: '',
ajaxSettings: {
type: 'GET',
url: '',
... ... @@ -106,6 +106,8 @@ function selectDistItem(options) {
distItemAreaId = options.distItemAreaId, // 当前选中areaId
config = options.config;
var nextDistItem;
var from;
if (distElement.hasClass('checked')) {
... ... @@ -129,6 +131,12 @@ function selectDistItem(options) {
// 选择之后关闭当前panel
distItem.trigger('click');
// 展开下一级
nextDistItem = distItem.parent().next().find('.dist-item');
if (nextDistItem) {
nextDistItem.trigger('click');
}
// console.log('current level:', level)
// console.log('distItemAreaId:', distItemAreaId)
// console.log('currAreaId:', currAreaId)
... ...
... ... @@ -14,44 +14,34 @@ var jQuery = require('yoho-jquery'),
var tplFn = Handlebars.compile(tpl);
var _that = this;
var $tips = null;
var methods = {
show: function() {
var topLeft = this.offset();
if (_that.isInit) {
var $parent = this.parent(),
topLeft = $parent.offset(),
$tips = this.find('.tips');
this.find('.rectangle').text(arguments[0]);
if ($tips.length !== 0) {
$tips.find('.rectangle').text(arguments[0]).removeClass('hide');
} else {
_that.isInit = true;
this.append(tplFn({content: arguments[0]}));
$tips = this.find('.tips').removeClass('hide');
$parent.append(tplFn({content: arguments[0]}));
$tips = $parent.find('.tips').removeClass('hide');
$tips.css({
top: topLeft.top + this.height() - 2,
top: $parent.height() - 2,
left: topLeft.left,
width: this.width() + 2,
height: this.height
});
}
return this;
return $tips;
},
hide: function() {
if (_that.isInit) {
this.find('.tips').addClass('hide');
_that.isInit = false;
}
var $parent = this.parent();
return this;
},
status: function() {
return _that.isInit;
return $parent.find('.tips').addClass('hide');
}
};
_that.isInit = false;
};
$.fn.tips = function(method) {
... ...