feat: 渠道预报前与销售产品落库前脚本接入 AI 赋值编辑
对齐下单字段白名单,复用中文赋值 DSL 与 AI 写脚本抽屉,方便改写地址/申报/件重尺。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3e7d895253
commit
29d7cbb226
@ -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',
|
||||
|
||||
@ -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': '状态',
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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 || ''
|
||||
}
|
||||
}
|
||||
|
||||
// 去掉可能的围栏残片
|
||||
|
||||
@ -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 @@
|
||||
<!-- 第五行 -->
|
||||
<div class="form-row">
|
||||
<div class="form-item full-width">
|
||||
<label class="form-label">{{ t('channel.salesProducts.form.preStorageScript') }}</label>
|
||||
<a-textarea
|
||||
<PreScriptEditor
|
||||
v-model="formData.preStorageScript"
|
||||
:placeholder="t('channel.salesProducts.form.placeholder.input')"
|
||||
:rows="4"
|
||||
class="form-textarea"
|
||||
:label="t('channel.salesProducts.form.preStorageScript')"
|
||||
:label-tip="t('channel.salesProducts.tip.preStorageScript')"
|
||||
:placeholder="t('channel.salesProducts.placeholder.preStorageScript')"
|
||||
:rows="5"
|
||||
:skill-scene="PRE_STORAGE_SCRIPT_AI_SCENE"
|
||||
:default-skill-key="PRE_STORAGE_SCRIPT_AI_DEFAULT_SKILL_KEY"
|
||||
:storage-key="PRE_STORAGE_SCRIPT_AI_STORAGE_KEY"
|
||||
:chat-scene="PRE_STORAGE_SCRIPT_AI_CHAT_SCENE"
|
||||
:quick-prompts="PRE_STORAGE_SCRIPT_AI_QUICK_PROMPTS"
|
||||
:fallback-system-prompt="preStorageFallbackPrompt"
|
||||
:short-system-prompt="preStorageShortPrompt"
|
||||
:hint-text="t('channel.salesProducts.preStorageScript.hint')"
|
||||
:field-hint-text="t('channel.salesProducts.preStorageScript.fieldHint')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -6320,18 +6341,21 @@
|
||||
</div>
|
||||
<div v-if="addProductShowAdvanced" class="form-row">
|
||||
<div class="form-item full-width">
|
||||
<label class="form-label label-with-tip">
|
||||
{{ t('channel.salesProducts.form.preStorageScript') }}
|
||||
<a-tooltip :content="t('channel.salesProducts.tip.preStorageScript')">
|
||||
<icon-question-circle class="tip-icon" />
|
||||
</a-tooltip>
|
||||
</label>
|
||||
<a-textarea
|
||||
<PreScriptEditor
|
||||
v-model="addProductFormData.preStorageScript"
|
||||
:label="t('channel.salesProducts.form.preStorageScript')"
|
||||
:label-tip="t('channel.salesProducts.tip.preStorageScript')"
|
||||
:placeholder="t('channel.salesProducts.placeholder.preStorageScript')"
|
||||
:auto-size="{ minRows: 3, maxRows: 8 }"
|
||||
class="form-textarea"
|
||||
allow-clear
|
||||
:rows="4"
|
||||
:skill-scene="PRE_STORAGE_SCRIPT_AI_SCENE"
|
||||
:default-skill-key="PRE_STORAGE_SCRIPT_AI_DEFAULT_SKILL_KEY"
|
||||
:storage-key="PRE_STORAGE_SCRIPT_AI_STORAGE_KEY"
|
||||
:chat-scene="PRE_STORAGE_SCRIPT_AI_CHAT_SCENE"
|
||||
:quick-prompts="PRE_STORAGE_SCRIPT_AI_QUICK_PROMPTS"
|
||||
:fallback-system-prompt="preStorageFallbackPrompt"
|
||||
:short-system-prompt="preStorageShortPrompt"
|
||||
:hint-text="t('channel.salesProducts.preStorageScript.hint')"
|
||||
:field-hint-text="t('channel.salesProducts.preStorageScript.fieldHint')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
64
src/views/channel/salesProducts/preStorageScriptAiSkill.ts
Normal file
64
src/views/channel/salesProducts/preStorageScriptAiSkill.ts
Normal file
@ -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',
|
||||
]
|
||||
440
src/views/channel/serviceChannels/components/PreScriptEditor.vue
Normal file
440
src/views/channel/serviceChannels/components/PreScriptEditor.vue
Normal file
@ -0,0 +1,440 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 服务渠道「预报前执行脚本」编辑器:
|
||||
* AI 写脚本 + 字段/运算符插入(中文赋值 DSL)。
|
||||
*/
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { IconQuestionCircle } from '@arco-design/web-vue/es/icon'
|
||||
import FormulaAiAssistDrawer from '@/views/channel/autoTrigger/components/FormulaAiAssistDrawer.vue'
|
||||
import {
|
||||
PRE_SCRIPT_AI_CHAT_SCENE,
|
||||
PRE_SCRIPT_AI_DEFAULT_SKILL_KEY,
|
||||
PRE_SCRIPT_AI_QUICK_PROMPTS,
|
||||
PRE_SCRIPT_AI_SCENE,
|
||||
PRE_SCRIPT_AI_STORAGE_KEY,
|
||||
buildPreScriptAiShortSystemPrompt,
|
||||
buildPreScriptAiSystemPrompt,
|
||||
} from '../preScriptAiSkill'
|
||||
import {
|
||||
PRE_SCRIPT_CATEGORIES,
|
||||
PRE_SCRIPT_MAX_LENGTH,
|
||||
PRE_SCRIPT_OPERATORS,
|
||||
appendPreScriptFieldCatalog,
|
||||
preScriptChipsByTable,
|
||||
} from '../preScriptMeta'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: string
|
||||
label?: string
|
||||
labelTip?: string
|
||||
placeholder?: string
|
||||
rows?: number
|
||||
/** 覆盖默认渠道预报前 AI 配置(落库前等场景传入) */
|
||||
skillScene?: string
|
||||
defaultSkillKey?: string
|
||||
storageKey?: string
|
||||
chatScene?: string
|
||||
quickPrompts?: string[]
|
||||
fallbackSystemPrompt?: string
|
||||
shortSystemPrompt?: string
|
||||
outputHint?: string
|
||||
hintText?: string
|
||||
fieldHintText?: string
|
||||
}>(),
|
||||
{
|
||||
label: '',
|
||||
labelTip: '',
|
||||
placeholder: '',
|
||||
rows: 4,
|
||||
skillScene: '',
|
||||
defaultSkillKey: '',
|
||||
storageKey: '',
|
||||
chatScene: '',
|
||||
quickPrompts: undefined,
|
||||
fallbackSystemPrompt: '',
|
||||
shortSystemPrompt: '',
|
||||
outputHint: '',
|
||||
hintText: '',
|
||||
fieldHintText: '',
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [string]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const textareaRef = ref<HTMLTextAreaElement | null>(null)
|
||||
const aiVisible = ref(false)
|
||||
const fieldPopoverVisible = ref(false)
|
||||
const activeCategory = ref('t_order_recipient')
|
||||
|
||||
const resolvedFallbackPrompt = computed(
|
||||
() => props.fallbackSystemPrompt || buildPreScriptAiSystemPrompt(),
|
||||
)
|
||||
const resolvedShortPrompt = computed(
|
||||
() => props.shortSystemPrompt || buildPreScriptAiShortSystemPrompt(),
|
||||
)
|
||||
const resolvedOutputHint = computed(
|
||||
() =>
|
||||
props.outputHint ||
|
||||
'请按 skill 规定的格式输出(脚本/说明)。多行赋值请放在「脚本:」后。',
|
||||
)
|
||||
const resolvedSkillScene = computed(() => props.skillScene || PRE_SCRIPT_AI_SCENE)
|
||||
const resolvedSkillKey = computed(
|
||||
() => props.defaultSkillKey || PRE_SCRIPT_AI_DEFAULT_SKILL_KEY,
|
||||
)
|
||||
const resolvedStorageKey = computed(() => props.storageKey || PRE_SCRIPT_AI_STORAGE_KEY)
|
||||
const resolvedChatScene = computed(() => props.chatScene || PRE_SCRIPT_AI_CHAT_SCENE)
|
||||
const resolvedQuickPrompts = computed(() =>
|
||||
props.quickPrompts?.length ? props.quickPrompts : PRE_SCRIPT_AI_QUICK_PROMPTS,
|
||||
)
|
||||
const resolvedHint = computed(
|
||||
() => props.hintText || t('channel.serviceChannels.preScript.hint'),
|
||||
)
|
||||
const resolvedFieldHint = computed(
|
||||
() => props.fieldHintText || t('channel.serviceChannels.preScript.fieldHint'),
|
||||
)
|
||||
|
||||
const charCount = computed(() => (props.modelValue || '').length)
|
||||
const activeChips = computed(() => preScriptChipsByTable(activeCategory.value))
|
||||
const toolbarInline = computed(() => !!props.label)
|
||||
|
||||
function updateValue(next: string) {
|
||||
emit('update:modelValue', next.slice(0, PRE_SCRIPT_MAX_LENGTH))
|
||||
}
|
||||
|
||||
function onInput(e: Event) {
|
||||
updateValue((e.target as HTMLTextAreaElement).value)
|
||||
}
|
||||
|
||||
function onAiApply(payload: { expression: string }) {
|
||||
updateValue((payload.expression || '').slice(0, PRE_SCRIPT_MAX_LENGTH))
|
||||
}
|
||||
|
||||
async function insertAtCursor(text: string) {
|
||||
const current = props.modelValue || ''
|
||||
const el = textareaRef.value
|
||||
if (!el) {
|
||||
updateValue((current + text).slice(0, PRE_SCRIPT_MAX_LENGTH))
|
||||
return
|
||||
}
|
||||
const start = el.selectionStart ?? current.length
|
||||
const end = el.selectionEnd ?? start
|
||||
const next = (current.slice(0, start) + text + current.slice(end)).slice(0, PRE_SCRIPT_MAX_LENGTH)
|
||||
updateValue(next)
|
||||
await nextTick()
|
||||
const pos = Math.min(start + text.length, next.length)
|
||||
el.focus()
|
||||
el.setSelectionRange(pos, pos)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
if ((val || '').length > PRE_SCRIPT_MAX_LENGTH) {
|
||||
updateValue((val || '').slice(0, PRE_SCRIPT_MAX_LENGTH))
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pre-script-editor" :class="{ 'has-inline-toolbar': toolbarInline }">
|
||||
<div v-if="toolbarInline" class="editor-label">
|
||||
{{ label }}
|
||||
<a-tooltip v-if="labelTip" :content="labelTip">
|
||||
<icon-question-circle class="tip-icon" />
|
||||
</a-tooltip>
|
||||
</div>
|
||||
|
||||
<div class="formula-text-wrap">
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
class="formula-textarea"
|
||||
:value="modelValue || ''"
|
||||
:rows="rows"
|
||||
:maxlength="PRE_SCRIPT_MAX_LENGTH"
|
||||
:placeholder="placeholder || t('channel.serviceChannels.form.placeholder.preScript')"
|
||||
@input="onInput"
|
||||
/>
|
||||
<div class="char-count">{{ charCount }}/{{ PRE_SCRIPT_MAX_LENGTH }}</div>
|
||||
</div>
|
||||
|
||||
<div class="editor-footer" :class="{ 'editor-footer--inline': toolbarInline }">
|
||||
<div class="editor-actions">
|
||||
<a-button
|
||||
type="secondary"
|
||||
:size="toolbarInline ? 'mini' : 'small'"
|
||||
@click="aiVisible = true"
|
||||
>
|
||||
{{ t('channel.serviceChannels.preScript.aiWrite') }}
|
||||
</a-button>
|
||||
<a-popover
|
||||
v-model:popup-visible="fieldPopoverVisible"
|
||||
trigger="click"
|
||||
position="bl"
|
||||
:content-style="{ padding: '16px', width: '520px', maxWidth: '92vw' }"
|
||||
>
|
||||
<a-button type="secondary" :size="toolbarInline ? 'mini' : 'small'">
|
||||
{{ t('channel.serviceChannels.preScript.insertField') }}
|
||||
</a-button>
|
||||
<template #content>
|
||||
<div class="field-popover">
|
||||
<div class="section-label">{{ t('channel.serviceChannels.preScript.operators') }}</div>
|
||||
<div class="chip-bar">
|
||||
<button
|
||||
v-for="op in PRE_SCRIPT_OPERATORS"
|
||||
:key="op.label"
|
||||
type="button"
|
||||
class="chip-btn"
|
||||
@click="insertAtCursor(op.insert)"
|
||||
>
|
||||
{{ op.label }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="section-label">{{ t('channel.serviceChannels.preScript.fields') }}</div>
|
||||
<div class="category-tabs">
|
||||
<button
|
||||
v-for="cat in PRE_SCRIPT_CATEGORIES"
|
||||
:key="cat.key"
|
||||
type="button"
|
||||
class="category-tab"
|
||||
:class="{ active: activeCategory === cat.key }"
|
||||
@click="activeCategory = cat.key"
|
||||
>
|
||||
{{ cat.label }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="field-hint">{{ resolvedFieldHint }}</p>
|
||||
<div class="chip-bar field-chips">
|
||||
<button
|
||||
v-for="(chip, idx) in activeChips"
|
||||
:key="`${chip.table}-${chip.label}-${idx}`"
|
||||
type="button"
|
||||
class="chip-btn"
|
||||
:class="{ writable: chip.writable }"
|
||||
:title="`${chip.refHint}${chip.writable ? '(可写)' : '(只读引用)'}`"
|
||||
@click="insertAtCursor(chip.insert)"
|
||||
>
|
||||
{{ chip.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</a-popover>
|
||||
</div>
|
||||
<span class="editor-hint">{{ resolvedHint }}</span>
|
||||
</div>
|
||||
|
||||
<FormulaAiAssistDrawer
|
||||
v-model:visible="aiVisible"
|
||||
:current-formula="modelValue || ''"
|
||||
:skill-scene="resolvedSkillScene"
|
||||
:default-skill-key="resolvedSkillKey"
|
||||
:storage-key="resolvedStorageKey"
|
||||
:chat-scene="resolvedChatScene"
|
||||
:quick-prompts="resolvedQuickPrompts"
|
||||
:fallback-system-prompt="resolvedFallbackPrompt"
|
||||
:short-system-prompt="resolvedShortPrompt"
|
||||
:output-hint="resolvedOutputHint"
|
||||
:append-catalog="appendPreScriptFieldCatalog"
|
||||
@apply="onAiApply"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.pre-script-editor {
|
||||
width: 100%;
|
||||
|
||||
&.has-inline-toolbar {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
grid-template-areas:
|
||||
'label footer'
|
||||
'text text';
|
||||
column-gap: 12px;
|
||||
row-gap: 6px;
|
||||
align-items: center;
|
||||
|
||||
.editor-label {
|
||||
grid-area: label;
|
||||
}
|
||||
|
||||
.editor-footer {
|
||||
grid-area: footer;
|
||||
margin-top: 0;
|
||||
justify-content: flex-end;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.formula-text-wrap {
|
||||
grid-area: text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.editor-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 14px;
|
||||
color: var(--color-text-2);
|
||||
white-space: nowrap;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.tip-icon {
|
||||
color: var(--color-text-3);
|
||||
cursor: help;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.formula-text-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.formula-textarea {
|
||||
width: 100%;
|
||||
min-height: 96px;
|
||||
max-height: 240px;
|
||||
resize: vertical;
|
||||
box-sizing: border-box;
|
||||
padding: 8px 12px 24px;
|
||||
border: 1px solid var(--color-border-2);
|
||||
border-radius: 4px;
|
||||
font-family: var(--app-font-mono);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--color-text-1);
|
||||
background: var(--app-card-bg);
|
||||
outline: none;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--color-border-3);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
border-color: var(--app-primary-color, #2d8c8c);
|
||||
box-shadow: 0 0 0 2px rgba(45, 140, 140, 0.12);
|
||||
}
|
||||
}
|
||||
|
||||
.char-count {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
bottom: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--color-text-3);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.editor-footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
margin-top: 6px;
|
||||
|
||||
&--inline {
|
||||
flex-wrap: nowrap;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-actions {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.editor-hint {
|
||||
font-size: 12px;
|
||||
color: var(--color-text-3);
|
||||
line-height: 1.4;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.field-popover {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
max-height: 480px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.section-label {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-2);
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--color-text-3);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.chip-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.field-chips {
|
||||
max-height: 280px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.chip-btn {
|
||||
height: 30px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid var(--color-border-2);
|
||||
border-radius: 4px;
|
||||
background: var(--color-fill-2);
|
||||
color: var(--color-text-1);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--app-primary-color, #2d8c8c);
|
||||
color: var(--app-primary-color, #2d8c8c);
|
||||
background: rgba(45, 140, 140, 0.06);
|
||||
}
|
||||
|
||||
&.writable {
|
||||
border-color: rgba(45, 140, 140, 0.35);
|
||||
}
|
||||
}
|
||||
|
||||
.category-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.category-tab {
|
||||
height: 26px;
|
||||
padding: 0 8px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
color: var(--color-text-3);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
|
||||
&.active {
|
||||
background: rgba(45, 140, 140, 0.1);
|
||||
color: var(--app-primary-color, #2d8c8c);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -318,12 +318,12 @@
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-item full-width">
|
||||
<label class="form-label">{{ t('channel.serviceChannels.form.preScript') }}</label>
|
||||
<a-textarea
|
||||
v-model="formData.preScript"
|
||||
<PreScriptEditor
|
||||
v-model="formData.preScript"
|
||||
:label="t('channel.serviceChannels.form.preScript')"
|
||||
:label-tip="t('channel.serviceChannels.tip.preScript')"
|
||||
:placeholder="t('channel.serviceChannels.form.placeholder.preScript')"
|
||||
:rows="4"
|
||||
class="form-textarea"
|
||||
:rows="5"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -1394,20 +1394,13 @@
|
||||
}}
|
||||
</a-button>
|
||||
</div>
|
||||
<a-form-item v-if="addChannelShowAdvanced">
|
||||
<template #label>
|
||||
<span class="label-with-tip">
|
||||
{{ t('channel.serviceChannels.form.preScript') }}
|
||||
<a-tooltip :content="t('channel.serviceChannels.tip.preScript')">
|
||||
<icon-question-circle class="tip-icon" />
|
||||
</a-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<a-textarea
|
||||
<a-form-item v-if="addChannelShowAdvanced" hide-label>
|
||||
<PreScriptEditor
|
||||
v-model="addChannelForm.preScript"
|
||||
:label="t('channel.serviceChannels.form.preScript')"
|
||||
:label-tip="t('channel.serviceChannels.tip.preScript')"
|
||||
:placeholder="t('channel.serviceChannels.form.placeholder.preScript')"
|
||||
:auto-size="{ minRows: 3, maxRows: 8 }"
|
||||
allow-clear
|
||||
:rows="4"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
@ -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'
|
||||
|
||||
|
||||
65
src/views/channel/serviceChannels/preScriptAiSkill.ts
Normal file
65
src/views/channel/serviceChannels/preScriptAiSkill.ts
Normal file
@ -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',
|
||||
]
|
||||
248
src/views/channel/serviceChannels/preScriptMeta.ts
Normal file
248
src/views/channel/serviceChannels/preScriptMeta.ts
Normal file
@ -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<string>([
|
||||
// 订单基本(下单「基本信息」+ 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<string>([
|
||||
'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<OrderTableFieldDef, 'table' | 'field'>) {
|
||||
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<string, OrderTableFieldDef[]>()
|
||||
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,
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user