Commit 8c509e56 by weiyudumei

feat: 优化自动提交逻辑,只校验必填字段

- 在 AttachmentContentField 类型中添加 required 字段
- 修改自动提交逻辑,只校验 required === true 的字段是否有值
- 如果没有必填字段或所有必填字段都有值,则自动提交
- 更新日志输出,显示必填字段信息
parent 5d5df55e
...@@ -86,8 +86,10 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({ ...@@ -86,8 +86,10 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
return return
} }
// 检查是否所有字段都有值(从 URL query 中读取的) // 检查是否所有必填字段都有值(从 URL query 中读取的)
const allFieldsHaveValues = textFields.every((field) => { // 只校验 required === true 的字段
const requiredFields = textFields.filter(field => field.required === true)
const allRequiredFieldsHaveValues = requiredFields.length === 0 || requiredFields.every((field) => {
const queryValue = searchParams.get(field.key) const queryValue = searchParams.get(field.key)
return queryValue && queryValue.trim() !== '' return queryValue && queryValue.trim() !== ''
}) })
...@@ -98,11 +100,13 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({ ...@@ -98,11 +100,13 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
isSubmitting, isSubmitting,
isCompleted, isCompleted,
textFieldsCount: textFields.length, textFieldsCount: textFields.length,
allFieldsHaveValues, requiredFieldsCount: requiredFields.length,
textFields: textFields.map(f => ({ key: f.key, label: f.label })), allRequiredFieldsHaveValues,
requiredFields: requiredFields.map(f => ({ key: f.key, label: f.label })),
textFields: textFields.map(f => ({ key: f.key, label: f.label, required: f.required })),
}) })
if (allFieldsHaveValues) { if (allRequiredFieldsHaveValues) {
// 立即设置 hasAutoSubmittedRef,防止重复提交 // 立即设置 hasAutoSubmittedRef,防止重复提交
hasAutoSubmittedRef.current = true hasAutoSubmittedRef.current = true
// 更新记录的值 // 更新记录的值
...@@ -133,8 +137,9 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({ ...@@ -133,8 +137,9 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
clearTimeout(timeoutId) clearTimeout(timeoutId)
} }
} else { } else {
console.log('[CardWorkflowForm] 自动提交:字段值不完整,跳过', { console.log('[CardWorkflowForm] 自动提交:必填字段值不完整,跳过', {
fields: textFields.map(f => ({ key: f.key, value: searchParams.get(f.key) })), requiredFields: requiredFields.map(f => ({ key: f.key, label: f.label, value: searchParams.get(f.key) })),
allFields: textFields.map(f => ({ key: f.key, label: f.label, required: f.required, value: searchParams.get(f.key) })),
}) })
// 更新记录的值 // 更新记录的值
lastFirstQaFlagRef.current = answer.firstQaFlag lastFirstQaFlagRef.current = answer.firstQaFlag
......
...@@ -20,6 +20,7 @@ interface AttachmentContentField { ...@@ -20,6 +20,7 @@ interface AttachmentContentField {
key: string key: string
label: string label: string
type: string type: string
required?: boolean
} }
interface AttachmentContent { interface AttachmentContent {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment