@gt6/sdk 1.0.24 → 1.0.26
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 +3 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/gt6-sdk.cjs.js +265 -0
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +265 -0
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/articles.d.ts +52 -0
- package/dist/modules/articles.d.ts.map +1 -1
- package/dist/modules/products.d.ts +4 -0
- package/dist/modules/products.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gt6-sdk.esm.js
CHANGED
@@ -103,6 +103,12 @@ class ArticlesAPI {
|
|
103
103
|
async getArticle(articleId) {
|
104
104
|
return this.client.request(`/articles/${articleId}.json`);
|
105
105
|
}
|
106
|
+
/**
|
107
|
+
* 1.1 根据文章ID获取文章详情(使用上级平台ID)
|
108
|
+
*/
|
109
|
+
async getArticle_p(articleId) {
|
110
|
+
return this.client.request(`/parentarticles/${articleId}.json`);
|
111
|
+
}
|
106
112
|
/**
|
107
113
|
* 2. 获取文章分类列表
|
108
114
|
*/
|
@@ -112,6 +118,15 @@ class ArticlesAPI {
|
|
112
118
|
const response = await this.client.request(`/article-categories/platform-${config.platformId}-root-${categoryId}.json`);
|
113
119
|
return response.categories;
|
114
120
|
}
|
121
|
+
/**
|
122
|
+
* 2.1 获取文章分类列表(使用下级平台ID)
|
123
|
+
*/
|
124
|
+
async getCategories_p(rootCategoryId_p) {
|
125
|
+
const config = this.client.getConfig();
|
126
|
+
const categoryId = rootCategoryId_p || config.rootCategoryId_p || '671920';
|
127
|
+
const response = await this.client.request(`/article-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
|
128
|
+
return response.categories;
|
129
|
+
}
|
115
130
|
/**
|
116
131
|
* 3. 获取文章标签列表
|
117
132
|
*/
|
@@ -121,6 +136,15 @@ class ArticlesAPI {
|
|
121
136
|
const response = await this.client.request(`/article-tags/platform-${config.platformId}-${alias}.json`);
|
122
137
|
return response.tags;
|
123
138
|
}
|
139
|
+
/**
|
140
|
+
* 3.1 获取文章标签列表(使用下级平台ID)
|
141
|
+
*/
|
142
|
+
async getTags_p(tagAlias_p) {
|
143
|
+
const config = this.client.getConfig();
|
144
|
+
const alias = tagAlias_p || config.tagAlias_p || '001';
|
145
|
+
const response = await this.client.request(`/article-tags/platform-${config.platformId_p}-${alias}.json`);
|
146
|
+
return response.tags;
|
147
|
+
}
|
124
148
|
/**
|
125
149
|
* 4. 根据分类ID获取文章列表
|
126
150
|
* 支持单个分类ID或分类ID数组
|
@@ -167,6 +191,98 @@ class ArticlesAPI {
|
|
167
191
|
limit
|
168
192
|
};
|
169
193
|
}
|
194
|
+
/**
|
195
|
+
* 4.1 根据分类ID获取文章列表
|
196
|
+
* 支持单个分类ID或分类ID数组
|
197
|
+
*/
|
198
|
+
async getArticlesByCategory_p(categoryId, options) {
|
199
|
+
// 获取分类数据
|
200
|
+
const categories = await this.getCategories_p();
|
201
|
+
// 将单个分类ID转换为数组
|
202
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
203
|
+
// 收集所有指定分类下的文章ID
|
204
|
+
const allArticleIds = [];
|
205
|
+
categoryIds.forEach(id => {
|
206
|
+
const targetCategory = categories.find(cat => cat.categoryId === id);
|
207
|
+
if (targetCategory) {
|
208
|
+
allArticleIds.push(...targetCategory.articleIds);
|
209
|
+
}
|
210
|
+
});
|
211
|
+
// 去重
|
212
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
213
|
+
if (uniqueArticleIds.length === 0) {
|
214
|
+
return {
|
215
|
+
articles: [],
|
216
|
+
total: 0,
|
217
|
+
page: options?.page || 1,
|
218
|
+
limit: options?.limit || 10
|
219
|
+
};
|
220
|
+
}
|
221
|
+
// 应用分页
|
222
|
+
const page = options?.page || 1;
|
223
|
+
const limit = options?.limit || 10;
|
224
|
+
const offset = (page - 1) * limit;
|
225
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
226
|
+
// 获取文章详情
|
227
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
228
|
+
// 应用状态过滤
|
229
|
+
let filteredArticles = articles;
|
230
|
+
if (options?.status) {
|
231
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
232
|
+
}
|
233
|
+
return {
|
234
|
+
articles: filteredArticles,
|
235
|
+
total: uniqueArticleIds.length,
|
236
|
+
page,
|
237
|
+
limit
|
238
|
+
};
|
239
|
+
}
|
240
|
+
/**
|
241
|
+
* 4.2 根据分类ID获取文章列表
|
242
|
+
* 支持单个分类ID或分类ID数组
|
243
|
+
*/
|
244
|
+
async getArticlesByCategory_t(categoryId, options) {
|
245
|
+
// 获取分类数据
|
246
|
+
const categories = await this.getCategories();
|
247
|
+
// 将单个分类ID转换为数组
|
248
|
+
const categoryIds = Array.isArray(categoryId) ? categoryId : [categoryId];
|
249
|
+
// 收集所有指定分类下的文章ID
|
250
|
+
const allArticleIds = [];
|
251
|
+
categoryIds.forEach(id => {
|
252
|
+
const targetCategory = categories.find(cat => cat.categoryId === id);
|
253
|
+
if (targetCategory) {
|
254
|
+
allArticleIds.push(...targetCategory.articleIds);
|
255
|
+
}
|
256
|
+
});
|
257
|
+
// 去重
|
258
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
259
|
+
if (uniqueArticleIds.length === 0) {
|
260
|
+
return {
|
261
|
+
articles: [],
|
262
|
+
total: 0,
|
263
|
+
page: options?.page || 1,
|
264
|
+
limit: options?.limit || 10
|
265
|
+
};
|
266
|
+
}
|
267
|
+
// 应用分页
|
268
|
+
const page = options?.page || 1;
|
269
|
+
const limit = options?.limit || 10;
|
270
|
+
const offset = (page - 1) * limit;
|
271
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
272
|
+
// 获取文章详情
|
273
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
274
|
+
// 应用状态过滤
|
275
|
+
let filteredArticles = articles;
|
276
|
+
if (options?.status) {
|
277
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
278
|
+
}
|
279
|
+
return {
|
280
|
+
articles: filteredArticles,
|
281
|
+
total: uniqueArticleIds.length,
|
282
|
+
page,
|
283
|
+
limit
|
284
|
+
};
|
285
|
+
}
|
170
286
|
/**
|
171
287
|
* 5. 根据标签ID获取文章列表
|
172
288
|
* 支持单个标签ID或标签ID数组
|
@@ -213,6 +329,98 @@ class ArticlesAPI {
|
|
213
329
|
limit
|
214
330
|
};
|
215
331
|
}
|
332
|
+
/**
|
333
|
+
* 5.1 根据标签ID获取文章列表
|
334
|
+
* 支持单个标签ID或标签ID数组
|
335
|
+
*/
|
336
|
+
async getArticlesByTag_p(tagId, options) {
|
337
|
+
// 获取标签数据,传递tagAlias参数
|
338
|
+
const tags = await this.getTags_p(options?.tagAlias);
|
339
|
+
// 将单个标签ID转换为数组
|
340
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
341
|
+
// 收集所有指定标签下的文章ID
|
342
|
+
const allArticleIds = [];
|
343
|
+
tagIds.forEach(id => {
|
344
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
345
|
+
if (targetTag) {
|
346
|
+
allArticleIds.push(...targetTag.articleIds);
|
347
|
+
}
|
348
|
+
});
|
349
|
+
// 去重
|
350
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
351
|
+
if (uniqueArticleIds.length === 0) {
|
352
|
+
return {
|
353
|
+
articles: [],
|
354
|
+
total: 0,
|
355
|
+
page: options?.page || 1,
|
356
|
+
limit: options?.limit || 10
|
357
|
+
};
|
358
|
+
}
|
359
|
+
// 应用分页
|
360
|
+
const page = options?.page || 1;
|
361
|
+
const limit = options?.limit || 10;
|
362
|
+
const offset = (page - 1) * limit;
|
363
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
364
|
+
// 获取文章详情
|
365
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
366
|
+
// 应用状态过滤
|
367
|
+
let filteredArticles = articles;
|
368
|
+
if (options?.status) {
|
369
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
370
|
+
}
|
371
|
+
return {
|
372
|
+
articles: filteredArticles,
|
373
|
+
total: uniqueArticleIds.length,
|
374
|
+
page,
|
375
|
+
limit
|
376
|
+
};
|
377
|
+
}
|
378
|
+
/**
|
379
|
+
* 5.2 根据标签ID获取文章列表
|
380
|
+
* 支持单个标签ID或标签ID数组
|
381
|
+
*/
|
382
|
+
async getArticlesByTag_t(tagId, options) {
|
383
|
+
// 获取标签数据,传递tagAlias参数
|
384
|
+
const tags = await this.getTags(options?.tagAlias);
|
385
|
+
// 将单个标签ID转换为数组
|
386
|
+
const tagIds = Array.isArray(tagId) ? tagId : [tagId];
|
387
|
+
// 收集所有指定标签下的文章ID
|
388
|
+
const allArticleIds = [];
|
389
|
+
tagIds.forEach(id => {
|
390
|
+
const targetTag = tags.find(tag => tag.tagId === id);
|
391
|
+
if (targetTag) {
|
392
|
+
allArticleIds.push(...targetTag.articleIds);
|
393
|
+
}
|
394
|
+
});
|
395
|
+
// 去重
|
396
|
+
const uniqueArticleIds = [...new Set(allArticleIds)];
|
397
|
+
if (uniqueArticleIds.length === 0) {
|
398
|
+
return {
|
399
|
+
articles: [],
|
400
|
+
total: 0,
|
401
|
+
page: options?.page || 1,
|
402
|
+
limit: options?.limit || 10
|
403
|
+
};
|
404
|
+
}
|
405
|
+
// 应用分页
|
406
|
+
const page = options?.page || 1;
|
407
|
+
const limit = options?.limit || 10;
|
408
|
+
const offset = (page - 1) * limit;
|
409
|
+
const paginatedArticleIds = uniqueArticleIds.slice(offset, offset + limit);
|
410
|
+
// 获取文章详情
|
411
|
+
const articles = await Promise.all(paginatedArticleIds.map(articleId => this.getArticle_p(articleId)));
|
412
|
+
// 应用状态过滤
|
413
|
+
let filteredArticles = articles;
|
414
|
+
if (options?.status) {
|
415
|
+
filteredArticles = articles.filter(article => article.status === options.status);
|
416
|
+
}
|
417
|
+
return {
|
418
|
+
articles: filteredArticles,
|
419
|
+
total: uniqueArticleIds.length,
|
420
|
+
page,
|
421
|
+
limit
|
422
|
+
};
|
423
|
+
}
|
216
424
|
/**
|
217
425
|
* 6. 根据分类ID获取该分类的层级路径
|
218
426
|
* 用于前端面包屑导航
|
@@ -449,6 +657,15 @@ class ProductsAPI {
|
|
449
657
|
const response = await this.client.request(`/product-categories/platform-${config.platformId_p}-root-${categoryId}.json`);
|
450
658
|
return response.categories;
|
451
659
|
}
|
660
|
+
/**
|
661
|
+
* 2.2. 获取平台产品分类列表
|
662
|
+
*/
|
663
|
+
async getCategories_b(productRootCategoryId) {
|
664
|
+
const config = this.client.getConfig();
|
665
|
+
const categoryId = productRootCategoryId || config.productRootCategoryId;
|
666
|
+
const response = await this.client.request(`/big-product-categories/platform-${config.platformId}-root-${categoryId}.json`);
|
667
|
+
return response.categories;
|
668
|
+
}
|
452
669
|
/**
|
453
670
|
* 3. 获取产品标签列表
|
454
671
|
*/
|
@@ -2329,30 +2546,72 @@ class GT6SDK {
|
|
2329
2546
|
async getArticle(articleId) {
|
2330
2547
|
return this.articles.getArticle(articleId);
|
2331
2548
|
}
|
2549
|
+
/**
|
2550
|
+
* 1.1. 便捷方法:根据文章ID获取文章详情(使用上级平台ID)
|
2551
|
+
*/
|
2552
|
+
async getArticle_p(articleId) {
|
2553
|
+
return this.articles.getArticle_p(articleId);
|
2554
|
+
}
|
2332
2555
|
/**
|
2333
2556
|
* 2. 便捷方法:获取文章分类列表
|
2334
2557
|
*/
|
2335
2558
|
async getCategories(rootCategoryId) {
|
2336
2559
|
return this.articles.getCategories(rootCategoryId);
|
2337
2560
|
}
|
2561
|
+
/**
|
2562
|
+
* 2.1. 便捷方法:获取文章分类列表(使用下级平台ID)
|
2563
|
+
*/
|
2564
|
+
async getCategories_p(rootCategoryId_p) {
|
2565
|
+
return this.articles.getCategories_p(rootCategoryId_p);
|
2566
|
+
}
|
2338
2567
|
/**
|
2339
2568
|
* 3. 便捷方法:获取文章标签列表
|
2340
2569
|
*/
|
2341
2570
|
async getTags(tagAlias) {
|
2342
2571
|
return this.articles.getTags(tagAlias);
|
2343
2572
|
}
|
2573
|
+
/**
|
2574
|
+
* 3.1. 便捷方法:获取文章标签列表(使用下级平台ID)
|
2575
|
+
*/
|
2576
|
+
async getTags_p(tagAlias_p) {
|
2577
|
+
return this.articles.getTags_p(tagAlias_p);
|
2578
|
+
}
|
2344
2579
|
/**
|
2345
2580
|
* 4. 便捷方法:根据分类ID获取文章列表
|
2346
2581
|
*/
|
2347
2582
|
async getArticlesByCategory(categoryId, options) {
|
2348
2583
|
return this.articles.getArticlesByCategory(categoryId, options);
|
2349
2584
|
}
|
2585
|
+
/**
|
2586
|
+
* 4.1. 便捷方法:根据分类ID获取文章列表(使用下级平台ID)
|
2587
|
+
*/
|
2588
|
+
async getArticlesByCategory_p(categoryId, options) {
|
2589
|
+
return this.articles.getArticlesByCategory_p(categoryId, options);
|
2590
|
+
}
|
2591
|
+
/**
|
2592
|
+
* 4.2. 便捷方法:根据分类ID获取文章列表(使用当前分类数据)
|
2593
|
+
*/
|
2594
|
+
async getArticlesByCategory_t(categoryId, options) {
|
2595
|
+
return this.articles.getArticlesByCategory_t(categoryId, options);
|
2596
|
+
}
|
2350
2597
|
/**
|
2351
2598
|
* 5. 便捷方法:根据标签ID获取文章列表
|
2352
2599
|
*/
|
2353
2600
|
async getArticlesByTag(tagId, options) {
|
2354
2601
|
return this.articles.getArticlesByTag(tagId, options);
|
2355
2602
|
}
|
2603
|
+
/**
|
2604
|
+
* 5.1. 便捷方法:根据标签ID获取文章列表(使用下级平台ID)
|
2605
|
+
*/
|
2606
|
+
async getArticlesByTag_p(tagId, options) {
|
2607
|
+
return this.articles.getArticlesByTag_p(tagId, options);
|
2608
|
+
}
|
2609
|
+
/**
|
2610
|
+
* 5.2. 便捷方法:根据标签ID获取文章列表(使用当前标签数据)
|
2611
|
+
*/
|
2612
|
+
async getArticlesByTag_t(tagId, options) {
|
2613
|
+
return this.articles.getArticlesByTag_t(tagId, options);
|
2614
|
+
}
|
2356
2615
|
/**
|
2357
2616
|
* 6. 便捷方法:根据分类ID获取该分类的层级路径
|
2358
2617
|
*/
|
@@ -2377,6 +2636,12 @@ class GT6SDK {
|
|
2377
2636
|
async getProduct_p(productId) {
|
2378
2637
|
return this.products.getProduct_p(productId);
|
2379
2638
|
}
|
2639
|
+
/**
|
2640
|
+
* 8.2. 便捷方法:获取父平台产品分类列表
|
2641
|
+
*/
|
2642
|
+
async getCategories_b(rootCategoryId) {
|
2643
|
+
return this.products.getCategories_b(rootCategoryId);
|
2644
|
+
}
|
2380
2645
|
/**
|
2381
2646
|
* 9. 便捷方法:获取产品分类列表
|
2382
2647
|
*/
|