From 29d7cbb2262dea609b910ce509c6ac25a7c72b3e Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Tue, 24 Nov 2026 15:10:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=A0=E9=81=93=E9=A2=84=E6=8A=A5?= =?UTF-8?q?=E5=89=8D=E4=B8=8E=E9=94=80=E5=94=AE=E4=BA=A7=E5=93=81=E8=90=BD?= =?UTF-8?q?=E5=BA=93=E5=89=8D=E8=84=9A=E6=9C=AC=E6=8E=A5=E5=85=A5=20AI=20?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对齐下单字段白名单,复用中文赋值 DSL 与 AI 写脚本抽屉,方便改写地址/申报/件重尺。 Co-authored-by: Cursor --- src/locale/en-US.ts | 24 +- src/locale/zh-CN.ts | 24 +- .../components/FormulaAiAssistDrawer.vue | 5 +- .../channel/autoTrigger/formulaAiSkill.ts | 49 +- src/views/channel/salesProducts/index.vue | 54 ++- .../salesProducts/preStorageScriptAiSkill.ts | 64 +++ .../components/PreScriptEditor.vue | 440 ++++++++++++++++++ src/views/channel/serviceChannels/index.vue | 28 +- .../serviceChannels/preScriptAiSkill.ts | 65 +++ .../channel/serviceChannels/preScriptMeta.ts | 248 ++++++++++ 10 files changed, 950 insertions(+), 51 deletions(-) create mode 100644 src/views/channel/salesProducts/preStorageScriptAiSkill.ts create mode 100644 src/views/channel/serviceChannels/components/PreScriptEditor.vue create mode 100644 src/views/channel/serviceChannels/preScriptAiSkill.ts create mode 100644 src/views/channel/serviceChannels/preScriptMeta.ts diff --git a/src/locale/en-US.ts b/src/locale/en-US.ts index c192203..7abe5db 100644 --- a/src/locale/en-US.ts +++ b/src/locale/en-US.ts @@ -6460,7 +6460,12 @@ export default { 'channel.salesProducts.placeholder.productCode': 'Uppercase, digits, - only', 'channel.salesProducts.placeholder.productName': 'Enter product name', 'channel.salesProducts.placeholder.productDescription': 'Customer-facing description (optional)', - 'channel.salesProducts.placeholder.preStorageScript': 'Script before order persistence (optional)', + 'channel.salesProducts.placeholder.preStorageScript': + "e.g. 收件人地址1 = 收件人地址1 + ' ' + 收件人地址2", + 'channel.salesProducts.preStorageScript.hint': + 'Chinese assign: field = expr; changes are persisted on the order', + 'channel.salesProducts.preStorageScript.fieldHint': + 'Aligned with place-order fields; writable: addresses/declaration strings and L/W/H/actual weight', 'channel.salesProducts.tip.productCode': 'Rule: region/country code + 01 line/02 express/03 postal/04 packet + other.\nExample: US04-5DAY\nUppercase letters, digits, and - only; can be changed later via the edit action', 'channel.salesProducts.form.editProductCode': 'Edit', @@ -6474,7 +6479,8 @@ export default { 'channel.salesProducts.tip.group': 'Used for website/admin grouping, e.g. express parcel', 'channel.salesProducts.tip.efficiency': 'Estimated transit days shown to customers', 'channel.salesProducts.tip.labelTemplate': 'System label template used when printing', - 'channel.salesProducts.tip.preStorageScript': 'Advanced: rewrite/validate order fields before save; leave empty if unused', + 'channel.salesProducts.tip.preStorageScript': + 'Rewrite recipient/sender fields before order persist (saved to DB); Chinese assign DSL; AI assisted', 'channel.salesProducts.form.placeholder.labelTemplate': 'Select label template (global default if empty)', 'channel.salesProducts.form.blacklistArea': 'Blacklist area', 'channel.salesProducts.form.remoteAreaDivision': 'Remote area division', @@ -6652,7 +6658,16 @@ export default { 'Weight rule for payable chargeable weight (independent of sales-product receivable weight)', 'channel.serviceChannels.tip.weightRounding': 'Weight rounding for payable chargeable weight (independent of sales-product receivable rounding)', - 'channel.serviceChannels.tip.preScript': 'Script to rewrite/validate fields before forecast; leave empty if unused', + 'channel.serviceChannels.tip.preScript': + 'Rewrite recipient/sender fields before downstream forecast (payload only, does not persist order); Chinese assign DSL; AI assisted', + 'channel.serviceChannels.preScript.aiWrite': 'AI write script', + 'channel.serviceChannels.preScript.insertField': 'Insert field', + 'channel.serviceChannels.preScript.operators': 'Operators', + 'channel.serviceChannels.preScript.fields': 'Fields', + 'channel.serviceChannels.preScript.fieldHint': + 'Aligned with place-order fields; writable: addresses/declaration strings and L/W/H/actual weight', + 'channel.serviceChannels.preScript.hint': + 'Chinese assign: field = expr; multi-line OK; affects forecast payload only', 'channel.serviceChannels.form.placeholder.input': 'Please enter', 'channel.serviceChannels.form.placeholder.select': 'Please select', 'channel.serviceChannels.form.placeholder.min': 'Min', @@ -6660,7 +6675,8 @@ export default { 'channel.serviceChannels.form.placeholder.selectForecastType': 'Please select forecast number type', 'channel.serviceChannels.form.placeholder.forecastCode': 'Enter forecast channel code', 'channel.serviceChannels.form.placeholder.description': 'Enter channel description', - 'channel.serviceChannels.form.placeholder.preScript': 'Enter pre-forecast script', + 'channel.serviceChannels.form.placeholder.preScript': + "e.g. 收件人地址1 = 收件人地址1 + ' ' + 收件人地址2", 'channel.serviceChannels.price.effectiveVersion': 'Effective version: {version}', 'channel.serviceChannels.price.table.serialNo': 'No.', 'channel.serviceChannels.price.table.status': 'Status', diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index c971556..de6211a 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -6466,7 +6466,12 @@ export default { 'channel.salesProducts.placeholder.productCode': '仅大写字母、数字、-', 'channel.salesProducts.placeholder.productName': '请输入产品名称', 'channel.salesProducts.placeholder.productDescription': '面向客户的产品说明(选填)', - 'channel.salesProducts.placeholder.preStorageScript': '订单落库前执行的脚本(选填)', + 'channel.salesProducts.placeholder.preStorageScript': + "例:收件人地址1 = 收件人地址1 + ' ' + 收件人地址2", + 'channel.salesProducts.preStorageScript.hint': + '中文赋值:字段 = 表达式;改写会写入订单', + 'channel.salesProducts.preStorageScript.fieldHint': + '字段对齐下单页;可写收/发件、申报字符串与长宽高/实重;其它为只读引用', 'channel.salesProducts.tip.productCode': '命名规则:地区/国家代码 + 01专线/02快递/03邮政/04小包 + 其他。\n示例:US04-5DAY\n仅支持大写字母、数字和 -;创建后可通过修改入口单独改代码', 'channel.salesProducts.form.editProductCode': '修改', @@ -6480,7 +6485,8 @@ export default { 'channel.salesProducts.tip.group': '用于官网/后台分组展示,如专线小包', 'channel.salesProducts.tip.efficiency': '预计时效区间(天),展示给客户参考', 'channel.salesProducts.tip.labelTemplate': '下单打印使用的系统面单模板', - 'channel.salesProducts.tip.preStorageScript': '高级能力:落库前改写/校验订单字段,无脚本可留空', + 'channel.salesProducts.tip.preStorageScript': + '下单落库前改写收/发件人字段并写入订单;中文赋值语法,可用 AI 生成', 'channel.salesProducts.form.blacklistArea': '黑名单区', 'channel.salesProducts.form.remoteAreaDivision': '偏远分区', 'channel.salesProducts.form.priceArea': '价格分区', @@ -6655,7 +6661,16 @@ export default { 'channel.serviceChannels.tip.blacklistArea': '收件地址命中该分区时跳过本渠道排货(与销售产品黑名单独立)', 'channel.serviceChannels.tip.weightRule': '应付计费重所用计重规则(与销售产品应收计重独立)', 'channel.serviceChannels.tip.weightRounding': '应付计费重所用计重进位(与销售产品应收进位独立)', - 'channel.serviceChannels.tip.preScript': '预报前改写/校验字段的脚本,无需求可留空', + 'channel.serviceChannels.tip.preScript': + '预报推下游前改写收/发件人字段(仅影响本次报文,不回写订单);中文赋值语法,可用 AI 生成', + 'channel.serviceChannels.preScript.aiWrite': 'AI 写脚本', + 'channel.serviceChannels.preScript.insertField': '插入字段', + 'channel.serviceChannels.preScript.operators': '运算符', + 'channel.serviceChannels.preScript.fields': '字段', + 'channel.serviceChannels.preScript.fieldHint': + '字段对齐下单页;可写收/发件、申报字符串与长宽高/实重;其它为只读引用', + 'channel.serviceChannels.preScript.hint': + '中文赋值:字段 = 表达式;多行换行;只改预报报文', 'channel.serviceChannels.form.placeholder.input': '请输入', 'channel.serviceChannels.form.placeholder.select': '请选择', 'channel.serviceChannels.form.placeholder.min': '最小值', @@ -6663,7 +6678,8 @@ export default { 'channel.serviceChannels.form.placeholder.selectForecastType': '请选择预报单号类型', 'channel.serviceChannels.form.placeholder.forecastCode': '请输入预报渠道code', 'channel.serviceChannels.form.placeholder.description': '请输入渠道说明', - 'channel.serviceChannels.form.placeholder.preScript': '请输入预报前执行脚本', + 'channel.serviceChannels.form.placeholder.preScript': + "例:收件人地址1 = 收件人地址1 + ' ' + 收件人地址2", 'channel.serviceChannels.price.effectiveVersion': '生效版本: {version}', 'channel.serviceChannels.price.table.serialNo': '序号', 'channel.serviceChannels.price.table.status': '状态', diff --git a/src/views/channel/autoTrigger/components/FormulaAiAssistDrawer.vue b/src/views/channel/autoTrigger/components/FormulaAiAssistDrawer.vue index 93b4f0d..90399d6 100644 --- a/src/views/channel/autoTrigger/components/FormulaAiAssistDrawer.vue +++ b/src/views/channel/autoTrigger/components/FormulaAiAssistDrawer.vue @@ -188,6 +188,8 @@ const props = defineProps<{ shortSystemPrompt?: string /** 用户消息末尾输出格式提示 */ outputHint?: string + /** 自定义字段目录拼接(如预报/落库脚本仅下单字段) */ + appendCatalog?: (core: string) => string }>() const resolvedStorageKey = computed(() => props.storageKey || DEFAULT_STORAGE_KEY) @@ -354,6 +356,7 @@ async function loadSkills() { } function resolveSystemPrompt(): string { + const appendCatalog = props.appendCatalog || appendFormulaFieldCatalog if (!sendSkill.value) { return ( props.shortSystemPrompt || @@ -362,7 +365,7 @@ function resolveSystemPrompt(): string { } const fromList = skills.value.find((s) => s.skillKey === skillKey.value) const content = String(fromList?.content || '').trim() - if (content) return appendFormulaFieldCatalog(content) + if (content) return appendCatalog(content) if (props.fallbackSystemPrompt?.trim()) return props.fallbackSystemPrompt.trim() return buildFormulaAiSystemPrompt() } diff --git a/src/views/channel/autoTrigger/formulaAiSkill.ts b/src/views/channel/autoTrigger/formulaAiSkill.ts index 97f2d06..b397a0d 100644 --- a/src/views/channel/autoTrigger/formulaAiSkill.ts +++ b/src/views/channel/autoTrigger/formulaAiSkill.ts @@ -104,6 +104,16 @@ export function appendFormulaFieldCatalog(core: string): string { export const FORMULA_AI_DEFAULT_SKILL_KEY = 'oms-auto-trigger-formula' +function isAssignLine(line: string): boolean { + const i = line.indexOf('=') + if (i <= 0) return false + const prev = line[i - 1] + const next = line[i + 1] + if (prev === '!' || prev === '<' || prev === '>' || prev === '=') return false + if (next === '=') return false + return true +} + /** 从 AI 回复中解析公式块 */ export function parseAiFormulaReply(raw: string): ParsedAiFormula { const text = String(raw || '').trim() @@ -120,28 +130,47 @@ export function parseAiFormulaReply(raw: string): ParsedAiFormula { text.match(/验证样例[::]\s*(.+?)(?:\n|$)/)?.[1]?.trim() ?? undefined - let expression = - text.match(/公式[::]\s*(.+?)(?:\n|$)/)?.[1]?.trim() ?? - '' + // 预报前脚本:支持「脚本:」后多行赋值 + let expression = '' + const scriptBlock = text.match(/脚本[::]\s*\n?([\s\S]*?)(?=\n\s*说明[::]|$)/) + if (scriptBlock?.[1]?.trim()) { + expression = scriptBlock[1].trim() + } if (!expression) { - // 尝试取 fenced code 或首行像公式的内容 + expression = text.match(/公式[::]\s*(.+?)(?:\n|$)/)?.[1]?.trim() ?? '' + } + + if (!expression) { + // 尝试取 fenced code 或首行像公式/赋值的内容 const fence = text.match(/```(?:\w*)?\s*\n?([\s\S]*?)```/) if (fence?.[1]) { const inner = fence[1].trim() expression = + inner.match(/脚本[::]\s*\n?([\s\S]*)/)?.[1]?.trim() || inner.match(/公式[::]\s*(.+?)(?:\n|$)/)?.[1]?.trim() || - inner.split('\n').find((l) => /包含\(|\(\)|&&|\|\|/.test(l))?.trim() || + inner + .split('\n') + .filter((l) => /包含\(|\(\)|&&|\|\|/.test(l) || isAssignLine(l)) + .join('\n') + .trim() || '' } } if (!expression) { - const candidate = text - .split('\n') - .map((l) => l.trim()) - .find((l) => /包含\(|\(\)|&&|\|\|/.test(l) && !/^(时机|操作|说明|验证)/.test(l)) - expression = candidate || '' + const lines = text.split('\n').map((l) => l.trim()) + const assignLines = lines.filter( + (l) => isAssignLine(l) && !/^(时机|操作|说明|验证|脚本|公式)/.test(l), + ) + if (assignLines.length) { + expression = assignLines.join('\n') + } else { + const candidate = lines.find( + (l) => /包含\(|\(\)|&&|\|\|/.test(l) && !/^(时机|操作|说明|验证)/.test(l), + ) + expression = candidate || '' + } } // 去掉可能的围栏残片 diff --git a/src/views/channel/salesProducts/index.vue b/src/views/channel/salesProducts/index.vue index ca236f5..96489b2 100644 --- a/src/views/channel/salesProducts/index.vue +++ b/src/views/channel/salesProducts/index.vue @@ -58,6 +58,16 @@ import { IconPlus, IconDelete, IconSearch, IconEdit, IconDragArrow, IconQuestionCircleFill, IconQuestionCircle, IconSync } from '@arco-design/web-vue/es/icon'; import FormLabelWithPreview from './components/FormLabelWithPreview.vue'; import BillingConditionEditor from './components/BillingConditionEditor.vue'; + import PreScriptEditor from '@/views/channel/serviceChannels/components/PreScriptEditor.vue'; + import { + PRE_STORAGE_SCRIPT_AI_CHAT_SCENE, + PRE_STORAGE_SCRIPT_AI_DEFAULT_SKILL_KEY, + PRE_STORAGE_SCRIPT_AI_QUICK_PROMPTS, + PRE_STORAGE_SCRIPT_AI_SCENE, + PRE_STORAGE_SCRIPT_AI_STORAGE_KEY, + buildPreStorageScriptAiShortSystemPrompt, + buildPreStorageScriptAiSystemPrompt, + } from './preStorageScriptAiSkill'; import ChannelReferencePreviewModal, { type ReferencePreviewType, } from './components/ChannelReferencePreviewModal.vue'; @@ -107,6 +117,8 @@ const { t } = useI18n(); const userStore = useUserStore(); const rbacUserStore = useRbacUserStore(); + const preStorageFallbackPrompt = buildPreStorageScriptAiSystemPrompt(); + const preStorageShortPrompt = buildPreStorageScriptAiShortSystemPrompt(); function getPricePublishOperatorName(): string { return ( @@ -5576,12 +5588,21 @@
- -
@@ -6320,18 +6341,21 @@
- -
diff --git a/src/views/channel/salesProducts/preStorageScriptAiSkill.ts b/src/views/channel/salesProducts/preStorageScriptAiSkill.ts new file mode 100644 index 0000000..cad177a --- /dev/null +++ b/src/views/channel/salesProducts/preStorageScriptAiSkill.ts @@ -0,0 +1,64 @@ +import { appendPreScriptFieldCatalog } from '@/views/channel/serviceChannels/preScriptMeta' + +const SKILL_CORE = `你是 OMS「销售产品落库前执行脚本」助手。根据用户中文描述,生成可粘贴到销售产品 PreStorageScript 的中文赋值脚本(ChineseAssignScriptEvaluator)。 + +## 场景 + +- 订单创建落库之前,改写下单相关字段(拼地址、拼品名 SKU、微调长宽高等) +- 改写结果会写入订单库(与渠道预报前脚本不同:预报前只改报文不落库) +- 字段范围对齐「单票下单」录入项;不要使用状态/问题件/计费重/体积重等无关字段 +- 不要生成接口通 Natasha C#,不要生成自动触发布尔公式 + +## 产出格式(必须) + +脚本: +一行或多行赋值语句 +说明:一句话 + +## 语法硬规则 + +- 每条语句:可写字段 = 表达式 +- 可写:收/发件人与申报字符串(申报首行);件重尺仅 长度/宽度/高度/实重 +- 右侧可引用目录中的字段(订单基本信息多为只读)、单引号字符串、数字、+ - * / () +- 字符串拼接用 +;多语句换行或分号;# 为注释 +- 禁止 == != && ||、包含()、有值()、为空()、双引号、英文字段名 +- 禁止写:计费重、体积重、体积、件重尺类型、HS编码(用进口/出口HS编码)、发件人是否默认 +- 总长度 ≤ 10000 + +## 示例 + +脚本: +收件人地址1 = 收件人地址1 + ' ' + 收件人地址2 +收件人地址2 = '' +说明:落库前把地址2拼进地址1并清空地址2 + +脚本: +英文品名 = 中文品名 + ' ' + SKU +说明:落库前英文品名拼上 SKU(申报首行) + +脚本: +长度 = 长度 + 1 +说明:落库前长边加 1cm +` + +export const PRE_STORAGE_SCRIPT_AI_DEFAULT_SKILL_KEY = 'oms-sales-product-pre-storage-script' +export const PRE_STORAGE_SCRIPT_AI_SCENE = 'salesProductPreStorageScript' +export const PRE_STORAGE_SCRIPT_AI_CHAT_SCENE = 'sales_product_pre_storage_script' +export const PRE_STORAGE_SCRIPT_AI_STORAGE_KEY = 'oms.salesProduct.preStorageScriptAi' + +export function buildPreStorageScriptAiSystemPrompt(): string { + return appendPreScriptFieldCatalog(SKILL_CORE) +} + +export function buildPreStorageScriptAiShortSystemPrompt(): string { + return ( + '你是 OMS 落库前脚本助手。只输出「脚本:」下的赋值语句;' + + '字段对齐下单页;改写会写入订单;勿写计费重/状态字段。' + ) +} + +export const PRE_STORAGE_SCRIPT_AI_QUICK_PROMPTS = [ + '把收件人地址2拼到地址1后面,中间空格,并清空地址2', + '英文品名拼上 SKU', + '长度加 1', +] diff --git a/src/views/channel/serviceChannels/components/PreScriptEditor.vue b/src/views/channel/serviceChannels/components/PreScriptEditor.vue new file mode 100644 index 0000000..f00ad9a --- /dev/null +++ b/src/views/channel/serviceChannels/components/PreScriptEditor.vue @@ -0,0 +1,440 @@ + + +