Authored by yyq

Merge branch 'feature/wp' into release/6.5

{
"presets": [
["env", {
"targets": {
"browsers": [">1%"]
}
}],
"es2015"
],
"plugins": [
"transform-runtime",
"transform-regenerator",
]
}
... ...
... ... @@ -9,6 +9,9 @@ var express = require('express'),
hbsEvent = require('../../config/hbsevent');
var app = express();
var router = require('./router');
var route = require('../../doraemon/middleware/route-intercept');
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
... ... @@ -18,6 +21,8 @@ app.disable('x-powered-by');
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
route.regist(app, parent, router);
});
app.use(global.yoho.hbs({
... ... @@ -31,6 +36,6 @@ app.use(global.yoho.hbs({
}));
// router
app.use(require('./router'));
app.use(router);
module.exports = app;
... ...
... ... @@ -110,7 +110,7 @@ router.get(/\/global\/([\d]+)(.*)/, globalCtrl.detail);
// router.get(/\/global\/([\d]+)(.*)/, globalCtrl.detail); // 全球购商品详情页
// 搜索
router.get('/search', gbk2utf, search.index);
router.get('/search', '/search', gbk2utf, search.index);
router.get('/search/filter/brands', search.searchFilterBrands);
router.get('/search/suggest', search.suggest); // 搜索提示
router.get('/api/suggest', search.suggest4Old);
... ... @@ -124,9 +124,9 @@ router.get('/list/new', list.newWithChannel);
router.get('/list/new/:pathQs', paramParse, list.newWithChannel);
// 商品分类列表页
router.get('/list', gbk2utf, list.index);
router.get('/list', '/list', gbk2utf, list.index);
router.get('/list/index', gbk2utf, list.index);
router.get('/list/:pathQs', paramParse, gbk2utf, list.index);
router.get('/list/:pathQs', '/list/:pathQs', paramParse, gbk2utf, list.index);
// 品牌店铺
router.get('/index/about', list.brandAbout); // 品牌店铺介绍页
... ... @@ -139,9 +139,9 @@ router.get('/shop/couponsync', list.shopCouponSync);
router.get('/shop', shop.index); // 店铺首页
// router.get('/shop/:domain/:shopId.html', shop.index); // 店铺首页
router.get('/shop/:shopInfo.html', shop.index); // 店铺首页
router.get('/shop/:shopInfo', shop.list); // 店铺列表页
router.get('/shop/:shopInfo/:pathQs', paramParse, shop.list); // 店铺列表页
router.get('/shop/:shopInfo.html', '/shop/:shopInfo.html', shop.index); // 店铺首页
router.get('/shop/:shopInfo', '/shop/:shopInfo', shop.list); // 店铺列表页
router.get('/shop/:shopInfo/:pathQs', '/shop/:shopInfo/:pathQs', paramParse, shop.list); // 店铺列表页
// router.get('/shoplist', shop.list); // 店铺列表页
router.post('/shop/article', shop.article); // 店铺推荐文章
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
... ...
... ... @@ -4,7 +4,10 @@
* @date: 2016/4/27
*/
const route = require('./doraemon/middleware/route-intercept');
module.exports = app => {
route.intercept(app); // 拦截app.use && router
// 公共服务
app.use('/common', require('./apps/common'));
... ...
... ... @@ -209,11 +209,11 @@ module.exports = [
return '/product/index/about';
}
},
{
type: TYPE.rewrite,
origin: /^\/(list|search|new|sale|shop)((\/|\?)(.*)|())$/,
target: (req) => {
return `/product${req.url}`;
}
},
// {
// type: TYPE.rewrite,
// origin: /^\/(list|search|new|sale|shop)((\/|\?)(.*)|())$/,
// target: (req) => {
// return `/product${req.url}`;
// }
// },
];
... ...
/**
* 路由拦截
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2018/1/22
*/
const _ = require('lodash');
const express = require('express');
const methods = require('methods');
const intercept = (app) => {
// 拦截调度器,获取原路径
app.use = ((appUse) => {
return (...args) => {
let rootPath = '';
const arg = args[0];
if (typeof arg !== 'function') {
rootPath = arg;
}
app.locals.rootPath = rootPath || '';
return appUse.call(app, ...args);
};
})(app.use);
// 拦截路由方法,解析新注册方式
express.Router = ((_router) => {
const baseRouter = _router();
return () => {
let router = _router();
methods.concat('all').forEach((method) => {
router[method] = (path, ...args) => {
const arg = args[0];
if (typeof arg !== 'function') {
args = _.drop(args);
router.rootRouter = router.rootRouter || [];
router.rootRouter.push({
path: arg,
relatedPath: path,
method: method,
args: args
});
}
return baseRouter[method].call(router, path, ...args);
};
});
return router;
};
})(express.Router);
};
// 注册根路由
const regist = (app, parent, router) => {
if (router.rootRouter && router.rootRouter.length) {
let rootPath = '';
if (app.locals.rootPath && _.isString(app.locals.rootPath)) {
rootPath = app.locals.rootPath;
}
router.rootRouter.forEach(el => {
let fullPath = rootPath;
if (el.relatedPath && _.isString(el.relatedPath)) {
fullPath += el.relatedPath;
}
const pathArr = _.compact(fullPath.split('/'));
parent[el.method](el.path, (req, res, next) => {
Object.assign(res.locals, {
module: pathArr[0] || res.locals.module,
page: pathArr[1] || res.locals.page
});
return next();
}, ...el.args);
});
}
};
module.exports = {
intercept,
regist
};
... ...
... ... @@ -62,6 +62,12 @@
},
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"bootstrap": "^3.3.7",
"css-loader": "^0.27.3",
"cssnano": "^3.10.0",
... ... @@ -91,6 +97,7 @@
"postcss-sprites": "^4.2.0",
"postcss-use": "^2.3.0",
"precss": "^1.4.0",
"regenerator-runtime": "^0.11.1",
"rewire": "^2.5.1",
"shelljs": "^0.7.0",
"style-loader": "^0.16.0",
... ...
... ... @@ -65,7 +65,8 @@ const getEntries = () => {
'yoho-jquery-lazyload',
'yoho-slider',
'yoho-jquery-pjax',
'yoho-jquery-dotdotdot'
'yoho-jquery-dotdotdot',
'regenerator-runtime/runtime'
],
base: path.join(__dirname, '../scss/base.css')
};
... ... @@ -117,6 +118,12 @@ module.exports = (env) => {
}
}]
}, {
test: /\.js$/,
exclude: [/node_modules/],
use: [{
loader: 'happypack/loader?id=js'
}]
}, {
test: /\.css$/,
use: cssLoader(env, 'css')
}, {
... ... @@ -145,6 +152,11 @@ module.exports = (env) => {
},
plugins: [
new HappyPack({
id: 'js',
threadPool: happyThreadPool,
loaders: ['babel-loader'],
}),
new HappyPack({
id: 'hbs',
threadPool: happyThreadPool,
loaders: [hbsLoader]
... ...
... ... @@ -4,6 +4,9 @@
* @date: 2015/11/23
*/
import {timeout} from './es6-test';
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
... ... @@ -13,6 +16,19 @@ var homePage = $('.home-page').data('page'),
var yas = require('../common/data-yas');
const defTimeout = (time, type = 'default') => {
return timeout(time).then(()=> {
console.log(`${type} timeout`);
});
};
(async function() {
await defTimeout(10000, 'await');
defTimeout(500);
console.log('async end');
}());
// 给头部js获取当前频道
window.homePage = homePage;
... ...
class Animal {
constructor() {
this.type = 'animal';
}
says(say = 'hi') {
setTimeout(() => {
console.log(`${this.type} says ${say}`);
}, 1000);
}
}
class Cat extends Animal {
constructor() {
super();
this.type = 'cat';
}
setInfo(info) {
let {name, age, color} = info;
name && (this.name = name);
age && (this.age = age);
color && (this.color = color);
}
infos() {
console.log(this);
}
}
const timeout = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
function* generator() {
yield 'hello';
yield 'generator';
}
let cat = new Cat();
cat.says();
cat.setInfo({name: 'mini', color: 'black'});
cat.infos();
console.log([...generator()]);
export {
cat,
timeout
};
... ...
... ... @@ -808,7 +808,7 @@ module.exports = (function() {
// Android 2.1 bug workaround
// http://code.google.com/p/android/issues/detail?id=5141
if (this._android && this._android <= 2.1) {
if (this && this._android && this._android <= 2.1) {
var factor = 1 / window.devicePixelRatio;
var drawImage = CanvasRenderingContext2D.prototype.drawImage;
CanvasRenderingContext2D.prototype.drawImage = function(image, sx, sy, sw, sh, dx, dy, dw, dh) {
... ... @@ -1059,7 +1059,7 @@ module.exports = (function() {
* @param {String} [vOption.colorLight="#ffffff"]
* @param {QRCode.CorrectLevel} [vOption.correctLevel=QRCode.CorrectLevel.H] [L|M|Q|H]
*/
QRCode = function(el, vOption) {
var QRCode = function(el, vOption) {
this._htOption = {
width: 256,
height: 256,
... ...