Skip to content

Commit b497deb

Browse files
refactor: 升级dayjs,移除 moment 使用 (#2907)
1 parent c043c4e commit b497deb

44 files changed

Lines changed: 192 additions & 468 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

webfe/package_vue/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"connect-history-api-fallback": "^1.3.0",
4343
"cookie": "^0.3.1",
4444
"cross-env": "^7.0.3",
45-
"dayjs": "^1.8.19",
45+
"dayjs": "^1.11.13",
4646
"echarts": "^3.6.1",
4747
"enhanced-resolve": "^5.10.0",
4848
"eventsource-polyfill": "^0.9.6",
@@ -62,7 +62,6 @@
6262
"lodash": "^4.18.1",
6363
"markdown-it": "^13.0.2",
6464
"marked": "^4.0.10",
65-
"moment": "^2.18.1",
6665
"monaco-editor": "0.38.0",
6766
"node-sass": "^6.0.1",
6867
"npm-run-all": "~4.1.5",

webfe/package_vue/src/common/datepicker_utils.js

Lines changed: 0 additions & 120 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* TencentBlueKing is pleased to support the open source community by making
3+
* 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
4+
* Copyright (C) Tencent. All rights reserved.
5+
* Licensed under the MIT License (the "License"); you may not use this file except
6+
* in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* http://opensource.org/licenses/MIT
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under
11+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
* either express or implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* We undertake not to change the open source license (MIT license) applicable
16+
* to the current version of the project delivered to anyone in the future.
17+
*/
18+
19+
import dayjs from 'dayjs';
20+
import relativeTime from 'dayjs/plugin/relativeTime';
21+
import cookie from 'cookie';
22+
import 'dayjs/locale/zh-cn';
23+
import 'dayjs/locale/en';
24+
25+
dayjs.extend(relativeTime);
26+
27+
export function setDayjsLocale(language) {
28+
const locale = language === 'en' ? 'en' : 'zh-cn';
29+
dayjs.locale(locale);
30+
}
31+
32+
setDayjsLocale(cookie.parse(document.cookie).blueking_language || 'zh-cn');
33+
34+
export default dayjs;

webfe/package_vue/src/components/filters/SmartTime.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,23 @@
1717
*/
1818

1919
import Vue from 'vue';
20-
import moment from 'moment';
21-
import cookie from 'cookie';
20+
import dayjs from '@/common/dayjs';
2221

2322
// 时间格式过滤器
2423
Vue.filter('time-smart', function (value, type) {
25-
let language = cookie.parse(document.cookie).blueking_language || 'zh-cn';
26-
27-
if (['zh-cn', 'zh-CN', 'None', 'none', ''].includes(language)) {
28-
language = 'zh-cn';
29-
}
30-
// moment日期中文显示
31-
moment.locale(language);
32-
3324
let formatTime;
3425
const curYear = new Date().getFullYear();
3526
switch (type) {
3627
case 'fromNow':
3728
// 距离当前时间多久
38-
formatTime = moment(value).startOf('minute').fromNow();
29+
formatTime = dayjs(value).startOf('minute').fromNow();
3930
break;
4031
case 'smartShorten':
4132
// 当年日期显示:07-25 16:16
42-
if (moment(value).format('YYYY') === curYear) {
43-
formatTime = moment(value).format('MM-DD HH:mm');
33+
if (dayjs(value).format('YYYY') === curYear) {
34+
formatTime = dayjs(value).format('MM-DD HH:mm');
4435
} else {
45-
formatTime = moment(value).format('YYYY-MM-DD HH:mm');
36+
formatTime = dayjs(value).format('YYYY-MM-DD HH:mm');
4637
}
4738
break;
4839
default:

webfe/package_vue/src/json/analysis-chart-option.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/**
2020
* @file echarts 图表配置
2121
*/
22-
// import moment from 'moment'
2322
import i18n from '@/language/i18n';
2423
export default {
2524
pv_uv: {

webfe/package_vue/src/json/instance-chart-option.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/**
2020
* @file echarts 图表配置
2121
*/
22-
// import moment from 'moment'
2322
import i18n from '@/language/i18n.js';
2423
export default {
2524
cpu: {

webfe/package_vue/src/json/plugin-overview-options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/**
2020
* @file echarts 图表配置
2121
*/
22-
// import moment from 'moment'
2322
import i18n from '@/language/i18n';
2423
export default {
2524
stat: {

webfe/package_vue/src/json/process-chart-option.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/**
2020
* @file echarts 图表配置
2121
*/
22-
// import moment from 'moment'
2322
import i18n from '@/language/i18n';
2423

2524
export default {

webfe/package_vue/src/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import $ from 'jquery';
3333
import '@/common/jquery_tools';
3434

3535
import { bkInfoBox, bkMessage, bkNotify } from 'bk-magic-vue';
36-
import moment from 'moment';
3736
import Clipboard from 'clipboard';
3837
import Directives from '@/directives';
3938
import '@/utils/dompurify';
@@ -135,7 +134,6 @@ Vue.prototype.GLOBAL = window.GLOBAL_CONFIG;
135134

136135
Vue.prototype.smartTime = SmartTime;
137136
window.Clipboard = Clipboard;
138-
window.moment = moment;
139137
window.showDeployTip = function () {
140138
Vue.prototype.$paasMessage({
141139
theme: 'error',

webfe/package_vue/src/store/modules/log.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
import http from '@/api';
2323
import bartOptions from '@/json/bar_chart_default';
24-
import moment from 'moment';
24+
import dayjs from '@/common/dayjs';
2525

2626
// store
2727
const state = {
@@ -51,7 +51,7 @@ const mutations = {
5151
}];
5252
const timestamps = data.timestamps.map((item) => {
5353
// 时间处理
54-
item = moment.unix(item).format('YYYY-MM-DD HH:mm:ss');
54+
item = dayjs.unix(item).format('YYYY-MM-DD HH:mm:ss');
5555
return item.substring(5);
5656
});
5757
chartOptions.xAxis.data = timestamps;

0 commit comments

Comments
 (0)