Страница Архива
1. Добавлены новые методы 2. Добавлена страница архивных задач.
This commit is contained in:
538
front_vue/src/views/ArchivePage.vue
Normal file
538
front_vue/src/views/ArchivePage.vue
Normal file
@@ -0,0 +1,538 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<!-- Боковая панель навигации -->
|
||||
<Sidebar />
|
||||
|
||||
<!-- Основной контент -->
|
||||
<div class="main-wrapper">
|
||||
<!-- Шапка с заголовком и фильтрами -->
|
||||
<Header title="Архив задач">
|
||||
<template #filters>
|
||||
<div class="filters">
|
||||
<button
|
||||
class="filter-tag"
|
||||
:class="{ active: activeDepartment === null }"
|
||||
@click="activeDepartment = null"
|
||||
>
|
||||
Все
|
||||
</button>
|
||||
<button
|
||||
v-for="dept in departments"
|
||||
:key="dept.id"
|
||||
class="filter-tag"
|
||||
:class="{ active: activeDepartment === dept.id }"
|
||||
@click="activeDepartment = activeDepartment === dept.id ? null : dept.id"
|
||||
>
|
||||
{{ dept.name_departments }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<template #stats>
|
||||
<div class="header-stats">
|
||||
<div class="stat">
|
||||
<span class="stat-value">{{ filteredCards.length }}</span>
|
||||
<span class="stat-label">в архиве</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Header>
|
||||
|
||||
<!-- Список архивных задач -->
|
||||
<main class="main">
|
||||
<div
|
||||
class="archive-list"
|
||||
:class="{ 'drag-over': isDragOver }"
|
||||
ref="listRef"
|
||||
@dragover.prevent="handleDragOver"
|
||||
@dragenter.prevent="handleDragEnter"
|
||||
@dragleave="handleDragLeave"
|
||||
@drop="handleDrop"
|
||||
>
|
||||
<template v-for="(card, index) in filteredCards" :key="card.id">
|
||||
<!-- Индикатор перед карточкой -->
|
||||
<div v-if="isDragOver && dropIndex === index" class="drop-indicator"></div>
|
||||
<ArchiveCard
|
||||
:card="card"
|
||||
:index="index"
|
||||
:departments="departments"
|
||||
:labels="labels"
|
||||
@click="openTaskPanel(card)"
|
||||
@restore="handleRestore"
|
||||
@delete="confirmDelete"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Индикатор в конце списка -->
|
||||
<div v-if="isDragOver && dropIndex === filteredCards.length" class="drop-indicator"></div>
|
||||
|
||||
<!-- Пустое состояние -->
|
||||
<div v-if="filteredCards.length === 0 && !loading" class="empty-state">
|
||||
<i data-lucide="archive-x"></i>
|
||||
<p>Архив пуст</p>
|
||||
<span>Архивированные задачи появятся здесь</span>
|
||||
</div>
|
||||
|
||||
<!-- Загрузка -->
|
||||
<div v-if="loading" class="loading-state">
|
||||
<i data-lucide="loader-2" class="spin"></i>
|
||||
<span>Загрузка...</span>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Панель редактирования задачи -->
|
||||
<TaskPanel
|
||||
:show="panelOpen"
|
||||
:card="editingCard"
|
||||
:column-id="null"
|
||||
:is-archived="true"
|
||||
:departments="departments"
|
||||
:labels="labels"
|
||||
:users="users"
|
||||
@close="closePanel"
|
||||
@save="handleSaveTask"
|
||||
@delete="handleDeleteTask"
|
||||
@restore="handleRestoreFromPanel"
|
||||
/>
|
||||
|
||||
<!-- Диалог подтверждения удаления -->
|
||||
<ConfirmDialog
|
||||
:show="confirmDialogOpen"
|
||||
title="Удалить задачу?"
|
||||
message="Задача будет удалена безвозвратно. Это действие нельзя отменить."
|
||||
confirm-text="Удалить"
|
||||
@confirm="handleConfirmDelete"
|
||||
@cancel="confirmDialogOpen = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import Sidebar from '../components/Sidebar.vue'
|
||||
import Header from '../components/Header.vue'
|
||||
import ArchiveCard from '../components/ArchiveCard.vue'
|
||||
import TaskPanel from '../components/TaskPanel.vue'
|
||||
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
||||
import { departmentsApi, labelsApi, cardsApi, usersApi } from '../api'
|
||||
|
||||
// Активный фильтр по отделу (синхронизация с основной доской)
|
||||
const savedDepartment = localStorage.getItem('activeDepartment')
|
||||
const activeDepartment = ref(savedDepartment ? parseInt(savedDepartment) : null)
|
||||
|
||||
// Сохраняем в localStorage при изменении
|
||||
watch(activeDepartment, (newVal) => {
|
||||
if (newVal === null) {
|
||||
localStorage.removeItem('activeDepartment')
|
||||
} else {
|
||||
localStorage.setItem('activeDepartment', newVal.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Данные
|
||||
const departments = ref([])
|
||||
const labels = ref([])
|
||||
const cards = ref([])
|
||||
const users = ref([])
|
||||
const loading = ref(true)
|
||||
|
||||
// Отфильтрованные карточки (сортируем по order)
|
||||
const filteredCards = computed(() => {
|
||||
let result = cards.value
|
||||
if (activeDepartment.value) {
|
||||
result = result.filter(card => card.departmentId === activeDepartment.value)
|
||||
}
|
||||
return result.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
})
|
||||
|
||||
// Drag & Drop
|
||||
const listRef = ref(null)
|
||||
const isDragOver = ref(false)
|
||||
const dropIndex = ref(-1)
|
||||
let dragEnterCounter = 0
|
||||
|
||||
const handleDragEnter = () => {
|
||||
dragEnterCounter++
|
||||
isDragOver.value = true
|
||||
}
|
||||
|
||||
const calculateDropIndex = (clientY) => {
|
||||
if (!listRef.value) return filteredCards.value.length
|
||||
|
||||
const cardElements = listRef.value.querySelectorAll('.archive-card')
|
||||
let index = filteredCards.value.length
|
||||
|
||||
for (let i = 0; i < cardElements.length; i++) {
|
||||
const rect = cardElements[i].getBoundingClientRect()
|
||||
const cardMiddle = rect.top + rect.height / 2
|
||||
|
||||
if (clientY < cardMiddle) {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return index
|
||||
}
|
||||
|
||||
const handleDragOver = (e) => {
|
||||
isDragOver.value = true
|
||||
dropIndex.value = calculateDropIndex(e.clientY)
|
||||
}
|
||||
|
||||
const handleDragLeave = () => {
|
||||
dragEnterCounter--
|
||||
if (dragEnterCounter === 0) {
|
||||
isDragOver.value = false
|
||||
dropIndex.value = -1
|
||||
}
|
||||
}
|
||||
|
||||
const handleDrop = async (e) => {
|
||||
const cardId = parseInt(e.dataTransfer.getData('cardId'))
|
||||
const fromIndex = parseInt(e.dataTransfer.getData('fromIndex'))
|
||||
const toIndex = calculateDropIndex(e.clientY)
|
||||
|
||||
dragEnterCounter = 0
|
||||
isDragOver.value = false
|
||||
dropIndex.value = -1
|
||||
|
||||
// Если позиция не изменилась — ничего не делаем
|
||||
if (fromIndex === toIndex || fromIndex === toIndex - 1) return
|
||||
|
||||
// Локально перемещаем карточку
|
||||
const card = cards.value.find(c => c.id === cardId)
|
||||
if (!card) return
|
||||
|
||||
// Удаляем из старой позиции
|
||||
const cardIndex = cards.value.indexOf(card)
|
||||
cards.value.splice(cardIndex, 1)
|
||||
|
||||
// Вычисляем новую позицию
|
||||
let newIndex = toIndex
|
||||
if (cardIndex < toIndex) newIndex--
|
||||
|
||||
// Вставляем в новую позицию
|
||||
cards.value.splice(newIndex, 0, card)
|
||||
|
||||
// Пересчитываем order для всех
|
||||
cards.value.forEach((c, idx) => {
|
||||
c.order = idx
|
||||
})
|
||||
|
||||
// Отправляем на сервер
|
||||
await cardsApi.updateOrder(cardId, card.columnId, newIndex)
|
||||
}
|
||||
|
||||
// Загрузка данных
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [departmentsData, labelsData, cardsData, usersData] = await Promise.all([
|
||||
departmentsApi.getAll(),
|
||||
labelsApi.getAll(),
|
||||
cardsApi.getAll(1), // archive = 1
|
||||
usersApi.getAll()
|
||||
])
|
||||
|
||||
if (departmentsData.success) departments.value = departmentsData.data
|
||||
if (labelsData.success) labels.value = labelsData.data
|
||||
if (usersData.success) users.value = usersData.data
|
||||
|
||||
if (cardsData.success) {
|
||||
cards.value = cardsData.data.map(card => ({
|
||||
id: card.id,
|
||||
title: card.title,
|
||||
description: card.descript,
|
||||
details: card.descript_full,
|
||||
departmentId: card.id_department,
|
||||
labelId: card.id_label,
|
||||
accountId: card.id_account,
|
||||
assignee: card.avatar_img,
|
||||
dueDate: card.date,
|
||||
dateCreate: card.date_create,
|
||||
dateClosed: card.date_closed,
|
||||
columnId: card.column_id,
|
||||
order: card.order ?? 0,
|
||||
files: card.files || (card.file_img || []).map(f => ({
|
||||
name: f.name,
|
||||
url: f.url,
|
||||
size: f.size,
|
||||
preview: f.url
|
||||
}))
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки данных:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Панель редактирования
|
||||
const panelOpen = ref(false)
|
||||
const editingCard = ref(null)
|
||||
|
||||
const openTaskPanel = (card) => {
|
||||
editingCard.value = card
|
||||
panelOpen.value = true
|
||||
}
|
||||
|
||||
const closePanel = () => {
|
||||
panelOpen.value = false
|
||||
editingCard.value = null
|
||||
}
|
||||
|
||||
// Сохранение задачи
|
||||
const handleSaveTask = async (taskData) => {
|
||||
if (taskData.id) {
|
||||
// Обновляем на сервере
|
||||
await cardsApi.update({
|
||||
id: taskData.id,
|
||||
id_department: taskData.departmentId,
|
||||
id_label: taskData.labelId,
|
||||
id_account: taskData.accountId,
|
||||
date: taskData.dueDate,
|
||||
title: taskData.title,
|
||||
descript: taskData.description,
|
||||
descript_full: taskData.details
|
||||
})
|
||||
|
||||
// Обновляем локально
|
||||
const card = cards.value.find(c => c.id === taskData.id)
|
||||
if (card) {
|
||||
card.title = taskData.title
|
||||
card.description = taskData.description
|
||||
card.details = taskData.details
|
||||
card.departmentId = taskData.departmentId
|
||||
card.labelId = taskData.labelId
|
||||
card.dueDate = taskData.dueDate
|
||||
card.accountId = taskData.accountId
|
||||
card.assignee = taskData.assignee
|
||||
card.files = taskData.files || []
|
||||
}
|
||||
}
|
||||
closePanel()
|
||||
}
|
||||
|
||||
// Удаление через панель
|
||||
const handleDeleteTask = async (cardId) => {
|
||||
const result = await cardsApi.delete(cardId)
|
||||
if (result.success) {
|
||||
cards.value = cards.value.filter(c => c.id !== cardId)
|
||||
}
|
||||
closePanel()
|
||||
}
|
||||
|
||||
// Диалог подтверждения удаления
|
||||
const confirmDialogOpen = ref(false)
|
||||
const cardToDelete = ref(null)
|
||||
|
||||
const confirmDelete = (cardId) => {
|
||||
cardToDelete.value = cardId
|
||||
confirmDialogOpen.value = true
|
||||
}
|
||||
|
||||
const handleConfirmDelete = async () => {
|
||||
if (cardToDelete.value) {
|
||||
const result = await cardsApi.delete(cardToDelete.value)
|
||||
if (result.success) {
|
||||
cards.value = cards.value.filter(c => c.id !== cardToDelete.value)
|
||||
}
|
||||
}
|
||||
confirmDialogOpen.value = false
|
||||
cardToDelete.value = null
|
||||
}
|
||||
|
||||
// Восстановление из архива
|
||||
const handleRestore = async (cardId) => {
|
||||
const result = await cardsApi.setArchive(cardId, 0)
|
||||
if (result.success) {
|
||||
cards.value = cards.value.filter(c => c.id !== cardId)
|
||||
}
|
||||
}
|
||||
|
||||
// Восстановление через панель редактирования
|
||||
const handleRestoreFromPanel = async (cardId) => {
|
||||
await handleRestore(cardId)
|
||||
closePanel()
|
||||
}
|
||||
|
||||
// Инициализация
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
if (window.lucide) {
|
||||
window.lucide.createIcons()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* Контейнер приложения */
|
||||
.app {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* Основная область контента */
|
||||
.main-wrapper {
|
||||
flex: 1;
|
||||
margin-left: 64px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--bg-main);
|
||||
}
|
||||
|
||||
/* Контейнер фильтров */
|
||||
.filters {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* Кнопка фильтра */
|
||||
.filter-tag {
|
||||
padding: 6px 12px;
|
||||
background: var(--bg-card);
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
color: var(--text-secondary);
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.3px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.filter-tag:hover {
|
||||
background: var(--bg-card-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Активный фильтр */
|
||||
.filter-tag.active {
|
||||
background: var(--accent);
|
||||
color: #000;
|
||||
}
|
||||
|
||||
/* Блок статистики */
|
||||
.header-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 10px 20px;
|
||||
background: var(--bg-card);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.stat {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* Основная область */
|
||||
.main {
|
||||
flex: 1;
|
||||
padding: 0 36px 36px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* Список архивных карточек */
|
||||
.archive-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
max-width: 1200px;
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.archive-list.drag-over {
|
||||
background: rgba(0, 212, 170, 0.03);
|
||||
border-radius: 12px;
|
||||
padding: 8px;
|
||||
margin: -8px;
|
||||
}
|
||||
|
||||
/* Индикатор места вставки */
|
||||
.drop-indicator {
|
||||
height: 4px;
|
||||
background: var(--accent);
|
||||
border-radius: 2px;
|
||||
margin: 4px 0;
|
||||
animation: pulse 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 0.5; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
/* Пустое состояние */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 80px 20px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
opacity: 0.4;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.empty-state span {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Загрузка */
|
||||
.loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.loading-state i {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user