|
|
import wx from 'weixin-js-sdk';
|
|
|
import {linkToMiniApp, invokeMethod, createLinkButton} from "../utils/common";
|
|
|
var common = require('../utils/common');
|
|
|
|
|
|
export default class {
|
|
|
constructor(_env) {
|
|
|
this.env = _env;
|
|
|
}
|
|
|
|
|
|
link(event) {
|
|
|
let element = event.currentTarget;
|
|
|
let type = element.getAttribute('data-type') || 'other';
|
|
|
let id = element.getAttribute('data-id') || '';
|
|
|
let url = element.getAttribute('data-url') || '';
|
|
|
let name = element.getAttribute('data-name') || '';
|
|
|
let linkUrl = '';
|
|
|
if (this.env === 'miniprogram') {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5'
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = '/pages/goodsList/brandStore?shop_id=' + id + '&shop_name=' + name
|
|
|
} else {
|
|
|
linkUrl = url
|
|
|
}
|
|
|
return linkToMiniApp(linkUrl, type);
|
|
|
} else if (this.env === 'pc') {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = 'https://www.yohobuy.com/product/' + id + '.html';
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = 'https://www.yohobuy.com/shop/' + name + '-' + id + '.html';
|
|
|
} else {
|
|
|
linkUrl = url
|
|
|
}
|
|
|
function goto(_env){
|
|
|
this.env = _env;
|
|
|
}
|
|
|
goto.prototype.link = function(event){
|
|
|
var element = event.currentTarget;
|
|
|
var type = element.getAttribute('data-type') || 'other';
|
|
|
var id = element.getAttribute('data-id') || '';
|
|
|
var url = element.getAttribute('data-url') || '';
|
|
|
var name = element.getAttribute('data-name') || '';
|
|
|
var linkUrl = '';
|
|
|
if (this.env === 'miniprogram') {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5'
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = '/pages/goodsList/brandStore?shop_id=' + id + '&shop_name=' + name
|
|
|
} else {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = '//m.yohobuy.com/product/' + id + '.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' + id + '}}'
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = '//m.yohobuy.com/product/index/brand?shop_id=' + id + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' + id + '","shop_template_type":"1","shop_name":"' + name + '","is_red_shop":"1"}}'
|
|
|
} else {
|
|
|
linkUrl = url
|
|
|
}
|
|
|
linkUrl = url
|
|
|
}
|
|
|
if (this.env === 'app') {
|
|
|
let dom = document.getElementById('yosdk-goto');
|
|
|
if (!dom) {
|
|
|
dom = createLinkButton(linkUrl, 'yosdk-goto');
|
|
|
} else {
|
|
|
dom.setAttribute('href', linkUrl);
|
|
|
}
|
|
|
return dom.click();
|
|
|
|
|
|
return common.linkToMiniApp(linkUrl, type);
|
|
|
} else if (this.env === 'pc') {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = 'https://www.yohobuy.com/product/' + id + '.html';
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = 'https://www.yohobuy.com/shop/' + name + '-' + id + '.html';
|
|
|
} else {
|
|
|
linkUrl = url
|
|
|
}
|
|
|
} else {
|
|
|
if (type === 'product') {
|
|
|
linkUrl = '//m.yohobuy.com/product/' + id + '.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' + id + '}}'
|
|
|
} else if (type === 'brand') {
|
|
|
linkUrl = '//m.yohobuy.com/product/index/brand?shop_id=' + id + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' + id + '","shop_template_type":"1","shop_name":"' + name + '","is_red_shop":"1"}}'
|
|
|
} else {
|
|
|
window.location.href = linkUrl
|
|
|
linkUrl = url
|
|
|
}
|
|
|
}
|
|
|
|
|
|
goBack() {
|
|
|
if (this.env === 'app') {
|
|
|
invokeMethod({method: 'go.back'})
|
|
|
} else if (this.env === 'miniprogram') {
|
|
|
wx.miniProgram.navigateBack();
|
|
|
if (this.env === 'app') {
|
|
|
var dom = document.getElementById('yosdk-goto');
|
|
|
if (!dom) {
|
|
|
dom = common.createLinkButton(linkUrl, 'yosdk-goto');
|
|
|
} else {
|
|
|
history.go(-1);
|
|
|
dom.setAttribute('href', linkUrl);
|
|
|
}
|
|
|
return dom.click();
|
|
|
|
|
|
} else {
|
|
|
window.location.href = linkUrl
|
|
|
}
|
|
|
};
|
|
|
|
|
|
} |
|
|
goto.prototype.goBack=function () {
|
|
|
if (this.env === 'app') {
|
|
|
common.invokeMethod({method: 'go.back'})
|
|
|
} else if (this.env === 'miniprogram') {
|
|
|
wx.miniProgram.navigateBack();
|
|
|
} else {
|
|
|
history.go(-1);
|
|
|
}
|
|
|
};
|
|
|
module.exports = goto; |
...
|
...
|
|