fix(documents): 提交后端时为无名称字段补默认标签
This commit is contained in:
@@ -6,6 +6,8 @@ import { request } from '@/utils/request'
|
|||||||
import { collectFieldDefs } from '@/utils/signing-fields'
|
import { collectFieldDefs } from '@/utils/signing-fields'
|
||||||
import type { ApiResponse, PageResult } from '@/types/common'
|
import type { ApiResponse, PageResult } from '@/types/common'
|
||||||
|
|
||||||
|
import type { SigningFieldKind } from '@/api/workbench/types'
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BackendCollection,
|
BackendCollection,
|
||||||
BackendPage,
|
BackendPage,
|
||||||
@@ -160,10 +162,27 @@ export function buildSignatureFieldsPayload(contentHtml: string): unknown[] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端对 formFields 的 `label` 有非空校验:整项名称为空时,`POST /v1/templates/{id}/versions`
|
||||||
|
* 直接返回 400「正文填写项标识、标签、类型无效或重复」——实测(2026-10-07,联调后端)
|
||||||
|
* 同一份请求只把 label 换上即可 200,与是否插在表格里无关。
|
||||||
|
*
|
||||||
|
* 不能改用「插入时必须命名」来绕:勾选项在设计上就是无名的(正文里只显示一个方框,
|
||||||
|
* 这一格勾什么由表格相邻列交代,见 WordEditorDialog 的 MANUAL_BUTTONS),
|
||||||
|
* 所以名称兜底只落在**提交给后端的这一层**:正文与编辑器仍以 data-label 为准,纸面上不多出文字。
|
||||||
|
*/
|
||||||
|
const FORM_FIELD_LABEL_FALLBACK: Record<SigningFieldKind, string> = {
|
||||||
|
checkbox: '勾选项',
|
||||||
|
choice: '选择项',
|
||||||
|
text: '填写项',
|
||||||
|
date: '日期',
|
||||||
|
signature: '签名',
|
||||||
|
}
|
||||||
|
|
||||||
export function buildFormFieldsPayload(contentHtml: string): unknown[] {
|
export function buildFormFieldsPayload(contentHtml: string): unknown[] {
|
||||||
return collectFieldDefs(contentHtml).map((field) => ({
|
return collectFieldDefs(contentHtml).map((field) => ({
|
||||||
id: field.id,
|
id: field.id,
|
||||||
label: field.label,
|
label: field.label || FORM_FIELD_LABEL_FALLBACK[field.kind],
|
||||||
kind: field.kind,
|
kind: field.kind,
|
||||||
required: field.required,
|
required: field.required,
|
||||||
options: field.options,
|
options: field.options,
|
||||||
|
|||||||
Reference in New Issue
Block a user