set duration and utc

This commit is contained in:
Qiuxia Fan 2022-03-10 16:51:40 +08:00
parent eda6bfe2d2
commit 4ce1180f1e
4 changed files with 14 additions and 48 deletions

View File

@ -21,7 +21,13 @@ limitations under the License. -->
</router-view>
</section>
</template>
<script lang="ts" setup></script>
<script lang="ts" setup>
import { useAppStoreWithOut } from "@/store/modules/app";
const appStore = useAppStoreWithOut();
appStore.queryOAPTimeInfo();
</script>
<style lang="scss" scoped>
.app-main {
height: calc(100% - 40px);

View File

@ -70,7 +70,7 @@ const handleReload = () => {
const time: Date[] = [new Date(new Date().getTime() - gap), new Date()];
appStore.setDuration(timeFormat(time));
};
function changeTimeRange(val: Date[]) {
function changeTimeRange(val: Date[] | any) {
timeRange.value =
val[1].getTime() - val[0].getTime() > 60 * 24 * 60 * 60 * 1000 ? 1 : 0;
if (timeRange.value) {

View File

@ -19,9 +19,9 @@ import { store } from "@/store";
import graphql from "@/graphql";
import { Duration, DurationTime } from "@/types/app";
import getLocalTime from "@/utils/localtime";
import getDurationRow from "@/utils/dateTime";
import { AxiosResponse } from "axios";
import dateFormatStep, { dateFormatTime } from "@/utils/dateFormat";
import { TimeType } from "@/constants/data";
/*global Nullable*/
interface AppState {
durationRow: any;
@ -37,7 +37,11 @@ interface AppState {
export const appStore = defineStore({
id: "app",
state: (): AppState => ({
durationRow: getDurationRow(),
durationRow: {
start: new Date(new Date().getTime() - 1800000),
end: new Date(),
step: TimeType.MINUTE_TIME,
},
utc: "",
utcHour: 0,
utcMin: 0,

View File

@ -1,44 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Duration } from "@/types/app";
import { TimeType } from "@/constants/data";
/**
* init or generate durationRow Obj and save localStorage.
*/
const getDurationRow = (): Duration => {
const durationRowString = localStorage.getItem("durationRow");
let durationRow: Duration;
if (durationRowString && durationRowString !== "") {
durationRow = JSON.parse(durationRowString);
durationRow = {
start: new Date(durationRow.start),
end: new Date(durationRow.end),
step: durationRow.step,
};
} else {
durationRow = {
start: new Date(new Date().getTime() - 900000),
end: new Date(),
step: TimeType.MINUTE_TIME,
};
localStorage.setItem("durationRow", JSON.stringify(durationRow, null, 0));
}
return durationRow;
};
export default getDurationRow;