fix dates

This commit is contained in:
Fine 2022-09-08 22:08:29 +08:00
parent 49bc349064
commit daeb1168c7

View File

@ -18,7 +18,7 @@ limitations under the License. -->
<div class="app-config"> <div class="app-config">
<span class="red" v-show="timeRange">{{ t("timeTips") }}</span> <span class="red" v-show="timeRange">{{ t("timeTips") }}</span>
<TimePicker <TimePicker
:value="time" :value="[appStore.durationRow.start, appStore.durationRow.end]"
position="bottom" position="bottom"
format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm"
@input="changeTimeRange" @input="changeTimeRange"
@ -55,17 +55,12 @@ import { useI18n } from "vue-i18n";
import timeFormat from "@/utils/timeFormat"; import timeFormat from "@/utils/timeFormat";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import getLocalTime from "@/utils/localtime";
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const route = useRoute(); const route = useRoute();
const pageName = ref<string>(""); const pageName = ref<string>("");
const timeRange = ref<number>(0); const timeRange = ref<number>(0);
const time = ref<Date[]>([
appStore.durationRow.start,
appStore.durationRow.end,
]);
resetDuration(); resetDuration();
getVersion(); getVersion();
@ -73,15 +68,13 @@ const setConfig = (value: string) => {
pageName.value = value || ""; pageName.value = value || "";
}; };
const handleReload = () => { function handleReload() {
const gap = const gap =
appStore.duration.end.getTime() - appStore.duration.start.getTime(); appStore.duration.end.getTime() - appStore.duration.start.getTime();
const dates: Date[] = [ const dates: Date[] = [new Date(new Date().getTime() - gap), new Date()];
getLocalTime(appStore.utc, new Date(new Date().getTime() - gap)),
getLocalTime(appStore.utc, new Date()),
];
appStore.setDuration(timeFormat(dates)); appStore.setDuration(timeFormat(dates));
}; }
function changeTimeRange(val: Date[] | any) { function changeTimeRange(val: Date[] | any) {
timeRange.value = timeRange.value =
val[1].getTime() - val[0].getTime() > 60 * 24 * 60 * 60 * 1000 ? 1 : 0; val[1].getTime() - val[0].getTime() > 60 * 24 * 60 * 60 * 1000 ? 1 : 0;
@ -114,7 +107,6 @@ function resetDuration() {
step: d.step, step: d.step,
}); });
appStore.updateUTC(d.utc); appStore.updateUTC(d.utc);
time.value = [new Date(d.start), new Date(d.end)];
} }
} }
</script> </script>