component-sanzhizhou 1.2.10 → 1.2.12
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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/lib/Tool.js +1 -1
- package/dist/lib/product-detail-link.d.ts +25 -9
- package/dist/lib/product-detail-link.js +83 -24
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,4 +20,5 @@ export { default as PayQr } from './pay/qr';
|
|
|
20
20
|
export { default as PayChannel } from './pay/pay-channel';
|
|
21
21
|
export { default as IdTag } from './UI/id-tag';
|
|
22
22
|
export { default as CollectConfigPrice } from './collect-price';
|
|
23
|
-
export { default as ProductDetailLink, getProductDetailUrl } from './lib/product-detail-link';
|
|
23
|
+
export { CommercePlatform, default as ProductDetailLink, getProductDetailUrl, } from './lib/product-detail-link';
|
|
24
|
+
export type { ProductDetailLinkProps, ProductDetailUrlParams, } from './lib/product-detail-link';
|
package/dist/index.js
CHANGED
|
@@ -20,4 +20,4 @@ export { default as PayQr } from "./pay/qr";
|
|
|
20
20
|
export { default as PayChannel } from "./pay/pay-channel";
|
|
21
21
|
export { default as IdTag } from "./UI/id-tag";
|
|
22
22
|
export { default as CollectConfigPrice } from "./collect-price";
|
|
23
|
-
export { default as ProductDetailLink, getProductDetailUrl } from "./lib/product-detail-link";
|
|
23
|
+
export { CommercePlatform, default as ProductDetailLink, getProductDetailUrl } from "./lib/product-detail-link";
|
package/dist/lib/Tool.js
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/**
|
|
3
|
+
* 电商平台枚举,取值与后端的 commercePlatformId 保持一致。
|
|
4
|
+
*/
|
|
5
|
+
export declare enum CommercePlatform {
|
|
6
|
+
/** OZON */
|
|
7
|
+
OZON = 7,
|
|
8
|
+
/** Wildberries */
|
|
9
|
+
Wildberries = 15
|
|
10
|
+
}
|
|
11
|
+
/** 生成商品详情链接所需的参数 */
|
|
12
|
+
export interface ProductDetailUrlParams {
|
|
13
|
+
/** 电商平台 */
|
|
14
|
+
platform: CommercePlatform | number;
|
|
15
|
+
/** 商品 ID / SKU */
|
|
16
|
+
skuId: number | string;
|
|
17
|
+
/** 附加到链接上的查询参数 */
|
|
18
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
8
19
|
}
|
|
9
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 根据电商平台和商品 ID 生成商品详情页链接。
|
|
22
|
+
* 平台不支持或 skuId 为空时返回空字符串。
|
|
23
|
+
*/
|
|
24
|
+
export declare const getProductDetailUrl: ({ platform, skuId, query, }: ProductDetailUrlParams) => string;
|
|
25
|
+
export interface ProductDetailLinkProps extends ProductDetailUrlParams, Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
26
|
+
children?: React.ReactNode;
|
|
10
27
|
}
|
|
11
|
-
|
|
12
|
-
declare const ProductDetailLink: React.FC<Props>;
|
|
28
|
+
declare const ProductDetailLink: React.FC<ProductDetailLinkProps>;
|
|
13
29
|
export default ProductDetailLink;
|
|
@@ -1,36 +1,95 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
var _excluded = ["platform", "skuId", "query", "children", "target", "rel", "onClick"];
|
|
1
5
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
6
|
+
import isInClient from "./isInClient";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 电商平台枚举,取值与后端的 commercePlatformId 保持一致。
|
|
10
|
+
*/
|
|
11
|
+
export var CommercePlatform = /*#__PURE__*/function (CommercePlatform) {
|
|
12
|
+
CommercePlatform[CommercePlatform["OZON"] = 7] = "OZON";
|
|
13
|
+
CommercePlatform[CommercePlatform["Wildberries"] = 15] = "Wildberries";
|
|
14
|
+
return CommercePlatform;
|
|
15
|
+
}({});
|
|
16
|
+
|
|
17
|
+
/** 生成商品详情链接所需的参数 */
|
|
18
|
+
|
|
19
|
+
/** 各平台的商品详情页 URL 生成器,扩展新平台时在此登记即可 */
|
|
20
|
+
var PLATFORM_URL_BUILDERS = _defineProperty(_defineProperty({}, CommercePlatform.OZON, function (skuId) {
|
|
21
|
+
return "https://ozon.ru/product/".concat(skuId);
|
|
22
|
+
}), CommercePlatform.Wildberries, function (skuId) {
|
|
23
|
+
return "https://www.wildberries.ru/catalog/".concat(skuId, "/detail.aspx");
|
|
24
|
+
});
|
|
25
|
+
function buildQueryString(query) {
|
|
26
|
+
if (!query) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
var pairs = Object.keys(query).filter(function (key) {
|
|
30
|
+
var value = query[key];
|
|
31
|
+
return value !== undefined && value !== null && value !== '';
|
|
32
|
+
}).map(function (key) {
|
|
33
|
+
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(query[key])));
|
|
34
|
+
});
|
|
35
|
+
return pairs.length ? "?".concat(pairs.join('&')) : '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 根据电商平台和商品 ID 生成商品详情页链接。
|
|
40
|
+
* 平台不支持或 skuId 为空时返回空字符串。
|
|
41
|
+
*/
|
|
42
|
+
export var getProductDetailUrl = function getProductDetailUrl(_ref) {
|
|
43
|
+
var platform = _ref.platform,
|
|
44
|
+
skuId = _ref.skuId,
|
|
45
|
+
query = _ref.query;
|
|
4
46
|
if (!skuId) {
|
|
5
47
|
return '';
|
|
6
48
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return "https://ozon.ru/product/".concat(skuId);
|
|
11
|
-
case 15:
|
|
12
|
-
// WB
|
|
13
|
-
return "https://www.wildberries.ru/catalog/".concat(skuId, "/detail.aspx");
|
|
14
|
-
default:
|
|
15
|
-
return '';
|
|
49
|
+
var build = PLATFORM_URL_BUILDERS[platform];
|
|
50
|
+
if (!build) {
|
|
51
|
+
return '';
|
|
16
52
|
}
|
|
53
|
+
return "".concat(build(encodeURIComponent(String(skuId)))).concat(buildQueryString(query));
|
|
17
54
|
};
|
|
18
|
-
var ProductDetailLink = function ProductDetailLink(
|
|
19
|
-
var
|
|
20
|
-
skuId =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
55
|
+
var ProductDetailLink = function ProductDetailLink(_ref2) {
|
|
56
|
+
var platform = _ref2.platform,
|
|
57
|
+
skuId = _ref2.skuId,
|
|
58
|
+
query = _ref2.query,
|
|
59
|
+
children = _ref2.children,
|
|
60
|
+
_ref2$target = _ref2.target,
|
|
61
|
+
target = _ref2$target === void 0 ? '_blank' : _ref2$target,
|
|
62
|
+
_ref2$rel = _ref2.rel,
|
|
63
|
+
rel = _ref2$rel === void 0 ? 'noopener noreferrer' : _ref2$rel,
|
|
64
|
+
onClick = _ref2.onClick,
|
|
65
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
66
|
+
var href = getProductDetailUrl({
|
|
67
|
+
platform: platform,
|
|
68
|
+
skuId: skuId,
|
|
69
|
+
query: query
|
|
70
|
+
});
|
|
25
71
|
if (!href) {
|
|
26
72
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
27
73
|
}
|
|
28
|
-
|
|
74
|
+
var handleClick = function handleClick(event) {
|
|
75
|
+
// 客户端内通过桥接在本机浏览器打开,避免新开浏览器标签页
|
|
76
|
+
if (isInClient()) {
|
|
77
|
+
var _window$getBridge, _window;
|
|
78
|
+
console.log('ProductDetailLink handleClick in client:', event);
|
|
79
|
+
var bridge = (_window$getBridge = (_window = window).getBridge) === null || _window$getBridge === void 0 ? void 0 : _window$getBridge.call(_window);
|
|
80
|
+
if (bridge !== null && bridge !== void 0 && bridge.openLocalBrowser) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
bridge.openLocalBrowser(href);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
87
|
+
};
|
|
88
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
29
89
|
href: href,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}, children);
|
|
90
|
+
target: target,
|
|
91
|
+
rel: rel,
|
|
92
|
+
onClick: handleClick
|
|
93
|
+
}, rest), children);
|
|
35
94
|
};
|
|
36
95
|
export default ProductDetailLink;
|