feat(jd-cookie): 支持批量创建Cookie失败详情返回

- 新增 KamiApiJdCookieV1BatchCreateResult 模型用于描述失败项
- 更新 KamiApiJdCookieV1BatchCreateRes 模型,增加 failedItems 字段
- 修改批量导入弹窗逻辑,支持显示详细的失败原因
- 优化批量创建结果的消息提示,区分成功、失败和部分成功情况
- 增加失败项索引和错误信息的控制台输出
- 更新相关文档和类型定义文件
This commit is contained in:
danial
2025-10-27 17:47:16 +08:00
parent 516b294874
commit 7d9094818c
7 changed files with 123 additions and 13 deletions

View File

@@ -226,6 +226,7 @@ docs/KamiApiJdCookieV1BatchCheckReq.md
docs/KamiApiJdCookieV1BatchCheckRes.md docs/KamiApiJdCookieV1BatchCheckRes.md
docs/KamiApiJdCookieV1BatchCreateReq.md docs/KamiApiJdCookieV1BatchCreateReq.md
docs/KamiApiJdCookieV1BatchCreateRes.md docs/KamiApiJdCookieV1BatchCreateRes.md
docs/KamiApiJdCookieV1BatchCreateResult.md
docs/KamiApiJdCookieV1CheckJdOrderPaymentReq.md docs/KamiApiJdCookieV1CheckJdOrderPaymentReq.md
docs/KamiApiJdCookieV1CheckJdOrderPaymentRes.md docs/KamiApiJdCookieV1CheckJdOrderPaymentRes.md
docs/KamiApiJdCookieV1CookieAccountInfo.md docs/KamiApiJdCookieV1CookieAccountInfo.md
@@ -607,6 +608,7 @@ models/kami-api-jd-cookie-v1-batch-check-req.ts
models/kami-api-jd-cookie-v1-batch-check-res.ts models/kami-api-jd-cookie-v1-batch-check-res.ts
models/kami-api-jd-cookie-v1-batch-create-req.ts models/kami-api-jd-cookie-v1-batch-create-req.ts
models/kami-api-jd-cookie-v1-batch-create-res.ts models/kami-api-jd-cookie-v1-batch-create-res.ts
models/kami-api-jd-cookie-v1-batch-create-result.ts
models/kami-api-jd-cookie-v1-check-jd-order-payment-req.ts models/kami-api-jd-cookie-v1-check-jd-order-payment-req.ts
models/kami-api-jd-cookie-v1-check-jd-order-payment-res.ts models/kami-api-jd-cookie-v1-check-jd-order-payment-res.ts
models/kami-api-jd-cookie-v1-cookie-account-info.ts models/kami-api-jd-cookie-v1-cookie-account-info.ts

View File

@@ -2,10 +2,11 @@
## Properties ## Properties
| Name | Type | Description | Notes | | Name | Type | Description | Notes |
| --------------- | ----------------------- | ----------------------- | --------------------------------- | | --------------- | -------------------------------------------------------------------------------------------- | ----------------------- | --------------------------------- |
| **successIds** | **Array<string>** | 成功创建的Cookie ID列表 | [optional] [default to undefined] | | **successIds** | **Array<string>** | 成功创建的Cookie ID列表 | [optional] [default to undefined] |
| **failedCount** | **number** | 失败数量 | [optional] [default to undefined] | | **failedCount** | **number** | 失败数量 | [optional] [default to undefined] |
| **failedItems** | [**Array<KamiApiJdCookieV1BatchCreateResult>**](KamiApiJdCookieV1BatchCreateResult.md) | 失败的Cookie详情 | [optional] [default to undefined] |
## Example ## Example
@@ -14,7 +15,8 @@ import { KamiApiJdCookieV1BatchCreateRes } from './api';
const instance: KamiApiJdCookieV1BatchCreateRes = { const instance: KamiApiJdCookieV1BatchCreateRes = {
successIds, successIds,
failedCount failedCount,
failedItems
}; };
``` ```

View File

@@ -0,0 +1,23 @@
# KamiApiJdCookieV1BatchCreateResult
## Properties
| Name | Type | Description | Notes |
| --------------- | ---------- | ----------------------- | --------------------------------- |
| **index** | **number** | 在请求中的索引(从0开始) | [optional] [default to undefined] |
| **accountName** | **string** | 账户名称 | [optional] [default to undefined] |
| **errorMsg** | **string** | 失败原因 | [optional] [default to undefined] |
## Example
```typescript
import { KamiApiJdCookieV1BatchCreateResult } from './api';
const instance: KamiApiJdCookieV1BatchCreateResult = {
index,
accountName,
errorMsg
};
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -211,6 +211,7 @@ export * from './kami-api-jd-cookie-v1-batch-check-req';
export * from './kami-api-jd-cookie-v1-batch-check-res'; export * from './kami-api-jd-cookie-v1-batch-check-res';
export * from './kami-api-jd-cookie-v1-batch-create-req'; export * from './kami-api-jd-cookie-v1-batch-create-req';
export * from './kami-api-jd-cookie-v1-batch-create-res'; export * from './kami-api-jd-cookie-v1-batch-create-res';
export * from './kami-api-jd-cookie-v1-batch-create-result';
export * from './kami-api-jd-cookie-v1-check-jd-order-payment-req'; export * from './kami-api-jd-cookie-v1-check-jd-order-payment-req';
export * from './kami-api-jd-cookie-v1-check-jd-order-payment-res'; export * from './kami-api-jd-cookie-v1-check-jd-order-payment-res';
export * from './kami-api-jd-cookie-v1-cookie-account-info'; export * from './kami-api-jd-cookie-v1-cookie-account-info';

View File

@@ -12,6 +12,10 @@
* Do not edit the class manually. * Do not edit the class manually.
*/ */
// May contain unused imports in some cases
// @ts-ignore
import type { KamiApiJdCookieV1BatchCreateResult } from './kami-api-jd-cookie-v1-batch-create-result';
export interface KamiApiJdCookieV1BatchCreateRes { export interface KamiApiJdCookieV1BatchCreateRes {
/** /**
* 成功创建的Cookie ID列表 * 成功创建的Cookie ID列表
@@ -21,4 +25,8 @@ export interface KamiApiJdCookieV1BatchCreateRes {
* 失败数量 * 失败数量
*/ */
failedCount?: number; failedCount?: number;
/**
* 失败的Cookie详情
*/
failedItems?: Array<KamiApiJdCookieV1BatchCreateResult>;
} }

View File

@@ -0,0 +1,28 @@
/* tslint:disable */
/**
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document:
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export interface KamiApiJdCookieV1BatchCreateResult {
/**
* 在请求中的索引(从0开始)
*/
index?: number;
/**
* 账户名称
*/
accountName?: string;
/**
* 失败原因
*/
errorMsg?: string;
}

View File

@@ -363,24 +363,70 @@ const handleSubmit = async (): Promise<boolean> => {
})); }));
// 调用批量创建API // 调用批量创建API
await jdCookieClient.apiJdCookieAccountBatchCreatePost({ const response = await jdCookieClient.apiJdCookieAccountBatchCreatePost({
kamiApiJdCookieV1BatchCreateReq: { kamiApiJdCookieV1BatchCreateReq: {
cookies: cookieAccounts cookies: cookieAccounts
} }
}); });
const invalidCount = parsedData.value.length - validCookies.length; // 处理新的返回结果结构
let successMessage = `成功添加 ${validCookies.length} 个Cookie`; const successCount = response.data.successIds?.length || 0;
if (invalidCount > 0) { const failedCount = response.data.failedCount || 0;
successMessage += `,跳过 ${invalidCount} 个无效数据`; const failedItems = response.data.failedItems || [];
// 构建详细的成功/失败消息
let message = '';
if (successCount > 0) {
message = `成功添加 ${successCount} 个Cookie`;
}
if (failedCount > 0) {
if (message) {
message += `${failedCount} 个添加失败`;
} else {
message = `${failedCount} 个Cookie添加失败`;
}
// 如果有具体的失败原因,显示详细信息
if (failedItems.length > 0) {
const errorDetails = failedItems
.map(item => {
const lineNumber = (item.index || 0) + 1;
const accountName = item.accountName || `账号${lineNumber}`;
const errorMsg = item.errorMsg || '未知错误';
return `${accountName}(第${lineNumber}行): ${errorMsg}`;
})
.join('\n');
// 显示错误详情弹窗
console.error('批量添加失败详情:', errorDetails);
// 可以考虑显示一个更友好的错误提示,这里先简单处理
message += `。失败原因请查看控制台`;
}
}
if (message) {
if (successCount > 0 && failedCount === 0) {
Message.success(message);
} else if (successCount === 0 && failedCount > 0) {
Message.error(message);
} else {
Message.warning(message);
}
}
// 只要有成功的就触发success事件
if (successCount > 0) {
emit('success');
} }
Message.success(successMessage);
emit('success');
handleCancel(); handleCancel();
return true; return true;
} catch (error) { } catch (error) {
Message.error('批量添加失败'); console.error('批量添加失败:', error);
Message.error('批量添加失败,请检查网络连接或联系管理员');
return false; return false;
} finally { } finally {
loading.value = false; loading.value = false;