From 0fdaf4afbaebfbdb2cc9867d85f8497eb90cb397 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 1 Oct 2026 19:57:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(gerp):=20=E6=97=A5=E6=9C=9F=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=BB=9F=E4=B8=80=E5=9B=9E=E4=BC=A0=E7=BA=AF=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E4=B8=B2=EF=BC=8C=E4=BF=AE=E6=AD=A3=20DateField=20?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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→本地时区转换。 --- src/components/CrudFormPanel.vue | 13 +++++++++++++ src/components/CrudTable.vue | 4 +++- src/views/system/UserDetail.vue | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/CrudFormPanel.vue b/src/components/CrudFormPanel.vue index 39a2351..36dca1e 100644 --- a/src/components/CrudFormPanel.vue +++ b/src/components/CrudFormPanel.vue @@ -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 { 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%" /> diff --git a/src/components/CrudTable.vue b/src/components/CrudTable.vue index 885ecb5..fa47b27 100644 --- a/src/components/CrudTable.vue +++ b/src/components/CrudTable.vue @@ -620,7 +620,9 @@ defineExpose({ {{ renderSelectLabel(col, (row as Record)[col.field]) }} - {{ formatUtcTime((row as Record)[col.field]) }} + {{ formatUtcTime((row as Record)[col.field]) }} + + {{ (row as Record)[col.field] || '-' }} {{ stripHtml((row as Record)[col.field]) }} diff --git a/src/views/system/UserDetail.vue b/src/views/system/UserDetail.vue index 6494224..ffcdce8 100644 --- a/src/views/system/UserDetail.vue +++ b/src/views/system/UserDetail.vue @@ -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) }