changes
This commit is contained in:
@@ -0,0 +1,315 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background-2">
|
||||
<!-- Header -->
|
||||
<div class="border-b border-line-2 bg-layer/50 backdrop-blur-sm sticky top-0 z-10 h-16">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-full">
|
||||
<div class="flex items-center h-full gap-3">
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="p-2 text-muted-foreground-1 hover:text-foreground hover:bg-muted-hover rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="arrow-left" size="5" />
|
||||
</a>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center">
|
||||
<DashboardIcon name="plus" size="5" class="text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-lg font-medium text-foreground">Добавление расписания</h1>
|
||||
<p class="text-xs text-muted-foreground-1">Загрузите файл расписания для учебной группы</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
||||
<!-- Flash Messages -->
|
||||
<transition
|
||||
enter-active-class="transition duration-300 ease-out"
|
||||
enter-from-class="opacity-0 -translate-y-2"
|
||||
enter-to-class="opacity-100 translate-y-0"
|
||||
leave-active-class="transition duration-200 ease-in"
|
||||
leave-from-class="opacity-100 translate-y-0"
|
||||
leave-to-class="opacity-0 -translate-y-2"
|
||||
>
|
||||
<div v-if="$page.props.flash?.error" class="mb-4 p-4 bg-rose-500/10 border border-rose-500/20 rounded-lg">
|
||||
<div class="flex items-start gap-3">
|
||||
<DashboardIcon name="exclamation-circle" size="5" class="text-rose-600 flex-shrink-0 mt-0.5" />
|
||||
<span class="text-sm text-foreground font-medium">{{ $page.props.flash.error }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<!-- Form Card -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs">
|
||||
<div class="p-6 border-b border-line-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="document" size="5" class="text-primary" />
|
||||
<h2 class="text-base font-medium text-foreground">Основная информация</h2>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground-1 mt-1">
|
||||
Заполните данные о расписании
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="submit" class="p-6">
|
||||
<div class="space-y-6">
|
||||
<!-- Educational Group -->
|
||||
<div>
|
||||
<label for="educational_group_id" class="block text-sm font-medium text-foreground mb-2">
|
||||
Учебная группа <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
id="educational_group_id"
|
||||
v-model="form.educational_group_id"
|
||||
:class="[
|
||||
'w-full px-4 py-2.5 bg-surface border rounded-lg text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all',
|
||||
errors.educational_group_id ? 'border-rose-500' : 'border-layer-line focus:border-primary'
|
||||
]"
|
||||
>
|
||||
<option value="">Выберите группу</option>
|
||||
<option v-for="group in educationalGroups" :key="group.id" :value="group.id">
|
||||
{{ group.title }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="errors.educational_group_id" class="mt-1.5 text-xs text-rose-500">{{ errors.educational_group_id }}</p>
|
||||
</div>
|
||||
|
||||
<!-- File Upload -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-foreground mb-2">
|
||||
Файл расписания <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<div class="space-y-3">
|
||||
<!-- Title Input -->
|
||||
<input
|
||||
v-model="form.file[0].title"
|
||||
type="text"
|
||||
placeholder="Название файла (например: Расписание на весенний семестр 2024)"
|
||||
:class="[
|
||||
'w-full px-4 py-2.5 bg-surface border rounded-lg text-sm text-foreground placeholder-muted-foreground-2 focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all',
|
||||
errors['file.0.title'] ? 'border-rose-500' : 'border-layer-line focus:border-primary'
|
||||
]"
|
||||
/>
|
||||
<p v-if="errors['file.0.title']" class="text-xs text-rose-500">{{ errors['file.0.title'] }}</p>
|
||||
|
||||
<!-- File Input -->
|
||||
<div
|
||||
class="relative border-2 border-dashed rounded-lg p-6 transition-all"
|
||||
:class="[
|
||||
isDragging ? 'border-primary bg-primary/5' : 'border-layer-line hover:border-primary/50',
|
||||
errors['file.0.path'] ? 'border-rose-500' : ''
|
||||
]"
|
||||
@dragover.prevent="isDragging = true"
|
||||
@dragleave="isDragging = false"
|
||||
@drop.prevent="handleDrop"
|
||||
>
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept=".pdf,application/pdf"
|
||||
class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||
:class="{ 'cursor-default': errors['file.0.path'] }"
|
||||
@change="handleFileChange"
|
||||
/>
|
||||
<div class="text-center">
|
||||
<DashboardIcon name="cloud-arrow-up" size="12" class="mx-auto text-muted-foreground-2" />
|
||||
<p class="mt-2 text-sm text-foreground">
|
||||
<span class="font-medium text-primary">Нажмите для загрузки</span> или перетащите файл
|
||||
</p>
|
||||
<p class="mt-1 text-xs text-muted-foreground-1">
|
||||
Только PDF файлы, макс. размер 10MB
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selected File Preview -->
|
||||
<div v-if="selectedFile" class="flex items-center gap-3 p-3 bg-surface border border-layer-line rounded-lg">
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-rose-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="document" size="5" class="text-rose-500" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-foreground truncate">{{ selectedFile.name }}</p>
|
||||
<p class="text-xs text-muted-foreground-1">{{ formatFileSize(selectedFile.size) }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@click="removeFile"
|
||||
class="p-2 text-muted-foreground-1 hover:text-rose-500 hover:bg-rose-500/10 rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="x-mark" size="4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="errors['file.0.path']" class="text-xs text-rose-500">{{ errors['file.0.path'] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end gap-3 mt-8 pt-6 border-t border-line-2">
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="inline-flex items-center gap-2 px-4 py-2.5 bg-surface border border-layer-line text-foreground text-sm font-medium rounded-lg hover:bg-muted-hover transition-all"
|
||||
>
|
||||
Отмена
|
||||
</a>
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="processing || !selectedFile"
|
||||
class="inline-flex items-center gap-2 px-4 py-2.5 bg-primary text-white text-sm font-medium rounded-lg hover:bg-primary-hover transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg v-if="processing" class="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||
</svg>
|
||||
<DashboardIcon v-else name="check" size="4" />
|
||||
{{ processing ? 'Сохранение...' : 'Создать расписание' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DashboardIcon from '../Components/DashboardIcon.vue';
|
||||
|
||||
export default {
|
||||
name: 'ScheduleCreate',
|
||||
components: {
|
||||
DashboardIcon,
|
||||
},
|
||||
|
||||
props: {
|
||||
educationalGroups: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
educationForms: {
|
||||
type: Array,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
educational_group_id: '',
|
||||
file: [
|
||||
{
|
||||
title: '',
|
||||
path: null
|
||||
}
|
||||
]
|
||||
},
|
||||
selectedFile: null,
|
||||
isDragging: false,
|
||||
errors: {},
|
||||
processing: false
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.SET_DOCUMENT_TITLE('Создание расписания');
|
||||
},
|
||||
|
||||
watch: {
|
||||
'form.file[0].path'(newFile) {
|
||||
if (newFile && !this.selectedFile) {
|
||||
this.selectedFile = newFile;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleFileChange(event) {
|
||||
const file = event.target.files[0];
|
||||
if (file) {
|
||||
this.validateFile(file);
|
||||
}
|
||||
},
|
||||
|
||||
handleDrop(event) {
|
||||
this.isDragging = false;
|
||||
const file = event.dataTransfer.files[0];
|
||||
if (file) {
|
||||
this.validateFile(file);
|
||||
}
|
||||
},
|
||||
|
||||
validateFile(file) {
|
||||
// Проверка типа файла
|
||||
if (file.type !== 'application/pdf') {
|
||||
this.errors['file.0.path'] = 'Разрешены только PDF файлы';
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверка размера (10MB)
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
this.errors['file.0.path'] = 'Размер файла не должен превышать 10MB';
|
||||
return;
|
||||
}
|
||||
|
||||
this.errors['file.0.path'] = '';
|
||||
this.selectedFile = file;
|
||||
this.form.file[0].path = file;
|
||||
|
||||
// Автозаполнение названия если пустое
|
||||
if (!this.form.file[0].title) {
|
||||
this.form.file[0].title = file.name.replace('.pdf', '');
|
||||
}
|
||||
},
|
||||
|
||||
removeFile() {
|
||||
this.selectedFile = null;
|
||||
this.form.file[0].path = null;
|
||||
this.$refs.fileInput.value = '';
|
||||
},
|
||||
|
||||
formatFileSize(bytes) {
|
||||
if (!bytes) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (!this.form.educational_group_id) {
|
||||
this.errors.educational_group_id = 'Необходимо выбрать учебную группу';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.form.file[0].path) {
|
||||
this.errors['file.0.path'] = 'Необходимо загрузить файл';
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing = true;
|
||||
this.errors = {};
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('educational_group_id', this.form.educational_group_id);
|
||||
formData.append('file[0][title]', this.form.file[0].title);
|
||||
formData.append('file[0][path]', this.form.file[0].path);
|
||||
|
||||
this.$inertia.post(route('dashboard.schedules.store'), formData, {
|
||||
onFinish: () => {
|
||||
this.processing = false;
|
||||
},
|
||||
onError: (errors) => {
|
||||
this.errors = errors;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
route(name, params) {
|
||||
return route(name, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,339 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background-2">
|
||||
<!-- Header -->
|
||||
<div class="border-b border-line-2 bg-layer/50 backdrop-blur-sm sticky top-0 z-10 h-16">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-full">
|
||||
<div class="flex items-center h-full gap-3">
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="p-2 text-muted-foreground-1 hover:text-foreground hover:bg-muted-hover rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="arrow-left" size="5" />
|
||||
</a>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center">
|
||||
<DashboardIcon name="pencil-square" size="5" class="text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-lg font-medium text-foreground">Редактирование расписания</h1>
|
||||
<p class="text-xs text-muted-foreground-1">{{ schedule.file?.[0]?.title || 'Расписание' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
||||
<!-- Flash Messages -->
|
||||
<transition
|
||||
enter-active-class="transition duration-300 ease-out"
|
||||
enter-from-class="opacity-0 -translate-y-2"
|
||||
enter-to-class="opacity-100 translate-y-0"
|
||||
leave-active-class="transition duration-200 ease-in"
|
||||
leave-from-class="opacity-100 translate-y-0"
|
||||
leave-to-class="opacity-0 -translate-y-2"
|
||||
>
|
||||
<div v-if="$page.props.flash?.error" class="mb-4 p-4 bg-rose-500/10 border border-rose-500/20 rounded-lg">
|
||||
<div class="flex items-start gap-3">
|
||||
<DashboardIcon name="exclamation-circle" size="5" class="text-rose-600 flex-shrink-0 mt-0.5" />
|
||||
<span class="text-sm text-foreground font-medium">{{ $page.props.flash.error }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<!-- Form Card -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs">
|
||||
<div class="p-6 border-b border-line-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="document" size="5" class="text-primary" />
|
||||
<h2 class="text-base font-medium text-foreground">Основная информация</h2>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground-1 mt-1">
|
||||
Измените данные о расписании
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="submit" class="p-6">
|
||||
<div class="space-y-6">
|
||||
<!-- Educational Group -->
|
||||
<div>
|
||||
<label for="educational_group_id" class="block text-sm font-medium text-foreground mb-2">
|
||||
Учебная группа <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
id="educational_group_id"
|
||||
v-model="form.educational_group_id"
|
||||
:class="[
|
||||
'w-full px-4 py-2.5 bg-surface border rounded-lg text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all',
|
||||
errors.educational_group_id ? 'border-rose-500' : 'border-layer-line focus:border-primary'
|
||||
]"
|
||||
>
|
||||
<option value="">Выберите группу</option>
|
||||
<option v-for="group in educationalGroups" :key="group.id" :value="group.id">
|
||||
{{ group.title }}
|
||||
</option>
|
||||
</select>
|
||||
<p v-if="errors.educational_group_id" class="mt-1.5 text-xs text-rose-500">{{ errors.educational_group_id }}</p>
|
||||
</div>
|
||||
|
||||
<!-- File Upload -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-foreground mb-2">
|
||||
Файл расписания
|
||||
</label>
|
||||
<div class="space-y-3">
|
||||
<!-- Current File Info -->
|
||||
<div v-if="currentFilePath" class="p-3 bg-surface border border-layer-line rounded-lg">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-rose-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="document" size="5" class="text-rose-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-foreground">Текущий файл</p>
|
||||
<a
|
||||
:href="getPdfUrl(currentFilePath)"
|
||||
target="_blank"
|
||||
class="text-xs text-primary hover:underline"
|
||||
>
|
||||
Скачать текущий файл
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Title Input -->
|
||||
<input
|
||||
v-model="form.file[0].title"
|
||||
type="text"
|
||||
placeholder="Название файла"
|
||||
:class="[
|
||||
'w-full px-4 py-2.5 bg-surface border rounded-lg text-sm text-foreground placeholder-muted-foreground-2 focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all',
|
||||
errors['file.0.title'] ? 'border-rose-500' : 'border-layer-line focus:border-primary'
|
||||
]"
|
||||
/>
|
||||
<p v-if="errors['file.0.title']" class="text-xs text-rose-500">{{ errors['file.0.title'] }}</p>
|
||||
|
||||
<!-- File Input -->
|
||||
<div
|
||||
class="relative border-2 border-dashed rounded-lg p-6 transition-all"
|
||||
:class="[
|
||||
isDragging ? 'border-primary bg-primary/5' : 'border-layer-line hover:border-primary/50',
|
||||
errors['file.0.path'] ? 'border-rose-500' : ''
|
||||
]"
|
||||
@dragover.prevent="isDragging = true"
|
||||
@dragleave="isDragging = false"
|
||||
@drop.prevent="handleDrop"
|
||||
>
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept=".pdf,application/pdf"
|
||||
class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||
@change="handleFileChange"
|
||||
/>
|
||||
<div class="text-center">
|
||||
<DashboardIcon name="cloud-arrow-up" size="12" class="mx-auto text-muted-foreground-2" />
|
||||
<p class="mt-2 text-sm text-foreground">
|
||||
<span class="font-medium text-primary">Нажмите для загрузки</span> нового файла или перетащите
|
||||
</p>
|
||||
<p class="mt-1 text-xs text-muted-foreground-1">
|
||||
Только PDF файлы, макс. размер 10MB. Оставьте пустым, чтобы сохранить текущий файл.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selected File Preview -->
|
||||
<div v-if="selectedFile" class="flex items-center gap-3 p-3 bg-surface border border-layer-line rounded-lg">
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-rose-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="document" size="5" class="text-rose-500" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-foreground truncate">{{ selectedFile.name }}</p>
|
||||
<p class="text-xs text-muted-foreground-1">{{ formatFileSize(selectedFile.size) }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@click="removeFile"
|
||||
class="p-2 text-muted-foreground-1 hover:text-rose-500 hover:bg-rose-500/10 rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="x-mark" size="4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="errors['file.0.path']" class="text-xs text-rose-500">{{ errors['file.0.path'] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end gap-3 mt-8 pt-6 border-t border-line-2">
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="inline-flex items-center gap-2 px-4 py-2.5 bg-surface border border-layer-line text-foreground text-sm font-medium rounded-lg hover:bg-muted-hover transition-all"
|
||||
>
|
||||
Отмена
|
||||
</a>
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="processing"
|
||||
class="inline-flex items-center gap-2 px-4 py-2.5 bg-primary text-white text-sm font-medium rounded-lg hover:bg-primary-hover transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg v-if="processing" class="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||
</svg>
|
||||
<DashboardIcon v-else name="check" size="4" />
|
||||
{{ processing ? 'Сохранение...' : 'Сохранить изменения' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DashboardIcon from '../Components/DashboardIcon.vue';
|
||||
|
||||
export default {
|
||||
name: 'ScheduleEdit',
|
||||
components: {
|
||||
DashboardIcon,
|
||||
},
|
||||
|
||||
props: {
|
||||
schedule: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
educationalGroups: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
educationForms: {
|
||||
type: Array,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
educational_group_id: this.schedule?.educational_group_id || '',
|
||||
file: [
|
||||
{
|
||||
title: this.schedule?.file?.[0]?.title || '',
|
||||
path: null
|
||||
}
|
||||
]
|
||||
},
|
||||
currentFilePath: this.schedule?.file?.[0]?.path || null,
|
||||
selectedFile: null,
|
||||
isDragging: false,
|
||||
errors: {},
|
||||
processing: false
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.SET_DOCUMENT_TITLE(`Редактирование расписания - ${this.schedule?.educational_group?.title}`);
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleFileChange(event) {
|
||||
const file = event.target.files[0];
|
||||
if (file) {
|
||||
this.validateFile(file);
|
||||
}
|
||||
},
|
||||
|
||||
handleDrop(event) {
|
||||
this.isDragging = false;
|
||||
const file = event.dataTransfer.files[0];
|
||||
if (file) {
|
||||
this.validateFile(file);
|
||||
}
|
||||
},
|
||||
|
||||
validateFile(file) {
|
||||
// Проверка типа файла
|
||||
if (file.type !== 'application/pdf') {
|
||||
this.errors['file.0.path'] = 'Разрешены только PDF файлы';
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверка размера (10MB)
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
this.errors['file.0.path'] = 'Размер файла не должен превышать 10MB';
|
||||
return;
|
||||
}
|
||||
|
||||
this.errors['file.0.path'] = '';
|
||||
this.selectedFile = file;
|
||||
this.form.file[0].path = file;
|
||||
|
||||
// Автозаполнение названия если пустое
|
||||
if (!this.form.file[0].title) {
|
||||
this.form.file[0].title = file.name.replace('.pdf', '');
|
||||
}
|
||||
},
|
||||
|
||||
removeFile() {
|
||||
this.selectedFile = null;
|
||||
this.form.file[0].path = null;
|
||||
this.$refs.fileInput.value = '';
|
||||
},
|
||||
|
||||
formatFileSize(bytes) {
|
||||
if (!bytes) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
},
|
||||
|
||||
getPdfUrl(path) {
|
||||
if (!path) return '#';
|
||||
return `/storage/${path}`;
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (!this.form.educational_group_id) {
|
||||
this.errors.educational_group_id = 'Необходимо выбрать учебную группу';
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing = true;
|
||||
this.errors = {};
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('educational_group_id', this.form.educational_group_id);
|
||||
|
||||
if (this.form.file[0].title) {
|
||||
formData.append('file[0][title]', this.form.file[0].title);
|
||||
}
|
||||
|
||||
if (this.form.file[0].path) {
|
||||
formData.append('file[0][path]', this.form.file[0].path);
|
||||
}
|
||||
|
||||
this.$inertia.post(route('dashboard.schedules.update', this.schedule.id), formData, {
|
||||
_method: 'PUT',
|
||||
onFinish: () => {
|
||||
this.processing = false;
|
||||
},
|
||||
onError: (errors) => {
|
||||
this.errors = errors;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
route(name, params) {
|
||||
return route(name, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<DashboardLayout>
|
||||
<template #header-icon>
|
||||
<DashboardIcon name="calendar" size="5" class="text-primary" />
|
||||
</template>
|
||||
<template #header-title>Расписания</template>
|
||||
<template #header-subtitle>Управление расписаниями занятий</template>
|
||||
<template #header-actions>
|
||||
<a
|
||||
:href="route('dashboard.schedules.upload.create')"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 bg-surface border border-layer-line text-foreground text-sm font-medium rounded-lg hover:bg-muted-hover transition-all duration-200 mr-2"
|
||||
>
|
||||
<DashboardIcon name="cloud-arrow-up" size="4" />
|
||||
Быстрая загрузка
|
||||
</a>
|
||||
<a
|
||||
:href="route('dashboard.schedules.create')"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 bg-primary text-white text-sm font-medium rounded-lg hover:bg-primary-hover transition-all duration-200 shadow-sm hover:shadow-md"
|
||||
>
|
||||
<DashboardIcon name="plus" size="4" />
|
||||
Добавить расписание
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<!-- Flash Messages -->
|
||||
<FlashMessages />
|
||||
|
||||
<!-- Filters Card -->
|
||||
<DataFilters title="Фильтры" @reset="resetFilters">
|
||||
<SearchInput
|
||||
v-model="searchQuery"
|
||||
label="Поиск по группе"
|
||||
placeholder="Введите название группы..."
|
||||
@search="search"
|
||||
/>
|
||||
|
||||
<SelectFilter
|
||||
v-model="educationalGroupQuery"
|
||||
label="Учебная группа"
|
||||
placeholder="Все группы"
|
||||
@change="filterByEducationalGroup"
|
||||
>
|
||||
<option v-for="group in educationalGroups" :key="group.id" :value="group.id">
|
||||
{{ group.title }}
|
||||
</option>
|
||||
</SelectFilter>
|
||||
|
||||
<SelectFilter
|
||||
v-model="educationFormQuery"
|
||||
label="Форма обучения"
|
||||
placeholder="Все формы"
|
||||
@change="filterByEducationForm"
|
||||
>
|
||||
<option v-for="form in educationForms" :key="form.value" :value="form.value">
|
||||
{{ EducationForm.fromValue(form.value)?.label || getEducationFormLabel(form.value) }}
|
||||
</option>
|
||||
</SelectFilter>
|
||||
</DataFilters>
|
||||
|
||||
<!-- Schedules Table -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs overflow-hidden">
|
||||
<!-- Table Header Stats -->
|
||||
<div class="px-6 py-4 border-b border-line-2 bg-surface/50">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<span class="text-sm text-foreground">
|
||||
Всего: <span class="font-medium">{{ schedules.total }}</span>
|
||||
</span>
|
||||
<span class="text-xs text-muted-foreground-1 px-2 py-0.5 bg-primary/10 text-primary rounded-full">
|
||||
{{ schedules.data.length }} на странице
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@click="refreshPage"
|
||||
class="p-2 text-muted-foreground-1 hover:text-foreground hover:bg-muted-hover rounded-lg transition-all"
|
||||
title="Обновить"
|
||||
>
|
||||
<DashboardIcon name="arrow-path" size="4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full divide-y divide-line-2">
|
||||
<thead class="bg-surface/50">
|
||||
<tr>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Название
|
||||
</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Учебная группа
|
||||
</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Факультет
|
||||
</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Форма обучения
|
||||
</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Обновлено
|
||||
</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
|
||||
Действия
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-line-2">
|
||||
<tr
|
||||
v-for="schedule in schedules.data"
|
||||
:key="schedule.id"
|
||||
class="group hover:bg-muted-hover/50 transition-all duration-200"
|
||||
>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg border border-layer-line bg-surface flex items-center justify-center">
|
||||
<DashboardIcon name="document" size="5" class="text-muted-foreground-2" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-medium text-foreground group-hover:text-primary transition-colors">
|
||||
{{ schedule.file?.[0]?.title || 'Без названия' }}
|
||||
</div>
|
||||
<div class="text-xs text-muted-foreground-2">
|
||||
PDF документ
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="text-sm text-foreground">
|
||||
{{ schedule.educational_group?.title || '—' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="text-sm text-foreground">
|
||||
{{ schedule.educational_group?.faculty?.title || '—' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span :class="getEducationFormBadgeClass(schedule.educational_group?.education_form_id)">
|
||||
{{ EducationForm.fromValue(schedule.educational_group?.education_form_id)?.label || getEducationFormLabel(schedule.educational_group?.education_form_id) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="text-sm text-foreground">{{ formatDate(schedule.updated_at) }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right">
|
||||
<div class="flex items-center justify-end gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<a
|
||||
:href="getPdfUrl(schedule.file?.[0]?.path)"
|
||||
target="_blank"
|
||||
class="p-2 text-muted-foreground-1 hover:text-primary hover:bg-primary/10 rounded-lg transition-all"
|
||||
title="Просмотреть PDF"
|
||||
>
|
||||
<DashboardIcon name="eye" size="4" />
|
||||
</a>
|
||||
<a
|
||||
:href="route('dashboard.schedules.edit', schedule.id)"
|
||||
class="p-2 text-muted-foreground-1 hover:text-primary hover:bg-primary/10 rounded-lg transition-all"
|
||||
title="Редактировать"
|
||||
>
|
||||
<DashboardIcon name="pencil-square" size="4" />
|
||||
</a>
|
||||
<button
|
||||
@click.prevent="confirmDelete(schedule)"
|
||||
class="p-2 text-muted-foreground-1 hover:text-rose-600 hover:bg-rose-500/10 rounded-lg transition-all"
|
||||
title="Удалить"
|
||||
>
|
||||
<DashboardIcon name="trash" size="4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Empty State -->
|
||||
<EmptyState
|
||||
v-if="schedules.data.length === 0"
|
||||
:columns="6"
|
||||
title="Расписания не найдены"
|
||||
description="Добавьте первое расписание или измените параметры поиска"
|
||||
:action-url="route('dashboard.schedules.create')"
|
||||
action-text="Добавить расписание"
|
||||
icon-path="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<Pagination :data="schedules" />
|
||||
</div>
|
||||
</DashboardLayout>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import EducationForm from '@/Enum/EducationForm.js';
|
||||
import DashboardLayout from '../Components/DashboardLayout.vue';
|
||||
import DashboardIcon from '../Components/DashboardIcon.vue';
|
||||
import FlashMessages from '../Components/shared/FlashMessages.vue';
|
||||
import DataFilters from '../Components/shared/DataFilters.vue';
|
||||
import SearchInput from '../Components/shared/SearchInput.vue';
|
||||
import SelectFilter from '../Components/shared/SelectFilter.vue';
|
||||
import EmptyState from '../Components/shared/EmptyState.vue';
|
||||
import Pagination from '../Components/shared/Pagination.vue';
|
||||
|
||||
export default {
|
||||
name: 'ScheduleIndex',
|
||||
components: {
|
||||
DashboardLayout,
|
||||
DashboardIcon,
|
||||
FlashMessages,
|
||||
DataFilters,
|
||||
SearchInput,
|
||||
SelectFilter,
|
||||
EmptyState,
|
||||
Pagination
|
||||
},
|
||||
|
||||
props: {
|
||||
schedules: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
filters: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
educational_group_id: '',
|
||||
education_form_id: '',
|
||||
search: ''
|
||||
})
|
||||
},
|
||||
educationalGroups: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
educationForms: {
|
||||
type: Array,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
searchQuery: this.filters?.search || '',
|
||||
educationalGroupQuery: this.filters?.educational_group_id || '',
|
||||
educationFormQuery: this.filters?.education_form_id || '',
|
||||
deletingSchedule: null,
|
||||
EducationForm
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.SET_DOCUMENT_TITLE('Расписание');
|
||||
},
|
||||
|
||||
methods: {
|
||||
getEducationFormBadgeClass(formId) {
|
||||
const eduForm = EducationForm.fromValue(formId);
|
||||
const colorClasses = {
|
||||
1: 'bg-info/10 text-info border-info/20',
|
||||
2: 'bg-success/10 text-success border-success/20',
|
||||
3: 'bg-primary/10 text-primary border-primary/20'
|
||||
};
|
||||
return `inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium border ${colorClasses[formId] || colorClasses[1]}`;
|
||||
},
|
||||
|
||||
getEducationFormLabel(formId) {
|
||||
const eduForm = EducationForm.fromValue(formId);
|
||||
if (eduForm) {
|
||||
return eduForm.label;
|
||||
}
|
||||
const labels = {
|
||||
1: 'Очное обучение',
|
||||
2: 'Очно-заочное обучение',
|
||||
3: 'Заочное обучение'
|
||||
};
|
||||
return labels[formId] || '—';
|
||||
},
|
||||
|
||||
formatDate(date) {
|
||||
if (!date) return '—';
|
||||
return new Date(date).toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
},
|
||||
|
||||
getPdfUrl(path) {
|
||||
if (!path) return '#';
|
||||
return `/storage/${path}`;
|
||||
},
|
||||
|
||||
search() {
|
||||
this.$inertia.get(route('dashboard.schedules.index'), {
|
||||
search: this.searchQuery,
|
||||
educational_group_id: this.educationalGroupQuery,
|
||||
education_form_id: this.educationFormQuery
|
||||
}, {
|
||||
preserveState: true
|
||||
});
|
||||
},
|
||||
|
||||
filterByEducationalGroup() {
|
||||
this.search();
|
||||
},
|
||||
|
||||
filterByEducationForm() {
|
||||
this.search();
|
||||
},
|
||||
|
||||
resetFilters() {
|
||||
this.searchQuery = '';
|
||||
this.educationalGroupQuery = '';
|
||||
this.educationFormQuery = '';
|
||||
this.$inertia.get(route('dashboard.schedules.index'), {}, {
|
||||
preserveState: true
|
||||
});
|
||||
},
|
||||
|
||||
confirmDelete(schedule) {
|
||||
if (confirm(`Вы уверены, что хотите удалить расписание "${schedule.file?.[0]?.title}"?`)) {
|
||||
this.deleteSchedule(schedule);
|
||||
}
|
||||
},
|
||||
|
||||
deleteSchedule(schedule) {
|
||||
this.$inertia.delete(route('dashboard.schedules.destroy', schedule.id), {
|
||||
preserveScroll: true
|
||||
});
|
||||
},
|
||||
|
||||
refreshPage() {
|
||||
this.$inertia.get(route('dashboard.schedules.index'), {
|
||||
search: this.searchQuery,
|
||||
educational_group_id: this.educationalGroupQuery,
|
||||
education_form_id: this.educationFormQuery
|
||||
}, {
|
||||
preserveState: true
|
||||
});
|
||||
},
|
||||
|
||||
route(name, params) {
|
||||
return route(name, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,461 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-background-2">
|
||||
<!-- Header -->
|
||||
<div class="border-b border-line-2 bg-layer/50 backdrop-blur-sm sticky top-0 z-10 h-16">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-full">
|
||||
<div class="flex items-center h-full gap-3">
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="p-2 text-muted-foreground-1 hover:text-foreground hover:bg-muted-hover rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="arrow-left" size="5" />
|
||||
</a>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center">
|
||||
<DashboardIcon name="cloud-arrow-up" size="5" class="text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-lg font-medium text-foreground">Быстрая загрузка расписаний</h1>
|
||||
<p class="text-xs text-muted-foreground-1">Массовая загрузка файлов с автоматическим определением групп</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
||||
<!-- Results Section (показываем сверху после загрузки) -->
|
||||
<div v-if="showResults" class="mb-6 space-y-4">
|
||||
<!-- Success Results -->
|
||||
<div v-if="processedFiles.length > 0" class="bg-emerald-500/5 border border-emerald-500/20 rounded-lg shadow-xs">
|
||||
<div class="p-4 border-b border-emerald-500/20">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="check-circle" size="5" class="text-emerald-500" />
|
||||
<h3 class="text-sm font-semibold text-emerald-700">
|
||||
Успешно загружено: {{ processedFiles.length }}
|
||||
</h3>
|
||||
</div>
|
||||
<a
|
||||
:href="route('dashboard.schedules.index')"
|
||||
class="inline-flex items-center gap-2 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-medium rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="list-bullet" size="4" />
|
||||
Перейти к расписаниям
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="(file, index) in processedFiles"
|
||||
:key="index"
|
||||
class="flex items-center gap-3 p-3 bg-white rounded-lg border border-emerald-500/20"
|
||||
>
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-emerald-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="check-circle" size="5" class="text-emerald-600" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-foreground truncate">{{ file.filename }}</p>
|
||||
<p class="text-xs text-emerald-600 font-medium">
|
||||
→ {{ file.group }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-emerald-100 text-emerald-800">
|
||||
Загружено
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Failed Files -->
|
||||
<div v-if="failedFiles.length > 0" class="bg-rose-500/5 border border-rose-500/20 rounded-lg shadow-xs">
|
||||
<div class="p-4 border-b border-rose-500/20">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="exclamation-circle" size="5" class="text-rose-500" />
|
||||
<h3 class="text-sm font-semibold text-rose-700">
|
||||
Ошибки при загрузке: {{ failedFiles.length }}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="(file, index) in failedFiles"
|
||||
:key="index"
|
||||
class="flex items-start gap-3 p-3 bg-white rounded-lg border border-rose-500/20"
|
||||
>
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-rose-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="x-mark" size="5" class="text-rose-600" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-foreground truncate">{{ file.filename }}</p>
|
||||
<p class="text-xs text-rose-600 mt-1">{{ file.error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Summary -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-foreground">
|
||||
<span class="font-medium">Итого обработано:</span> {{ processedFiles.length + failedFiles.length }} файлов
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
@click="resetResults"
|
||||
class="inline-flex items-center gap-2 px-3 py-1.5 bg-primary hover:bg-primary-hover text-white text-xs font-medium rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="arrow-path" size="4" />
|
||||
Загрузить ещё
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Flash Messages -->
|
||||
<transition
|
||||
enter-active-class="transition duration-300 ease-out"
|
||||
enter-from-class="opacity-0 -translate-y-2"
|
||||
enter-to-class="opacity-100 translate-y-0"
|
||||
leave-active-class="transition duration-200 ease-in"
|
||||
leave-from-class="opacity-100 translate-y-0"
|
||||
leave-to-class="opacity-0 -translate-y-2"
|
||||
>
|
||||
<div v-if="flashMessage && !showResults" :class="flashMessageClasses" class="mb-4 p-4 rounded-lg border">
|
||||
<div class="flex items-start gap-3">
|
||||
<DashboardIcon v-if="flashMessageType === 'success'" name="check-circle" size="5" class="text-emerald-600 flex-shrink-0 mt-0.5" />
|
||||
<DashboardIcon v-else-if="flashMessageType === 'error'" name="exclamation-circle" size="5" class="text-rose-600 flex-shrink-0 mt-0.5" />
|
||||
<DashboardIcon v-else name="exclamation-triangle" size="5" class="text-amber-600 flex-shrink-0 mt-0.5" />
|
||||
<span class="text-sm text-foreground font-medium">{{ flashMessage }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<!-- Info Card -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs mb-6">
|
||||
<div class="p-4 border-b border-line-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="information-circle" size="5" class="text-primary" />
|
||||
<h2 class="text-base font-medium text-foreground">Как это работает</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<ul class="space-y-2 text-sm text-foreground">
|
||||
<li class="flex items-start gap-2">
|
||||
<DashboardIcon name="check" size="4" class="text-primary mt-0.5 flex-shrink-0" />
|
||||
<span>Загрузите несколько PDF файлов одновременно</span>
|
||||
</li>
|
||||
<li class="flex items-start gap-2">
|
||||
<DashboardIcon name="check" size="4" class="text-primary mt-0.5 flex-shrink-0" />
|
||||
<span>Система автоматически определит учебную группу по названию файла</span>
|
||||
</li>
|
||||
<li class="flex items-start gap-2">
|
||||
<DashboardIcon name="check" size="4" class="text-primary mt-0.5 flex-shrink-0" />
|
||||
<span>Название файла должно содержать код группы (например: "Нт-102 Экзамены.pdf")</span>
|
||||
</li>
|
||||
<li class="flex items-start gap-2">
|
||||
<DashboardIcon name="check" size="4" class="text-primary mt-0.5 flex-shrink-0" />
|
||||
<span>Максимальный размер файла: 10MB</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Upload Form -->
|
||||
<div class="bg-layer border border-layer-line rounded-lg shadow-xs">
|
||||
<div class="p-6 border-b border-line-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<DashboardIcon name="cloud-arrow-up" size="5" class="text-primary" />
|
||||
<h2 class="text-base font-medium text-foreground">Загрузка файлов</h2>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground-1 mt-1">
|
||||
Выберите PDF файлы для загрузки
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="p-6">
|
||||
<!-- Drop Zone -->
|
||||
<div
|
||||
class="relative border-2 border-dashed rounded-lg p-8 transition-all cursor-pointer"
|
||||
:class="[
|
||||
isDragging ? 'border-primary bg-primary/5' : 'border-layer-line hover:border-primary/50',
|
||||
errors.files ? 'border-rose-500' : ''
|
||||
]"
|
||||
@dragover.prevent="isDragging = true"
|
||||
@dragleave="isDragging = false"
|
||||
@drop.prevent="handleDrop"
|
||||
@click="$refs.fileInput.click()"
|
||||
>
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept=".pdf,application/pdf"
|
||||
multiple
|
||||
class="hidden"
|
||||
@change="handleFileChange"
|
||||
/>
|
||||
<div class="text-center">
|
||||
<DashboardIcon name="cloud-arrow-up" size="16" class="mx-auto text-muted-foreground-2" />
|
||||
<p class="mt-4 text-sm text-foreground">
|
||||
<span class="font-medium text-primary">Нажмите для выбора</span> или перетащите файлы
|
||||
</p>
|
||||
<p class="mt-2 text-xs text-muted-foreground-1">
|
||||
Только PDF файлы, макс. размер 10MB каждый
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selected Files List -->
|
||||
<div v-if="selectedFiles.length > 0" class="mt-6">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="text-sm font-medium text-foreground">
|
||||
Выбрано файлов: {{ selectedFiles.length }}
|
||||
</h3>
|
||||
<button
|
||||
type="button"
|
||||
@click="clearAllFiles"
|
||||
class="text-xs text-rose-500 hover:text-rose-600 hover:underline"
|
||||
>
|
||||
Очистить все
|
||||
</button>
|
||||
</div>
|
||||
<div class="space-y-2 max-h-64 overflow-y-auto">
|
||||
<div
|
||||
v-for="(file, index) in selectedFiles"
|
||||
:key="index"
|
||||
class="flex items-center gap-3 p-3 bg-surface border border-layer-line rounded-lg"
|
||||
>
|
||||
<div class="w-10 h-10 flex-shrink-0 rounded-lg bg-rose-500/10 flex items-center justify-center">
|
||||
<DashboardIcon name="document" size="5" class="text-rose-500" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-sm font-medium text-foreground truncate">{{ file.name }}</p>
|
||||
<p class="text-xs text-muted-foreground-1">{{ formatFileSize(file.size) }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@click.stop="removeFile(index)"
|
||||
class="p-2 text-muted-foreground-1 hover:text-rose-500 hover:bg-rose-500/10 rounded-lg transition-all"
|
||||
>
|
||||
<DashboardIcon name="x-mark" size="4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error Message -->
|
||||
<p v-if="errors.files" class="mt-2 text-xs text-rose-500">{{ errors.files }}</p>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end mt-6 pt-6 border-t border-line-2">
|
||||
<button
|
||||
type="button"
|
||||
@click="submit"
|
||||
:disabled="processing || selectedFiles.length === 0"
|
||||
class="inline-flex items-center gap-2 px-4 py-2.5 bg-primary text-white text-sm font-medium rounded-lg hover:bg-primary-hover transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<svg v-if="processing" class="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||
</svg>
|
||||
<DashboardIcon v-else name="cloud-arrow-up" size="4" />
|
||||
{{ processing ? 'Загрузка...' : 'Загрузить файлы' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DashboardIcon from '../Components/DashboardIcon.vue';
|
||||
|
||||
export default {
|
||||
name: 'UploadSchedules',
|
||||
components: {
|
||||
DashboardIcon,
|
||||
},
|
||||
|
||||
props: {
|
||||
flash: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
selectedFiles: [],
|
||||
isDragging: false,
|
||||
processing: false,
|
||||
errors: {},
|
||||
flashMessage: null,
|
||||
flashMessageType: 'success',
|
||||
showResults: false,
|
||||
processedFiles: [],
|
||||
failedFiles: []
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.SET_DOCUMENT_TITLE('Загрузка расписаний');
|
||||
},
|
||||
|
||||
watch: {
|
||||
flash: {
|
||||
handler(newFlash) {
|
||||
if (newFlash) {
|
||||
this.flashMessage = newFlash.message;
|
||||
this.flashMessageType = newFlash.type;
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
data: {
|
||||
handler(newData) {
|
||||
if (newData) {
|
||||
this.processedFiles = newData.processed || [];
|
||||
this.failedFiles = newData.failed || [];
|
||||
this.showResults = this.processedFiles.length > 0 || this.failedFiles.length > 0;
|
||||
|
||||
// Очищаем выбранные файлы после загрузки
|
||||
if (this.processedFiles.length > 0 || this.failedFiles.length > 0) {
|
||||
this.selectedFiles = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
flashMessageClasses() {
|
||||
const baseClasses = 'border';
|
||||
const typeClasses = {
|
||||
success: 'bg-emerald-500/10 border-emerald-500/20',
|
||||
error: 'bg-rose-500/10 border-rose-500/20',
|
||||
warning: 'bg-amber-500/10 border-amber-500/20'
|
||||
};
|
||||
return `${baseClasses} ${typeClasses[this.flashMessageType]}`;
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleFileChange(event) {
|
||||
const files = Array.from(event.target.files);
|
||||
this.addFiles(files);
|
||||
event.target.value = '';
|
||||
},
|
||||
|
||||
handleDrop(event) {
|
||||
this.isDragging = false;
|
||||
const files = Array.from(event.dataTransfer.files);
|
||||
this.addFiles(files);
|
||||
},
|
||||
|
||||
addFiles(files) {
|
||||
const validFiles = [];
|
||||
const errors = [];
|
||||
|
||||
files.forEach(file => {
|
||||
if (file.type !== 'application/pdf') {
|
||||
errors.push(`Файл "${file.name}" не является PDF`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
errors.push(`Файл "${file.name}" превышает 10MB`);
|
||||
return;
|
||||
}
|
||||
|
||||
validFiles.push(file);
|
||||
});
|
||||
|
||||
if (errors.length > 0) {
|
||||
this.errors.files = errors.join('. ');
|
||||
} else {
|
||||
this.errors.files = '';
|
||||
}
|
||||
|
||||
this.selectedFiles = [...this.selectedFiles, ...validFiles];
|
||||
},
|
||||
|
||||
removeFile(index) {
|
||||
this.selectedFiles.splice(index, 1);
|
||||
},
|
||||
|
||||
clearAllFiles() {
|
||||
this.selectedFiles = [];
|
||||
this.errors.files = '';
|
||||
},
|
||||
|
||||
resetResults() {
|
||||
this.showResults = false;
|
||||
this.processedFiles = [];
|
||||
this.failedFiles = [];
|
||||
this.flashMessage = null;
|
||||
this.flashMessageType = 'success';
|
||||
this.errors = {};
|
||||
// Прокручиваем к началу страницы
|
||||
this.$nextTick(() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
},
|
||||
|
||||
formatFileSize(bytes) {
|
||||
if (!bytes) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (this.selectedFiles.length === 0) {
|
||||
this.errors.files = 'Выберите файлы для загрузки';
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing = true;
|
||||
this.errors = {};
|
||||
this.showResults = false;
|
||||
this.processedFiles = [];
|
||||
this.failedFiles = [];
|
||||
|
||||
const formData = new FormData();
|
||||
this.selectedFiles.forEach(file => {
|
||||
formData.append('files[]', file);
|
||||
});
|
||||
|
||||
this.$inertia.post(route('dashboard.schedules.upload.store'), formData, {
|
||||
preserveScroll: true,
|
||||
onError: (errors) => {
|
||||
this.errors = { ...errors };
|
||||
const firstError = Object.values(errors)[0];
|
||||
this.flashMessage = firstError || 'Ошибка при загрузке файлов';
|
||||
this.flashMessageType = 'error';
|
||||
},
|
||||
onFinish: () => {
|
||||
this.processing = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
route(name, params) {
|
||||
return route(name, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user