优化系统化待办列表操作体验 #553

Merged
yueyang merged 1 commits from feature/yueyang-systemization-todo-usability into main 2026-10-25 19:03:21 +08:00
3 changed files with 366 additions and 59 deletions

View File

@ -19,6 +19,17 @@ class SystemizationTodos extends Controller
public function page(): array
{
$filters = $this->filters();
if (
$filters['date_from'] !== ''
&& $filters['date_to'] !== ''
&& $filters['date_from'] > $filters['date_to']
) {
[$filters['date_from'], $filters['date_to']] = [
$filters['date_to'],
$filters['date_from'],
];
}
$query = SystemizationTodo::query()
->with('attachments')
->withCount('attachments');
@ -35,6 +46,12 @@ class SystemizationTodos extends Controller
->orWhere('assignee', $filters['owner']);
});
}
if ($filters['date_from'] !== '') {
$query->whereDate($filters['date_scope'], '>=', $filters['date_from']);
}
if ($filters['date_to'] !== '') {
$query->whereDate($filters['date_scope'], '<=', $filters['date_to']);
}
if ($filters['keyword'] !== '') {
$like = '%' . addcslashes($filters['keyword'], '%_\\') . '%';
$query->where(function ($builder) use ($like): void {
@ -50,6 +67,10 @@ class SystemizationTodos extends Controller
$items = $query
->orderByRaw("CASE WHEN status = '已完成' THEN 1 ELSE 0 END")
->orderByRaw("CASE WHEN category IS NULL OR category = '' THEN 1 ELSE 0 END")
->orderBy('category')
->orderByRaw("CASE WHEN section IS NULL OR section = '' THEN 1 ELSE 0 END")
->orderBy('section')
->orderByRaw('CASE WHEN due_date IS NULL THEN 1 ELSE 0 END')
->orderBy('due_date')
->orderBy('sort_order')
@ -88,6 +109,7 @@ class SystemizationTodos extends Controller
'todoCategories' => $categories,
'todoOwners' => $owners,
'todoStatuses' => SystemizationTodo::STATUSES,
'todoDateScopes' => $this->dateScopes(),
'todoSummary' => [
'total' => (clone $base)->count(),
'pending' => (clone $base)->where('status', SystemizationTodo::STATUS_PENDING)->count(),
@ -207,6 +229,9 @@ class SystemizationTodos extends Controller
private function filters(): array
{
$dateScopes = $this->dateScopes();
$dateScope = (string) request('date_scope', 'due_date');
return [
'status' => in_array(request('status'), SystemizationTodo::STATUSES, true)
? (string) request('status')
@ -214,9 +239,35 @@ class SystemizationTodos extends Controller
'category' => trim((string) request('category', '')),
'owner' => trim((string) request('owner', '')),
'keyword' => trim((string) request('keyword', '')),
'date_scope' => array_key_exists($dateScope, $dateScopes) ? $dateScope : 'due_date',
'date_from' => $this->normalizeDateFilter(request('date_from')),
'date_to' => $this->normalizeDateFilter(request('date_to')),
];
}
private function dateScopes(): array
{
return [
'due_date' => '完成时间',
'start_date' => '开始时间',
'created_at' => '新增时间',
];
}
private function normalizeDateFilter(mixed $value): string
{
$value = trim((string) $value);
if ($value === '') {
return '';
}
$date = \DateTimeImmutable::createFromFormat('!Y-m-d', $value);
return $date instanceof \DateTimeImmutable && $date->format('Y-m-d') === $value
? $value
: '';
}
private function validated(Request $request): array
{
return $request->validate([

View File

@ -11,34 +11,54 @@
.sys-todo-page__button--primary:hover { background:#6a5129; color:#fff; }
.sys-todo-page__button .material-icons-outlined { font-size:1rem; }
.sys-todo-page__intro { margin:.35rem 0 0; color:var(--sys-muted); font-size:.75rem; line-height:1.6; }
.sys-todo-summary { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:.75rem; margin:1rem 0; }
.sys-todo-summary__item { padding:.75rem .85rem; border:1px solid #e6dfd2; border-radius:.6rem; background:#fffdf9; }
.sys-todo-summary { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:.55rem; margin:.8rem 0; }
.sys-todo-summary__item { display:flex; align-items:center; justify-content:space-between; gap:.6rem; padding:.5rem .7rem; border:1px solid #e6dfd2; border-radius:.5rem; background:#fffdf9; }
.sys-todo-summary__label { color:var(--sys-muted); font-size:.72rem; }
.sys-todo-summary__value { margin-top:.15rem; color:#171717; font-size:1.25rem; font-weight:700; font-variant-numeric:tabular-nums; }
.sys-todo-summary__value { color:#171717; font-size:1rem; font-weight:700; font-variant-numeric:tabular-nums; }
.sys-todo-summary__item.is-warning .sys-todo-summary__value { color:#935f07; }
.sys-todo-summary__item.is-success .sys-todo-summary__value { color:#53793e; }
.sys-todo-filter { display:grid; grid-template-columns:minmax(8rem,.8fr) minmax(10rem,1fr) minmax(10rem,1fr) minmax(18rem,2fr) auto; gap:.65rem .75rem; align-items:end; margin:0 0 1rem; padding:.85rem; border:1px solid #e6dfd2; border-radius:.65rem; background:#fcfaf5; }
.sys-todo-filter label { display:grid; gap:.3rem; color:#595959; font-size:.75rem; }
.sys-todo-filter { display:flex; flex-wrap:wrap; gap:.65rem .55rem; align-items:end; margin:0 0 .85rem; padding:.7rem; border:1px solid #e6dfd2; border-radius:.65rem; background:#fcfaf5; }
.sys-todo-filter label { display:grid; flex:1 1 7.4rem; gap:.25rem; min-width:0; color:#595959; font-size:.72rem; }
.sys-todo-filter label.sys-todo-filter__keyword { flex:2.2 1 16rem; }
.sys-todo-filter input, .sys-todo-filter select { width:100%; height:2.125rem; padding:0 .6rem; border:1px solid var(--sys-border); border-radius:.45rem; background:#fff; color:#171717; font:inherit; font-size:.8125rem; }
.sys-todo-filter__actions { display:flex; gap:.45rem; }
.sys-todo-filter__actions { display:flex; flex:0 0 auto; gap:.45rem; }
.sys-todo-table-wrap { overflow:auto; border:1px solid var(--sys-border); border-radius:.65rem; background:#fff; }
.sys-todo-table { width:100%; min-width:94rem; border-collapse:collapse; font-size:.78rem; }
.sys-todo-table th { position:sticky; top:0; z-index:1; padding:.65rem .55rem; border-bottom:1px solid var(--sys-border); background:#f3ece0; color:#3d3a35; text-align:left; white-space:nowrap; }
.sys-todo-table td { padding:.6rem .55rem; border-bottom:1px solid #eee7da; color:#2f2a23; vertical-align:top; }
.sys-todo-table tbody tr:hover { background:#fdfbf6; }
.sys-todo-table__title, .sys-todo-table__progress, .sys-todo-table__notes { min-width:14rem; max-width:28rem; white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.55; }
.sys-todo-table__title { min-width:24rem; font-weight:600; }
.sys-todo-table-wrap { max-height:clamp(24rem,58vh,46rem); overscroll-behavior:contain; scrollbar-gutter:stable; }
.sys-todo-table { width:100%; min-width:88rem; border-collapse:separate; border-spacing:0; font-size:.75rem; }
.sys-todo-table th { position:sticky; top:0; z-index:4; padding:.55rem .48rem; border-bottom:1px solid var(--sys-border); background:#f3ece0; color:#3d3a35; text-align:left; white-space:nowrap; }
.sys-todo-table td { padding:.45rem .48rem; border-bottom:1px solid #eee7da; background:#fff; color:#2f2a23; vertical-align:top; }
.sys-todo-table tbody tr { cursor:pointer; }
.sys-todo-table tbody tr:hover td { background:#fdfbf6; }
.sys-todo-table tbody tr:focus-visible { outline:2px solid var(--sys-gold); outline-offset:-2px; }
.sys-todo-table th:first-child, .sys-todo-table td:first-child { position:sticky; left:0; z-index:3; width:4rem; min-width:4rem; text-align:center; box-shadow:1px 0 0 #e5ddcf; }
.sys-todo-table th:first-child { z-index:6; background:#f3ece0; }
.sys-todo-table th:last-child, .sys-todo-table td:last-child { position:sticky; right:0; z-index:3; width:5.8rem; min-width:5.8rem; background:#fff; box-shadow:-1px 0 0 #e5ddcf; }
.sys-todo-table th:last-child { z-index:6; background:#f3ece0; }
.sys-todo-table tbody tr:hover td:first-child, .sys-todo-table tbody tr:hover td:last-child { background:#fdfbf6; }
.sys-todo-table__index { color:#6d5630; font-weight:600; font-variant-numeric:tabular-nums; white-space:nowrap; }
.sys-todo-table__group { vertical-align:middle; background:#fcfaf5; font-weight:600; }
.sys-todo-table__section { min-width:14rem; max-width:20rem; }
.sys-todo-table__title, .sys-todo-table__progress, .sys-todo-table__notes { line-height:1.45; white-space:pre-line; overflow-wrap:anywhere; }
.sys-todo-table__title { min-width:20rem; max-width:27rem; font-weight:600; }
.sys-todo-table__progress { min-width:15rem; max-width:23rem; }
.sys-todo-table__notes { min-width:11rem; max-width:18rem; }
.sys-todo-table__clamp { display:-webkit-box; overflow:hidden; -webkit-box-orient:vertical; -webkit-line-clamp:3; }
.sys-todo-table__section .sys-todo-table__clamp { -webkit-line-clamp:2; }
.sys-todo-badge { display:inline-flex; align-items:center; padding:.1rem .45rem; border:1px solid #dfd6c5; border-radius:999px; background:#faf6ee; color:#51483c; white-space:nowrap; }
.sys-todo-badge--progress { border-color:#dbbf7a; background:#fff7df; color:#935f07; }
.sys-todo-badge--completed { border-color:#bad0ac; background:#f2f8ed; color:#53793e; }
.sys-todo-badge--delayed { border-color:#e7c3c3; background:#fff3f3; color:#b80000; }
.sys-todo-badge--overdue { border-color:#e7c3c3; color:#b80000; }
.sys-todo-shots { display:flex; flex-wrap:wrap; gap:.3rem; max-width:13rem; }
.sys-todo-shots a { display:block; width:4.25rem; height:3.2rem; border:1px solid #ddd4c4; border-radius:.35rem; overflow:hidden; background:#faf8f3; }
.sys-todo-shots button { display:block; width:4.25rem; height:3.2rem; padding:0; border:1px solid #ddd4c4; border-radius:.35rem; overflow:hidden; background:#faf8f3; cursor:zoom-in; }
.sys-todo-shots img { width:100%; height:100%; object-fit:cover; }
.sys-todo-row-actions { display:flex; flex-wrap:wrap; gap:.35rem; }
.sys-todo-row-actions button, .sys-todo-row-actions a { padding:.2rem .45rem; border:1px solid var(--sys-border); border-radius:.35rem; background:#fff; color:#51483c; font:inherit; font-size:.72rem; text-decoration:none; cursor:pointer; }
.sys-todo-row-actions button:hover, .sys-todo-row-actions a:hover { border-color:#c7b687; background:var(--sys-gold-soft); }
.sys-todo-table__add { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:.65rem; margin-top:.6rem; padding:.55rem .7rem; border:1px dashed #d8cdb8; border-radius:.55rem; background:#fcfaf5; color:#666; font-size:.72rem; }
.sys-todo-table__add button { display:inline-flex; align-items:center; gap:.25rem; min-height:2rem; padding:0 .7rem; border:1px solid var(--sys-border); border-radius:.4rem; background:#fff; color:#51483c; font:inherit; font-size:.76rem; cursor:pointer; }
.sys-todo-table__add button:hover { border-color:#c7b687; background:var(--sys-gold-soft); }
.sys-todo-table__add .material-icons-outlined { font-size:1rem; }
.sys-todo-empty { padding:2rem 1rem; color:#777; text-align:center; }
.sys-todo-pagination { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:.75rem; padding:.85rem 0 0; color:#595959; font-size:.75rem; }
.sys-todo-pagination__actions { display:flex; gap:.5rem; }
@ -65,18 +85,32 @@
.sys-todo-field input, .sys-todo-field select, .sys-todo-field textarea { width:100%; padding:.5rem .6rem; border:1px solid var(--sys-border); border-radius:.45rem; background:#fff; color:#171717; font:inherit; font-size:.8125rem; }
.sys-todo-field input, .sys-todo-field select { min-height:2.15rem; }
.sys-todo-field textarea { min-height:5.5rem; resize:vertical; line-height:1.55; }
.sys-todo-field input[type="file"] { padding:.35rem; }
.sys-todo-upload-note { color:#777; font-size:.72rem; }
.sys-todo-upload-zone { display:flex; flex-wrap:wrap; align-items:center; gap:.45rem .65rem; min-height:4.5rem; padding:.7rem; border:1px dashed #cfc3ad; border-radius:.55rem; background:#fcfaf5; }
.sys-todo-upload-zone input[type="file"] { position:absolute; width:1px; height:1px; padding:0; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.sys-todo-upload-button { display:inline-flex; align-items:center; justify-content:center; min-height:2rem; padding:0 .75rem; border:1px solid var(--sys-gold); border-radius:.4rem; background:var(--sys-gold); color:#fff; font-size:.78rem; cursor:pointer; }
.sys-todo-upload-button:hover { background:#6a5129; }
.sys-todo-upload-note { flex:1 1 15rem; color:#666; font-size:.72rem; line-height:1.5; }
.sys-todo-field.is-dragging { outline:2px dashed var(--sys-gold); outline-offset:3px; border-radius:.55rem; background:var(--sys-gold-soft); }
.sys-todo-existing { display:flex; flex-wrap:wrap; gap:.55rem; margin-top:.45rem; }
.sys-todo-existing__item { display:grid; gap:.25rem; width:8rem; padding:.4rem; border:1px solid #e4dccd; border-radius:.45rem; background:#fcfaf5; font-size:.7rem; }
.sys-todo-existing__item img { width:100%; height:5rem; object-fit:cover; border-radius:.3rem; background:#fff; }
.sys-todo-existing__item { display:grid; gap:.25rem; width:8.5rem; padding:.4rem; border:1px solid #e4dccd; border-radius:.45rem; background:#fcfaf5; font-size:.7rem; }
.sys-todo-existing__item button { display:block; width:100%; padding:0; border:0; border-radius:.3rem; background:#fff; cursor:zoom-in; overflow:hidden; }
.sys-todo-existing__item img { display:block; width:100%; height:5rem; object-fit:cover; background:#fff; }
.sys-todo-existing__item label { display:flex; align-items:center; gap:.25rem; color:#b80000; }
.sys-todo-dialog__foot { display:flex; justify-content:flex-end; gap:.5rem; padding:.75rem 1.25rem; border-top:1px solid #e8e0d2; background:#fcfaf5; }
.sys-todo-dialog__foot button { min-height:2.1rem; padding:0 .9rem; border:1px solid var(--sys-border); border-radius:.45rem; background:#fff; font:inherit; font-size:.8125rem; cursor:pointer; }
.sys-todo-dialog__foot button[type="submit"] { border-color:var(--sys-gold); background:var(--sys-gold); color:#fff; }
@media (max-width:1100px) { .sys-todo-summary { grid-template-columns:repeat(3,minmax(0,1fr)); } .sys-todo-filter { grid-template-columns:repeat(2,minmax(0,1fr)); } .sys-todo-filter__actions { justify-self:end; } }
@media (max-width:720px) { .sys-todo-summary { grid-template-columns:repeat(2,minmax(0,1fr)); } .sys-todo-filter { grid-template-columns:1fr; } .sys-todo-filter__actions { justify-self:stretch; } .sys-todo-filter__actions .sys-todo-page__button { flex:1; } .sys-todo-field--3,.sys-todo-field--4,.sys-todo-field--6 { grid-column:span 12; } }
.sys-todo-image-dialog { width:min(72rem,calc(100vw - 2rem)); max-height:92vh; padding:0; border:1px solid var(--sys-border); border-radius:.8rem; background:#111; color:#fff; overflow:hidden; }
.sys-todo-image-dialog::backdrop { background:rgba(5,5,6,.78); }
.sys-todo-image-dialog__head { display:flex; align-items:center; gap:1rem; padding:.65rem .85rem; background:#1d1d1f; }
.sys-todo-image-dialog__head h2 { margin:0; min-width:0; overflow:hidden; font-size:.82rem; text-overflow:ellipsis; white-space:nowrap; }
.sys-todo-image-dialog__head button { margin-left:auto; width:2rem; height:2rem; border:1px solid #5a554d; border-radius:999px; background:#2a2927; color:#fff; cursor:pointer; }
.sys-todo-image-dialog__body { display:grid; place-items:center; height:calc(92vh - 7rem); padding:.75rem; background:#111; overflow:auto; }
.sys-todo-image-dialog__body img { max-width:100%; max-height:100%; object-fit:contain; }
.sys-todo-image-dialog__foot { display:flex; justify-content:flex-end; padding:.55rem .85rem; background:#1d1d1f; }
.sys-todo-image-dialog__foot a { color:#f0e4bf; font-size:.75rem; }
@media (max-width:1300px) { .sys-todo-summary { grid-template-columns:repeat(3,minmax(0,1fr)); } }
@media (max-width:900px) { .sys-todo-filter label, .sys-todo-filter label.sys-todo-filter__keyword { flex-basis:9rem; } .sys-todo-filter__actions { width:100%; } .sys-todo-filter__actions .sys-todo-page__button { flex:1; } }
@media (max-width:720px) { .sys-todo-summary { grid-template-columns:repeat(2,minmax(0,1fr)); } .sys-todo-filter label, .sys-todo-filter label.sys-todo-filter__keyword { flex-basis:10rem; } .sys-todo-field--3,.sys-todo-field--4,.sys-todo-field--6 { grid-column:span 12; } .sys-todo-table-wrap { max-height:65vh; } }
</style>
<div class="biz-card-head">
@ -139,19 +173,62 @@
<option value="{{ $owner }}" @selected($todoFilters['owner'] === $owner)>{{ $owner }}</option>
@endforeach
</select></label>
<label>关键词<input type="search" name="keyword" value="{{ $todoFilters['keyword'] }}" placeholder="事项、内容、责任人、进展或备注"></label>
<label>时间类型<select name="date_scope" data-sys-todo-filter-date-scope>
@foreach ($todoDateScopes as $value => $label)
<option value="{{ $value }}" @selected($todoFilters['date_scope'] === $value)>{{ $label }}</option>
@endforeach
</select></label>
<label>从<input type="date" name="date_from" value="{{ $todoFilters['date_from'] }}"></label>
<label>至<input type="date" name="date_to" value="{{ $todoFilters['date_to'] }}"></label>
<label class="sys-todo-filter__keyword">关键词<input type="search" name="keyword" value="{{ $todoFilters['keyword'] }}" placeholder="事项、内容、责任人、进展或备注"></label>
<div class="sys-todo-filter__actions">
<button type="submit" class="sys-todo-page__button sys-todo-page__button--primary">筛选</button>
<a class="sys-todo-page__button" href="{{ request()->url() }}">重置</a>
</div>
</form>
<div class="sys-todo-table-wrap">
@php
$groupRowspans = ['category' => [], 'section' => []];
foreach (['category', 'section'] as $groupField) {
$start = 0;
$previous = null;
$count = 0;
foreach ($items as $index => $groupItem) {
$current = trim((string) ($groupItem->{$groupField} ?? ''));
if ($index === 0) {
$start = 0;
$previous = $current;
$count = 1;
continue;
}
if ($current === $previous) {
$count++;
continue;
}
if ($previous !== '' && $count > 0) {
for ($rowIndex = $start; $rowIndex < $start + $count; $rowIndex++) {
$groupRowspans[$groupField][$rowIndex] = $rowIndex === $start ? $count : 0;
}
}
$start = $index;
$previous = $current;
$count = 1;
}
if ($previous !== null && $previous !== '' && $count > 0) {
for ($rowIndex = $start; $rowIndex < $start + $count; $rowIndex++) {
$groupRowspans[$groupField][$rowIndex] = $rowIndex === $start ? $count : 0;
}
}
}
$lastItem = $items->last();
@endphp
<div class="sys-todo-table-wrap" tabindex="0" aria-label="待办列表,可滚动查看全部内容">
<table class="sys-todo-table" aria-label="财务系统化待办清单">
<thead>
<tr>
<th>序号</th><th>类型</th><th>内容</th><th>待办事项</th><th>总负责人</th><th>责任人</th>
<th>开始时间</th><th>完成时间</th><th>状态</th><th>完成情况</th><th>完成截图</th><th>备注</th><th>操作</th>
<th scope="col">序号</th><th scope="col">类型</th><th scope="col">内容</th><th scope="col">待办事项</th><th scope="col">总负责人</th><th scope="col">责任人</th>
<th scope="col">开始时间</th><th scope="col">完成时间</th><th scope="col">状态</th><th scope="col">完成情况</th><th scope="col">完成截图</th><th scope="col">备注</th><th scope="col">操作</th>
</tr>
</thead>
<tbody>
@ -188,12 +265,21 @@
]),
])->values()->all(),
];
$todoPayloadEncoded = base64_encode(json_encode($todoPayload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
$categorySpan = $groupRowspans['category'][$loop->index] ?? 1;
$sectionSpan = $groupRowspans['section'][$loop->index] ?? 1;
@endphp
<tr>
<td>{{ $items->firstItem() + $loop->index }}</td>
<td>{{ $item->category ?: '—' }}</td>
<td>{{ $item->section ?: '—' }}</td>
<td class="sys-todo-table__title">{!! nl2br(e($item->title)) !!}</td>
<tr tabindex="0" data-sys-todo-row-edit="{{ $todoPayloadEncoded }}" title="点击整行直接编辑">
<td><span class="sys-todo-table__index" title="固定系统序号">{{ $item->sort_order ?: $item->id }}</span></td>
@if ($categorySpan !== 0)
<td class="sys-todo-table__group" @if ($categorySpan > 1) rowspan="{{ $categorySpan }}" @endif>{{ $item->category ?: '—' }}</td>
@endif
@if ($sectionSpan !== 0)
<td class="sys-todo-table__group sys-todo-table__section" @if ($sectionSpan > 1) rowspan="{{ $sectionSpan }}" @endif>
<div class="sys-todo-table__clamp" title="{{ $item->section ?: '—' }}">{{ $item->section ?: '—' }}</div>
</td>
@endif
<td class="sys-todo-table__title"><div class="sys-todo-table__clamp" title="{{ $item->title }}">{{ $item->title }}</div></td>
<td>{{ $item->owner ?: '—' }}</td>
<td>{{ $item->assignee ?: '—' }}</td>
<td>{{ $item->start_date?->format('Y-m-d') ?: ($item->start_note ?: '—') }}</td>
@ -202,26 +288,31 @@
@if ($isOverdue)<br><span class="sys-todo-badge sys-todo-badge--overdue">已逾期</span>@endif
</td>
<td><span class="sys-todo-badge {{ $statusClass }}">{{ $item->status }}</span></td>
<td class="sys-todo-table__progress">{!! nl2br(e($item->progress ?: '—')) !!}</td>
<td class="sys-todo-table__progress"><div class="sys-todo-table__clamp" title="{{ $item->progress ?: '—' }}">{{ $item->progress ?: '—' }}</div></td>
<td>
@if ($item->attachments->isNotEmpty())
<div class="sys-todo-shots">
@foreach ($item->attachments as $attachment)
<a href="{{ route('business.systemization-todos.attachments.show', ['todo' => $item->id, 'attachment' => $attachment->id]) }}"
target="_blank" rel="noopener" title="{{ $attachment->original_name }}">
@php
$attachmentUrl = route('business.systemization-todos.attachments.show', [
'todo' => $item->id,
'attachment' => $attachment->id,
]);
@endphp
<button type="button" data-sys-todo-image-url="{{ $attachmentUrl }}" data-sys-todo-image-name="{{ $attachment->original_name }}" title="点击预览:{{ $attachment->original_name }}">
<img src="{{ route('business.systemization-todos.attachments.show', ['todo' => $item->id, 'attachment' => $attachment->id]) }}"
alt="{{ $attachment->original_name }}" loading="lazy">
</a>
</button>
@endforeach
</div>
@else
—
@endif
</td>
<td class="sys-todo-table__notes">{!! nl2br(e($item->notes ?: '—')) !!}</td>
<td class="sys-todo-table__notes"><div class="sys-todo-table__clamp" title="{{ $item->notes ?: '—' }}">{{ $item->notes ?: '—' }}</div></td>
<td>
<div class="sys-todo-row-actions">
<button type="button" data-sys-todo-edit="{{ base64_encode(json_encode($todoPayload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) }}">编辑</button>
<button type="button" data-sys-todo-edit="{{ $todoPayloadEncoded }}">编辑</button>
<form method="POST" action="{{ route('business.systemization-todos.destroy', ['todo' => $item->id]) }}" onsubmit="return confirm('确定删除这条待办吗?');">
@csrf
@method('DELETE')
@ -237,6 +328,15 @@
</table>
</div>
<div class="sys-todo-table__add">
<span>点击表内任意事项可直接编辑;表格在框内滚动,表头、序号和操作列保持可见。</span>
<button type="button" data-sys-todo-create
data-sys-todo-default-category="{{ $lastItem?->category ?? '' }}"
data-sys-todo-default-section="{{ $lastItem?->section ?? '' }}">
<span class="material-icons-outlined" aria-hidden="true">playlist_add</span>在列表底部新增一条
</button>
</div>
@if ($items->hasPages())
<div class="sys-todo-pagination">
<span>共 {{ number_format($items->total()) }} 条 · 第 {{ $items->currentPage() }} / {{ $items->lastPage() }} 页</span>
@ -276,9 +376,12 @@
<label class="sys-todo-field sys-todo-field--6">完成情况<textarea name="progress" maxlength="10000"></textarea></label>
<label class="sys-todo-field sys-todo-field--6">备注<textarea name="notes" maxlength="10000"></textarea></label>
<div class="sys-todo-field sys-todo-field--6" data-sys-todo-upload>
<label for="sysTodoScreenshots">完成截图</label>
<input id="sysTodoScreenshots" type="file" name="screenshots[]" accept=".jpg,.jpeg,.png,.webp" multiple>
<span class="sys-todo-upload-note" data-sys-todo-upload-note>可选择、拖入或直接粘贴截图,每张不超过 10 MB。</span>
<span>完成截图</span>
<div class="sys-todo-upload-zone">
<button type="button" class="sys-todo-upload-button" data-sys-todo-choose-files>选择截图</button>
<input id="sysTodoScreenshots" type="file" name="screenshots[]" accept=".jpg,.jpeg,.png,.webp" multiple>
<span class="sys-todo-upload-note" data-sys-todo-upload-note>点击选择、拖入此区域或直接粘贴,支持多张,每张不超过 10 MB。</span>
</div>
<span class="sys-todo-existing" data-sys-todo-existing></span>
</div>
</div>
@ -290,6 +393,19 @@
</form>
</dialog>
<dialog class="sys-todo-image-dialog" id="sysTodoImageViewer" aria-labelledby="sysTodoImageViewerTitle">
<div class="sys-todo-image-dialog__head">
<h2 id="sysTodoImageViewerTitle" data-sys-todo-image-title>完成截图预览</h2>
<button type="button" data-sys-todo-image-close aria-label="关闭截图预览">×</button>
</div>
<div class="sys-todo-image-dialog__body">
<img src="" alt="" data-sys-todo-image-preview>
</div>
<div class="sys-todo-image-dialog__foot">
<a href="" target="_blank" rel="noopener" data-sys-todo-image-open>在新页面打开原图</a>
</div>
</dialog>
<datalist id="sysTodoCategories">@foreach ($todoCategories as $category)<option value="{{ $category }}">@endforeach</datalist>
<datalist id="sysTodoOwners">@foreach ($todoOwners as $owner)<option value="{{ $owner }}">@endforeach</datalist>
@ -303,8 +419,13 @@
var uploadField = dialog.querySelector('[data-sys-todo-upload]');
var screenshotInput = document.getElementById('sysTodoScreenshots');
var uploadNote = dialog.querySelector('[data-sys-todo-upload-note]');
var imageViewer = document.getElementById('sysTodoImageViewer');
var imagePreview = imageViewer.querySelector('[data-sys-todo-image-preview]');
var imageTitle = imageViewer.querySelector('[data-sys-todo-image-title]');
var imageOpen = imageViewer.querySelector('[data-sys-todo-image-open]');
var routes = @json($todoRoutes, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
var currentTodoId = null;
var uploadPrompt = '点击选择、拖入此区域或直接粘贴,支持多张,每张不超过 10 MB。';
function decodePayload(value) {
var binary = atob(value);
@ -318,21 +439,50 @@
if (field) field.value = value || '';
}
function selectedFilesLabel() {
return Array.prototype.slice.call(screenshotInput.files || [])
.map(function (file) { return file.name; })
.join('、');
}
function appendScreenshotFiles(files) {
var images = Array.prototype.slice.call(files || []).filter(function (file) {
return /^image\/(jpeg|png|webp)$/.test(file.type);
return /^image\/(jpeg|png|webp)$/.test(file.type)
|| /\.(jpe?g|png|webp)$/i.test(file.name || '');
});
if (!images.length) return;
if (!images.length) {
uploadNote.textContent = '没有识别到 JPG、PNG 或 WebP 图片。';
return;
}
var transfer = new DataTransfer();
Array.prototype.slice.call(screenshotInput.files || []).forEach(function (file) {
transfer.items.add(file);
});
images.forEach(function (file) {
transfer.items.add(file);
});
screenshotInput.files = transfer.files;
uploadNote.textContent = '已选择 ' + screenshotInput.files.length + ' 张截图,保存后上传。';
try {
var transfer = new DataTransfer();
Array.prototype.slice.call(screenshotInput.files || []).forEach(function (file) {
transfer.items.add(file);
});
images.forEach(function (file) {
transfer.items.add(file);
});
screenshotInput.files = transfer.files;
uploadNote.textContent = '已选择 ' + screenshotInput.files.length + ' 张:' + selectedFilesLabel() + '。保存后上传。';
} catch (error) {
uploadNote.textContent = '当前浏览器不能合并拖入的图片,请点击“选择截图”后再保存。';
}
}
function openImageViewer(url, name) {
imageTitle.textContent = name || '完成截图预览';
imagePreview.src = url;
imagePreview.alt = name || '完成截图';
imageOpen.href = url;
if (typeof imageViewer.showModal === 'function') imageViewer.showModal();
else imageViewer.setAttribute('open', '');
}
function closeImageViewer() {
if (typeof imageViewer.close === 'function') imageViewer.close();
else imageViewer.removeAttribute('open');
imagePreview.removeAttribute('src');
}
function openDialog(payload) {
@ -353,7 +503,8 @@
setValue('completed_at', payload.completed_at);
setValue('progress', payload.progress);
setValue('notes', payload.notes);
} else {
}
if (!currentTodoId && !(payload && payload.status)) {
setValue('status', '待办');
}
@ -361,15 +512,16 @@
((payload && payload.attachments) || []).forEach(function (attachment) {
var item = document.createElement('span');
item.className = 'sys-todo-existing__item';
var link = document.createElement('a');
link.href = attachment.url;
link.target = '_blank';
link.rel = 'noopener';
var preview = document.createElement('button');
preview.type = 'button';
preview.setAttribute('data-sys-todo-image-url', attachment.url);
preview.setAttribute('data-sys-todo-image-name', attachment.name);
preview.title = '点击预览:' + attachment.name;
var image = document.createElement('img');
image.src = attachment.url;
image.alt = attachment.name;
link.appendChild(image);
item.appendChild(link);
preview.appendChild(image);
item.appendChild(preview);
var label = document.createElement('label');
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
@ -383,7 +535,7 @@
if (typeof dialog.showModal === 'function') dialog.showModal();
else dialog.setAttribute('open', '');
uploadNote.textContent = '可选择、拖入或直接粘贴截图,每张不超过 10 MB。';
uploadNote.textContent = uploadPrompt;
window.setTimeout(function () {
var titleField = form.querySelector('[name="title"]');
if (titleField) titleField.focus();
@ -396,9 +548,21 @@
}
document.addEventListener('click', function (event) {
var image = event.target.closest('[data-sys-todo-image-url]');
if (image) {
event.preventDefault();
openImageViewer(
image.getAttribute('data-sys-todo-image-url'),
image.getAttribute('data-sys-todo-image-name')
);
return;
}
var create = event.target.closest('[data-sys-todo-create]');
if (create) {
openDialog(null);
openDialog({
category: create.getAttribute('data-sys-todo-default-category') || '',
section: create.getAttribute('data-sys-todo-default-section') || '',
});
return;
}
var edit = event.target.closest('[data-sys-todo-edit]');
@ -406,7 +570,14 @@
openDialog(decodePayload(edit.getAttribute('data-sys-todo-edit')));
return;
}
var row = event.target.closest('[data-sys-todo-row-edit]');
if (row && !event.target.closest('a,button,input,select,textarea,form')) {
openDialog(decodePayload(row.getAttribute('data-sys-todo-row-edit')));
return;
}
if (event.target.closest('[data-sys-todo-close]')) closeDialog();
if (event.target.closest('[data-sys-todo-image-close]')) closeImageViewer();
if (event.target.closest('[data-sys-todo-choose-files]')) screenshotInput.click();
});
dialog.addEventListener('click', function (event) {
if (event.target === dialog) closeDialog();
@ -421,6 +592,21 @@
appendScreenshotFiles(files);
}
});
imageViewer.addEventListener('click', function (event) {
if (event.target === imageViewer) closeImageViewer();
});
document.addEventListener('keydown', function (event) {
if (event.target.matches('[data-sys-todo-image-close]') && (event.key === 'Enter' || event.key === ' ')) {
event.preventDefault();
closeImageViewer();
return;
}
var row = event.target.closest('[data-sys-todo-row-edit]');
if (row && event.target === row && (event.key === 'Enter' || event.key === ' ')) {
event.preventDefault();
openDialog(decodePayload(row.getAttribute('data-sys-todo-row-edit')));
}
});
uploadField.addEventListener('dragover', function (event) {
event.preventDefault();
uploadField.classList.add('is-dragging');
@ -435,7 +621,9 @@
});
screenshotInput.addEventListener('change', function () {
if (screenshotInput.files.length) {
uploadNote.textContent = '已选择 ' + screenshotInput.files.length + ' 张截图,保存后上传。';
uploadNote.textContent = '已选择 ' + screenshotInput.files.length + ' 张:' + selectedFilesLabel() + '。保存后上传。';
} else {
uploadNote.textContent = uploadPrompt;
}
});
})();

View File

@ -26,7 +26,11 @@ class SystemizationTodosTest extends FeatureTestCase
->assertSeeText('财务系统化待办')
->assertSeeText('新增待办')
->assertSeeText('从 Excel 导入现有待办')
->assertSee('data-sys-todo-create', false);
->assertSeeText('时间类型')
->assertSeeText('在列表底部新增一条')
->assertSee('data-sys-todo-create', false)
->assertSee('data-sys-todo-choose-files', false)
->assertSee('id="sysTodoImageViewer"', false);
$this->post(route('business.systemization-todos.store'), [
'category' => '收入',
@ -52,6 +56,13 @@ class SystemizationTodosTest extends FeatureTestCase
$this->assertSame('收入', $todo->category);
$this->assertSame(SystemizationTodo::STATUS_IN_PROGRESS, $todo->status);
$this->assertSame(2, $todo->attachments()->count());
$this->get(route('business.pages.show', [
'section' => 'other',
'page' => 'systemization-todos',
]))
->assertOk()
->assertSee('data-sys-todo-row-edit', false)
->assertSee('data-sys-todo-image-url', false);
$firstAttachment = $todo->attachments()->firstOrFail();
$existingAttachment = $todo->attachments()->reorder()->orderByDesc('id')->firstOrFail();
Storage::disk('uploads')->assertExists($firstAttachment->path);
@ -142,6 +153,63 @@ class SystemizationTodosTest extends FeatureTestCase
}
}
public function test_page_filters_by_date_and_merges_adjacent_category_and_section_cells(): void
{
$this->loginAs();
$this->createTodo('收入', '平台收入核对', '收入事项 A', '2026-10-26', 1);
$this->createTodo('收入', '平台收入核对', '收入事项 B', '2026-10-27', 2);
$this->createTodo('成本', '退款核销', '成本事项', '2026-10-26', 3);
$this->get(route('business.pages.show', [
'section' => 'other',
'page' => 'systemization-todos',
]))
->assertOk()
->assertSee('rowspan="2"', false)
->assertSee('收入事项 A')
->assertSee('收入事项 B');
$response = $this->get(route('business.pages.show', [
'section' => 'other',
'page' => 'systemization-todos',
'date_scope' => 'due_date',
'date_from' => '2026-10-26',
'date_to' => '2026-10-26',
]));
$response->assertOk()->assertSee('收入事项 A')->assertSee('成本事项');
$content = $response->viewData('content');
$this->assertNotContains('收入事项 B', $content['items']->pluck('title')->all());
$this->assertSame([
'date_from' => '2026-10-26',
'date_to' => '2026-10-26',
], array_intersect_key($content['todoFilters'], array_flip(['date_from', 'date_to'])));
}
private function createTodo(
string $category,
string $section,
string $title,
string $dueDate,
int $sortOrder,
): SystemizationTodo {
return SystemizationTodo::query()->create([
'company_id' => (int) company_id(),
'category' => $category,
'section' => $section,
'title' => $title,
'owner' => '晨曦',
'assignee' => '栎阳',
'start_date' => '2026-10-25',
'due_date' => $dueDate,
'status' => SystemizationTodo::STATUS_PENDING,
'sort_order' => $sortOrder,
'created_by' => user_id(),
'updated_by' => user_id(),
]);
}
private function pngUpload(string $name): UploadedFile
{
return UploadedFile::fake()->createWithContent(