zz-shopify-components 0.0.2 → 0.0.4

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.
@@ -44,7 +44,9 @@ var bindSiteJump = bindSiteJump
44
44
  const country = countryElement.innerText.trim();
45
45
  const targetUrl = siteMap[country] || siteMap['default'] || '/';
46
46
  // window.location.href = targetUrl; // 跳转到匹配的站点
47
- toSubSiteBP(targetUrl);
47
+ if (toSubSiteBP) {
48
+ toSubSiteBP(targetUrl);
49
+ }
48
50
  } else {
49
51
  console.error('SiteJump: Country element not found');
50
52
  }
@@ -5,31 +5,32 @@
5
5
  var bindSiteJump = bindSiteJump
6
6
  ? bindSiteJump
7
7
  : function bindSiteJump(el, links) {
8
- if (!links) {
9
- console.log('SiteJump: links are required');
10
- return;
11
- }
12
-
13
- const SITE_JUMP_MAP = links;
14
- console.log(SITE_JUMP_MAP, 'SITE_JUMP_MAP');
15
- const arr = SITE_JUMP_MAP.split('\n'); // 按换行符拆分为数组
16
- const siteMap = {};
17
- // 将站点地图解析成对象
18
- arr.forEach((item) => {
19
- const [key, value] = item.split(': ');
20
- if (key && value) {
21
- siteMap[key.trim()] = value.trim();
8
+ if (!links) {
9
+ console.log('SiteJump: links are required');
10
+ return;
22
11
  }
23
- });
24
12
 
25
- const countryElement =
26
- document.getElementsByClassName('countryWord')[0];
27
- if (countryElement) {
28
- const country = countryElement.innerText.trim();
29
- const targetUrl = siteMap[country] || siteMap['default'] || '/';
30
- // 加跟踪参数并跳转到匹配的站点
31
- toSubSiteBP(targetUrl);
32
- } else {
33
- console.error('SiteJump: Country element not found');
34
- }
35
- };
13
+ const SITE_JUMP_MAP = links;
14
+ console.log(SITE_JUMP_MAP, 'SITE_JUMP_MAP');
15
+ const arr = SITE_JUMP_MAP.split('\n'); // 按换行符拆分为数组
16
+ const siteMap = {};
17
+ // 将站点地图解析成对象
18
+ arr.forEach((item) => {
19
+ const [key, value] = item.split(': ');
20
+ if (key && value) {
21
+ siteMap[key.trim()] = value.trim();
22
+ }
23
+ });
24
+
25
+ const countryElement = document.getElementsByClassName('countryWord')[0];
26
+ if (countryElement) {
27
+ const country = countryElement.innerText.trim();
28
+ const targetUrl = siteMap[country] || siteMap['default'] || '/';
29
+ // 加跟踪参数并跳转到匹配的站点
30
+ if (toSubSiteBP) {
31
+ toSubSiteBP(targetUrl);
32
+ }
33
+ } else {
34
+ console.error('SiteJump: Country element not found');
35
+ }
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zz-shopify-components",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Reusable Shopify components for theme projects",
5
5
  "keywords": ["shopify", "theme", "components"],
6
6
  "license": "CC BY-NC-ND",
@@ -1,73 +0,0 @@
1
- (function () {
2
- const DEFAULT_BASE_URL = 'https://h130-app-server-us.hoverx1.cn';
3
-
4
- const DEFAULT_TIMEOUT = 60000;
5
-
6
- function getToken() {
7
- return localStorage.getItem('token') || '';
8
- }
9
-
10
- function buildUrl(url, params = {}) {
11
- const queryString = new URLSearchParams(params).toString();
12
- return queryString ? `${url}?${queryString}` : url;
13
- }
14
-
15
- function timeoutFetch(fetchPromise, timeout = DEFAULT_TIMEOUT) {
16
- return Promise.race([
17
- fetchPromise,
18
- new Promise((_, reject) =>
19
- setTimeout(() => reject(new Error('请求超时,请重试')), timeout)
20
- ),
21
- ]);
22
- }
23
-
24
- function request(method, url, params = {}, options = {}) {
25
- const baseUrl = options.baseUrl || DEFAULT_BASE_URL;
26
-
27
- const timeout = options.timeout || DEFAULT_TIMEOUT;
28
-
29
- const fullUrl = baseUrl + url;
30
-
31
- let fetchOptions = {
32
- method: method.toUpperCase(),
33
- headers: {
34
- 'Content-Type': 'application/json',
35
- ...(options.headers || {}),
36
- },
37
- ...options,
38
- };
39
-
40
- if (method.toLowerCase() === 'get') {
41
- return timeoutFetch(
42
- fetch(buildUrl(fullUrl, params), fetchOptions),
43
- timeout
44
- ).then(handleResponse);
45
- } else {
46
- fetchOptions.body = JSON.stringify(params);
47
- return timeoutFetch(fetch(fullUrl, fetchOptions), timeout).then(
48
- handleResponse
49
- );
50
- }
51
- }
52
-
53
- function handleResponse(response) {
54
- if (!response.ok) {
55
- if (response.status === 401) {
56
- // 未登录或登录过期,即将跳转登录页
57
- }
58
- return response.json().then((err) => {
59
- throw err;
60
- });
61
- }
62
- return response.json();
63
- }
64
-
65
- window.httpRequest = {
66
- get: function (url, params = {}, options = {}) {
67
- return request('get', url, params, options);
68
- },
69
- post: function (url, params = {}, options = {}) {
70
- return request('post', url, params, options);
71
- },
72
- };
73
- })();