fix(gerp): 日期字段统一回传纯日期串,修正 DateField 提交报错

date 类型(后端 DateField)此前按 Date 对象绑定,提交时被序列化成带时区的 ISO 时刻(2019-08-31T16:00:00.000Z),后端只接受 YYYY-MM-DD 而 500;改为 el-date-picker 显式 value-format=YYYY-MM-DD,跨时区也不会算偏一天。datetime 保持原样。列表与档案只读展示对 date 类型原样输出,不再走 UTC→本地时区转换。
This commit is contained in:
TermiNexus committed 2026-10-01 19:57:46 +08:00
1 parent a25cae3089
commit 0fdaf4afba
3 files changed
+19 -2

No files matched your search

+13
View File
@@ -83,6 +83,18 @@ function joinTags(values: string[], separator = ','): string {
return (values || []).filter(Boolean).join(separator)
}
/**
* 日期选择器的绑定值格式
*
* date(后端 DateField)必须回传纯日期串 `YYYY-MM-DD`:
* 传 Date 对象会被 JSON 序列化成带时区的 ISO 时刻(如 2019-08-31T16:00:00.000Z),
* 后端只接受 `YYYY-MM-DD`,且跨时区会把日期算偏一天。
* datetime 保持默认(Date 对象 → ISO),由后端按 UTC 解析后再统一转换,不要改动。
*/
function dateValueFormat(type: ColumnSchema['type']): string | undefined {
return type === 'date' ? 'YYYY-MM-DD' : undefined
}
/** 保存:先校验,通过后交父组件提交 */
async function onSubmit(): Promise<void> {
if (!formRef.value) return
@@ -293,6 +305,7 @@ watch(
v-else-if="col.type === 'date' || col.type === 'datetime'"
v-model="formModel[col.field]"
:type="col.type as 'date' | 'datetime'"
:value-format="dateValueFormat(col.type)"
:placeholder="col.placeholder"
style="width: 100%"
/>
+3 -1
View File
@@ -620,7 +620,9 @@ defineExpose({
<!-- select:options 匹配显示 label(状态码等) -->
<span v-else-if="col.type === 'select'">{{ renderSelectLabel(col, (row as Record<string, unknown>)[col.field]) }}</span>
<!-- datetime:后端 UTC-0 → 用户本地时区显示 -->
<span v-else-if="col.type === 'datetime' || col.type === 'date'">{{ formatUtcTime((row as Record<string, unknown>)[col.field]) }}</span>
<span v-else-if="col.type === 'datetime'">{{ formatUtcTime((row as Record<string, unknown>)[col.field]) }}</span>
<!-- date:后端 DateField 纯日期(YYYY-MM-DD),无时区语义,原样展示 -->
<span v-else-if="col.type === 'date'">{{ (row as Record<string, unknown>)[col.field] || '-' }}</span>
<!-- richtext:去 HTML 纯文本预览 -->
<span v-else-if="col.type === 'richtext'">{{ stripHtml((row as Record<string, unknown>)[col.field]) }}</span>
<!-- 默认:原值 -->
+3 -1
View File
@@ -283,7 +283,9 @@ function profileValue(col: ColumnSchema): string {
const items = String(raw).split(col.tagsSeparator || ',').map((s) => s.trim()).filter(Boolean)
return items.length ? items.join('、') : '-'
}
if (col.type === 'date' || col.type === 'datetime') return formatTime(String(raw))
// 日期:date 为 DateField 纯日期(无时区语义)原样展示;datetime 按 UTC-0 → 本地时区
if (col.type === 'date') return String(raw)
if (col.type === 'datetime') return formatTime(String(raw))
return String(raw)
}