mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(utils): moment换成dayjs
This commit is contained in:
parent
5f78bbd7b7
commit
9ac3e12487
@ -38,7 +38,6 @@
|
|||||||
"@tmagic/utils": "1.1.0-beta.6",
|
"@tmagic/utils": "1.1.0-beta.6",
|
||||||
"element-plus": "^2.2.6",
|
"element-plus": "^2.2.6",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"moment": "^2.29.2",
|
|
||||||
"sortablejs": "^1.14.0",
|
"sortablejs": "^1.14.0",
|
||||||
"vue": "^3.2.37"
|
"vue": "^3.2.37"
|
||||||
},
|
},
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tmagic/schema": "1.1.0-beta.6",
|
"@tmagic/schema": "1.1.0-beta.6",
|
||||||
"moment": "^2.29.2"
|
"dayjs": "^1.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^15.12.4",
|
"@types/node": "^15.12.4",
|
||||||
"typescript": "^4.7.4",
|
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
"typescript": "^4.7.4",
|
||||||
"vite": "^3.0.4"
|
"vite": "^3.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import moment from 'moment';
|
import dayjs from 'dayjs';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
|
||||||
import type { MNode } from '@tmagic/schema';
|
import type { MNode } from '@tmagic/schema';
|
||||||
import { NodeType } from '@tmagic/schema';
|
import { NodeType } from '@tmagic/schema';
|
||||||
|
|
||||||
export * from './dom';
|
export * from './dom';
|
||||||
|
|
||||||
|
dayjs.extend(utc);
|
||||||
|
|
||||||
export const sleep = (ms: number): Promise<void> =>
|
export const sleep = (ms: number): Promise<void> =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
@ -31,26 +34,20 @@ export const sleep = (ms: number): Promise<void> =>
|
|||||||
}, ms);
|
}, ms);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const datetimeFormatter = (v: string | Date, defaultValue = '-', f = 'YYYY-MM-DD HH:mm:ss'): any => {
|
export const datetimeFormatter = (v: string | Date, defaultValue = '-', format = 'YYYY-MM-DD HH:mm:ss'): any => {
|
||||||
let format = f;
|
|
||||||
if (format === 'timestamp') {
|
|
||||||
format = 'x';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v) {
|
if (v) {
|
||||||
let time = null;
|
let time = null;
|
||||||
if ((typeof v === 'string' && v.includes('Z')) || v.constructor === Date) {
|
if (['x', 'timestamp'].includes(format)) {
|
||||||
|
time = dayjs(v).valueOf();
|
||||||
|
} else if ((typeof v === 'string' && v.includes('Z')) || v.constructor === Date) {
|
||||||
// UTC字符串时间或Date对象格式化为北京时间
|
// UTC字符串时间或Date对象格式化为北京时间
|
||||||
time = moment(v).utcOffset('+08:00').format(format);
|
time = dayjs(v).utcOffset(8).format(format);
|
||||||
} else {
|
} else {
|
||||||
time = moment(v).format(format);
|
time = dayjs(v).format(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format === 'x') {
|
|
||||||
return +time;
|
|
||||||
}
|
|
||||||
// 格式化为北京时间
|
// 格式化为北京时间
|
||||||
if (time !== 'Invalid date') {
|
if (time !== 'Invalid Date') {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@ -227,7 +227,6 @@ importers:
|
|||||||
'@vue/test-utils': ^2.0.0
|
'@vue/test-utils': ^2.0.0
|
||||||
element-plus: ^2.2.6
|
element-plus: ^2.2.6
|
||||||
lodash-es: ^4.17.21
|
lodash-es: ^4.17.21
|
||||||
moment: ^2.29.2
|
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
sass: ^1.35.1
|
sass: ^1.35.1
|
||||||
sortablejs: ^1.14.0
|
sortablejs: ^1.14.0
|
||||||
@ -240,7 +239,6 @@ importers:
|
|||||||
'@tmagic/utils': link:../utils
|
'@tmagic/utils': link:../utils
|
||||||
element-plus: 2.2.6_vue@3.2.37
|
element-plus: 2.2.6_vue@3.2.37
|
||||||
lodash-es: 4.17.21
|
lodash-es: 4.17.21
|
||||||
moment: 2.29.3
|
|
||||||
sortablejs: 1.15.0
|
sortablejs: 1.15.0
|
||||||
vue: 3.2.37
|
vue: 3.2.37
|
||||||
devDependencies:
|
devDependencies:
|
||||||
@ -414,13 +412,13 @@ importers:
|
|||||||
specifiers:
|
specifiers:
|
||||||
'@tmagic/schema': 1.1.0-beta.6
|
'@tmagic/schema': 1.1.0-beta.6
|
||||||
'@types/node': ^15.12.4
|
'@types/node': ^15.12.4
|
||||||
moment: ^2.29.2
|
dayjs: ^1.11.4
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
typescript: ^4.7.4
|
typescript: ^4.7.4
|
||||||
vite: ^3.0.4
|
vite: ^3.0.4
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tmagic/schema': link:../schema
|
'@tmagic/schema': link:../schema
|
||||||
moment: 2.29.3
|
dayjs: 1.11.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/node': 15.14.9
|
'@types/node': 15.14.9
|
||||||
rimraf: 3.0.2
|
rimraf: 3.0.2
|
||||||
@ -3153,6 +3151,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==}
|
resolution: {integrity: sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/dayjs/1.11.4:
|
||||||
|
resolution: {integrity: sha512-Zj/lPM5hOvQ1Bf7uAvewDaUcsJoI6JmNqmHhHl3nyumwe0XHwt8sWdOVAPACJzCebL8gQCi+K49w7iKWnGwX9g==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/de-indent/1.0.2:
|
/de-indent/1.0.2:
|
||||||
resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==}
|
resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==}
|
||||||
dev: true
|
dev: true
|
||||||
@ -5264,10 +5266,6 @@ packages:
|
|||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/moment/2.29.3:
|
|
||||||
resolution: {integrity: sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/monaco-editor/0.32.1:
|
/monaco-editor/0.32.1:
|
||||||
resolution: {integrity: sha512-LUt2wsUvQmEi2tfTOK+tjAPvt7eQ+K5C4rZPr6SeuyzjAuAHrIvlUloTcOiGjZW3fn3a/jFQCONrEJbNOaCqbA==}
|
resolution: {integrity: sha512-LUt2wsUvQmEi2tfTOK+tjAPvt7eQ+K5C4rZPr6SeuyzjAuAHrIvlUloTcOiGjZW3fn3a/jFQCONrEJbNOaCqbA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user