|
|
/* global wx */
|
|
|
import $ from 'yoho-jquery';
|
|
|
import tip from 'js/plugin/tip';
|
|
|
import {transToMiniappPath} from 'js/common/miniapp-path-rules';
|
|
|
|
|
|
class LinkHandle {
|
|
|
constructor() {
|
...
|
...
|
@@ -39,58 +40,13 @@ class LinkHandle { |
|
|
* 转换为小程序页面地址
|
|
|
*/
|
|
|
transToPath(href) {
|
|
|
let path = '';
|
|
|
let openbyParamsArr = href.split(/openby:yohobuy(=|=)/);
|
|
|
let paramsStr = openbyParamsArr[openbyParamsArr.length - 1];
|
|
|
let paramsObj = {};
|
|
|
let transData = transToMiniappPath(href);
|
|
|
|
|
|
try {
|
|
|
paramsObj = JSON.parse(paramsStr);
|
|
|
} catch (error) {
|
|
|
console.error('paramsStr is: ', paramsStr);
|
|
|
}
|
|
|
|
|
|
if (paramsObj.action === 'go.productDetail' && paramsObj.params && paramsObj.params.product_skn) { // 商品详情页
|
|
|
path = `/pages/goodsDetail/goodsDetail?productSkn=${paramsObj.params.product_skn}&page_name=home`;
|
|
|
} else if (paramsObj.action === 'go.list') { // 列表页、专区
|
|
|
let queryParams = this.transOpenbyParams(paramsObj.params);
|
|
|
|
|
|
path = `/pages/goodsList/goodsList${queryParams}`;
|
|
|
} else if (paramsObj.action === 'go.poollist') { // 商品池
|
|
|
let queryParams = this.transOpenbyParams(paramsObj.params);
|
|
|
|
|
|
path = `/pages/goodsList/productPool${queryParams}`;
|
|
|
} else if (paramsObj.action === 'go.h5' && paramsObj.params && paramsObj.params.url) { // 活动模板
|
|
|
let queryParams = this.transOpenbyParams(paramsObj.params.param);
|
|
|
let url = `${paramsObj.params.url}${queryParams}`;
|
|
|
|
|
|
path = `/pages/webview/webview?page_name=home&url=${url}`;
|
|
|
} else if (paramsObj.action === 'go.shop') { // 店铺
|
|
|
path = `/pages/goodsList/brandStore?shopId=${paramsObj.params.shop_id}`;
|
|
|
} else {
|
|
|
if (!transData.path) {
|
|
|
tip.show('暂不支持,请使用Yoho!buy有货APP选购');
|
|
|
}
|
|
|
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转换 openby 参数
|
|
|
*/
|
|
|
transOpenbyParams(params) {
|
|
|
let paramsArr = [];
|
|
|
|
|
|
if (params && $.isPlainObject(params)) {
|
|
|
for (let key in params) {
|
|
|
if (params.hasOwnProperty(key)) {
|
|
|
paramsArr.push(`${key}=${params[key]}`);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
console.info('params is:', params);
|
|
|
}
|
|
|
|
|
|
return paramsArr.length ? `?${paramsArr.join('&')}` : '';
|
|
|
return transData.path || '';
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|