Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Cloudbase Extension Cms
Commits
b7fb4619
Commit
b7fb4619
authored
4 years ago
by
cwuyiqing
Browse files
Options
Download
Email Patches
Plain Diff
fix: fix date type display wrong
parent
7c603777
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
packages/admin/src/components/Fields/Date.tsx
+2
-2
packages/admin/src/components/Fields/Date.tsx
packages/admin/src/components/Fields/FieldContentRender.tsx
+13
-3
packages/admin/src/components/Fields/FieldContentRender.tsx
packages/admin/src/pages/project/schema/components/SchemaFieldEditor/SchemaFieldEdit.tsx
+2
-2
...t/schema/components/SchemaFieldEditor/SchemaFieldEdit.tsx
packages/admin/src/utils/date.ts
+32
-1
packages/admin/src/utils/date.ts
with
49 additions
and
8 deletions
+49
-8
packages/admin/src/components/Fields/Date.tsx
+
2
-
2
View file @
b7fb4619
...
...
@@ -3,7 +3,7 @@ import moment from 'moment'
import
'
moment/locale/zh-cn
'
import
{
DatePicker
}
from
'
antd
'
import
locale
from
'
antd/es/date-picker/locale/zh_CN
'
import
{
formatTimeByType
}
from
'
@/utils
'
import
{
format
Store
TimeByType
}
from
'
@/utils
'
export
const
IDatePicker
:
React
.
FC
<
{
type
?:
string
...
...
@@ -35,7 +35,7 @@ export const IDatePicker: React.FC<{
}
// 格式化时间
const
formatDate
:
number
|
string
=
formatTimeByType
(
v
,
dateFormatType
,
type
)
const
formatDate
:
number
|
string
=
format
Store
TimeByType
(
v
,
dateFormatType
,
type
)
onChange
(
formatDate
)
}
}
/>
...
...
This diff is collapsed.
Click to expand it.
packages/admin/src/components/Fields/FieldContentRender.tsx
+
13
-
3
View file @
b7fb4619
import
React
from
'
react
'
import
{
Space
,
Tag
,
Tooltip
,
Typography
}
from
'
antd
'
import
{
IConnectRender
,
IFileRender
,
ImageRender
}
from
'
@/components/Fields
'
import
{
calculateFieldWidth
}
from
'
@/utils
'
import
{
calculateFieldWidth
,
formatDisplayTimeByType
}
from
'
@/utils
'
import
{
IObjectRender
}
from
'
./Object
'
import
{
IMedia
}
from
'
./Media
'
...
...
@@ -87,9 +87,19 @@ export function getFieldRender(field: SchemaField) {
action
:
any
):
React
.
ReactNode
|
React
.
ReactNode
[]
=>
<
Text
>
{
text
}
</
Text
>
case
'
Date
'
:
return
undefined
case
'
DateTime
'
:
return
undefined
return
(
text
:
React
.
ReactNode
,
record
:
any
,
index
:
number
,
action
:
any
):
React
.
ReactNode
|
React
.
ReactNode
[]
=>
{
const
date
=
typeof
record
[
name
]
===
'
undefined
'
?
'
-
'
:
formatDisplayTimeByType
(
record
[
name
],
field
.
dateFormatType
,
type
)
return
<
Text
>
{
date
}
</
Text
>
}
case
'
Image
'
:
return
(
text
:
React
.
ReactNode
,
...
...
This diff is collapsed.
Click to expand it.
packages/admin/src/pages/project/schema/components/SchemaFieldEditor/SchemaFieldEdit.tsx
+
2
-
2
View file @
b7fb4619
...
...
@@ -19,7 +19,7 @@ import {
import
{
ContentCtx
,
SchmeaCtx
}
from
'
typings/store
'
import
{
getFieldDefaultValueInput
,
getFieldFormItem
}
from
'
./Field
'
import
{
FieldTypes
,
SYSTEM_FIELDS
}
from
'
@/common
'
import
{
formatTimeByType
,
isDateType
,
isResourceType
,
random
}
from
'
@/utils
'
import
{
format
Store
TimeByType
,
isDateType
,
isResourceType
,
random
}
from
'
@/utils
'
const
{
TextArea
}
=
Input
const
{
Text
}
=
Typography
...
...
@@ -203,7 +203,7 @@ export const SchemaFieldEditorModal: React.FC<{
// 格式化默认时间,与 dateFormatType 保持一致
if
(
v
.
dateFormatType
&&
v
.
defaultValue
)
{
v
.
defaultValue
=
formatTimeByType
(
v
.
defaultValue
,
v
.
dateFormatType
)
v
.
defaultValue
=
format
Store
TimeByType
(
v
.
defaultValue
,
v
.
dateFormatType
)
}
createField
(
v
)
...
...
This diff is collapsed.
Click to expand it.
packages/admin/src/utils/date.ts
+
32
-
1
View file @
b7fb4619
...
...
@@ -5,7 +5,13 @@ export const getFullDate = (v = Date.now()) => moment(v).format('YYYY-MM-DD')
export
const
getDateValue
=
(
v
?:
string
|
number
)
=>
moment
(
v
).
valueOf
()
export
const
formatTimeByType
=
(
/**
* 格式化保存到数据库中的时间
* @param v
* @param dateType
* @param valueType
*/
export
const
formatStoreTimeByType
=
(
v
:
string
,
dateType
?:
'
timestamp-ms
'
|
'
timestamp-s
'
|
'
date
'
|
'
string
'
,
valueType
?:
string
...
...
@@ -33,3 +39,28 @@ export const formatTimeByType = (
return
formatDate
}
/**
* 格式化展示的时间
* @param v
* @param dateType
* @param valueType
*/
export
const
formatDisplayTimeByType
=
(
v
:
string
|
number
,
dateType
?:
'
timestamp-ms
'
|
'
timestamp-s
'
|
'
date
'
|
'
string
'
,
valueType
?:
string
)
=>
{
const
format
=
valueType
===
'
Date
'
?
'
YYYY-MM-DD
'
:
'
YYYY-MM-DD HH:mm:ss
'
// 字符串
if
(
dateType
===
'
string
'
)
{
return
v
}
if
(
dateType
===
'
timestamp-s
'
)
{
return
moment
(
Number
(
v
)
*
1000
).
format
(
format
)
}
return
moment
(
v
).
format
(
format
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment