@gt6/sdk 1.0.23 → 1.0.24
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/core/types.d.ts +4 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/gt6-sdk.cjs.js +364 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +364 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/products.d.ts +48 -0
- package/dist/modules/products.d.ts.map +1 -1
- package/dist/modules/settings.d.ts +10 -0
- package/dist/modules/settings.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.esm.js
CHANGED
@@ -372,6 +372,65 @@ class ProductsAPI {
|
|
372
372
|
}
|
373
373
|
return product;
|
374
374
|
}
|
375
|
+
/**
|
376
|
+
* 1.1. 根据产品ID获取父平台产品详情
|
377
|
+
*/
|
378
|
+
async getProduct_p(productId) {
|
379
|
+
const product = await this.client.request(`/parentproducts/${productId}.json`);
|
380
|
+
// 检查产品是否有销售区域和税费模板
|
381
|
+
if (product.regions && product.regions.length > 0 &&
|
382
|
+
product.taxTemplates && product.taxTemplates.length > 0) {
|
383
|
+
try {
|
384
|
+
// 获取税费信息
|
385
|
+
const taxInfo = await this.getTaxInfo();
|
386
|
+
// 为每个税费模板添加规则
|
387
|
+
product.taxTemplates = product.taxTemplates.map(template => {
|
388
|
+
const matchingTemplate = taxInfo.templates.find(t => t.templateId === template.templateId);
|
389
|
+
if (matchingTemplate) {
|
390
|
+
// 过滤出产品可销售区域的规则
|
391
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
392
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
393
|
+
return {
|
394
|
+
...template,
|
395
|
+
rules: applicableRules
|
396
|
+
};
|
397
|
+
}
|
398
|
+
return template;
|
399
|
+
});
|
400
|
+
}
|
401
|
+
catch (error) {
|
402
|
+
// 如果获取税费信息失败,不影响产品详情返回
|
403
|
+
console.warn('Failed to fetch tax info:', error);
|
404
|
+
}
|
405
|
+
}
|
406
|
+
// 检查产品是否有销售区域和运费模板
|
407
|
+
if (product.regions && product.regions.length > 0 &&
|
408
|
+
product.shippingTemplates && product.shippingTemplates.length > 0) {
|
409
|
+
try {
|
410
|
+
// 获取运费信息
|
411
|
+
const shippingInfo = await this.getShippingInfo();
|
412
|
+
// 为每个运费模板添加规则
|
413
|
+
product.shippingTemplates = product.shippingTemplates.map(template => {
|
414
|
+
const matchingTemplate = shippingInfo.templates.find(t => t.templateId === template.templateId);
|
415
|
+
if (matchingTemplate) {
|
416
|
+
// 过滤出产品可销售区域的规则
|
417
|
+
const productRegionIds = product.regions.map(r => r.regionId);
|
418
|
+
const applicableRules = matchingTemplate.rules.filter(rule => productRegionIds.includes(rule.regionId));
|
419
|
+
return {
|
420
|
+
...template,
|
421
|
+
rules: applicableRules
|
422
|
+
};
|
423
|
+
}
|
424
|
+
return template;
|
425
|
+
});
|
426
|
+
}
|
427
|
+
catch (error) {
|
428
|
+
// 如果获取运费信息失败,不影响产品详情返回
|
429
|
+
console.warn('Failed to fetch shipping info:', error);
|
430
|
+
}
|
431
|
+
}
|
432
|
+
return product;
|
433
|
+
}
|
375
434
|
/**
|
376
435
|
* 2. 获取产品分类列表
|
377
436
|
*/
|
@@ -381,6 +440,15 @@ class ProductsAPI {
|
|
381
440
|
const response = await this.client.request(`/product-categories/platform-${config.platformId}-root-${categoryId}.json`);
|
382
441
|
return response.categories;
|
383
442
|
}
|
443
|
+
/**
|
444
|
+
* 2.1. 获取平台产品分类列表
|
445
|
+
*/
|
446
|
+
async getCategories_p(productRootCategoryId_p) {
|
447
|
+
const config = this.client.getConfig();
|
448
|
+
const categoryId = productRootCategoryId_p || config.productRootCategoryId_p;
|
449
|
+
const response = await this.client.request(`/product-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
|
450
|
+
return response.categories;
|
451
|
+
}
|
384
452
|
/**
|
385
453
|
* 3. 获取产品标签列表
|
386
454
|
*/
|
@@ -390,6 +458,15 @@ class ProductsAPI {
|
|
390
458
|
const response = await this.client.request(`/product-tags/platform-${config.platformId}-${alias}.json`);
|
391
459
|
return response.tags;
|
392
460
|
}
|
461
|
+
/**
|
462
|
+
* 3.1. 获取平台产品标签列表
|
463
|
+
*/
|
464
|
+
async getTags_p(productTagAlias_p) {
|
465
|
+
const config = this.client.getConfig();
|
466
|
+
const alias = productTagAlias_p || config.productTagAlias_p;
|
467
|
+
const response = await this.client.request(`/product-tags/platform-${config.platformId_p}-${alias}.json`);
|
468
|
+
return response.tags;
|
469
|
+
}
|
393
470
|
/**
|
394
471
|
* 4. 根据分类ID获取产品列表
|
395
472
|
* 支持单个分类ID或分类ID数组
|
@@ -450,6 +527,124 @@ class ProductsAPI {
|
|
450
527
|
limit
|
451
528
|
};
|
452
529
|
}
|
530
|
+
/**
|
531
|
+
* 4.1. 根据分类ID获取平台产品列表
|
532
|
+
*/
|
533
|
+
async getProductsByCategory_p(categoryId, options) {
|
534
|
+
// 获取分类数据
|
535
|
+
const categories = await this.getCategories_p();
|
536
|
+
// 递归查找分类的函数
|
537
|
+
const findCategoryById = (cats, targetId) => {
|
538
|
+
for (const cat of cats) {
|
539
|
+
if (cat.categoryId === targetId) {
|
540
|
+
return cat;
|
541
|
+
}
|
542
|
+
if (cat.children && cat.children.length > 0) {
|
543
|
+
const found = findCategoryById(cat.children, targetId);
|
544
|
+
if (found)
|
545
|
+
return found;
|
546
|
+
}
|
547
|
+
}
|
548
|
+
return null;
|
549
|
+
};
|
550
|
+
// 将单个分类ID转换为数组
|
551
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
552
|
+
// 收集所有指定分类下的产品ID
|
553
|
+
const allProductIds = [];
|
554
|
+
categoryIds.forEach(id => {
|
555
|
+
const targetCategory = findCategoryById(categories, id);
|
556
|
+
if (targetCategory) {
|
557
|
+
allProductIds.push(...targetCategory.productIds);
|
558
|
+
}
|
559
|
+
});
|
560
|
+
// 去重
|
561
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
562
|
+
if (uniqueProductIds.length === 0) {
|
563
|
+
return {
|
564
|
+
products: [],
|
565
|
+
total: 0,
|
566
|
+
page: options?.page || 1,
|
567
|
+
limit: options?.limit || 10
|
568
|
+
};
|
569
|
+
}
|
570
|
+
// 应用分页
|
571
|
+
const page = options?.page || 1;
|
572
|
+
const limit = options?.limit || 10;
|
573
|
+
const offset = (page - 1) * limit;
|
574
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
575
|
+
// 获取产品详情
|
576
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
577
|
+
// 应用状态过滤
|
578
|
+
let filteredProducts = products;
|
579
|
+
if (options?.status !== undefined) {
|
580
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
581
|
+
}
|
582
|
+
return {
|
583
|
+
products: filteredProducts,
|
584
|
+
total: uniqueProductIds.length,
|
585
|
+
page,
|
586
|
+
limit
|
587
|
+
};
|
588
|
+
}
|
589
|
+
/**
|
590
|
+
* 4.2. 根据分类ID获取平台产品列表
|
591
|
+
*/
|
592
|
+
async getProductsByCategory_t(categoryId, options) {
|
593
|
+
// 获取分类数据
|
594
|
+
const categories = await this.getCategories();
|
595
|
+
// 递归查找分类的函数
|
596
|
+
const findCategoryById = (cats, targetId) => {
|
597
|
+
for (const cat of cats) {
|
598
|
+
if (cat.categoryId === targetId) {
|
599
|
+
return cat;
|
600
|
+
}
|
601
|
+
if (cat.children && cat.children.length > 0) {
|
602
|
+
const found = findCategoryById(cat.children, targetId);
|
603
|
+
if (found)
|
604
|
+
return found;
|
605
|
+
}
|
606
|
+
}
|
607
|
+
return null;
|
608
|
+
};
|
609
|
+
// 将单个分类ID转换为数组
|
610
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
611
|
+
// 收集所有指定分类下的产品ID
|
612
|
+
const allProductIds = [];
|
613
|
+
categoryIds.forEach(id => {
|
614
|
+
const targetCategory = findCategoryById(categories, id);
|
615
|
+
if (targetCategory) {
|
616
|
+
allProductIds.push(...targetCategory.productIds);
|
617
|
+
}
|
618
|
+
});
|
619
|
+
// 去重
|
620
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
621
|
+
if (uniqueProductIds.length === 0) {
|
622
|
+
return {
|
623
|
+
products: [],
|
624
|
+
total: 0,
|
625
|
+
page: options?.page || 1,
|
626
|
+
limit: options?.limit || 10
|
627
|
+
};
|
628
|
+
}
|
629
|
+
// 应用分页
|
630
|
+
const page = options?.page || 1;
|
631
|
+
const limit = options?.limit || 10;
|
632
|
+
const offset = (page - 1) * limit;
|
633
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
634
|
+
// 获取产品详情
|
635
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
636
|
+
// 应用状态过滤
|
637
|
+
let filteredProducts = products;
|
638
|
+
if (options?.status !== undefined) {
|
639
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
640
|
+
}
|
641
|
+
return {
|
642
|
+
products: filteredProducts,
|
643
|
+
total: uniqueProductIds.length,
|
644
|
+
page,
|
645
|
+
limit
|
646
|
+
};
|
647
|
+
}
|
453
648
|
/**
|
454
649
|
* 5. 根据标签ID获取产品列表
|
455
650
|
* 支持单个标签ID或标签ID数组
|
@@ -496,6 +691,96 @@ class ProductsAPI {
|
|
496
691
|
limit
|
497
692
|
};
|
498
693
|
}
|
694
|
+
/**
|
695
|
+
* 5.1. 根据标签ID获取平台产品列表
|
696
|
+
*/
|
697
|
+
async getProductsByTag_p(tagId, options) {
|
698
|
+
// 获取标签数据,传递productTagAlias参数
|
699
|
+
const tags = await this.getTags_p(options?.productTagAlias);
|
700
|
+
// 将单个标签ID转换为数组
|
701
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
702
|
+
// 收集所有指定标签下的产品ID
|
703
|
+
const allProductIds = [];
|
704
|
+
tagIds.forEach(id => {
|
705
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
706
|
+
if (targetTag) {
|
707
|
+
allProductIds.push(...targetTag.productIds);
|
708
|
+
}
|
709
|
+
});
|
710
|
+
// 去重
|
711
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
712
|
+
if (uniqueProductIds.length === 0) {
|
713
|
+
return {
|
714
|
+
products: [],
|
715
|
+
total: 0,
|
716
|
+
page: options?.page || 1,
|
717
|
+
limit: options?.limit || 10
|
718
|
+
};
|
719
|
+
}
|
720
|
+
// 应用分页
|
721
|
+
const page = options?.page || 1;
|
722
|
+
const limit = options?.limit || 10;
|
723
|
+
const offset = (page - 1) * limit;
|
724
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
725
|
+
// 获取产品详情
|
726
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
727
|
+
// 应用状态过滤
|
728
|
+
let filteredProducts = products;
|
729
|
+
if (options?.status !== undefined) {
|
730
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
731
|
+
}
|
732
|
+
return {
|
733
|
+
products: filteredProducts,
|
734
|
+
total: uniqueProductIds.length,
|
735
|
+
page,
|
736
|
+
limit
|
737
|
+
};
|
738
|
+
}
|
739
|
+
/**
|
740
|
+
* 5.2. 根据标签ID获取平台产品列表
|
741
|
+
*/
|
742
|
+
async getProductsByTag_t(tagId, options) {
|
743
|
+
// 获取标签数据,传递productTagAlias参数
|
744
|
+
const tags = await this.getTags(options?.productTagAlias);
|
745
|
+
// 将单个标签ID转换为数组
|
746
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
747
|
+
// 收集所有指定标签下的产品ID
|
748
|
+
const allProductIds = [];
|
749
|
+
tagIds.forEach(id => {
|
750
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
751
|
+
if (targetTag) {
|
752
|
+
allProductIds.push(...targetTag.productIds);
|
753
|
+
}
|
754
|
+
});
|
755
|
+
// 去重
|
756
|
+
const uniqueProductIds = [...new Set(allProductIds)];
|
757
|
+
if (uniqueProductIds.length === 0) {
|
758
|
+
return {
|
759
|
+
products: [],
|
760
|
+
total: 0,
|
761
|
+
page: options?.page || 1,
|
762
|
+
limit: options?.limit || 10
|
763
|
+
};
|
764
|
+
}
|
765
|
+
// 应用分页
|
766
|
+
const page = options?.page || 1;
|
767
|
+
const limit = options?.limit || 10;
|
768
|
+
const offset = (page - 1) * limit;
|
769
|
+
const paginatedProductIds = uniqueProductIds.slice(offset, offset + limit);
|
770
|
+
// 获取产品详情
|
771
|
+
const products = await Promise.all(paginatedProductIds.map(productId => this.getProduct_p(productId)));
|
772
|
+
// 应用状态过滤
|
773
|
+
let filteredProducts = products;
|
774
|
+
if (options?.status !== undefined) {
|
775
|
+
filteredProducts = products.filter(product => product.status === options.status);
|
776
|
+
}
|
777
|
+
return {
|
778
|
+
products: filteredProducts,
|
779
|
+
total: uniqueProductIds.length,
|
780
|
+
page,
|
781
|
+
limit
|
782
|
+
};
|
783
|
+
}
|
499
784
|
/**
|
500
785
|
* 6. 根据分类ID获取该分类的层级路径
|
501
786
|
* 用于前端面包屑导航
|
@@ -711,6 +996,16 @@ class SettingsAPI {
|
|
711
996
|
const response = await this.client.request(`/settings/platform-${config.platformId}-${alias}.json`);
|
712
997
|
return response.settings;
|
713
998
|
}
|
999
|
+
/**
|
1000
|
+
* 获取平台全局设置列表
|
1001
|
+
* 根据平台ID和别名获取所有全局设置
|
1002
|
+
*/
|
1003
|
+
async getSettings_p(settingAlias_p) {
|
1004
|
+
const config = this.client.getConfig();
|
1005
|
+
const alias = settingAlias_p || config.settingAlias_p || '01';
|
1006
|
+
const response = await this.client.request(`/settings/platform-${config.platformId_p}-${alias}.json`);
|
1007
|
+
return response.settings;
|
1008
|
+
}
|
714
1009
|
/**
|
715
1010
|
* 获取指定设置
|
716
1011
|
* 根据设置key直接获取单个设置
|
@@ -726,6 +1021,21 @@ class SettingsAPI {
|
|
726
1021
|
return null;
|
727
1022
|
}
|
728
1023
|
}
|
1024
|
+
/**
|
1025
|
+
* 获取平台用户指定设置
|
1026
|
+
* 根据设置key直接获取单个设置
|
1027
|
+
*/
|
1028
|
+
async getSetting_p(key) {
|
1029
|
+
const config = this.client.getConfig();
|
1030
|
+
try {
|
1031
|
+
const response = await this.client.request(`/settings/platform-${config.platformId_p}-${key}.json`);
|
1032
|
+
return response.setting;
|
1033
|
+
}
|
1034
|
+
catch (error) {
|
1035
|
+
console.warn(`Failed to fetch setting ${key}:`, error);
|
1036
|
+
return null;
|
1037
|
+
}
|
1038
|
+
}
|
729
1039
|
}
|
730
1040
|
|
731
1041
|
class FormsAPI {
|
@@ -2061,30 +2371,72 @@ class GT6SDK {
|
|
2061
2371
|
async getProduct(productId) {
|
2062
2372
|
return this.products.getProduct(productId);
|
2063
2373
|
}
|
2374
|
+
/**
|
2375
|
+
* 8.1. 便捷方法:根据产品ID获取父平台产品详情
|
2376
|
+
*/
|
2377
|
+
async getProduct_p(productId) {
|
2378
|
+
return this.products.getProduct_p(productId);
|
2379
|
+
}
|
2064
2380
|
/**
|
2065
2381
|
* 9. 便捷方法:获取产品分类列表
|
2066
2382
|
*/
|
2067
2383
|
async getProductCategories(productRootCategoryId) {
|
2068
2384
|
return this.products.getCategories(productRootCategoryId);
|
2069
2385
|
}
|
2386
|
+
/**
|
2387
|
+
* 9.1. 便捷方法:获取父平台产品分类列表
|
2388
|
+
*/
|
2389
|
+
async getProductCategories_p(productRootCategoryId_p) {
|
2390
|
+
return this.products.getCategories_p(productRootCategoryId_p);
|
2391
|
+
}
|
2070
2392
|
/**
|
2071
2393
|
* 10. 便捷方法:获取产品标签列表
|
2072
2394
|
*/
|
2073
2395
|
async getProductTags(productTagAlias) {
|
2074
2396
|
return this.products.getTags(productTagAlias);
|
2075
2397
|
}
|
2398
|
+
/**
|
2399
|
+
* 10.1. 便捷方法:获取父平台产品标签列表
|
2400
|
+
*/
|
2401
|
+
async getProductTags_p(productTagAlias_p) {
|
2402
|
+
return this.products.getTags_p(productTagAlias_p);
|
2403
|
+
}
|
2076
2404
|
/**
|
2077
2405
|
* 11. 便捷方法:根据分类ID获取产品列表
|
2078
2406
|
*/
|
2079
2407
|
async getProductsByCategory(categoryId, options) {
|
2080
2408
|
return this.products.getProductsByCategory(categoryId, options);
|
2081
2409
|
}
|
2410
|
+
/**
|
2411
|
+
* 11.1. 便捷方法:根据分类ID获取父平台产品列表
|
2412
|
+
*/
|
2413
|
+
async getProductsByCategory_p(categoryId, options) {
|
2414
|
+
return this.products.getProductsByCategory_p(categoryId, options);
|
2415
|
+
}
|
2416
|
+
/**
|
2417
|
+
* 11.2. 便捷方法:根据分类ID获取父平台产品列表(使用当前分类数据)
|
2418
|
+
*/
|
2419
|
+
async getProductsByCategory_t(categoryId, options) {
|
2420
|
+
return this.products.getProductsByCategory_t(categoryId, options);
|
2421
|
+
}
|
2082
2422
|
/**
|
2083
2423
|
* 12. 便捷方法:根据标签ID获取产品列表
|
2084
2424
|
*/
|
2085
2425
|
async getProductsByTag(tagId, options) {
|
2086
2426
|
return this.products.getProductsByTag(tagId, options);
|
2087
2427
|
}
|
2428
|
+
/**
|
2429
|
+
* 12.1. 便捷方法:根据标签ID获取父平台产品列表
|
2430
|
+
*/
|
2431
|
+
async getProductsByTag_p(tagId, options) {
|
2432
|
+
return this.products.getProductsByTag_p(tagId, options);
|
2433
|
+
}
|
2434
|
+
/**
|
2435
|
+
* 12.2. 便捷方法:根据标签ID获取父平台产品列表(使用当前标签数据)
|
2436
|
+
*/
|
2437
|
+
async getProductsByTag_t(tagId, options) {
|
2438
|
+
return this.products.getProductsByTag_t(tagId, options);
|
2439
|
+
}
|
2088
2440
|
/**
|
2089
2441
|
* 13. 便捷方法:根据分类ID获取该分类的层级路径
|
2090
2442
|
*/
|
@@ -2121,12 +2473,24 @@ class GT6SDK {
|
|
2121
2473
|
async getSettings(settingAlias) {
|
2122
2474
|
return this.settings.getSettings(settingAlias);
|
2123
2475
|
}
|
2476
|
+
/**
|
2477
|
+
* 18.1. 便捷方法:获取父平台全局设置列表
|
2478
|
+
*/
|
2479
|
+
async getSettings_p(settingAlias_p) {
|
2480
|
+
return this.settings.getSettings_p(settingAlias_p);
|
2481
|
+
}
|
2124
2482
|
/**
|
2125
2483
|
* 19. 便捷方法:获取指定设置
|
2126
2484
|
*/
|
2127
2485
|
async getSetting(key) {
|
2128
2486
|
return this.settings.getSetting(key);
|
2129
2487
|
}
|
2488
|
+
/**
|
2489
|
+
* 19.1. 便捷方法:获取父平台指定设置
|
2490
|
+
*/
|
2491
|
+
async getSetting_p(key) {
|
2492
|
+
return this.settings.getSetting_p(key);
|
2493
|
+
}
|
2130
2494
|
/**
|
2131
2495
|
* 20. 便捷方法:获取支付方式列表
|
2132
2496
|
*/
|