fix:修改因为时区导致的查不到数据的问题 以及 修改metrics的正则

This commit is contained in:
zhangyu
2021-05-07 14:29:07 +08:00
parent e39e71708b
commit 31c169d8e1
4 changed files with 24 additions and 12 deletions

View File

@@ -182,6 +182,7 @@ import chartDataFormat from './chartDataFormat'
import { randomcolor } from '../common/js/radomcolor/randomcolor.js'
import chartAlertList from './chart-alert-list'
import chartConfig from '../page/dashboard/overview/chartConfig'
import moment from "moment-timezone";
export default {
name: 'chartPreview',
components: {
@@ -878,7 +879,8 @@ export default {
const tip = legend[item.seriesIndex]
const color = self.bgColorList[item.seriesIndex]
if (i === 0) {
const tData = new Date(item.data[0])
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += [tData.getFullYear(), tData.getMonth() + 1, tData.getDate()].join('-') + ' ' +
[tData.getHours(), tData.getMinutes(), tData.getSeconds()].join(':')
str += '<br/>'

View File

@@ -199,6 +199,7 @@ import { randomcolor } from '../common/js/radomcolor/randomcolor.js'
import chartConfig from '../page/dashboard/overview/chartConfig'
import { getChart, setChart, lineChartMove, getMousePoint } from '../common/js/common'
import { getMetricTypeValue } from '../common/js/tools'
import moment from 'moment-timezone'
export default {
name: 'lineChartBlock',
@@ -742,7 +743,7 @@ export default {
const tip = legend[item.seriesIndex]
const color = self.bgColorList[item.seriesIndex]
if (i === 0 && tip.alias.indexOf('Previous ') === -1) {
const value = item.data[0]
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += '<div style="margin-bottom: 5px">'
str += bus.timeFormate(tData)
@@ -752,7 +753,7 @@ export default {
if (i !== 0) {
str += '<div style="border:1px dashed #333;width:100%;margin-top: 5px"></div>'
}
const value = item.data[0] - self.minusTime
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += '<div style="margin-bottom: 5px;margin-top: 5px">'
str += bus.timeFormate(tData)
@@ -834,7 +835,11 @@ export default {
show: true,
fontSize: 10,
formatter: function (value) {
const tData = new Date(value)
let offset = localStorage.getItem('nz-sys-timezone')
offset = moment.tz(offset).format('Z')
offset = Number.parseInt(offset)
const localOffset = new Date().getTimezoneOffset() * 60 * 1000 * -1 // 默认 一分钟显示时区偏移的结果
const tData = new Date(value - localOffset + offset * 60 * 60 * 1000)
let hour = tData.getHours()
hour = hour > 9 ? hour : '0' + hour // 加0补充为两位数字
let minute = tData.getMinutes()
@@ -1011,7 +1016,7 @@ export default {
const tip = self.legendMagicType[item.seriesIndex]
const color = self.bgColorList[item.seriesIndex]
if (i === 0) {
const value = item.data[0]
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += '<div style="margin-bottom: 5px">'
str += bus.timeFormate(tData)
@@ -1179,7 +1184,7 @@ export default {
const tip = self.legendMagicType[item.seriesIndex]
const color = self.bgColorList[item.seriesIndex]
if (i === 0 && tip.alias.indexOf('Previous ') === -1) {
const value = item.data[0]
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += '<div style="margin-bottom: 5px">'
str += bus.timeFormate(tData)
@@ -1189,7 +1194,7 @@ export default {
if (i !== 0) {
str += '<div style="border:1px dashed #333;width:100%;margin-top: 5px"></div>'
}
const value = item.data[0] - self.minusTime
const value = bus.computeTimezone(item.data[0])
const tData = new Date(value)
str += '<div style="margin-bottom: 5px;margin-top: 5px">'
str += bus.timeFormate(tData)

View File

@@ -2,6 +2,7 @@ import { getChart } from './common'
import MessageBox from 'element-ui/packages/message-box/src/main'
import i18n from '../i18n'
import bus from '@/libs/bus'
import moment from 'moment-timezone'
/* 弹窗点击外部后关闭 */
const exceptClassName = ['prevent-clickoutside', 'config-dropdown', 'nz-pop', 'el-picker', 'chart-box-dropdown', 'metric-dropdown', 'el-cascader__dropdown', 'no-style-class', 'el-message-box', 'nz-dashboard-dropdown', 'el-autocomplete-suggestion', 'nz-temp-box', 'el-time-panel'] // clickoutside排除的class(白名单) no-style-class没有任何样式的class
export const clickoutside = {
@@ -281,7 +282,13 @@ export const bottomBoxWindow = {
}
}
export function stringTimeParseToUnix (stringTime) {
const time = new Date(stringTime).getTime()
let time = new Date(stringTime).getTime()
let offset = localStorage.getItem('nz-sys-timezone')
offset = moment.tz(offset).format('Z')
offset = Number.parseInt(offset)
const localOffset = new Date().getTimezoneOffset() * 60 * 1000 * -1 // 默认 一分钟显示时区偏移的结果
console.log(offset,localOffset, time)
time = time + localOffset - offset * 60 * 60 * 1000
return time / 1000
}
export function getTime (size, unit) { // 计算时间

View File

@@ -245,10 +245,8 @@ export default {
const metricMap = new Map()
metrics.forEach((item) => {
let key = ''
if (/^[a-zA-Z]+?_[a-zA-Z]*/.test(item)) {
key = item.split('_')[0]
} else if (/^_\w*/.test(item)) {
key = ' '
if (/^[a-zA-Z_:][a-zA-Z0-9_:]*/.test(item)) {
key = item.split(/[_:]/, 1)[0]
} else {
key = item
}