fix(xiaoyi): preserve Feishu intake placeholder aliases in enterprise template metadata
This commit is contained in:
parent
5aa64164e0
commit
26503bd6cc
@ -359,6 +359,10 @@ export function intakeMetadata(value) {
|
||||
(field.required !== undefined && typeof field.required !== 'boolean') ||
|
||||
(field.multiline !== undefined && typeof field.multiline !== 'boolean') ||
|
||||
(field.placeholder !== undefined && typeof field.placeholder !== 'string') ||
|
||||
(field.hint !== undefined && typeof field.hint !== 'string') ||
|
||||
(field.example !== undefined && typeof field.example !== 'string') ||
|
||||
(field.promptHint !== undefined && typeof field.promptHint !== 'string') ||
|
||||
(field.description !== undefined && typeof field.description !== 'string') ||
|
||||
(field.help !== undefined && typeof field.help !== 'string') ||
|
||||
(field.unit !== undefined && typeof field.unit !== 'string') ||
|
||||
(field.options !== undefined && (!Array.isArray(field.options) || field.options.some(option => typeof option !== 'string'))) ||
|
||||
@ -367,13 +371,18 @@ export function intakeMetadata(value) {
|
||||
}
|
||||
if (ids.has(id)) throw Error('小壹模板产品资料字段编号重复');
|
||||
ids.add(id);
|
||||
const aliasPlaceholder = [field.hint, field.example, field.promptHint, field.description]
|
||||
.find(text => typeof text === 'string' && text.trim());
|
||||
const placeholder = typeof field.placeholder === 'string' && field.placeholder.trim()
|
||||
? field.placeholder
|
||||
: aliasPlaceholder ?? field.placeholder;
|
||||
return {
|
||||
id, label:field.label, type,
|
||||
...(type === 'image' && {multiple:field.multiple ?? true}),
|
||||
...(field.imageRole !== undefined && {imageRole:field.imageRole}),
|
||||
...(field.required !== undefined && {required:field.required}),
|
||||
...(field.multiline !== undefined && {multiline:field.multiline}),
|
||||
...(field.placeholder !== undefined && {placeholder:field.placeholder}),
|
||||
...(placeholder !== undefined && {placeholder}),
|
||||
...(field.help !== undefined && {help:field.help}),
|
||||
...(field.unit !== undefined && {unit:field.unit}),
|
||||
...(field.options !== undefined && {options:field.options}),
|
||||
|
||||
@ -158,3 +158,26 @@ test('normalized production briefs retain shared assets and image references fro
|
||||
assert.deepEqual(scopedProductionBrief(source, 'black', 'sku_images').brief.normalizedProduct.assets.map(asset => asset.id),
|
||||
['common', 'black-image']);
|
||||
});
|
||||
|
||||
test('intakeMetadata promotes hint aliases into placeholder without overwriting explicit placeholder', () => {
|
||||
const schema = intakeMetadata({
|
||||
version: 1,
|
||||
productFields: [
|
||||
{ id: 'explicit', type: 'text', label: '品牌工艺', placeholder: '显式灰字', hint: '备选提示' },
|
||||
{ id: 'from_hint', type: 'text', label: '坐高', hint: '请填写座面离地高度' },
|
||||
{ id: 'from_example', type: 'text', label: '材质', example: '例如:北美黑胡桃木' },
|
||||
{ id: 'from_prompt_hint', type: 'text', label: '场景', promptHint: '客厅自然采光环境', multiline: true },
|
||||
{ id: 'from_desc', type: 'text', label: '说明', description: '补充结构要点' },
|
||||
],
|
||||
barcodeFields: [
|
||||
{ id: 'sku_hint', type: 'text', label: '规格提示', hint: '1600x800mm' },
|
||||
],
|
||||
});
|
||||
assert.equal(schema.productFields[0].placeholder, '显式灰字');
|
||||
assert.equal(schema.productFields[1].placeholder, '请填写座面离地高度');
|
||||
assert.equal(schema.productFields[2].placeholder, '例如:北美黑胡桃木');
|
||||
assert.equal(schema.productFields[3].placeholder, '客厅自然采光环境');
|
||||
assert.equal(schema.productFields[4].placeholder, '补充结构要点');
|
||||
assert.equal(schema.barcodeFields[0].placeholder, '1600x800mm');
|
||||
assert.throws(() => intakeMetadata({ version: 1, productFields: [{ id: 'bad', type: 'text', label: '坏字段', hint: 123 }], barcodeFields: [] }), /字段格式无效/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user