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 @@
+
+
+
+
+
+
+
+
+
{{ charCount }}/{{ PRE_SCRIPT_MAX_LENGTH }}
+
+
+
+
+
+
+
+
+
diff --git a/src/views/channel/serviceChannels/index.vue b/src/views/channel/serviceChannels/index.vue
index e2bd899..60c421b 100644
--- a/src/views/channel/serviceChannels/index.vue
+++ b/src/views/channel/serviceChannels/index.vue
@@ -318,12 +318,12 @@
@@ -1394,20 +1394,13 @@
}}
-
-
-
- {{ t('channel.serviceChannels.form.preScript') }}
-
-
-
-
-
-
+
@@ -1602,6 +1595,7 @@ import { getWarehouseList } from '@/api/system/warehouse'
import CustomLeftMenu from '@/components/CustomLeftMenu/index.vue'
import type { CustomLeftMenuTreeNode } from '@/components/CustomLeftMenu/types'
import BillingConditionEditor from '@/views/channel/salesProducts/components/BillingConditionEditor.vue'
+import PreScriptEditor from '@/views/channel/serviceChannels/components/PreScriptEditor.vue'
import { ENABLE_STATUS, isEnableStatusEnabled, toEnableStatus } from '@/utils/enableStatus'
import { pickResolvedAudit } from '@/utils/auditFields'
diff --git a/src/views/channel/serviceChannels/preScriptAiSkill.ts b/src/views/channel/serviceChannels/preScriptAiSkill.ts
new file mode 100644
index 0000000..913de0a
--- /dev/null
+++ b/src/views/channel/serviceChannels/preScriptAiSkill.ts
@@ -0,0 +1,65 @@
+import { appendPreScriptFieldCatalog } from './preScriptMeta'
+
+const SKILL_CORE = `你是 OMS「服务渠道预报前执行脚本」助手。根据用户中文描述,生成可粘贴到渠道 PreScript 的中文赋值脚本(ChineseAssignScriptEvaluator)。
+
+## 场景
+
+- 预报推送给下游之前,改写下单相关字段(拼地址、拼品名 SKU、微调长宽高等)
+- 只影响本次预报报文,不回写订单库
+- 字段范围对齐「单票下单」录入项;不要使用状态/问题件/计费重/体积重等无关字段
+- 不要生成接口通 Natasha C#,不要生成自动触发布尔公式
+
+## 产出格式(必须)
+
+脚本:
+一行或多行赋值语句
+说明:一句话
+
+## 语法硬规则
+
+- 每条语句:可写字段 = 表达式
+- 可写:收/发件人与申报字符串(申报首行);件重尺仅 长度/宽度/高度/实重
+- 右侧可引用目录中的字段(订单基本信息多为只读)、单引号字符串、数字、+ - * / ()
+- 字符串拼接用 +;多语句换行或分号;# 为注释
+- 禁止 == != && ||、包含()、有值()、为空()、双引号、英文字段名
+- 禁止写:计费重、体积重、体积、件重尺类型、HS编码(用进口/出口HS编码)、发件人是否默认
+- 总长度 ≤ 10000
+
+## 示例
+
+脚本:
+收件人地址1 = 收件人地址1 + ' ' + 收件人地址2
+收件人地址2 = ''
+说明:把地址2拼进地址1并清空地址2
+
+脚本:
+英文品名 = 中文品名 + ' ' + SKU
+说明:预报时英文品名拼上 SKU(申报首行)
+
+脚本:
+长度 = 长度 + 1
+说明:预报时长边加 1cm
+`
+
+export const PRE_SCRIPT_AI_DEFAULT_SKILL_KEY = 'oms-service-channel-pre-script'
+export const PRE_SCRIPT_AI_SCENE = 'serviceChannelPreScript'
+export const PRE_SCRIPT_AI_CHAT_SCENE = 'service_channel_pre_script'
+export const PRE_SCRIPT_AI_STORAGE_KEY = 'oms.serviceChannel.preScriptAi'
+
+export function buildPreScriptAiSystemPrompt(): string {
+ return appendPreScriptFieldCatalog(SKILL_CORE)
+}
+
+export function buildPreScriptAiShortSystemPrompt(): string {
+ return (
+ '你是 OMS 预报前脚本助手。只输出「脚本:」下的赋值语句;' +
+ "字段对齐下单页;可写如收件人地址1、英文品名、长度/实重;勿写计费重/状态字段。"
+ )
+}
+
+export const PRE_SCRIPT_AI_QUICK_PROMPTS = [
+ '把收件人地址2拼到地址1后面,中间空格,并清空地址2',
+ '把省州、城市拼到收件人地址1前面',
+ '英文品名拼上 SKU',
+ '长度加 1',
+]
diff --git a/src/views/channel/serviceChannels/preScriptMeta.ts b/src/views/channel/serviceChannels/preScriptMeta.ts
new file mode 100644
index 0000000..d830fee
--- /dev/null
+++ b/src/views/channel/serviceChannels/preScriptMeta.ts
@@ -0,0 +1,248 @@
+import {
+ FORMULA_MAX_LENGTH,
+ ORDER_TABLE_CATEGORIES,
+ ORDER_TABLE_FIELDS,
+ type OrderTableFieldDef,
+} from '@/views/channel/autoTrigger/formulaMeta'
+
+/**
+ * 对齐单票下单页(placeOrder)录入/回填字段:
+ * 剔除状态/问题件/理赔/下游凭证、系统计算件重尺、通用 HS编码、发件人是否默认等。
+ * table.field → 是否出现在脚本字段面板(RHS 可引用)。
+ */
+const PLACE_ORDER_FIELD_KEYS = new Set([
+ // 订单基本(下单「基本信息」+ H5 COD/跟踪号)
+ 't_order.ClientNo',
+ 't_order.TrackNo',
+ 't_order.ServiceNo',
+ 't_order.ProductCode',
+ 't_order.ConsigneeCountry',
+ 't_order.ConsigneeCountryName',
+ 't_order.CargoAttribute',
+ 't_order.ExportCustomsMode',
+ 't_order.WarehouseId',
+ 't_order.CustomerId',
+ 't_order.IsCod',
+ 't_order.CodCurrency',
+ 't_order.CodSum',
+ 't_order.DeclaredCurrency',
+ 't_order.DeclaredSum',
+ 't_order.Quantity',
+ 't_order.AdditionalServices',
+
+ // 收件人
+ 't_order_recipient.RecipientsName',
+ 't_order_recipient.CompanyName',
+ 't_order_recipient.Phone',
+ 't_order_recipient.TelePhone',
+ 't_order_recipient.Email',
+ 't_order_recipient.ZipCode',
+ 't_order_recipient.Province',
+ 't_order_recipient.City',
+ 't_order_recipient.StreetNumber',
+ 't_order_recipient.StreetAddress1',
+ 't_order_recipient.StreetAddress2',
+ 't_order_recipient.StreetAddress3',
+ 't_order_recipient.TaxNo',
+ 't_order_recipient.CertificateNo',
+ 't_order_recipient.Eori',
+ 't_order_recipient.Vat',
+
+ // 发件人(地址簿回填;不含 IsDefault)
+ 't_order_sender.SenderName',
+ 't_order_sender.Company',
+ 't_order_sender.Province',
+ 't_order_sender.City',
+ 't_order_sender.ZipCode',
+ 't_order_sender.StreetAddress1',
+ 't_order_sender.StreetAddress2',
+ 't_order_sender.StreetAddress3',
+ 't_order_sender.HouseNumber',
+ 't_order_sender.Phone',
+ 't_order_sender.TelePhone',
+ 't_order_sender.Email',
+
+ // 申报(不含通用 HsCode;金额/总重派生仍可引用)
+ 't_order_declaration.CnName',
+ 't_order_declaration.EnName',
+ 't_order_declaration.Sku',
+ 't_order_declaration.Unit',
+ 't_order_declaration.UnitPrice',
+ 't_order_declaration.UnitWeight',
+ 't_order_declaration.Quantity',
+ 't_order_declaration.Amount',
+ 't_order_declaration.Weight',
+ 't_order_declaration.ImHsCode',
+ 't_order_declaration.ExHsCode',
+ 't_order_declaration.DeclareElement',
+ 't_order_declaration.ProductId',
+ 't_order_declaration.NonStdProductId',
+ 't_order_declaration.StdProductId',
+ 't_order_declaration.Category',
+ 't_order_declaration.Brand',
+ 't_order_declaration.BrandType',
+ 't_order_declaration.Distribution',
+ 't_order_declaration.Material',
+ 't_order_declaration.EnMaterial',
+ 't_order_declaration.Purpose',
+ 't_order_declaration.Attributes',
+ 't_order_declaration.OriginCountry',
+ 't_order_declaration.SalesLink',
+ 't_order_declaration.Model',
+ 't_order_declaration.Specifications',
+ 't_order_declaration.Comment',
+
+ // 件重尺:下单只填实重+长宽高
+ 't_order_weight.Length',
+ 't_order_weight.Width',
+ 't_order_weight.Height',
+ 't_order_weight.ActualWeight',
+])
+
+/** 可写字段(LHS):收/发件人与申报字符串 + 件重尺四数值 */
+const WRITABLE_FIELD_KEYS = new Set([
+ 't_order_recipient.RecipientsName',
+ 't_order_recipient.CompanyName',
+ 't_order_recipient.Phone',
+ 't_order_recipient.TelePhone',
+ 't_order_recipient.Email',
+ 't_order_recipient.ZipCode',
+ 't_order_recipient.Province',
+ 't_order_recipient.City',
+ 't_order_recipient.StreetNumber',
+ 't_order_recipient.StreetAddress1',
+ 't_order_recipient.StreetAddress2',
+ 't_order_recipient.StreetAddress3',
+ 't_order_recipient.TaxNo',
+ 't_order_recipient.CertificateNo',
+ 't_order_recipient.Eori',
+ 't_order_recipient.Vat',
+
+ 't_order_sender.SenderName',
+ 't_order_sender.Company',
+ 't_order_sender.Province',
+ 't_order_sender.City',
+ 't_order_sender.ZipCode',
+ 't_order_sender.StreetAddress1',
+ 't_order_sender.StreetAddress2',
+ 't_order_sender.StreetAddress3',
+ 't_order_sender.HouseNumber',
+ 't_order_sender.Phone',
+ 't_order_sender.TelePhone',
+ 't_order_sender.Email',
+
+ 't_order_declaration.CnName',
+ 't_order_declaration.EnName',
+ 't_order_declaration.Sku',
+ 't_order_declaration.Unit',
+ 't_order_declaration.ImHsCode',
+ 't_order_declaration.ExHsCode',
+ 't_order_declaration.DeclareElement',
+ 't_order_declaration.ProductId',
+ 't_order_declaration.NonStdProductId',
+ 't_order_declaration.StdProductId',
+ 't_order_declaration.Category',
+ 't_order_declaration.Brand',
+ 't_order_declaration.BrandType',
+ 't_order_declaration.Distribution',
+ 't_order_declaration.Material',
+ 't_order_declaration.EnMaterial',
+ 't_order_declaration.Purpose',
+ 't_order_declaration.Attributes',
+ 't_order_declaration.OriginCountry',
+ 't_order_declaration.SalesLink',
+ 't_order_declaration.Model',
+ 't_order_declaration.Specifications',
+ 't_order_declaration.Comment',
+
+ 't_order_weight.Length',
+ 't_order_weight.Width',
+ 't_order_weight.Height',
+ 't_order_weight.ActualWeight',
+])
+
+function fieldKey(f: Pick) {
+ return `${f.table}.${f.field}`
+}
+
+export const PRE_SCRIPT_VISIBLE_FIELDS: OrderTableFieldDef[] = ORDER_TABLE_FIELDS.filter((f) =>
+ PLACE_ORDER_FIELD_KEYS.has(fieldKey(f)),
+)
+
+export const PRE_SCRIPT_WRITABLE_FIELDS: OrderTableFieldDef[] = PRE_SCRIPT_VISIBLE_FIELDS.filter((f) =>
+ WRITABLE_FIELD_KEYS.has(fieldKey(f)),
+)
+
+export const PRE_SCRIPT_WRITABLE_LABELS = new Set(
+ PRE_SCRIPT_WRITABLE_FIELDS.map((f) => f.label),
+)
+
+/** 插入字段分类(与下单步骤对齐) */
+export const PRE_SCRIPT_CATEGORIES = ORDER_TABLE_CATEGORIES.filter((c) =>
+ [
+ 't_order',
+ 't_order_recipient',
+ 't_order_sender',
+ 't_order_declaration',
+ 't_order_weight',
+ ].includes(c.key),
+)
+
+export const PRE_SCRIPT_OPERATORS = [
+ { label: '=', insert: ' = ' },
+ { label: '+', insert: ' + ' },
+ { label: '-', insert: ' - ' },
+ { label: '×', insert: ' * ' },
+ { label: '÷', insert: ' / ' },
+ { label: "''", insert: "''" },
+ { label: '(', insert: '(' },
+ { label: ')', insert: ')' },
+ { label: ';', insert: ';\n' },
+]
+
+export const PRE_SCRIPT_MAX_LENGTH = FORMULA_MAX_LENGTH
+
+function fieldUsageHint(f: OrderTableFieldDef): string {
+ const writable = WRITABLE_FIELD_KEYS.has(fieldKey(f))
+ if (writable && f.valueType === 'string') {
+ return `${f.label}(可写)|右侧引用直接写中文名`
+ }
+ if (writable && f.valueType === 'number') {
+ return `${f.label}(可写数值)|如 ${f.label} = ${f.label} + 1`
+ }
+ return `${f.label}(只读引用)`
+}
+
+/** 拼进 AI system:仅下单相关字段 */
+export function appendPreScriptFieldCatalog(core: string): string {
+ const byTable = new Map()
+ for (const f of PRE_SCRIPT_VISIBLE_FIELDS) {
+ const list = byTable.get(f.table) ?? []
+ list.push(f)
+ byTable.set(f.table, list)
+ }
+ const lines: string[] = ['## 可用字段目录(仅下单相关;勿编造未列出的中文名)', '']
+ for (const [table, fields] of byTable) {
+ lines.push(`### ${table}`)
+ for (const f of fields) {
+ lines.push(`- ${f.label} (${f.valueType}) → ${fieldUsageHint(f)}`)
+ }
+ lines.push('')
+ }
+ return `${core.trim()}\n\n${lines.join('\n').trim()}`
+}
+
+export function preScriptChipsByTable(tableKey: string) {
+ return PRE_SCRIPT_VISIBLE_FIELDS.filter((f) => f.table === tableKey).map((f) => {
+ const writable = WRITABLE_FIELD_KEYS.has(fieldKey(f))
+ return {
+ label: f.label,
+ table: f.table,
+ insert: f.label,
+ refHint: writable
+ ? `${f.table}.${f.field}(可写)`
+ : `${f.table}.${f.field}(只读引用)`,
+ writable,
+ }
+ })
+}