From 9bbb01fdee6703f4008ac73e627e928c3dcab439 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Tue, 20 Oct 2026 11:39:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8B=BC=E5=A4=9A=E5=A4=9A=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=A0=87=E9=A2=98=E6=8C=89=E6=B1=89=E5=AD=972/ASCII1?= =?UTF-8?q?=E5=90=88=E8=AE=A160=E5=AD=97=E7=AC=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/agent/agent/tools/publish_ui.py | 5 ++- apps/agent/application/system_prompt.py | 1 + .../model/dto/publish/PddGoodsPublishDTO.java | 1 + .../impl/PddGoodsPublishServiceImpl.java | 15 ++++++++ .../goods/publish/editor/PddPublishEditor.vue | 21 ++++++++++- .../editor/composables/use-publish-agent.ts | 5 +-- .../editor/composables/use-publish-draft.ts | 16 +++++++-- .../publish/editor/utils/pdd-title-length.ts | 36 +++++++++++++++++++ 8 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/utils/pdd-title-length.ts diff --git a/apps/agent/agent/tools/publish_ui.py b/apps/agent/agent/tools/publish_ui.py index 7a9a611b..4d82e320 100644 --- a/apps/agent/agent/tools/publish_ui.py +++ b/apps/agent/agent/tools/publish_ui.py @@ -15,7 +15,10 @@ from pydantic import BaseModel, Field class PatchBasicArgs(BaseModel): """只填要改的字段;未出现的字段保持页面原值。""" - goodsName: str | None = Field(default=None, description="商品标题,60 字内") + goodsName: str | None = Field( + default=None, + description="商品标题:汉字算 2、英文数字算 1,合计最多 60(约 30 汉字)", + ) goodsDesc: str | None = Field(default=None, description="商品描述;空字符串表示清空") marketPriceYuan: float | None = Field(default=None, description="参考价,元") twoPiecesDiscount: float | None = Field( diff --git a/apps/agent/application/system_prompt.py b/apps/agent/application/system_prompt.py index 56e46d2e..f2637d6b 100644 --- a/apps/agent/application/system_prompt.py +++ b/apps/agent/application/system_prompt.py @@ -36,6 +36,7 @@ _PUBLISH_SYSTEM = ( "假一赔十/7天无理由/预售/二手、运费模板)、ui_set_spec_axes(规格轴)、" "ui_patch_skus(按 outSkuSn 改单买价、拼单价、库存、重量)、ui_patch_props(类目属性)。" "每次只传要改的字段,未传的保持原样。" + "商品标题字数:汉字算 2、英文数字算 1,合计最多 60(约 30 汉字);生成或改写标题时自行压缩到上限内,不要写超再指望页面截断。" "运费模板 ID 必须来自快照 costTemplates;发货时限只能用快照里的秒数;" "类目属性枚举用 goodsProperties 里的 vid 或文案,多选英文逗号分隔。" "不能改店铺、叶子类目、轮播图、详情图、SKU 缩略图;用户要求这些时用一句话说明对话里改不了。" diff --git a/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java b/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java index 9a51ae60..13033988 100644 --- a/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java +++ b/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java @@ -24,6 +24,7 @@ public class PddGoodsPublishDTO { */ private Long systemDraftId; + /** 拼多多标题:汉字算 2、ASCII 算 1,合计不超过 60(约 30 汉字) */ @NotBlank(message = "商品标题不能为空") private String goodsName; diff --git a/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java b/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java index c09e08c9..b445329c 100644 --- a/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java +++ b/apps/server/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java @@ -436,6 +436,10 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { if (strict && !StringUtils.hasText(goodsName)) { throw new BusinessException("商品标题不能为空"); } + // 拼多多:汉字算 2、ASCII 算 1,合计不超过 60(约 30 汉字) + if (strict && goodsName != null && pddTitleCharUnits(goodsName) > 60) { + throw new BusinessException("商品标题超长(汉字约30个/60字符)"); + } return new PddGoodsPublishPopApiClient.GoodsAddCommand( goodsName, @@ -517,6 +521,17 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { return imageTransfer.transfer(companyId, ctx.mallId(), ctx.accessToken(), fileId); } + /** 拼多多标题字符单位:code point ≤ 0xFF 算 1,否则算 2。 */ + private static int pddTitleCharUnits(String text) { + int n = 0; + for (int i = 0; i < text.length(); ) { + int cp = text.codePointAt(i); + n += cp <= 0xff ? 1 : 2; + i += Character.charCount(cp); + } + return n; + } + private static boolean looksLikeUrl(String s) { String lower = s.toLowerCase(); return lower.startsWith("http://") || lower.startsWith("https://"); diff --git a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue index a887cb8f..08c489fd 100644 --- a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue +++ b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue @@ -50,6 +50,11 @@ import { usePublishDraft } from './composables/use-publish-draft'; import { usePublishImages } from './composables/use-publish-images'; import { usePublishSku } from './composables/use-publish-sku'; import { usePublishSpecs } from './composables/use-publish-specs'; +import { + PDD_GOODS_NAME_MAX_UNITS, + pddTitleCharUnits, + truncatePddTitle, +} from './utils/pdd-title-length'; defineOptions({ name: 'PddPublishEditor' }); @@ -363,6 +368,15 @@ function onSpecAxesListRef(el: HTMLElement | null) { function onSkuTableWrapRef(el: HTMLElement | null) { sku.skuTableWrapRef.value = el; } + +/** 标题:汉字算 2、ASCII 算 1,上限 60 */ +function onGoodsNameChange(value: string) { + form.goodsName = truncatePddTitle(value); +} + +function goodsNameCountFormatter(info: { value: string }) { + return `${pddTitleCharUnits(info.value)} / ${PDD_GOODS_NAME_MAX_UNITS}`; +}