fix [P-47]: исправления выбора дат в форме
This commit is contained in:
1 parent
6013c4ed0f
commit
678a683e4d
3 files changed
+84
-74
No files matched your search
@@ -29,7 +29,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted, watch } from 'vue';
|
||||||
import { useWeekendsStore } from '@/store/WeekendsStore';
|
import { useWeekendsStore } from '@/store/WeekendsStore';
|
||||||
import EventCreate from '@/components/calendar_of_events/event-create.vue';
|
import EventCreate from '@/components/calendar_of_events/event-create.vue';
|
||||||
import CustomCalendar from '@/components/calendar_of_events/UI_calendar/CustomCalendar.vue';
|
import CustomCalendar from '@/components/calendar_of_events/UI_calendar/CustomCalendar.vue';
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
<v-col lg="3" :class="`order-${order[0]}`">
|
<v-col lg="3" :class="`order-${order[0]}`">
|
||||||
<v-menu
|
<v-menu
|
||||||
v-model="menudate"
|
v-model="menudate"
|
||||||
:close-on-content-click="false"
|
|
||||||
:nudge-right="40"
|
:nudge-right="40"
|
||||||
transition="scale-transition"
|
transition="scale-transition"
|
||||||
offset-y
|
offset-y
|
||||||
|
:close-on-content-click="false"
|
||||||
>
|
>
|
||||||
<template v-slot:activator="{ props }">
|
<template v-slot:activator="{ props }">
|
||||||
<v-textarea
|
<v-textarea
|
||||||
@@ -21,12 +21,7 @@
|
|||||||
hide-details
|
hide-details
|
||||||
>
|
>
|
||||||
<template v-slot:prepend-inner>
|
<template v-slot:prepend-inner>
|
||||||
<v-icon
|
<v-icon v-bind="props" icon="mdi-calendar-today" color="cyan-darken-3" size="x-small" />
|
||||||
v-bind="props"
|
|
||||||
icon="mdi-calendar-today"
|
|
||||||
color="cyan-darken-3"
|
|
||||||
size="x-small"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</v-textarea>
|
</v-textarea>
|
||||||
</template>
|
</template>
|
||||||
@@ -38,7 +33,7 @@
|
|||||||
hide-header
|
hide-header
|
||||||
border
|
border
|
||||||
no-time
|
no-time
|
||||||
:max="order[0] == 2 ? new Date(limitation) : endMax()"
|
:max="endMax()"
|
||||||
:min="order[0] == 2 ? startMin() : minData()"
|
:min="order[0] == 2 ? startMin() : minData()"
|
||||||
/>
|
/>
|
||||||
</v-locale-provider>
|
</v-locale-provider>
|
||||||
@@ -66,29 +61,24 @@
|
|||||||
activator="parent"
|
activator="parent"
|
||||||
transition="scale-transition"
|
transition="scale-transition"
|
||||||
>
|
>
|
||||||
<v-time-picker
|
<v-time-picker v-if="menutime" v-model="timeEvent" full-width format="24hr"></v-time-picker>
|
||||||
v-if="menutime"
|
|
||||||
v-model="timeEvent"
|
|
||||||
full-width
|
|
||||||
format="24hr"
|
|
||||||
></v-time-picker>
|
|
||||||
</v-menu>
|
</v-menu>
|
||||||
</v-col>
|
</v-col>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed } from 'vue';
|
||||||
import { formatComa, formatDash } from "@/utils/universal_functions";
|
import { formatComa, formatDash } from '@/utils/universal_functions';
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
dateEvent: {
|
dateEvent: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
limitation: {
|
limitation: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
order: {
|
order: {
|
||||||
@@ -111,7 +101,7 @@ export default {
|
|||||||
|
|
||||||
const propsDateEvent = computed({
|
const propsDateEvent = computed({
|
||||||
get: () => new Date(props.dateEvent),
|
get: () => new Date(props.dateEvent),
|
||||||
set: (value) => emit("update:dateEvent", value),
|
set: (value) => emit('update:dateEvent', value),
|
||||||
});
|
});
|
||||||
|
|
||||||
const modelDate = computed({
|
const modelDate = computed({
|
||||||
@@ -119,77 +109,100 @@ export default {
|
|||||||
return propsDateEvent.value;
|
return propsDateEvent.value;
|
||||||
},
|
},
|
||||||
set(newValue) {
|
set(newValue) {
|
||||||
creatwdDate(newValue, timeEvent.value);
|
createdDate(newValue, timeEvent.value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const timeEvent = computed({
|
const timeEvent = computed({
|
||||||
get() {
|
get() {
|
||||||
return `${new Date(propsDateEvent.value).getHours()}:${String(
|
return `${new Date(propsDateEvent.value).getHours()}:${String(
|
||||||
new Date(propsDateEvent.value).getMinutes()
|
new Date(propsDateEvent.value).getMinutes(),
|
||||||
).padStart(2, "0")}`;
|
).padStart(2, '0')}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
set(newValue) {
|
set(newValue) {
|
||||||
creatwdDate(modelDate.value, newValue);
|
createdDate(modelDate.value, newValue);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const creatwdDate = (date, time) => {
|
// const creatwdDate = (date, time) => {
|
||||||
let tzero = time.split(":");
|
// let tzero = time.split(':');
|
||||||
time = tzero[0].padStart(2, "0") + ":" + tzero[1];
|
// time = tzero[0].padStart(2, '0') + ':' + tzero[1];
|
||||||
|
|
||||||
|
// if (props.order[0] == 4) {
|
||||||
|
// if (time == '0:00') {
|
||||||
|
// propsDateEvent.value = date;
|
||||||
|
// } else if (new Date(formatDash(date) + 'T' + time) >= new Date(props.limitation)) {
|
||||||
|
// propsDateEvent.value = new Date(formatDash(date) + 'T' + time);
|
||||||
|
// } else {
|
||||||
|
// propsDateEvent.value = new Date(props.limitation);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// propsDateEvent.value = time == '0:00' ? date : new Date(formatDash(date) + 'T' + time);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
const createdDate = (date, time) => {
|
||||||
|
const [hours, minutes] = time.split(':').map(Number);
|
||||||
|
const newDate = new Date(date);
|
||||||
|
newDate.setHours(hours, minutes, 0, 0);
|
||||||
|
|
||||||
if (props.order[0] == 4) {
|
if (props.order[0] == 4) {
|
||||||
if (time == "0:00") {
|
// Для окончания: проверяем чтобы не было раньше начала
|
||||||
propsDateEvent.value = date;
|
const startDate = new Date(props.limitation);
|
||||||
} else if (
|
propsDateEvent.value = newDate >= startDate ? newDate : startDate;
|
||||||
new Date(formatDash(date) + "T" + time) >= new Date(props.limitation)
|
|
||||||
) {
|
|
||||||
propsDateEvent.value = new Date(formatDash(date) + "T" + time);
|
|
||||||
} else {
|
} else {
|
||||||
propsDateEvent.value = new Date(props.limitation);
|
// Для начала: просто устанавливаем дату
|
||||||
}
|
propsDateEvent.value = newDate;
|
||||||
} else {
|
|
||||||
propsDateEvent.value =
|
|
||||||
time == "0:00" ? date : new Date(formatDash(date) + "T" + time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menudate.value = false;
|
||||||
|
menutime.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const minData = () => {
|
const minData = () => {
|
||||||
let h = `${new Date(props.limitation).getHours()}:${String(
|
// let h = `${new Date(props.limitation).getHours()}:${String(
|
||||||
new Date(props.limitation).getMinutes()
|
// new Date(props.limitation).getMinutes()
|
||||||
).padStart(2, "0")}`;
|
// ).padStart(2, "0")}`;
|
||||||
let min =
|
// let min =
|
||||||
h == "0:00"
|
// h == "0:00"
|
||||||
? new Date(props.limitation)
|
// ? new Date(props.limitation)
|
||||||
: new Date(
|
// : new Date(
|
||||||
new Date(props.limitation).setDate(
|
// new Date(props.limitation).setDate(
|
||||||
new Date(props.limitation).getDate() - 1
|
// new Date(props.limitation).getDate() - 1
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
return new Date(min);
|
// return new Date(min);
|
||||||
|
return new Date(props.limitation);
|
||||||
};
|
};
|
||||||
|
|
||||||
const startMin = () => {
|
const startMin = () => {
|
||||||
if (props.rule == 2) {
|
// if (props.rule == 2) {
|
||||||
return new Date(
|
// return new Date(
|
||||||
new Date(props.limitation).setDate(
|
// new Date(props.limitation).setDate(
|
||||||
new Date(props.limitation).getDate() - 7
|
// new Date(props.limitation).getDate() - 7
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
|
return new Date(); // ← По умолчанию: нельзя выбрать прошедшие даты
|
||||||
};
|
};
|
||||||
|
|
||||||
const endMax = () => {
|
const endMax = () => {
|
||||||
if (props.rule == 2) {
|
// if (props.rule == 2) {
|
||||||
|
// return new Date(
|
||||||
|
// new Date(props.limitation).setDate(new Date(props.limitation).getDate() + 6),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
if (props.order[0] == 2 && props.rule == 2) {
|
||||||
|
// Для недельного повторения: ограничение сверху +6 дней от начала
|
||||||
return new Date(
|
return new Date(
|
||||||
new Date(props.limitation).setDate(
|
new Date(props.limitation).setDate(new Date(props.limitation).getDate() + 6),
|
||||||
new Date(props.limitation).getDate() + 6
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false; // ← Без ограничения сверху
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -52,6 +52,8 @@
|
|||||||
return-object
|
return-object
|
||||||
:rules="rules.calendar"
|
:rules="rules.calendar"
|
||||||
:disabled="'id' in propsEvent.event"
|
:disabled="'id' in propsEvent.event"
|
||||||
|
clearable
|
||||||
|
auto-select-first
|
||||||
>
|
>
|
||||||
<template v-slot:selection="{ item }">
|
<template v-slot:selection="{ item }">
|
||||||
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
||||||
@@ -59,17 +61,13 @@
|
|||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:item="{ item }">
|
<template v-slot:item="{ item, props }">
|
||||||
<v-list-item
|
<v-list-item :key="item.raw.id" :value="item" color="primary" v-bind="props"
|
||||||
:key="item.title"
|
@click.stop="myCalendar = item.raw" >
|
||||||
:value="item"
|
|
||||||
color="primary"
|
|
||||||
@click.stop="myCalendar = item.raw"
|
|
||||||
>
|
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
||||||
</template>
|
</template>
|
||||||
{{ item.title }}
|
<!-- {{ item.title }} -->
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</template>
|
</template>
|
||||||
</v-autocomplete>
|
</v-autocomplete>
|
||||||
@@ -213,6 +211,7 @@ export default {
|
|||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const createDialog = ref(null);
|
const createDialog = ref(null);
|
||||||
|
const calendarAutocompleteRef = ref(null);
|
||||||
|
|
||||||
const propsEvent = computed({
|
const propsEvent = computed({
|
||||||
get: () => {
|
get: () => {
|
||||||
@@ -223,9 +222,6 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ВАЛИДАЦИЯ
|
// ВАЛИДАЦИЯ
|
||||||
|
|
||||||
const isFormValid = ref(false);
|
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
name: [
|
name: [
|
||||||
(val) => !!val || 'Поле обязательно для заполнения',
|
(val) => !!val || 'Поле обязательно для заполнения',
|
||||||
@@ -441,6 +437,7 @@ export default {
|
|||||||
|
|
||||||
// Computed property с защитой от undefined
|
// Computed property с защитой от undefined
|
||||||
const safeCalendars = computed(() => props.myCalendars || []);
|
const safeCalendars = computed(() => props.myCalendars || []);
|
||||||
|
|
||||||
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
|
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
|
||||||
|
|
||||||
// Автовыбор при появлении данных
|
// Автовыбор при появлении данных
|
||||||
|
|||||||
Reference in new issue
Block a user