v1.0.7, fix bugs and UI improvments

This commit is contained in:
2026-09-19 03:05:36 +03:00
parent cbd44a0516
commit ecb93e14aa
6 changed files with 566 additions and 140 deletions

View File

@ -14,12 +14,34 @@ export const COLOR_MODES = [
export const FORMATS = ['A4', 'A5']; export const FORMATS = ['A4', 'A5'];
/** /**
* Расчет цены за страницу в зависимости от объема * Возвращает количество физических листов.
* Для двусторонней печати: страницы / 2, округлённые вверх.
*/ */
export function getPricePerPage(pagesCount) { export function getSheetsCount(pagesCount, isDuplex = false) {
if (pagesCount >= 1000) return 4; const pages = Math.max(0, Number(pagesCount) || 0);
if (pagesCount >= 25) return 9;
return 10; if (!isDuplex) {
return pages;
}
return Math.ceil(pages / 2);
}
/**
* Расчет цены за лист.
* Для двусторонней печати фиксированно 15 ₽/лист.
* Для односторонней остаются старые тарифы.
*/
export function getPricePerPage(pagesOrSheetsCount, sides = 'Односторонняя') {
if (sides === 'Двусторонняя') {
return 15;
}
const n = Math.max(0, Number(pagesOrSheetsCount) || 0);
if (n >= 25) return 9;
return 10;
} }
/** /**

View File

@ -205,5 +205,5 @@
<div class="version"> <div class="version">
<span>v{backendVersion}</span> <span>v{backendVersion}</span>
<span>v1.0.5</span> <span>v1.0.7</span>
</div> </div>

View File

@ -16,12 +16,23 @@
event.target.value = ''; event.target.value = '';
} }
const hasTierSmall = $derived(store.files.some((f) => (f.selectedPages?.size || 0) < 25)); const hasDuplex = $derived(
const hasTierMedium = $derived(store.files.some((f) => { store.files.some((f) => f.sides === 'Двусторонняя')
);
const hasTierSmall = $derived(
store.files.some((f) => {
const s = f.selectedPages?.size || 0; const s = f.selectedPages?.size || 0;
return s >= 25 && s < 1000; return f.sides !== 'Двусторонняя' && s > 0 && s < 25;
})); })
const hasTierLarge = $derived(store.files.some((f) => (f.selectedPages?.size || 0) >= 1000)); );
const hasTierMedium = $derived(
store.files.some((f) => {
const s = f.selectedPages?.size || 0;
return f.sides !== 'Двусторонняя' && s >= 25;
})
);
</script> </script>
{#if store.job} {#if store.job}
@ -60,17 +71,17 @@
{/if} {/if}
</main> </main>
<PrintUI <PrintUI
as="footer" as="footer"
totalPrice={store.totalPrice} totalPrice={store.totalPrice}
filesCount={store.files.length} filesCount={store.files.length}
extraCopies={store.extraCopies} extraCopies={store.extraCopies}
isPrinting={store.isPrinting} isPrinting={store.isPrinting}
onSubmit={store.openPayment} onSubmit={store.openPayment}
hasTierSmall={hasTierSmall} hasDuplex={hasDuplex}
hasTierMedium={hasTierMedium} hasTierSmall={hasTierSmall}
hasTierLarge={hasTierLarge} hasTierMedium={hasTierMedium}
plFiles={plFiles} plFiles={plFiles}
plCopies={plCopies} plCopies={plCopies}
/> />
<input <input
type="file" type="file"

View File

@ -4,9 +4,11 @@
const currentStatus = $derived.by(() => { const currentStatus = $derived.by(() => {
if (!store.job) return 'idle'; if (!store.job) return 'idle';
const f = store.job.files.find(f => f.status === 'printing');
const f = store.job.files?.find((x) => x.status === 'printing');
if (f) return 'printing'; if (f) return 'printing';
const q = store.job.files.find(f => f.status === 'queued');
const q = store.job.files?.find((x) => x.status === 'queued');
return q ? 'queued' : store.job.phase; return q ? 'queued' : store.job.phase;
}); });
@ -36,7 +38,121 @@
}); });
const canCancel = $derived( const canCancel = $derived(
store.job?.files.some(f => f.status === 'queued' || f.status === 'printing') store.job?.files?.some((f) => f.status === 'queued' || f.status === 'printing') ?? false
);
const jobPhase = $derived(store.job?.phase);
const jobFiles = $derived(store.job?.files ?? []);
/**
* Двусторонняя печать определяется по настройкам файлов,
* которые всё ещё лежат в store.files после отправки задания.
*/
const isDuplex = $derived(
store.files.some((f) => f.sides === 'Двусторонняя')
);
/**
* Текущие запросы сервера на пользовательские действия.
*/
const hasClearPhase = $derived(jobPhase === 'awaiting_clear_output');
const hasFlip = $derived(
jobPhase === 'awaiting_flip' ||
jobFiles.some((f) => f.status === 'awaiting_flip')
);
const hasPickup = $derived(
jobPhase === 'awaiting_pickup' ||
jobFiles.some((f) => f.status === 'awaiting_pickup')
);
/**
* Проверяем, есть ли уже напечатанные или отправленные файлы.
* Если нет — значит это первая печать и лоток выдачи принтера пуст.
*/
const hasPrintedFiles = $derived(
store.job?.files?.some(f => ['done', 'sent', 'awaiting_flip', 'awaiting_pickup'].includes(f.status)) ?? false
);
/**
* Нам важно запомнить, что первый проход уже был,
* иначе при печати второй стороны инструкция очистки может появиться снова.
*/
let hadFlip = $state(false);
let hadPickup = $state(false);
$effect(() => {
if (!store.job) return;
if (
jobPhase === 'awaiting_flip' ||
jobFiles.some((f) => f.status === 'awaiting_flip')
) {
hadFlip = true;
}
if (
jobPhase === 'awaiting_pickup' ||
jobFiles.some((f) => f.status === 'awaiting_pickup')
) {
hadPickup = true;
}
});
const firstSideFinished = $derived(
hadFlip ||
hadPickup ||
jobPhase === 'finished' ||
jobPhase === 'cancelled' ||
jobFiles.some((f) => f.status === 'done')
);
/**
* Инструкция очистки лотка:
* - если сервер явно просит awaiting_clear_output И есть уже напечатанные файлы;
* - для двусторонней печати — до первого прохода,
* пока ещё не было flip/pickup/done И есть напечатанные файлы.
*/
const showClearOutput = $derived(
store.jobActive &&
!firstSideFinished &&
(
(hasClearPhase && hasPrintedFiles) ||
(isDuplex && hasPrintedFiles && ['waiting_start', 'printing', 'awaiting_clear_output'].includes(jobPhase ?? ''))
)
);
const showFlip = $derived(
store.jobActive &&
hasFlip &&
jobPhase !== 'finished' &&
jobPhase !== 'cancelled'
);
const showPickup = $derived(
store.jobActive &&
hasPickup &&
!showFlip &&
jobPhase !== 'finished' &&
jobPhase !== 'cancelled'
);
const clearActionAvailable = $derived(
showClearOutput &&
(jobPhase === 'awaiting_clear_output' || jobPhase === 'waiting_start')
);
const flipActionAvailable = $derived(
showFlip && jobPhase === 'awaiting_flip'
);
const pickupActionAvailable = $derived(
showPickup && jobPhase === 'awaiting_pickup'
);
const clearButtonLabel = $derived(
jobPhase === 'waiting_start'
? 'Убрал листы — начать печать'
: 'Убрал листы — продолжать'
); );
const HOLD_MS = 1500; const HOLD_MS = 1500;
@ -46,14 +162,23 @@
function startHold(e) { function startHold(e) {
if (!store.jobActive || !canCancel) return; if (!store.jobActive || !canCancel) return;
e.preventDefault(); e.preventDefault();
e.currentTarget.setPointerCapture?.(e.pointerId); e.currentTarget.setPointerCapture?.(e.pointerId);
t0 = performance.now(); t0 = performance.now();
const step = (now) => { const step = (now) => {
hold = Math.min(1, (now - t0) / HOLD_MS); hold = Math.min(1, (now - t0) / HOLD_MS);
if (hold >= 1) { raf = 0; hold = 0; store.cancelJob(); return; } if (hold >= 1) {
raf = 0;
hold = 0;
store.cancelJob();
return;
}
raf = requestAnimationFrame(step); raf = requestAnimationFrame(step);
}; };
raf = requestAnimationFrame(step); raf = requestAnimationFrame(step);
} }
@ -76,6 +201,50 @@
</header> </header>
<main class="list"> <main class="list">
{#if showClearOutput}
<section class="instruction-card clear">
<p class="instruction-title">
Уберите распечатанные листы из выходного лотка
</p>
<ol class="instruction-list">
<li>Уберите распечатанные листы из выходного лотка</li>
{#if clearActionAvailable}
<li>Нажмите кнопку ниже для продолжения</li>
{:else}
<li>Дождитесь завершения первого прохода</li>
{/if}
</ol>
</section>
{:else if showFlip}
<section class="instruction-card flip">
<p class="instruction-title">
Переложите бумагу
</p>
<ol class="instruction-list">
<li>Не переворачивая, положите листы в слот ручной подачи</li>
{#if flipActionAvailable}
<li>Нажмите кнопку ниже для печати обратной стороны</li>
{:else}
<li>Дождитесь завершения текущего этапа</li>
{/if}
</ol>
</section>
{:else if showPickup}
<section class="instruction-card pickup">
<p class="instruction-title">
Печать завершается...
</p>
<ol class="instruction-list">
<li>Дождитесь завершения печати</li>
{#if pickupActionAvailable}
<li>Нажмите кнопку ниже для подтверждения</li>
{:else}
<li>Дождитесь завершения текущего этапа</li>
{/if}
</ol>
</section>
{/if}
{#if store.job} {#if store.job}
{#each store.job.files as f, i (i + '-' + f.name)} {#each store.job.files as f, i (i + '-' + f.name)}
{@const b = badge(f.name)} {@const b = badge(f.name)}
@ -93,23 +262,6 @@
</span> </span>
</div> </div>
{#if f.status === 'awaiting_pickup'}
<ol class="pickup-hint">
<li>Дождитесь завершения печати</li>
<li>Нажмите кнопку ниже для подтверждения</li>
</ol>
{:else if f.status === 'awaiting_clear_output'}
<ol class="pickup-hint clear-hint">
<li>Уберите распечатанные листы из выходного лотка</li>
<li>Нажмите кнопку ниже для продолжения</li>
</ol>
{:else if f.status === 'awaiting_flip'}
<ol class="pickup-hint flip-hint">
<li>Не переворачивая, положите листы в слот ручной подачи</li>
<li>Нажмите кнопку ниже для печати обратной стороны</li>
</ol>
{/if}
{#if f.error} {#if f.error}
<p class="file-error">{f.error}</p> <p class="file-error">{f.error}</p>
{/if} {/if}
@ -119,32 +271,34 @@
</main> </main>
<footer class="actions"> <footer class="actions">
<label class="auto-row"> {#if canCancel}
<input <label class="auto-row">
type="checkbox" <input
checked={store.autoContinue} type="checkbox"
onchange={(e) => store.setAutoContinue(e.target.checked)} checked={store.autoContinue}
/> onchange={(e) => store.setAutoContinue(e.target.checked)}
<span>Автоматически продолжать печать</span> />
</label> <span>Автоматически продолжать печать</span>
</label>
{#if store.autoContinue} {#if store.autoContinue}
<p class="auto-warning">⚠️ Отправленные файлы нельзя будет отменить</p> <p class="auto-warning">⚠️ Отправленные файлы нельзя будет отменить</p>
{/if}
{/if} {/if}
{#if store.jobActive} {#if store.jobActive}
{#if store.job?.phase === 'awaiting_pickup'} {#if pickupActionAvailable}
<button class="next-btn" onclick={store.advanceJob}> <button class="next-btn" onclick={store.advanceJob}>
Печать закончена — далее Печать закончена — далее
</button> </button>
{:else if store.job?.phase === 'awaiting_clear_output'} {:else if flipActionAvailable}
<button class="next-btn next-btn-clear" onclick={store.advanceJob}>
Убрал листы — продолжать
</button>
{:else if store.job?.phase === 'awaiting_flip'}
<button class="next-btn next-btn-flip" onclick={store.advanceJob}> <button class="next-btn next-btn-flip" onclick={store.advanceJob}>
Переложил — печатать обратную сторону Переложил — печатать обратную сторону
</button> </button>
{:else if clearActionAvailable}
<button class="next-btn next-btn-clear" onclick={store.advanceJob}>
{clearButtonLabel}
</button>
{:else} {:else}
<button class="next-btn next-btn-disabled" disabled> <button class="next-btn next-btn-disabled" disabled>
{currentStatus === 'printing' ? 'Отправка...' : 'Ожидание...'} {currentStatus === 'printing' ? 'Отправка...' : 'Ожидание...'}
@ -184,9 +338,6 @@
.st-error { color: #ef4444; } .st-error { color: #ef4444; }
.st-cancelled { color: #6b7280; } .st-cancelled { color: #6b7280; }
.clear-hint { color: #f59e0b; }
.flip-hint { color: #f59e0b; }
.auto-warning { .auto-warning {
margin: -4px 0 8px; margin: -4px 0 8px;
text-align: center; text-align: center;
@ -196,69 +347,198 @@
} }
.page-container { .page-container {
width: 100%; min-height: 100dvh; width: 100%;
display: flex; flex-direction: column; min-height: 100dvh;
display: flex;
flex-direction: column;
background: radial-gradient(120% 60% at 50% -10%, rgba(99,102,241,0.18) 0%, transparent 60%); background: radial-gradient(120% 60% at 50% -10%, rgba(99,102,241,0.18) 0%, transparent 60%);
font-family: system-ui, -apple-system, sans-serif; font-family: system-ui, -apple-system, sans-serif;
color: #f5f7fa; color: #f5f7fa;
} }
.header { padding: 24px 20px 8px; display: flex; align-items: center; position: relative; } .header {
.back-btn { padding: 24px 20px 8px;
background: none; border: none; color: #6366f1; display: flex;
font-size: 15px; font-weight: 600; cursor: pointer; align-items: center;
padding: 8px 4px; margin-right: auto; min-height: 44px; position: relative;
} }
.back-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.back-btn {
background: none;
border: none;
color: #6366f1;
font-size: 15px;
font-weight: 600;
cursor: pointer;
padding: 8px 4px;
margin-right: auto;
min-height: 44px;
}
.back-btn:disabled {
opacity: 0.3;
cursor: not-allowed;
}
.header h1 { .header h1 {
margin: 0; font-size: 28px; font-weight: 700; margin: 0;
position: absolute; left: 50%; transform: translateX(-50%); font-size: 28px;
font-weight: 700;
position: absolute;
left: 50%;
transform: translateX(-50%);
white-space: nowrap; white-space: nowrap;
} }
.list { flex: 1; padding: 24px 20px 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; } .list {
flex: 1;
padding: 24px 20px 16px;
display: flex;
flex-direction: column;
gap: 14px;
overflow-y: auto;
text-align: left;
}
.instruction-card {
border-radius: 16px;
padding: 14px;
display: flex;
flex-direction: column;
gap: 8px;
border: 1px solid rgba(245, 158, 11, 0.35);
background: rgba(245, 158, 11, 0.08);
text-align: left;
}
.instruction-card.pickup {
border-color: rgba(165, 180, 252, 0.35);
background: rgba(99, 102, 241, 0.08);
}
.instruction-title {
margin: 0;
font-size: 15px;
font-weight: 700;
color: #f59e0b;
}
.instruction-card.pickup .instruction-title {
color: #a5b4fc;
}
.instruction-list {
margin: 0;
padding-left: 22px;
color: #f59e0b;
font-size: 14px;
line-height: 1.6;
font-weight: 600;
text-align: left;
}
.instruction-card.pickup .instruction-list {
color: #a5b4fc;
}
.file-card { .file-card {
border-radius: 16px; background: rgba(255,255,255,0.04); border-radius: 16px;
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.08);
padding: 14px; display: flex; flex-direction: column; gap: 8px; padding: 14px;
display: flex;
flex-direction: column;
gap: 8px;
transition: border-color 0.2s ease, background 0.2s ease; transition: border-color 0.2s ease, background 0.2s ease;
text-align: left;
} }
.file-card.current { border-color: rgba(99,102,241,0.45); background: rgba(99,102,241,0.07); }
.file-row { display: flex; align-items: center; gap: 12px; min-width: 0; } .file-card.current {
.file-name { border-color: rgba(99,102,241,0.45);
flex: 1; min-width: 0; font-size: 15px; font-weight: 500; background: rgba(99,102,241,0.07);
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
text-align: left;
}
.file-name {
flex: 1;
min-width: 0;
font-size: 15px;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-status {
flex-shrink: 0;
font-size: 14px;
font-weight: 700;
} }
.file-status { flex-shrink: 0; font-size: 14px; font-weight: 700; }
.type-badge { .type-badge {
flex-shrink: 0; padding: 3px 7px; border-radius: 6px; flex-shrink: 0;
background: rgba(99,102,241,0.2); border: 1px solid rgba(99,102,241,0.35); padding: 3px 7px;
color: #a5b4fc; font-size: 10px; font-weight: 700; border-radius: 6px;
letter-spacing: 0.04em; line-height: 1.2; user-select: none; background: rgba(99,102,241,0.2);
border: 1px solid rgba(99,102,241,0.35);
color: #a5b4fc;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
line-height: 1.2;
user-select: none;
} }
.pickup-hint { .file-error {
margin: 0; padding-left: 22px; margin: 0;
color: #eab308; font-size: 14px; line-height: 1.6; font-weight: 600; color: #fca5a5;
font-size: 12px;
line-height: 1.4;
text-align: left;
} }
.file-error { margin: 0; color: #fca5a5; font-size: 12px; line-height: 1.4; } .actions {
padding: 16px 20px 32px;
.actions { padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 12px; } display: flex;
flex-direction: column;
gap: 12px;
}
.auto-row { .auto-row {
display: flex; align-items: center; justify-content: center; gap: 10px; display: flex;
color: #a9b0c0; font-size: 14px; font-weight: 600; align-items: center;
user-select: none; cursor: pointer; justify-content: center;
gap: 10px;
color: #a9b0c0;
font-size: 14px;
font-weight: 600;
user-select: none;
cursor: pointer;
}
.auto-row input {
width: 18px;
height: 18px;
accent-color: #6366f1;
cursor: pointer;
} }
.auto-row input { width: 18px; height: 18px; accent-color: #6366f1; cursor: pointer; }
.next-btn { .next-btn {
width: 100%; padding: 16px 24px; border-radius: 16px; width: 100%;
font-size: 16px; font-weight: 700; cursor: pointer; border: none; color: #fff; padding: 16px 24px;
border-radius: 16px;
font-size: 16px;
font-weight: 700;
cursor: pointer;
border: none;
color: #fff;
background: linear-gradient(135deg, #5b8cff 0%, #38c6ff 100%); background: linear-gradient(135deg, #5b8cff 0%, #38c6ff 100%);
box-shadow: 0 8px 24px -6px rgba(72,150,255,0.4); box-shadow: 0 8px 24px -6px rgba(72,150,255,0.4);
} }
@ -274,31 +554,68 @@
} }
.next-btn-disabled { .next-btn-disabled {
opacity: 0.5; cursor: wait; pointer-events: none; opacity: 0.5;
cursor: wait;
pointer-events: none;
background: linear-gradient(135deg, #475569 0%, #64748b 100%); background: linear-gradient(135deg, #475569 0%, #64748b 100%);
box-shadow: none; box-shadow: none;
} }
.cancel-btn { .cancel-btn {
position: relative; overflow: hidden; width: 100%; padding: 16px 24px; position: relative;
border-radius: 16px; border: 1px solid rgba(239,68,68,0.35); overflow: hidden;
background: rgba(239,68,68,0.08); color: #fca5a5; width: 100%;
font-size: 16px; font-weight: 700; cursor: pointer; padding: 16px 24px;
touch-action: none; user-select: none; border-radius: 16px;
-webkit-user-select: none; -webkit-touch-callout: none; border: 1px solid rgba(239,68,68,0.35);
background: rgba(239,68,68,0.08);
color: #fca5a5;
font-size: 16px;
font-weight: 700;
cursor: pointer;
touch-action: none;
user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
} }
.cancel-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.cancel-fill { .cancel-btn:disabled {
position: absolute; left: 0; top: 0; bottom: 0; width: 0%; opacity: 0.4;
background: rgba(239,68,68,0.35); pointer-events: none; cursor: not-allowed;
pointer-events: none;
}
.cancel-fill {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 0%;
background: rgba(239,68,68,0.35);
pointer-events: none;
}
.cancel-label {
position: relative;
}
.hold-hint {
margin: -4px 0 0;
text-align: center;
color: rgba(139,147,161,0.6);
font-size: 11px;
} }
.cancel-label { position: relative; }
.hold-hint { margin: -4px 0 0; text-align: center; color: rgba(139,147,161,0.6); font-size: 11px; }
.home-btn { .home-btn {
width: 100%; padding: 16px 24px; border-radius: 16px; width: 100%;
font-size: 16px; font-weight: 700; cursor: pointer; border: none; color: #fff; padding: 16px 24px;
border-radius: 16px;
font-size: 16px;
font-weight: 700;
cursor: pointer;
border: none;
color: #fff;
background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
box-shadow: 0 8px 24px -6px rgba(34,197,94,0.4); box-shadow: 0 8px 24px -6px rgba(34,197,94,0.4);
} }

View File

@ -36,6 +36,17 @@
function isOffice(file) { function isOffice(file) {
return file?.fileType === 'office'; return file?.fileType === 'office';
} }
/** Можно ли разрешить двустороннюю печать для файла */
function canDuplex(file) {
if (!file) return false;
// Для office число страниц неизвестно.
// Если нужно блокировать и office, убери эту строку.
if (file.fileType === 'office') return true;
return (file.selectedPages?.size ?? 0) > 1;
}
</script> </script>
{#if as === 'button'} {#if as === 'button'}
@ -149,12 +160,14 @@
<GearOption value={formatText(file)} open={formatOpen} onclick={() => (formatOpen = !formatOpen)} /> <GearOption value={formatText(file)} open={formatOpen} onclick={() => (formatOpen = !formatOpen)} />
</div> </div>
<div class="duo-row"> <div class="duo-row">
<ToggleOption <ToggleOption
label="Печать" label="Печать"
options={SIDES_OPTIONS} options={SIDES_OPTIONS}
value={file.sides ?? 'Односторонняя'} value={file.sides ?? 'Односторонняя'}
onchange={(v) => props.onUpdate?.(file.id, { sides: v })} disabled={!canDuplex(file)}
/> hint={canDuplex(file) ? '' : 'Двусторонняя доступна при выборе 2 и более страниц'}
onchange={(v) => props.onUpdate?.(file.id, { sides: v })}
/>
<ToggleOption <ToggleOption
label="Цветность" label="Цветность"
options={COLOR_LABELS} options={COLOR_LABELS}
@ -221,11 +234,23 @@
{#if props.extraCopies > 0}, {props.extraCopies} {props.plCopies(props.extraCopies)}{/if} {#if props.extraCopies > 0}, {props.extraCopies} {props.plCopies(props.extraCopies)}{/if}
</p> </p>
{/if} {/if}
<div class="pricing-info"> <div class="pricing-info">
<span class="price-tier" class:active={props.hasTierSmall}>10р от 1</span> <div class="pricing-row pricing-row-duplex">
<span class="price-tier" class:active={props.hasTierMedium}>9р от 25</span> <span class="price-tier" class:active={!!props.hasDuplex}>
<span class="price-tier" class:active={props.hasTierLarge}>4р от 1000</span> Двусторонняя 15р
</div> </span>
</div>
<div class="pricing-row">
<span class="price-tier" class:active={props.hasTierSmall}>
10р/л от 1
</span>
<span class="price-tier" class:active={props.hasTierMedium}>
9р/л от 25
</span>
</div>
</div>
<div class="price-summary"> <div class="price-summary">
<span class="summary-itogo">Итого</span> <span class="summary-itogo">Итого</span>
<span class="summary-price">{props.totalPrice}</span> <span class="summary-price">{props.totalPrice}</span>
@ -272,7 +297,26 @@
.empty-hint { color: #8b93a1; font-size: 15px; margin: 0; } .empty-hint { color: #8b93a1; font-size: 15px; margin: 0; }
.actions { padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 12px; } .actions { padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 12px; }
.file-count { color: #8b93a1; font-size: 13px; margin: 0; text-align: center; line-height: 1.4; } .file-count { color: #8b93a1; font-size: 13px; margin: 0; text-align: center; line-height: 1.4; }
.pricing-info { display: flex; justify-content: center; gap: 12px; font-size: 10px; line-height: 1.2; color: rgba(255,255,255,0.25); margin-bottom: 4px; user-select: none; flex-wrap: wrap; } .pricing-info {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
margin-bottom: 4px;
user-select: none;
}
.pricing-row {
display: flex;
justify-content: center;
gap: 12px;
font-size: 10px;
line-height: 1.2;
color: rgba(255, 255, 255, 0.25);
flex-wrap: wrap;
}
.pricing-row-duplex {
margin-bottom: 2px;
}
.price-tier { transition: color 0.2s ease; } .price-tier { transition: color 0.2s ease; }
.price-tier.active { color: rgba(255,255,255,0.6); } .price-tier.active { color: rgba(255,255,255,0.6); }
.price-summary { display: flex; justify-content: space-between; align-items: baseline; width: 100%; } .price-summary { display: flex; justify-content: space-between; align-items: baseline; width: 100%; }

View File

@ -1,6 +1,6 @@
// lib/pages/print/store.svelte.js // lib/pages/print/store.svelte.js
import { onDestroy, tick } from 'svelte'; import { onDestroy, tick } from 'svelte';
import { getPricePerPage } from '$lib/common/utils/pricing.util.js'; import { getPricePerPage, getSheetsCount } from '$lib/common/utils/pricing.util.js';
import { detectFileType, pagesLabel as _pagesLabel } from '$lib/common/utils/file.util.js'; import { detectFileType, pagesLabel as _pagesLabel } from '$lib/common/utils/file.util.js';
import { loadPdfDocument, renderPageToImage } from '$lib/common/services/pdf.service.js'; import { loadPdfDocument, renderPageToImage } from '$lib/common/services/pdf.service.js';
@ -34,20 +34,44 @@ export function createPrintStore() {
const jobActive = $derived(!!job && job.phase !== 'finished' && job.phase !== 'cancelled'); const jobActive = $derived(!!job && job.phase !== 'finished' && job.phase !== 'cancelled');
let uid = 0; let uid = 0;
const totalPrice = $derived( const totalPrice = $derived(
files.reduce((sum, f) => { files.reduce((sum, f) => {
const pages = f.selectedPages?.size || 0; const pages = f.selectedPages?.size || 0;
return sum + pages * f.copies * getPricePerPage(pages); const isDuplex = f.sides === 'Двусторонняя';
}, 0)
); const sheets = getSheetsCount(pages, isDuplex);
const pricePerSheet = getPricePerPage(
isDuplex ? sheets : pages,
f.sides ?? 'Односторонняя'
);
return sum + sheets * f.copies * pricePerSheet;
}, 0)
);
const extraCopies = $derived(files.reduce((sum, f) => sum + (f.copies - 1), 0)); const extraCopies = $derived(files.reduce((sum, f) => sum + (f.copies - 1), 0));
function updateFile(id, changes) { function updateFile(id, changes) {
files = files.map((f) => (f.id === id ? { ...f, ...changes } : f)); files = files.map((f) => {
if (activeFile?.id === id) { if (f.id !== id) return f;
activeFile = files.find((f) => f.id === id);
} const next = { ...f, ...changes };
}
const blockDuplex =
next.fileType !== 'office' &&
(next.selectedPages?.size ?? 0) <= 1;
if (blockDuplex && next.sides === 'Двусторонняя') {
next.sides = 'Односторонняя';
}
return next;
});
if (activeFile?.id === id) {
activeFile = files.find((f) => f.id === id);
}
}
async function ensurePdfLoaded(entry) { async function ensurePdfLoaded(entry) {
if (entry.pdfDoc) return entry.pdfDoc; if (entry.pdfDoc) return entry.pdfDoc;
@ -227,9 +251,17 @@ export function createPrintStore() {
alert('⚠️ Некорректный ответ сервера печати.'); alert('⚠️ Некорректный ответ сервера печати.');
return; return;
} }
job = data; job = data;
showPayment = false; showPayment = false;
await advanceJob();
const hasDuplex = files.some((f) => f.sides === 'Двусторонняя');
const needsManualStart =
hasDuplex &&
(job.phase === 'waiting_start' || job.phase === 'awaiting_clear_output');
if (!needsManualStart) {
await advanceJob();
}
} catch { } catch {
alert('⚠️ Не удалось связаться с сервером печати.'); alert('⚠️ Не удалось связаться с сервером печати.');
} finally { } finally {