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) }