merge: bring latest origin/main into dev (main wins conflicts)
This commit is contained in:
@@ -3,7 +3,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
|
||||
import { formatRelativeDayLabel, toFaDigits } from '@/lib/jalali';
|
||||
import PipelineToolbar from '@/components/pipeline/PipelineToolbar.vue';
|
||||
import type { PipelineViewMode } from '@/components/pipeline/PipelineToolbar.vue';
|
||||
import PipelineBoard from '@/components/pipeline/PipelineBoard.vue';
|
||||
@@ -109,6 +109,7 @@ const overlayAccent = ref<PipelineStage['color']>('green');
|
||||
const overlayPos = ref({ x: 0, y: 0 });
|
||||
const menuOpenId = ref<string | null>(null);
|
||||
const moving = ref(false);
|
||||
let dragSessionId: string | null = null;
|
||||
|
||||
const pipelineOptions = computed(() =>
|
||||
pipelines.value.map((p) => ({
|
||||
@@ -165,9 +166,7 @@ function applyDealsSavedFilters(filters: Record<string, unknown>) {
|
||||
}
|
||||
|
||||
function formatDealDate(iso: string) {
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return iso;
|
||||
return formatJalaliNumeric(d);
|
||||
return formatRelativeDayLabel(iso);
|
||||
}
|
||||
|
||||
function findAccent(dealId: string): PipelineStage['color'] {
|
||||
@@ -178,7 +177,9 @@ function findAccent(dealId: string): PipelineStage['color'] {
|
||||
}
|
||||
|
||||
async function loadPipelines() {
|
||||
const { data } = await api.get<PipelineDto[]>('/pipelines');
|
||||
const { data } = await api.get<PipelineDto[]>('/pipelines', {
|
||||
params: { forLens: '1' },
|
||||
});
|
||||
pipelines.value = data;
|
||||
}
|
||||
|
||||
@@ -187,16 +188,23 @@ async function load() {
|
||||
error.value = '';
|
||||
try {
|
||||
await loadPipelines();
|
||||
const pipelineId =
|
||||
typeof route.query.pipelineId === 'string'
|
||||
? route.query.pipelineId
|
||||
: undefined;
|
||||
const requested =
|
||||
typeof route.query.pipelineId === 'string' ? route.query.pipelineId : '';
|
||||
const pipelineId = pipelines.value.some((item) => item.id === requested)
|
||||
? requested
|
||||
: pipelines.value[0]?.id;
|
||||
if (!pipelineId) {
|
||||
boardPipelineId.value = '';
|
||||
stages.value = [];
|
||||
if (requested) await router.replace({ name: 'pipeline', query: {} });
|
||||
return;
|
||||
}
|
||||
const { data } = await api.get<PipelineBoardDto>('/pipelines/board', {
|
||||
params: pipelineId ? { pipelineId } : undefined,
|
||||
params: { pipelineId },
|
||||
});
|
||||
boardPipelineId.value = data.pipeline.id;
|
||||
stages.value = mapBoardToStages(data, formatDealDate);
|
||||
if (!pipelineId || pipelineId !== data.pipeline.id) {
|
||||
if (requested !== data.pipeline.id) {
|
||||
await router.replace({
|
||||
name: 'pipeline',
|
||||
query: { pipelineId: data.pipeline.id },
|
||||
@@ -236,13 +244,9 @@ function onPointerMove(event: PointerEvent | MouseEvent) {
|
||||
}
|
||||
|
||||
function onDragStart(deal: PipelineDeal, event: DragEvent) {
|
||||
draggingId.value = deal.id;
|
||||
overlayDeal.value = deal;
|
||||
overlayAccent.value = findAccent(deal.id);
|
||||
overlayPos.value = {
|
||||
x: (event.clientX || 0) + 12,
|
||||
y: (event.clientY || 0) + 12,
|
||||
};
|
||||
draggingColumnId.value = null;
|
||||
if (moving.value) moving.value = false;
|
||||
dragSessionId = deal.id;
|
||||
event.dataTransfer?.setData('text/plain', deal.id);
|
||||
event.dataTransfer!.effectAllowed = 'move';
|
||||
if (event.dataTransfer) {
|
||||
@@ -251,12 +255,29 @@ function onDragStart(deal: PipelineDeal, event: DragEvent) {
|
||||
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
||||
event.dataTransfer.setDragImage(img, 0, 0);
|
||||
}
|
||||
overlayAccent.value = findAccent(deal.id);
|
||||
overlayPos.value = {
|
||||
x: (event.clientX || 0) + 12,
|
||||
y: (event.clientY || 0) + 12,
|
||||
};
|
||||
// DOM را بعد از dragstart عوض کن تا کروم درگ را لغو نکند
|
||||
window.setTimeout(() => {
|
||||
if (dragSessionId !== deal.id) return;
|
||||
draggingId.value = deal.id;
|
||||
overlayDeal.value = deal;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function onDragEnd() {
|
||||
draggingId.value = null;
|
||||
dropStageId.value = null;
|
||||
overlayDeal.value = null;
|
||||
const endedId = dragSessionId ?? draggingId.value;
|
||||
window.setTimeout(() => {
|
||||
if (dragSessionId && dragSessionId !== endedId) return;
|
||||
if (draggingId.value && draggingId.value !== endedId) return;
|
||||
dragSessionId = null;
|
||||
draggingId.value = null;
|
||||
dropStageId.value = null;
|
||||
overlayDeal.value = null;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function onDragOver(stageId: string, event: DragEvent) {
|
||||
@@ -296,37 +317,45 @@ async function applyUpdateDealStage(
|
||||
|
||||
async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
||||
event.preventDefault();
|
||||
const raw =
|
||||
event.dataTransfer?.getData('text/plain') ||
|
||||
draggingColumnId.value ||
|
||||
draggingId.value ||
|
||||
'';
|
||||
const transfer = event.dataTransfer?.getData('text/plain') || '';
|
||||
const draggedCardId = dragSessionId || draggingId.value;
|
||||
const columnId = draggingColumnId.value;
|
||||
dropStageId.value = null;
|
||||
dragSessionId = null;
|
||||
draggingId.value = null;
|
||||
overlayDeal.value = null;
|
||||
if (raw.startsWith('stage:') || draggingColumnId.value) {
|
||||
const fromId = raw.replace(/^stage:/, '') || draggingColumnId.value;
|
||||
draggingColumnId.value = null;
|
||||
if (fromId) await reorderColumn(fromId, stageId);
|
||||
draggingColumnId.value = null;
|
||||
|
||||
// کارت بر payload ستون اولویت دارد
|
||||
const dealId =
|
||||
draggedCardId || (transfer && !transfer.startsWith('stage:') ? transfer : '');
|
||||
if (dealId) {
|
||||
const current = stages.value.find((stage) => stage.deals.some((deal) => deal.id === dealId));
|
||||
if (current?.id === stageId && index == null) return;
|
||||
|
||||
const next = updateDealStage(stages.value, dealId, stageId, index);
|
||||
const unchanged = next.every((stage, stageIndex) => {
|
||||
const prev = stages.value[stageIndex];
|
||||
return (
|
||||
stage.deals.length === (prev?.deals.length ?? -1) &&
|
||||
stage.deals.every((deal, dealIndex) => deal.id === prev?.deals[dealIndex]?.id)
|
||||
);
|
||||
});
|
||||
if (unchanged) return;
|
||||
|
||||
// اگر جابهجایی قبلی هنوز در جریان است، این یکی را صف نکن — فقط رد نکن بیصدا با early return قدیمی
|
||||
if (moving.value) {
|
||||
moving.value = false;
|
||||
}
|
||||
await applyUpdateDealStage(dealId, stageId, index);
|
||||
return;
|
||||
}
|
||||
const dealId = raw;
|
||||
if (!dealId || moving.value) return;
|
||||
|
||||
const current = stages.value.find((stage) => stage.deals.some((deal) => deal.id === dealId));
|
||||
if (current?.id === stageId && index == null) return;
|
||||
|
||||
const next = updateDealStage(stages.value, dealId, stageId, index);
|
||||
const unchanged = next.every((stage, stageIndex) => {
|
||||
const prev = stages.value[stageIndex];
|
||||
return (
|
||||
stage.deals.length === (prev?.deals.length ?? -1) &&
|
||||
stage.deals.every((deal, dealIndex) => deal.id === prev?.deals[dealIndex]?.id)
|
||||
);
|
||||
});
|
||||
if (unchanged) return;
|
||||
|
||||
await applyUpdateDealStage(dealId, stageId, index);
|
||||
const isStageDrag = transfer.startsWith('stage:');
|
||||
if (isStageDrag || columnId) {
|
||||
const fromId = isStageDrag ? transfer.slice('stage:'.length) : columnId;
|
||||
if (fromId) await reorderColumn(fromId, stageId);
|
||||
}
|
||||
}
|
||||
|
||||
function apiMessage(e: unknown, fallback: string) {
|
||||
@@ -343,6 +372,8 @@ function onAddDeal(stageId: string) {
|
||||
}
|
||||
|
||||
function onColumnDragStart(stageId: string) {
|
||||
draggingId.value = null;
|
||||
overlayDeal.value = null;
|
||||
draggingColumnId.value = stageId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user