fix: 修改 alertRule evalLog 时间错误的问题

This commit is contained in:
zhangyu
2021-11-04 14:24:01 +08:00
parent 7262a32fa1
commit 219e71f7e0
6 changed files with 42 additions and 34 deletions

View File

@@ -98,35 +98,11 @@ export default {
if (this.obj) {
this.$set(this.searchLabel, 'id', this.obj.id)
}
this.$get(this.url, { ...this.searchLabel, ...this.searchCheckBox }).then(response => {
this.$get('alert/rule/' + this.obj.id + '/evalLog').then(response => {
this.tools.loading = false
this.nowTime = this.utcTimeToTimezoneStr(response.time)
// response = {
// code: 200,
// msg: 'success',
// data: {
// list: [{
// ruleId: 1,
// state: 200,
// msg: 'success',
// stts: 1634215095277,
// etts: 1634215095377
// }, {
// ruleId: 1,
// state: 201,
// msg: 'success',
// stts: 1634215095477,
// etts: 1634215095577
// }
// ]
// }
// }
if (response.code === 200) {
for (let i = 0; i < response.data.list.length; i++) {
response.data.list[i].status = response.data.list[i].status + ''
}
this.tableData = response.data.list
this.pageObj.total = response.data.total
this.tableData = response.data
if (!this.scrollbarWrap) {
this.$nextTick(() => {
this.scrollbarWrap = this.$refs.dataTable.$refs.dataTable.bodyWrapper

View File

@@ -27,7 +27,7 @@
<el-checkbox-group v-model="selectValue[item.key]">
<el-dropdown-item v-for="(item3,index3) in item.children" :key="index3" :title="item3.name" class="nz-dropdown-menu__item-hover">
<el-checkbox :label="item3.id">{{item3.name}}</el-checkbox>
<span class="right-box-select-num">{{item3.num}}</span>
<span class="right-box-select-num">{{item3.num || 0}}</span>
</el-dropdown-item>
</el-checkbox-group>
</el-dropdown-menu>
@@ -61,7 +61,7 @@
<!-- <span :title="item3.name" class="children-title-name"> {{item3.name}}</span>-->
<div v-for="(item4,index4) in item3.children" :key="index4" class="el-dropdown-menu__item nz-dropdown-menu__item-hover">
<el-checkbox :label="item3.id+'-'+item4.id" :title="item3.name+'/'+item4.name">{{item3.name+'/'+item4.name}}</el-checkbox>
<span class="right-box-select-num">{{item4.num}}</span>
<span class="right-box-select-num">{{item4.num || 0}}</span>
</div>
</el-dropdown-item>
</el-checkbox-group>
@@ -96,7 +96,7 @@
<span :title="item3.name" class="children-title-name"> {{item3.name}}</span>
<div :key="index4" v-for="(item4,index4) in item3.children" class="el-dropdown-menu__item nz-dropdown-menu__item-hover">
<el-checkbox :label="item3.id+'-'+item4.id" :title="item4.name" :a="item3.id+'-'+item4.id">{{item4.name}}</el-checkbox>
<span class="right-box-select-num">{{item4.num}}</span>
<span class="right-box-select-num">{{item4.num || 0}}</span>
</div>
</el-dropdown-item>
</el-checkbox-group>

View File

@@ -294,6 +294,15 @@ export function stringTimeParseToUnix (stringTime) {
time = time + localOffset - offset * 60 * 60 * 1000
return parseInt(time / 1000)
}
export function stringTimeParseToUnixMs (stringTime) {
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 // 默认 一分钟显示时区偏移的结果
time = time + localOffset - offset * 60 * 60 * 1000
return parseInt(time)
}
export function getTime (size, unit) { // 计算时间
const now = new Date(bus.computeTimezone(new Date().getTime()))
if (unit) {
@@ -361,6 +370,28 @@ export function calcDurationByStringTimeB (startTime, endTime) {
return result
}
export function calcDurationByStringTimeMs (startTime, endTime) {
let durationSecond = stringTimeParseToUnixMs(endTime) - stringTimeParseToUnixMs(startTime)
let result = ''
if (durationSecond < 1000) {
result = `${durationSecond % 1000}ms`
return result
} else {
durationSecond = durationSecond / 1000
}
result = `${durationSecond % 60}s`
if (durationSecond >= 60 * 60 * 24) {
result = `${(Math.floor(durationSecond / 3600)) % 24}h`
result = `${Math.floor(durationSecond / (60 * 60 * 24))}d ${result}`
} else if (durationSecond >= 60 * 60) {
result = `${(Math.floor(durationSecond / 60)) % 60}m`
result = `${Math.floor(durationSecond / (60 * 60))}h ${result}`
} else if (durationSecond >= 60) {
result = `${(Math.floor(durationSecond / 60)) % 60}m ${result}`
}
return result
}
export function unixTimeParseToString (unixTime, fmt = 'yyyy-MM-dd hh:mm:ss') {
const date = new Date(unixTime * 1000)
const o = {

View File

@@ -76,7 +76,7 @@ export function nzNumber (rule, value, callback) {
}
export function noSpecialChar (rule, value, callback) {
const charReg = /^[\u4e00-\u9fa5a-z0-9A-Z-_.]+$/
const charReg = /[\u0000-\uFFFF]/
setTimeout(() => {
if (charReg.test(value)) {
callback()

View File

@@ -20,7 +20,7 @@
>
<template slot-scope="{ node, data }">
<span>{{ data.name }}</span>
<span class="search-content-num">({{data.num}})</span>
<span class="search-content-num">({{data.num || 0 }})</span>
</template>
</el-cascader>
</div>

View File

@@ -41,6 +41,7 @@
<div>
<div :class="{'active-icon green-bg':scope.row.state == 200,'active-icon red-bg':scope.row.state != 200}" style="position: relative">
</div>
<span>{{scope.row.state == 200?'Ok':'Error'}}</span>
</div>
</template>
<template v-else-if="item.prop === 'duration'">
@@ -73,7 +74,7 @@
<script>
import table from '@/components/common/mixin/table'
import { calcDurationByStringTimeB } from '@/components/common/js/tools'
import { calcDurationByStringTimeMs } from '@/components/common/js/tools'
export default {
name: 'alertRuleTable',
mixins: [table],
@@ -113,9 +114,9 @@ export default {
methods: {
getDuration (record) {
if (record.etts) {
return calcDurationByStringTimeB(record.stts, record.etts)
return calcDurationByStringTimeMs(record.stts, record.etts)
}
return calcDurationByStringTimeB(record.stts, this.utcTimeToTimezoneStr(this.nowTime))
return calcDurationByStringTimeMs(record.stts, this.utcTimeToTimezoneStr(this.nowTime))
}
}
}