feat(jd-cookie): 支持批量创建Cookie失败详情返回
- 新增 KamiApiJdCookieV1BatchCreateResult 模型用于描述失败项 - 更新 KamiApiJdCookieV1BatchCreateRes 模型,增加 failedItems 字段 - 修改批量导入弹窗逻辑,支持显示详细的失败原因 - 优化批量创建结果的消息提示,区分成功、失败和部分成功情况 - 增加失败项索引和错误信息的控制台输出 - 更新相关文档和类型定义文件
This commit is contained in:
@@ -226,6 +226,7 @@ docs/KamiApiJdCookieV1BatchCheckReq.md
|
||||
docs/KamiApiJdCookieV1BatchCheckRes.md
|
||||
docs/KamiApiJdCookieV1BatchCreateReq.md
|
||||
docs/KamiApiJdCookieV1BatchCreateRes.md
|
||||
docs/KamiApiJdCookieV1BatchCreateResult.md
|
||||
docs/KamiApiJdCookieV1CheckJdOrderPaymentReq.md
|
||||
docs/KamiApiJdCookieV1CheckJdOrderPaymentRes.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-create-req.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-res.ts
|
||||
models/kami-api-jd-cookie-v1-cookie-account-info.ts
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
| --------------- | ----------------------- | ----------------------- | --------------------------------- |
|
||||
| **successIds** | **Array<string>** | 成功创建的Cookie ID列表 | [optional] [default to undefined] |
|
||||
| **failedCount** | **number** | 失败数量 | [optional] [default to undefined] |
|
||||
| Name | Type | Description | Notes |
|
||||
| --------------- | -------------------------------------------------------------------------------------------- | ----------------------- | --------------------------------- |
|
||||
| **successIds** | **Array<string>** | 成功创建的Cookie ID列表 | [optional] [default to undefined] |
|
||||
| **failedCount** | **number** | 失败数量 | [optional] [default to undefined] |
|
||||
| **failedItems** | [**Array<KamiApiJdCookieV1BatchCreateResult>**](KamiApiJdCookieV1BatchCreateResult.md) | 失败的Cookie详情 | [optional] [default to undefined] |
|
||||
|
||||
## Example
|
||||
|
||||
@@ -14,7 +15,8 @@ import { KamiApiJdCookieV1BatchCreateRes } from './api';
|
||||
|
||||
const instance: KamiApiJdCookieV1BatchCreateRes = {
|
||||
successIds,
|
||||
failedCount
|
||||
failedCount,
|
||||
failedItems
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
23
src/api/generated/docs/KamiApiJdCookieV1BatchCreateResult.md
Normal file
23
src/api/generated/docs/KamiApiJdCookieV1BatchCreateResult.md
Normal 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)
|
||||
@@ -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-create-req';
|
||||
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-res';
|
||||
export * from './kami-api-jd-cookie-v1-cookie-account-info';
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
* 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 {
|
||||
/**
|
||||
* 成功创建的Cookie ID列表
|
||||
@@ -21,4 +25,8 @@ export interface KamiApiJdCookieV1BatchCreateRes {
|
||||
* 失败数量
|
||||
*/
|
||||
failedCount?: number;
|
||||
/**
|
||||
* 失败的Cookie详情
|
||||
*/
|
||||
failedItems?: Array<KamiApiJdCookieV1BatchCreateResult>;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -363,24 +363,70 @@ const handleSubmit = async (): Promise<boolean> => {
|
||||
}));
|
||||
|
||||
// 调用批量创建API
|
||||
await jdCookieClient.apiJdCookieAccountBatchCreatePost({
|
||||
const response = await jdCookieClient.apiJdCookieAccountBatchCreatePost({
|
||||
kamiApiJdCookieV1BatchCreateReq: {
|
||||
cookies: cookieAccounts
|
||||
}
|
||||
});
|
||||
|
||||
const invalidCount = parsedData.value.length - validCookies.length;
|
||||
let successMessage = `成功添加 ${validCookies.length} 个Cookie`;
|
||||
if (invalidCount > 0) {
|
||||
successMessage += `,跳过 ${invalidCount} 个无效数据`;
|
||||
// 处理新的返回结果结构
|
||||
const successCount = response.data.successIds?.length || 0;
|
||||
const failedCount = response.data.failedCount || 0;
|
||||
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();
|
||||
return true;
|
||||
} catch (error) {
|
||||
Message.error('批量添加失败');
|
||||
console.error('批量添加失败:', error);
|
||||
Message.error('批量添加失败,请检查网络连接或联系管理员');
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user