@conecli/cone-render 0.10.1-shop3.54 → 0.10.1-shop3.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview 京东店铺JS桥
|
|
3
|
+
* @description 用于在京东店铺内嵌入H5页面时,与店铺原生交互。目前只用于外部团队开发H5页面内嵌到店铺原生环境,同时需要使用店铺原生能力的场景。当前接入业务:圈子tab页
|
|
4
|
+
* @updateOperate 更新方式:执行 build:openShopBridge 命令,生成压缩后代码,会自动放在 openShopBridge.min.js 文件中。同步将这个内容更新到 mpaas 店铺空间下 key=shop-bridge-js 的配置内容
|
|
5
|
+
* @h5UseExample 见代码最底部
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
window.JdShopBridge = {
|
|
9
|
+
_callRouterAndroid: function ({ routerURL, routerParam, callBackName = '' }) {
|
|
10
|
+
const getCallBackName = `window.${callBackName}`;
|
|
11
|
+
window?.JDJshop?.wrtNative(
|
|
12
|
+
JSON.stringify({
|
|
13
|
+
routerParam: JSON.stringify(routerParam), // 需要传入的参数,这里的key自定义的,optional,可选参数
|
|
14
|
+
serialize: '1', // 序列化参数,否则可能出现router返回的字符串里有特殊字符,导致js执行失败
|
|
15
|
+
callBackName: getCallBackName, // h5自定义的函数名称,optional,可选参数
|
|
16
|
+
callBackId: `${callBackName}Android`, // h5自定义的参数,用于区分同一个页面,optional,可选参数
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
_callRouterIOS: function ({ routerURL, routerParam, callBackName = '', isSync = false }) {
|
|
21
|
+
const getCallBackName = `window.${callBackName}`;
|
|
22
|
+
const params = {
|
|
23
|
+
routerURL, // required,必选参数
|
|
24
|
+
serialize: '1', // 序列化参数,否则可能出现router返回的字符串里有特殊字符,导致js执行失败
|
|
25
|
+
routerParam, // 需要传入的参数,这里的key自定义的,optional,可选参数
|
|
26
|
+
callBackName: getCallBackName, // h5自定义的函数名称,optional,可选参数
|
|
27
|
+
callBackId: `${callBackName}Ios`, // h5自定义的参数,用于区分同一个页面,optional,可选参数
|
|
28
|
+
};
|
|
29
|
+
window?.webkit?.messageHandlers?.JDAppUnite?.postMessage({
|
|
30
|
+
method: isSync ? 'callSyncRouterModuleWithParams' : 'callRouterModuleWithParams',
|
|
31
|
+
params: JSON.stringify(params),
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
// 通用店铺桥方法
|
|
35
|
+
callNativeBridge: function (type = 'pageReady', sendData = null, callBackName = '') {
|
|
36
|
+
const ua = navigator.userAgent;
|
|
37
|
+
const getCallBackName = `window.${callBackName}`;
|
|
38
|
+
const getRouterParam = {
|
|
39
|
+
type,
|
|
40
|
+
callBackName: getCallBackName,
|
|
41
|
+
newHomePage: true,
|
|
42
|
+
};
|
|
43
|
+
if (sendData) {
|
|
44
|
+
Object.assign(getRouterParam, sendData);
|
|
45
|
+
}
|
|
46
|
+
if (/ip(hone|od)|ipad/i.test(ua)) {
|
|
47
|
+
console.log('调用店铺IOS桥');
|
|
48
|
+
this._callRouterIOS({
|
|
49
|
+
routerURL: 'router://JDShopModule/wrtNative',
|
|
50
|
+
routerParam: getRouterParam,
|
|
51
|
+
});
|
|
52
|
+
} else if (/android/i.test(ua)) {
|
|
53
|
+
console.log('调用店铺Android桥');
|
|
54
|
+
this._callRouterAndroid({
|
|
55
|
+
routerURL: 'router://JDJShopModule/wrtNative', // 京东主站中router多一个J,相比店铺内JDShopModule
|
|
56
|
+
routerParam: getRouterParam,
|
|
57
|
+
});
|
|
58
|
+
} else if ('harmony' === (ua.split(';')[1] || '').toLowerCase() || /arkweb/i.test(ua)) {
|
|
59
|
+
console.log('调用店铺Harmony桥');
|
|
60
|
+
const params = {
|
|
61
|
+
routerURL: '', // 鸿蒙暂时没用到该属性
|
|
62
|
+
routerParam: getRouterParam, // 需要传入的参数,这里的key自定义的,optional,可选参数
|
|
63
|
+
};
|
|
64
|
+
window.XWebView &&
|
|
65
|
+
window.XWebView.callNative(
|
|
66
|
+
'JdShopPlugin',
|
|
67
|
+
type,
|
|
68
|
+
JSON.stringify(params),
|
|
69
|
+
getCallBackName,
|
|
70
|
+
`${callBackName}HarmonyOS`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
// 设置页码信息
|
|
75
|
+
setPageInfo: function (params) {
|
|
76
|
+
this.callNativeBridge('pageCountInfo', {
|
|
77
|
+
data: params,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
// 展示隐藏购物车icon
|
|
81
|
+
showCartIcon: function (isShow = true) {
|
|
82
|
+
this.callNativeBridge('showCartButton', {
|
|
83
|
+
data: {
|
|
84
|
+
isShow,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
// 展示隐藏返回顶部icon
|
|
89
|
+
showBackToTopIcon: function (isShow = true) {
|
|
90
|
+
this.callNativeBridge('showBackToTop', {
|
|
91
|
+
data: isShow,
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
// 注册返回顶部icon点击回调
|
|
95
|
+
registerBackToTopClickCallback: function (callBackName = '') {
|
|
96
|
+
if (typeof window[callBackName] === 'function') {
|
|
97
|
+
this.callNativeBridge('registerBackToTopClickCallback', {
|
|
98
|
+
data: callBackName,
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
console.error(`registerBackToTopClickCallback: "${callBackName}" is not a global function`);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
init: function () {
|
|
105
|
+
console.log('JdShopBridge V1.0 初始化完成');
|
|
106
|
+
return this;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
window.JdShopBridge = JdShopBridge.init();
|
|
110
|
+
|
|
111
|
+
// 注册返回顶部icon点击回调示例
|
|
112
|
+
// function shopEmbedH5BackToTop(){
|
|
113
|
+
// console.log('shopEmbedH5BackToTop() 触发拉')
|
|
114
|
+
// document.getElementById('/circle/home?stamp=AA').scrollTop = 0;
|
|
115
|
+
// }
|
|
116
|
+
// window.JdShopBridge.registerBackToTopClickCallback('shopEmbedH5BackToTop')
|
|
117
|
+
|
|
118
|
+
// 更新页码icon页码信息示例
|
|
119
|
+
// sentNativePageScrollPageInfo({"pageIdx":1,"totalPage":24})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";window.JdShopBridge={_callRouterAndroid:function(o){o.routerURL;var a,i=o.routerParam,e=o.callBackName,t=void 0===e?"":e,r="window.".concat(t);null===(a=window)||void 0===a||null===(a=a.JDJshop)||void 0===a||a.wrtNative(JSON.stringify({routerParam:JSON.stringify(i),serialize:"1",callBackName:r,callBackId:"".concat(t,"Android")}))},_callRouterIOS:function(o){var a,i=o.routerURL,e=o.routerParam,t=o.callBackName,r=void 0===t?"":t,l=o.isSync,n=void 0!==l&&l,c={routerURL:i,serialize:"1",routerParam:e,callBackName:"window.".concat(r),callBackId:"".concat(r,"Ios")};null===(a=window)||void 0===a||null===(a=a.webkit)||void 0===a||null===(a=a.messageHandlers)||void 0===a||null===(a=a.JDAppUnite)||void 0===a||a.postMessage({method:n?"callSyncRouterModuleWithParams":"callRouterModuleWithParams",params:JSON.stringify(c)})},callNativeBridge:function(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"pageReady",a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",e=navigator.userAgent,t="window.".concat(i),r={type:o,callBackName:t,newHomePage:!0};if(a&&Object.assign(r,a),/ip(hone|od)|ipad/i.test(e))console.log("调用店铺IOS桥"),this._callRouterIOS({routerURL:"router://JDShopModule/wrtNative",routerParam:r});else if(/android/i.test(e))console.log("调用店铺Android桥"),this._callRouterAndroid({routerURL:"router://JDJShopModule/wrtNative",routerParam:r});else if("harmony"===(e.split(";")[1]||"").toLowerCase()||/arkweb/i.test(e)){console.log("调用店铺Harmony桥");var l={routerURL:"",routerParam:r};window.XWebView&&window.XWebView.callNative("JdShopPlugin",o,JSON.stringify(l),t,"".concat(i,"HarmonyOS"))}},setPageInfo:function(o){this.callNativeBridge("pageCountInfo",{data:o})},showCartIcon:function(){var o=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.callNativeBridge("showCartButton",{data:{isShow:o}})},showBackToTopIcon:function(){var o=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.callNativeBridge("showBackToTop",{data:o})},registerBackToTopClickCallback:function(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";"function"==typeof window[o]?this.callNativeBridge("registerBackToTopClickCallback",{data:o}):console.error('registerBackToTopClickCallback: "'.concat(o,'" is not a global function'))},init:function(){return console.log("JdShopBridge V1.0 初始化完成"),this}},window.JdShopBridge=JdShopBridge.init();
|