mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-22 14:42:51 +08:00
create datetime mixin
This commit is contained in:
53
src/mixins/datetime.js
Normal file
53
src/mixins/datetime.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userTimezone: localStorage.timezone || "auto",
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
datetime(value) {
|
||||
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss");
|
||||
},
|
||||
|
||||
date(value) {
|
||||
return this.datetimeFormat(value, "YYYY-MM-DD");
|
||||
},
|
||||
|
||||
time(value, second = true) {
|
||||
let secondString;
|
||||
if (second) {
|
||||
secondString = ":ss";
|
||||
} else {
|
||||
secondString = "";
|
||||
}
|
||||
return this.datetimeFormat(value, "HH:mm" + secondString);
|
||||
},
|
||||
|
||||
datetimeFormat(value, format) {
|
||||
if (value !== undefined && value !== "") {
|
||||
return dayjs.utc(value).tz(this.timezone).format(format);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
timezone() {
|
||||
if (this.userTimezone === "auto") {
|
||||
return dayjs.tz.guess()
|
||||
}
|
||||
|
||||
return this.userTimezone
|
||||
},
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,3 @@
|
||||
import dayjs from "dayjs";
|
||||
import { io } from "socket.io-client";
|
||||
import { useToast } from "vue-toastification";
|
||||
const toast = useToast()
|
||||
@@ -17,7 +16,6 @@ export default {
|
||||
connectCount: 0,
|
||||
},
|
||||
remember: (localStorage.remember !== "0"),
|
||||
userTimezone: localStorage.timezone || "auto",
|
||||
allowLoginDialog: false, // Allowed to show login dialog, but "loggedIn" have to be true too. This exists because prevent the login dialog show 0.1s in first before the socket server auth-ed.
|
||||
loggedIn: false,
|
||||
monitorList: { },
|
||||
@@ -265,15 +263,6 @@ export default {
|
||||
|
||||
computed: {
|
||||
|
||||
timezone() {
|
||||
|
||||
if (this.userTimezone === "auto") {
|
||||
return dayjs.tz.guess()
|
||||
}
|
||||
|
||||
return this.userTimezone
|
||||
},
|
||||
|
||||
lastHeartbeatList() {
|
||||
let result = {}
|
||||
|
||||
|
Reference in New Issue
Block a user