diff --git a/CHANGELOG.md b/CHANGELOG.md index 172ac107b64866a82794d568bbb32f39f7a225f3..5a3234a2e09911ee1d14de05fc20c5c286402e1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - 支持表格的固定列配置,操作列默认固定 - 支持代码表文本样式 - 支持placeholder占位控件 +- span编辑器支持时间类型数据的值格式化 ### Fixed diff --git a/src/editor/span/span/span.tsx b/src/editor/span/span/span.tsx index 8c21f05eee6fdad18ef9c2305c69b240c1d7c1c8..9655b99436c79f4e7db9b04a186019a916312313 100644 --- a/src/editor/span/span/span.tsx +++ b/src/editor/span/span/span.tsx @@ -7,6 +7,8 @@ import { import './span.scss'; import { CodeListItem } from '@ibiz-template/runtime'; import { isNil } from 'ramda'; +import { DataTypes } from '@ibiz-template/core'; +import dayjs from 'dayjs'; import { SpanEditorController } from '../span-editor.controller'; export const IBizSpan = defineComponent({ @@ -29,21 +31,23 @@ export const IBizSpan = defineComponent({ text.value = ''; return; } - if (c.parent.valueFormat) { + const { valueFormat, dataType, unitName } = c.parent; + if (valueFormat) { try { - text.value = ibiz.util.text.format( - `${newVal}`, - c.parent.valueFormat, - ); + if (dataType != null && DataTypes.isDate(dataType)) { + text.value = dayjs(newVal).format(valueFormat); + } else { + text.value = ibiz.util.text.format(`${newVal}`, valueFormat); + } } catch (error) { text.value = `${newVal}`; ibiz.log.error(`${newVal} 值格式化错误`); } } else { - text.value = newVal ? `${newVal}` : ''; + text.value = `${newVal}`; } - if (c.parent.unitName) { - text.value += c.parent.unitName; + if (unitName) { + text.value += unitName; } } }, diff --git a/src/panel-component/panel-field/panel-field.controller.ts b/src/panel-component/panel-field/panel-field.controller.ts index eb35478bf54850ac2d664b3ee4d456656862d25f..8ed3dde863486fd5a4d8b7f68bcd8a7ed4f1f4f8 100644 --- a/src/panel-component/panel-field/panel-field.controller.ts +++ b/src/panel-component/panel-field/panel-field.controller.ts @@ -35,6 +35,10 @@ export class PanelFieldController return this.model.valueFormat; } + get dataType(): number | undefined { + return undefined; + } + get context(): IContext { return this.panel.context; }