add max range for time picker

This commit is contained in:
Fine 2025-05-13 17:52:08 +08:00
parent 16094885b0
commit 96a7133c65
5 changed files with 51 additions and 8 deletions

View File

@ -175,6 +175,7 @@ limitations under the License. -->
type: String, type: String,
default: "YYYY-MM-DD", default: "YYYY-MM-DD",
}, },
maxRange: { type: Array as PropType<Date[]>, default: () => [] },
}); });
const state = reactive({ const state = reactive({
pre: "", pre: "",
@ -241,6 +242,12 @@ limitations under the License. -->
const end = computed(() => { const end = computed(() => {
return parse(Number(props.dates[1])); return parse(Number(props.dates[1]));
}); });
const minStart = computed(() => {
return parse(Number(props.maxRange[0]));
});
const maxEnd = computed(() => {
return parse(Number(props.maxRange[1]));
});
const ys = computed(() => { const ys = computed(() => {
return Math.floor(state.year / 10) * 10; return Math.floor(state.year / 10) * 10;
}); });
@ -369,7 +376,10 @@ limitations under the License. -->
flag = tf(props.value, format) === tf(time, format); flag = tf(props.value, format) === tf(time, format);
} }
classObj[`${state.pre}-date`] = true; classObj[`${state.pre}-date`] = true;
classObj[`${state.pre}-date-disabled`] = (props.right && t < start.value) || props.disabledDate(time, format); classObj[`${state.pre}-date-disabled`] =
(props.right && (t < start.value || t > maxEnd.value)) ||
(props.left && t < minStart.value) ||
props.disabledDate(time, format);
classObj[`${state.pre}-date-on`] = (props.left && t > start.value) || (props.right && t < end.value); classObj[`${state.pre}-date-on`] = (props.left && t > start.value) || (props.right && t < end.value);
classObj[`${state.pre}-date-selected`] = flag; classObj[`${state.pre}-date-selected`] = flag;
return classObj; return classObj;

View File

@ -68,6 +68,7 @@ limitations under the License. -->
:left="true" :left="true"
:disabledDate="disabledDate" :disabledDate="disabledDate"
:format="format" :format="format"
:maxRange="maxRange"
@ok="ok" @ok="ok"
@setDates="setDates" @setDates="setDates"
/> />
@ -78,6 +79,7 @@ limitations under the License. -->
:right="true" :right="true"
:disabledDate="disabledDate" :disabledDate="disabledDate"
:format="format" :format="format"
:maxRange="maxRange"
@ok="ok" @ok="ok"
@setDates="setDates" @setDates="setDates"
/> />
@ -112,7 +114,7 @@ limitations under the License. -->
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import DateCalendar from "./DateCalendar.vue"; import DateCalendar from "./DateCalendar.vue";
import { useTimeoutFn } from "@/hooks/useTimeout"; import { useTimeoutFn } from "@/hooks/useTimeout";
/*global defineProps, defineEmits*/ /*global PropType, defineProps, defineEmits*/
const datepicker = ref(null); const datepicker = ref(null);
const { t } = useI18n(); const { t } = useI18n();
const show = ref<boolean>(false); const show = ref<boolean>(false);
@ -149,6 +151,7 @@ limitations under the License. -->
type: Boolean, type: Boolean,
default: false, default: false,
}, },
maxRange: { type: Array as PropType<Date[]>, default: () => [] },
}); });
const emit = defineEmits(["clear", "input", "confirm", "cancel"]); const emit = defineEmits(["clear", "input", "confirm", "cancel"]);
const local = computed(() => { const local = computed(() => {

View File

@ -43,6 +43,7 @@ limitations under the License. -->
<span class="red" v-show="timeRange">{{ t("timeTips") }}</span> <span class="red" v-show="timeRange">{{ t("timeTips") }}</span>
<TimePicker <TimePicker
:value="[appStore.durationRow.start, appStore.durationRow.end]" :value="[appStore.durationRow.start, appStore.durationRow.end]"
:maxRange="appStore.maxRange"
position="bottom" position="bottom"
format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm"
@input="changeTimeRange" @input="changeTimeRange"
@ -212,10 +213,35 @@ limitations under the License. -->
} }
async function getMetricsTTL() { async function getMetricsTTL() {
const resp = await appStore.queryMetricsTTL(); // const resp = await appStore.queryMetricsTTL();
// const gap = appStore.duration.end.getTime() - appStore.duration.start.getTime(); // mock data
// const dates: Date[] = [new Date(new Date().getTime() - gap), new Date()]; const data = {
// appStore.setDuration(timeFormat(dates)); minute: 20,
hour: 2,
day: 3,
coldMinute: 10,
coldHour: 10,
coldDay: 9,
};
if (coldStage.value) {
handleMetricsTTL({
minute: data.coldMinute,
hour: data.coldHour,
day: data.coldDay,
});
} else {
handleMetricsTTL({
minute: data.minute,
hour: data.hour,
day: data.day,
});
}
}
function handleMetricsTTL(params: { minute: number; hour: number; day: number }) {
const gap = (params.day + 1) * 24 * 60 * 60 * 1000 + params.hour * 60 * 60 * 1000 + params.minute * 60 * 1000;
const dates: Date[] = [new Date(new Date().getTime() - gap), new Date()];
appStore.setMaxRange(dates);
} }
function getNavPaths() { function getNavPaths() {

View File

@ -38,6 +38,7 @@ interface AppState {
allMenus: MenuOptions[]; allMenus: MenuOptions[];
theme: string; theme: string;
coldStageMode: boolean; coldStageMode: boolean;
maxRange: Date[];
} }
export const appStore = defineStore({ export const appStore = defineStore({
@ -60,6 +61,7 @@ export const appStore = defineStore({
allMenus: [], allMenus: [],
theme: Themes.Dark, theme: Themes.Dark,
coldStageMode: false, coldStageMode: false,
maxRange: [],
}), }),
getters: { getters: {
duration(): Duration { duration(): Duration {
@ -124,6 +126,9 @@ export const appStore = defineStore({
updateDurationRow(data: Duration) { updateDurationRow(data: Duration) {
this.durationRow = data; this.durationRow = data;
}, },
setMaxRange(times: Date[]) {
this.maxRange = times;
},
setTheme(data: string) { setTheme(data: string) {
this.theme = data; this.theme = data;
}, },

View File

@ -94,7 +94,6 @@ limitations under the License. -->
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
import timeFormat from "@/utils/timeFormat";
import ConditionTags from "@/views/components/ConditionTags.vue"; import ConditionTags from "@/views/components/ConditionTags.vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { EntityType, QueryOrders, Status } from "../../data"; import { EntityType, QueryOrders, Status } from "../../data";
@ -265,7 +264,7 @@ limitations under the License. -->
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
} }
} }
function changeTimeRange(val: Date[]) { function changeTimeRange() {
// duration.value = timeFormat(val); // duration.value = timeFormat(val);
} }
onUnmounted(() => { onUnmounted(() => {