@aliretail/cuckoo-official-retailforce-form-banner
Version:
official-retailforce-form-banner
153 lines (135 loc) • 4.11 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import { cHost } from "./config";
export var getHash = function getHash(key, str) {
str = str || window.location.search;
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
var r = str.substr(1).match(reg);
if (r !== null) {
return unescape(r[2]);
}
return null;
};
export var transfer = function transfer(componentList) {
var finalList = [];
var nameMap = {
navigation_bar: "导航",
banner_image: "焦点图",
swiper_new: "轮播图",
title: "标题",
popup: "广告弹窗",
product_list: "商品列表"
};
componentList.map(function (item) {
var node = item.getNode();
var title = item.getTitle();
var moduleName = node.componentName,
id = node.id;
var itemProps = item.props || {};
var behavior = {
behaviorCode: 0,
behaviorDesc: "锚点"
};
if (moduleName === "popup") {
behavior = {
behaviorCode: 1,
behaviorDesc: "弹窗"
};
}
finalList.push(_extends({}, behavior, {
id: moduleName + "_" + id,
imgUrl: "",
name: (itemProps.moduleTitle || title) + " - " + id,
type: nameMap[moduleName] || title
}));
});
console.log("finalList==", finalList);
return finalList;
}; // 将链接变更为小程序
var transferMiniApp = function transferMiniApp(result) {
var bizId = getHash("bizId");
var bizCode = getHash("bizCode");
var appLink = "/pages/home/biz/index";
var uiConfig = JSON.parse(result && result.globalData && result.globalData.uiConfig ? result.globalData.uiConfig : "{}");
console.log("uiConfig", uiConfig);
var res = "h5#" + cHost + "?path=" + result.path + "&bizCode=" + bizCode + "&bizId=" + bizId; // 如果支持多端,修改链接为小程序链接
if (uiConfig.multipleSupport) {
res = "appLink#" + appLink + "?path=" + result.path + "&bizCode=" + bizCode + "&bizId=" + bizId;
}
return res;
};
export var getLink = function getLink(obj, item) {
if (item === void 0) {
item = {};
}
var url = "";
var result = obj.result[0] || obj.result || {};
item.actionLinkType = obj.type;
item.actionLinkMeta = {};
console.log("obj.type", obj.type);
switch (obj.type) {
case "current":
item.actionLink = "action#" + result.id;
item.actionLinkMeta = {
name: "\u5185\u90E8\u7EC4\u4EF6(" + result.name + ")",
obj: obj
};
break;
case "outside":
if (result.appLink) {
item.actionLink = "appLink#" + result.appLink;
} else if (result.h5Link) {
if (/^action\:/g.test(result.h5Link)) {
item.actionLink = result.h5Link;
} else {
item.actionLink = "h5#" + result.h5Link;
}
} else if (result.liveLink) {
item.actionLink = "live#" + result.liveLink;
} else if (result.appCode) {
item.actionLink = "notice#" + result.appCode;
} else {
item.actionLink = "";
}
if (item.actionLink) {
item.actionLinkMeta = {
name: "\u5916\u90E8\u94FE\u63A5(" + item.actionLink + ")",
obj: obj
};
} else {
item.actionLinkMeta = {};
}
break;
case "base":
url = transferMiniApp(result);
console.log("url", url);
item.actionLink = url;
item.actionLinkMeta = {
name: "\u57FA\u7840\u9875(" + result.pageName + ")",
obj: obj
};
break;
case "activity":
url = transferMiniApp(result);
console.log("url", url);
item.actionLink = url;
item.actionLinkMeta = {
name: "\u6D3B\u52A8\u9875(" + result.pageName + ")",
obj: obj
};
break;
case "detail":
url = "/pages/trade/trade_detail/index?params[itemId]=" + result;
console.log("result", result, url);
item.actionLink = "appLink#" + url;
item.actionLinkMeta = {
id: result,
name: "\u5546\u54C1\u94FE\u63A5(" + result + ")",
obj: obj
};
break;
default:
item.actionLink = "";
break;
}
return item;
};