fix [P-290]: фикс повтора событий
This commit is contained in:
1 parent
225f2fa50a
commit
ae46081e18
4 files changed
+69
-59
No files matched your search
@@ -4,15 +4,14 @@
|
|||||||
label="Добавить файл (размер файла не должен превышать 2Мб)"
|
label="Добавить файл (размер файла не должен превышать 2Мб)"
|
||||||
chips
|
chips
|
||||||
multiple
|
multiple
|
||||||
v-model="newFiles"
|
v-model="localNewFiles"
|
||||||
density="compact"
|
density="compact"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@update:modelValue="handleFilesChange"
|
|
||||||
:error-messages="errorMessages"
|
:error-messages="errorMessages"
|
||||||
|
@update:model-value="handleFilesChange"
|
||||||
>
|
>
|
||||||
<template v-slot:selection>
|
<template v-slot:selection>
|
||||||
|
<template v-for="(file, index) in localNewFiles" :key="getFileKey(file, index)">
|
||||||
<template v-for="(file, index) in newFiles" :key="index">
|
|
||||||
<v-chip
|
<v-chip
|
||||||
class="me-2 mb-1"
|
class="me-2 mb-1"
|
||||||
color="teal-darken-3"
|
color="teal-darken-3"
|
||||||
@@ -28,7 +27,7 @@
|
|||||||
</v-chip>
|
</v-chip>
|
||||||
</template>
|
</template>
|
||||||
<!-- <span v-if="newFiles.length > 0" class="text-caption text-grey ms-2">
|
<!-- <span v-if="newFiles.length > 0" class="text-caption text-grey ms-2">
|
||||||
{{ newFiles.length }}/5
|
{{ localNewFiles.length }}/5
|
||||||
</span> -->
|
</span> -->
|
||||||
</template>
|
</template>
|
||||||
</v-file-input>
|
</v-file-input>
|
||||||
@@ -71,11 +70,16 @@ export default {
|
|||||||
emits: ['update:files', 'postFiles'],
|
emits: ['update:files', 'postFiles'],
|
||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const newFiles = ref([]);
|
const localNewFiles = ref([]);
|
||||||
const errorMessages = ref([]);
|
const errorMessages = ref([]);
|
||||||
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2 МБ
|
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2 МБ
|
||||||
const MAX_NEW_FILES = 5;
|
const MAX_NEW_FILES = 5;
|
||||||
|
|
||||||
|
// const newFiles = computed({
|
||||||
|
// get: () => props.newFiles,
|
||||||
|
// set: (value) => emit('update:newFiles', value),
|
||||||
|
// });
|
||||||
|
|
||||||
const formatFileSize = (bytes) => {
|
const formatFileSize = (bytes) => {
|
||||||
if (bytes === 0) return '0 Б';
|
if (bytes === 0) return '0 Б';
|
||||||
const k = 1024;
|
const k = 1024;
|
||||||
@@ -87,8 +91,9 @@ export default {
|
|||||||
const validateFiles = (files) => {
|
const validateFiles = (files) => {
|
||||||
errorMessages.value = [];
|
errorMessages.value = [];
|
||||||
|
|
||||||
|
const totalFiles = localNewFiles.value.length + files.length;
|
||||||
// Проверка количества
|
// Проверка количества
|
||||||
if (files.length > MAX_NEW_FILES) {
|
if (totalFiles > MAX_NEW_FILES) {
|
||||||
errorMessages.value.push(`Можно добавить не более ${MAX_NEW_FILES} файлов`);
|
errorMessages.value.push(`Можно добавить не более ${MAX_NEW_FILES} файлов`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -104,10 +109,15 @@ export default {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Существующие файлы из event.files
|
// Существующие файлы из event.files
|
||||||
const existingFiles = computed(() => (Array.isArray(props.files) ? props.files : []));
|
const existingFiles = computed(() => (Array.isArray(props.files) ? props.files : []));
|
||||||
|
|
||||||
|
const getFileKey = (file, index) => {
|
||||||
|
return file instanceof File
|
||||||
|
? `${file.name}-${file.size}-${file.lastModified}`
|
||||||
|
: file.id || index;
|
||||||
|
};
|
||||||
|
|
||||||
// Получаем имя файла из объекта файла
|
// Получаем имя файла из объекта файла
|
||||||
const getFileName = (fileData) => {
|
const getFileName = (fileData) => {
|
||||||
if (fileData instanceof File) {
|
if (fileData instanceof File) {
|
||||||
@@ -165,18 +175,22 @@ export default {
|
|||||||
// Обработка изменения новых файлов
|
// Обработка изменения новых файлов
|
||||||
const handleFilesChange = (files) => {
|
const handleFilesChange = (files) => {
|
||||||
if (!files) {
|
if (!files) {
|
||||||
newFiles.value = [];
|
// localNewFiles.value = [];
|
||||||
emit('postFiles', []);
|
emit('postFiles', []);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Валидация
|
const validFiles = files.filter((file) => file instanceof File);
|
||||||
if (!validateFiles(files)) {
|
|
||||||
|
if (validFiles.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorMessages.value = [];
|
// Валидация
|
||||||
// newFiles.value = [...files];
|
if (!validateFiles(validFiles)) {
|
||||||
emit('postFiles', files);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('postFiles', validFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Удаление существующего файла
|
// Удаление существующего файла
|
||||||
@@ -185,7 +199,7 @@ export default {
|
|||||||
// Создаем копию event и удаляем файл
|
// Создаем копию event и удаляем файл
|
||||||
const updatedFiles = props.files.filter((file) => file.id !== fileId);
|
const updatedFiles = props.files.filter((file) => file.id !== fileId);
|
||||||
// props.files = updatedFiles;
|
// props.files = updatedFiles;
|
||||||
emit('update:files', [...updatedFiles]);
|
emit('update:files', updatedFiles);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка при удалении файла:', error);
|
console.error('Ошибка при удалении файла:', error);
|
||||||
}
|
}
|
||||||
@@ -193,14 +207,12 @@ export default {
|
|||||||
|
|
||||||
// Удаление нового файла (еще не загруженного)
|
// Удаление нового файла (еще не загруженного)
|
||||||
const removeNewFile = (index) => {
|
const removeNewFile = (index) => {
|
||||||
const updatedFiles = [...newFiles.value];
|
localNewFiles.value.splice(index, 1);
|
||||||
updatedFiles.splice(index, 1);
|
emit('postFiles', localNewFiles.value);
|
||||||
newFiles.value = updatedFiles;
|
|
||||||
emit('postFiles', updatedFiles);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
newFiles,
|
localNewFiles,
|
||||||
existingFiles,
|
existingFiles,
|
||||||
handleFilesChange,
|
handleFilesChange,
|
||||||
removeExistingFile,
|
removeExistingFile,
|
||||||
@@ -210,6 +222,7 @@ export default {
|
|||||||
formatFileSize,
|
formatFileSize,
|
||||||
errorMessages,
|
errorMessages,
|
||||||
validateFiles,
|
validateFiles,
|
||||||
|
getFileKey,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,15 +6,7 @@
|
|||||||
<v-col class="d-flex flex-column">
|
<v-col class="d-flex flex-column">
|
||||||
<custom-calendar @openEventDialog="openEventDialog" />
|
<custom-calendar @openEventDialog="openEventDialog" />
|
||||||
</v-col>
|
</v-col>
|
||||||
<!--
|
|
||||||
<v-navigation-drawer
|
|
||||||
floating
|
|
||||||
permanent
|
|
||||||
location="right"
|
|
||||||
rail-width="400"
|
|
||||||
rail
|
|
||||||
>
|
|
||||||
</v-navigation-drawer> -->
|
|
||||||
<v-dialog v-model="showEventDialog" max-width="700">
|
<v-dialog v-model="showEventDialog" max-width="700">
|
||||||
<event-create
|
<event-create
|
||||||
@closeDialog="closeEventDialog"
|
@closeDialog="closeEventDialog"
|
||||||
@@ -22,8 +14,9 @@
|
|||||||
:myCalendars="calendarStore.myCalendars"
|
:myCalendars="calendarStore.myCalendars"
|
||||||
@getCalendar="getCalendar"
|
@getCalendar="getCalendar"
|
||||||
@update:eventCalendar="eventFromCalendar = $event"
|
@update:eventCalendar="eventFromCalendar = $event"
|
||||||
|
ref="createEvents"
|
||||||
|
:key="eventKey"
|
||||||
/>
|
/>
|
||||||
<!-- ref="createEvents" -->
|
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
</v-row>
|
</v-row>
|
||||||
</template>
|
</template>
|
||||||
@@ -48,6 +41,7 @@ export default {
|
|||||||
const MyMonth = ref(selectdate.value.getMonth() + 1);
|
const MyMonth = ref(selectdate.value.getMonth() + 1);
|
||||||
const calendarForMy = ref([]);
|
const calendarForMy = ref([]);
|
||||||
const eventFromCalendar = ref({});
|
const eventFromCalendar = ref({});
|
||||||
|
const eventKey = ref(0);
|
||||||
|
|
||||||
const calendarStore = useCalendarStore();
|
const calendarStore = useCalendarStore();
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
@@ -112,6 +106,7 @@ export default {
|
|||||||
|
|
||||||
const openEventDialog = (selectedEvent) => {
|
const openEventDialog = (selectedEvent) => {
|
||||||
getEvent(selectedEvent.event.id);
|
getEvent(selectedEvent.event.id);
|
||||||
|
|
||||||
calendarStore.openEventDialog();
|
calendarStore.openEventDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,6 +117,7 @@ export default {
|
|||||||
|
|
||||||
const closeEventDialog = () => {
|
const closeEventDialog = () => {
|
||||||
calendarStore.closeEventDialog();
|
calendarStore.closeEventDialog();
|
||||||
|
|
||||||
eventFromCalendar.value = createEmptyEvent(); // Очищаем событие
|
eventFromCalendar.value = createEmptyEvent(); // Очищаем событие
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,6 +129,16 @@ export default {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => calendarStore.showEventDialog,
|
||||||
|
(newValue) => {
|
||||||
|
if (!newValue) {
|
||||||
|
// Когда диалог закрывается (любым способом), очищаем данные
|
||||||
|
eventFromCalendar.value = createEmptyEvent();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedDate,
|
selectedDate,
|
||||||
getMonth,
|
getMonth,
|
||||||
@@ -149,6 +155,7 @@ export default {
|
|||||||
closeEventDialog,
|
closeEventDialog,
|
||||||
openEventDialog,
|
openEventDialog,
|
||||||
createEmptyEvent,
|
createEmptyEvent,
|
||||||
|
eventKey,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -145,12 +145,18 @@
|
|||||||
</v-row>
|
</v-row>
|
||||||
</v-col></v-row
|
</v-col></v-row
|
||||||
>
|
>
|
||||||
<v-row no-gutters class="align-start d-flex pt-3" style="min-height: 150px">
|
<v-row
|
||||||
|
no-gutters
|
||||||
|
class="align-start d-flex pt-3"
|
||||||
|
style="min-height: 180px; max-height: 180px"
|
||||||
|
>
|
||||||
<v-col class="text-body-2 text-text_grey pb-5 pt-3" lg="2"> Файлы </v-col>
|
<v-col class="text-body-2 text-text_grey pb-5 pt-3" lg="2"> Файлы </v-col>
|
||||||
|
|
||||||
<uploading-file
|
<uploading-file
|
||||||
:files="propsEvent.event.files"
|
:files="propsEvent.event.files"
|
||||||
|
:new-files="newFiles"
|
||||||
@update:files="propsEvent.event.files = $event"
|
@update:files="propsEvent.event.files = $event"
|
||||||
|
@update:new-files="newFiles = $event"
|
||||||
@postFiles="postFiles"
|
@postFiles="postFiles"
|
||||||
/>
|
/>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -337,18 +343,9 @@ export default {
|
|||||||
(newEvent) => {
|
(newEvent) => {
|
||||||
if (!newEvent || !safeCalendars.value.length) return;
|
if (!newEvent || !safeCalendars.value.length) return;
|
||||||
|
|
||||||
const isNewEvent = !newEvent.event.id;
|
|
||||||
|
|
||||||
if (isNewEvent) {
|
|
||||||
// НОВОЕ СОБЫТИЕ - первый календарь из списка или календарь по умолчанию
|
|
||||||
myCalendar.value = safeCalendars.value[0];
|
|
||||||
} else {
|
|
||||||
// РЕДАКТИРОВАНИЕ - календарь из события
|
// РЕДАКТИРОВАНИЕ - календарь из события
|
||||||
const eventCalendar = safeCalendars.value.find(
|
const eventCalendar = safeCalendars.value.find((cal) => cal.id === newEvent.event.calendar);
|
||||||
(cal) => cal.id === newEvent.event.calendar,
|
|
||||||
);
|
|
||||||
myCalendar.value = eventCalendar || safeCalendars.value[0];
|
myCalendar.value = eventCalendar || safeCalendars.value[0];
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ immediate: true, deep: true },
|
{ immediate: true, deep: true },
|
||||||
);
|
);
|
||||||
@@ -446,13 +443,10 @@ export default {
|
|||||||
emit('closeDialog');
|
emit('closeDialog');
|
||||||
};
|
};
|
||||||
|
|
||||||
const files = ref([]);
|
const newFiles = ref([]);
|
||||||
|
|
||||||
const postFiles = (newFiles) => {
|
const postFiles = (updatedFiles) => {
|
||||||
files.value = newFiles;
|
newFiles.value = updatedFiles;
|
||||||
|
|
||||||
const updatedFiles = [...propsEvent.value.event.files, ...newFiles];
|
|
||||||
propsEvent.value.event.files = updatedFiles;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const returnIdParticant = (idPart) => {
|
const returnIdParticant = (idPart) => {
|
||||||
@@ -491,11 +485,16 @@ export default {
|
|||||||
|
|
||||||
let postEvent = new FormData();
|
let postEvent = new FormData();
|
||||||
postEvent.append('event', JSON.stringify({ ...propsEvent.value.event, files: [] }));
|
postEvent.append('event', JSON.stringify({ ...propsEvent.value.event, files: [] }));
|
||||||
if (propsEvent.value.event.files !== null) {
|
// if (propsEvent.value.event.files !== null) {
|
||||||
files.value.forEach((e) => postEvent.append('files', e));
|
// files.value.forEach((e) => postEvent.append('files', e));
|
||||||
|
// }
|
||||||
|
if (newFiles.value.length > 0) {
|
||||||
|
newFiles.value.forEach((file) => {
|
||||||
|
postEvent.append('files', file);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(postEvent);
|
console.log('Отправляемые файлы:', newFiles.value);
|
||||||
|
|
||||||
axiosApiInstance.post('api/calendar_of_events/my_events/', postEvent).then((result) => {
|
axiosApiInstance.post('api/calendar_of_events/my_events/', postEvent).then((result) => {
|
||||||
feedalert.alert = true;
|
feedalert.alert = true;
|
||||||
|
|||||||
@@ -21,15 +21,6 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
|||||||
// Getters
|
// Getters
|
||||||
const formattedSelectedDate = computed(() => selectedDate.value.toISOString().split('T')[0]);
|
const formattedSelectedDate = computed(() => selectedDate.value.toISOString().split('T')[0]);
|
||||||
|
|
||||||
// const myCalendars = computed(() =>
|
|
||||||
// calendars.value
|
|
||||||
// .filter((e) => e.author === accountStore.user.is_idEmployee)
|
|
||||||
// .map((calendar) => ({
|
|
||||||
// ...calendar,
|
|
||||||
// // Видимый, если его нет в массиве скрытых
|
|
||||||
// visible: !hiddenCalendarIds.value.includes(calendar.id),
|
|
||||||
// })),
|
|
||||||
// );
|
|
||||||
const myCalendars = computed(() => {
|
const myCalendars = computed(() => {
|
||||||
const userId = accountStore.user.is_idEmployee;
|
const userId = accountStore.user.is_idEmployee;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user