2022-04-20 16:57:14 +08:00
|
|
|
import bus from '@/libs/bus'
|
2022-06-06 10:38:57 +08:00
|
|
|
import moment from 'moment-timezone'
|
2022-04-20 16:57:14 +08:00
|
|
|
import i18n from '@/components/common/i18n'
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
utcTimeToTimezone: function (time) { // 将utc时间 转为系统设者的时间 返回时间戳
|
|
|
|
|
if (time) {
|
|
|
|
|
return bus.UTCTimeToConfigTimezone(time)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
utcTimeToTimezoneStr: function (time, fmt) { // 将utc时间 转为系统设者的时间 返回String
|
|
|
|
|
if (!fmt) {
|
|
|
|
|
fmt = localStorage.getItem('nz-default-dateFormat') || 'YYYY-MM-DD HH:mm:ss'
|
|
|
|
|
}
|
|
|
|
|
if (time) {
|
|
|
|
|
return bus.timeFormate(bus.UTCTimeToConfigTimezone(time), fmt)
|
|
|
|
|
} else {
|
|
|
|
|
return '-'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
timezoneToUtcTime: function (time) { // 将系统设者的时间 转为utc时间 返回时间戳
|
|
|
|
|
if (time) {
|
|
|
|
|
return bus.configTimezoneToUTCTime(time)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
timezoneToUtcTimeStr: function (time, fmt) { // 将系统设者的时间 转为utc时间 返回String
|
|
|
|
|
if (!fmt) {
|
|
|
|
|
fmt = localStorage.getItem('nz-default-dateFormat') || 'YYYY-MM-DD HH:mm:ss'
|
|
|
|
|
}
|
|
|
|
|
if (time) {
|
|
|
|
|
return bus.timeFormate(this.timezoneToUtcTime(time), fmt)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
timeFormate (time) {
|
|
|
|
|
return bus.timeFormate(time)
|
|
|
|
|
},
|
|
|
|
|
numberWithEConvent (num) {
|
|
|
|
|
if (num) {
|
|
|
|
|
if ((('' + num).indexOf('E') !== -1) || (('' + num).indexOf('e') !== -1)) {
|
|
|
|
|
const regExp = /'^((\\d+.?\\d+)[Ee]{1}(\\d+))$', 'ig'/
|
|
|
|
|
let result = regExp.exec(num)
|
|
|
|
|
let resultValue = ''
|
|
|
|
|
let power
|
|
|
|
|
if (result != null) {
|
|
|
|
|
resultValue = result[2]
|
|
|
|
|
power = result[3]
|
|
|
|
|
result = regExp.exec(num)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resultValue) {
|
|
|
|
|
if (power) {
|
|
|
|
|
const powVer = Math.pow(10, power)
|
|
|
|
|
resultValue = resultValue * powVer
|
|
|
|
|
return resultValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return num
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
translation (key) {
|
|
|
|
|
return i18n.t(key)
|
|
|
|
|
},
|
2022-08-03 10:42:45 +08:00
|
|
|
timeFormatStrToDatePickFormat (str = localStorage.getItem('nz-default-dateFormat') ? localStorage.getItem('nz-default-dateFormat') : 'YYYY-MM-DD HH:mm:ss', flag) {
|
2022-04-20 16:57:14 +08:00
|
|
|
if (flag) {
|
|
|
|
|
const reg = /Y/g
|
|
|
|
|
str = str.replace(reg, 'y')
|
|
|
|
|
const reg1 = /D/g
|
|
|
|
|
str = str.replace(reg1, 'd')
|
|
|
|
|
const reg2 = /[H,m,s,:]/g
|
|
|
|
|
str = str.replace(reg2, '')
|
|
|
|
|
return str
|
|
|
|
|
} else {
|
|
|
|
|
const reg = /Y/g
|
|
|
|
|
str = str.replace(reg, 'y')
|
|
|
|
|
const reg1 = /D/g
|
|
|
|
|
str = str.replace(reg1, 'd')
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-06-06 10:38:57 +08:00
|
|
|
momentTz (timestamp, fmt) { // moment 转化时间戳为str
|
|
|
|
|
const offset = localStorage.getItem('nz-sys-timezone')
|
|
|
|
|
const format = fmt || localStorage.getItem('nz-default-dateFormat')
|
|
|
|
|
return moment.tz(timestamp, offset).format(format)
|
|
|
|
|
},
|
|
|
|
|
momentStrToTimestamp (str, fmt) {
|
|
|
|
|
const offset = localStorage.getItem('nz-sys-timezone')
|
|
|
|
|
const format = fmt || localStorage.getItem('nz-default-dateFormat')
|
|
|
|
|
const date = moment.tz(str, format, offset).valueOf()
|
|
|
|
|
return date
|
2022-06-22 16:25:25 +08:00
|
|
|
},
|
|
|
|
|
onCopy (txt) {
|
|
|
|
|
this.$copyText(txt).then(() => {
|
|
|
|
|
this.$message.success({ message: this.$t('overall.copySuccess') })
|
|
|
|
|
})
|
2022-11-21 18:40:28 +08:00
|
|
|
},
|
|
|
|
|
animateCSS (node, animation, prefix = 'animate__') {
|
|
|
|
|
// We create a Promise and return it
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const animationName = `${prefix}${animation}`
|
|
|
|
|
node.classList.add(`${prefix}animated`, animationName)
|
|
|
|
|
|
|
|
|
|
// When the animation ends, we clean the classes and resolve the Promise
|
|
|
|
|
function handleAnimationEnd (event) {
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
node.classList.remove(`${prefix}animated`, animationName)
|
|
|
|
|
resolve('Animation ended')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.addEventListener('animationend', handleAnimationEnd, { once: true })
|
|
|
|
|
})
|
2022-06-06 10:38:57 +08:00
|
|
|
}
|
2022-04-20 16:57:14 +08:00
|
|
|
}
|
|
|
|
|
}
|