|
|
import wx from "weixin-js-sdk";
|
|
|
|
|
|
const invokeMethod = (obj) => {
|
|
|
var invokeMethod = function(obj) {
|
|
|
if (window.yohoInterface) {
|
|
|
window.yohoInterface.triggerEvent(obj.success || function () {
|
|
|
}, obj.fail || function () {
|
...
|
...
|
@@ -13,20 +11,20 @@ const invokeMethod = (obj) => { |
|
|
}
|
|
|
}
|
|
|
|
|
|
const linkToMiniApp = (goUrl, type) => {
|
|
|
let url = goUrl || '';
|
|
|
var linkToMiniApp = function(goUrl, type) {
|
|
|
var url = goUrl || '';
|
|
|
if (url && url.indexOf('http') < 0 && type === 'other') {
|
|
|
url = document.location.protocol + '//' + document.location.host + url;
|
|
|
}
|
|
|
if (url) {
|
|
|
let scene;
|
|
|
var scene;
|
|
|
if (type === 'product' || type === 'brand') {
|
|
|
scene = url;
|
|
|
} else {
|
|
|
let base_url = decodeURIComponent(url).split('?')[0];
|
|
|
let params = getQueryObj(url);
|
|
|
let paramStr = '';
|
|
|
Object.keys(params).forEach(key => {
|
|
|
var base_url = decodeURIComponent(url).split('?')[0];
|
|
|
var params = getQueryObj(url);
|
|
|
var paramStr = '';
|
|
|
Object.keys(params).forEach(function(key) {
|
|
|
paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key];
|
|
|
})
|
|
|
scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr);
|
...
|
...
|
@@ -39,14 +37,14 @@ const linkToMiniApp = (goUrl, type) => { |
|
|
};
|
|
|
|
|
|
|
|
|
const getQueryObj = (link) => {
|
|
|
let loc = decodeURIComponent(document.location.href);
|
|
|
var getQueryObj = function(link) {
|
|
|
var loc = decodeURIComponent(document.location.href);
|
|
|
if (link) {
|
|
|
loc = decodeURIComponent(link);
|
|
|
}
|
|
|
let variables = '';
|
|
|
let variableArr = [];
|
|
|
let finalArr = [];
|
|
|
var variables = '';
|
|
|
var variableArr = [];
|
|
|
var finalArr = [];
|
|
|
|
|
|
if (loc.indexOf('?') > 0) {
|
|
|
variables = loc.split('?')[1];
|
...
|
...
|
@@ -56,30 +54,30 @@ const getQueryObj = (link) => { |
|
|
variableArr = variables.split('#')[0].split('&');
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < variableArr.length; i++) {
|
|
|
let obj = {};
|
|
|
for (var i = 0; i < variableArr.length; i++) {
|
|
|
var obj = {};
|
|
|
|
|
|
obj.name = variableArr[i].split('=')[0];
|
|
|
obj.value = variableArr[i].split('=')[1];
|
|
|
if (variableArr[i].split('=').length > 2) {
|
|
|
for (let j = 2; j < variableArr[i].split('=').length; j++) {
|
|
|
for (var j = 2; j < variableArr[i].split('=').length; j++) {
|
|
|
obj.value += '=' + variableArr[i].split('=')[j];
|
|
|
}
|
|
|
}
|
|
|
finalArr.push(obj);
|
|
|
}
|
|
|
|
|
|
let query_obj = {};
|
|
|
var query_obj = {};
|
|
|
|
|
|
for (let i = 0; i < finalArr.length; i++) {
|
|
|
for (var i = 0; i < finalArr.length; i++) {
|
|
|
query_obj[finalArr[i].name] = finalArr[i].value;
|
|
|
}
|
|
|
|
|
|
return query_obj;
|
|
|
};
|
|
|
|
|
|
const createLinkButton = (url, id) => {
|
|
|
let a = document.createElement('a');
|
|
|
var createLinkButton = function(url, id) {
|
|
|
var a = document.createElement('a');
|
|
|
a.style.position = 'fixed';
|
|
|
a.style.top = 0;
|
|
|
a.style.left = 0;
|
...
|
...
|
@@ -92,10 +90,11 @@ const createLinkButton = (url, id) => { |
|
|
a.setAttribute('href', url);
|
|
|
document.body.appendChild(a);
|
|
|
return a;
|
|
|
}
|
|
|
export {
|
|
|
invokeMethod,
|
|
|
getQueryObj,
|
|
|
linkToMiniApp,
|
|
|
createLinkButton
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
invokeMethod: invokeMethod,
|
|
|
getQueryObj: getQueryObj,
|
|
|
linkToMiniApp: linkToMiniApp,
|
|
|
createLinkButton: createLinkButton
|
|
|
}; |
...
|
...
|
|