feat: 支持系统化待办负责人多选
This commit is contained in:
parent
533d25783f
commit
a0b467c27a
@ -76,11 +76,21 @@
|
||||
.sys-todo-grid-value { display:block; min-width:0; min-height:1.65rem; padding:.18rem .25rem; border:1px solid transparent; border-radius:.3rem; cursor:text; outline:none; }
|
||||
.sys-todo-grid-value:hover { border-color:#ded4c3; background:#fffdf8; }
|
||||
.sys-todo-grid-value:focus-visible, .sys-todo-grid-value.is-selected { border-color:var(--sys-gold); background:var(--sys-gold-soft); box-shadow:0 0 0 2px rgba(133,102,50,.16); }
|
||||
.sys-todo-grid-value.is-editing { position:relative; padding:0; border-color:var(--sys-gold); background:#fff; box-shadow:0 0 0 3px rgba(133,102,50,.18); }
|
||||
.sys-todo-grid-value.is-editing { position:relative; z-index:25; padding:0; border-color:var(--sys-gold); background:#fff; box-shadow:0 0 0 3px rgba(133,102,50,.18); }
|
||||
.sys-todo-grid-value.is-date-anchor { border-color:var(--sys-gold); background:#fff; box-shadow:0 0 0 3px rgba(133,102,50,.18); }
|
||||
.sys-todo-grid-value.is-dirty { background:#fff8e8; }
|
||||
.sys-todo-grid-editor { display:block; box-sizing:border-box; width:100%; min-height:1.9rem; padding:.3rem .4rem; border:0; border-radius:.28rem; background:#fff; color:#171717; font:inherit; font-size:.78rem; line-height:1.5; outline:none; resize:vertical; }
|
||||
textarea.sys-todo-grid-editor { min-height:4rem; }
|
||||
.sys-todo-grid-people-editor { position:absolute; top:calc(100% + .3rem); left:-.25rem; z-index:30; display:grid; box-sizing:border-box; width:min(17rem,calc(100vw - 2rem)); padding:.5rem; border:1px solid var(--sys-gold); border-radius:.5rem; background:#fff; box-shadow:0 8px 24px rgba(23,23,23,.18); gap:.45rem; }
|
||||
.sys-todo-grid-people-editor__options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.2rem .55rem; max-height:9rem; padding:.1rem; overflow:auto; }
|
||||
.sys-todo-grid-people-editor__options label { display:flex; align-items:center; gap:.35rem; min-height:1.8rem; padding:.12rem .25rem; border-radius:.3rem; color:#333; font-size:.75rem; cursor:pointer; }
|
||||
.sys-todo-grid-people-editor__options label:hover { background:var(--sys-gold-soft); }
|
||||
.sys-todo-grid-people-editor__options input[type="checkbox"] { flex:0 0 auto; width:1rem; height:1rem; margin:0; }
|
||||
.sys-todo-grid-people-editor__actions { display:flex; justify-content:flex-end; gap:.4rem; }
|
||||
.sys-todo-grid-people-editor__actions button { min-height:1.8rem; padding:0 .65rem; border:1px solid var(--sys-border); border-radius:.35rem; background:#fff; color:#51483c; font:inherit; font-size:.7rem; cursor:pointer; }
|
||||
.sys-todo-grid-people-editor__actions button:hover { border-color:var(--sys-gold); background:var(--sys-gold-soft); }
|
||||
.sys-todo-grid-people-editor__actions button[data-sys-todo-people-save] { border-color:var(--sys-gold); background:var(--sys-gold); color:#fff; }
|
||||
.sys-todo-grid-people-editor__actions button[data-sys-todo-people-save]:hover { border-color:#6a5129; background:#6a5129; }
|
||||
.sys-todo-grid-date-editor { --sys-gold:#856632; --sys-gold-soft:#f7f0de; --sys-border:#d8d2c7; --sys-muted:#666; position:fixed; top:0; left:0; z-index:45; display:grid; box-sizing:border-box; width:min(18rem,calc(100vw - 1rem)); padding:.55rem; border:1px solid var(--sys-border); border-radius:.55rem; background:#fff; box-shadow:0 6px 18px rgba(23,23,23,.16); gap:.45rem; overflow:visible; }
|
||||
.sys-todo-grid-date-editor .upstream-data-date { width:100%; }
|
||||
.sys-todo-grid-date-editor .upstream-data-date input { height:2rem; font-size:.75rem; }
|
||||
@ -3110,6 +3120,108 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
function openPeopleEditor(cell, field, original, scope) {
|
||||
var label = field === 'owner' ? '总负责人' : '责任人';
|
||||
var choices = (field === 'owner' ? ownerOptions : assigneeOptions).slice();
|
||||
var selected = splitPeople(original);
|
||||
if (field === 'owner' && selected.length === 0) selected = ['待定'];
|
||||
selected.forEach(function (name) {
|
||||
if (choices.indexOf(name) === -1) choices.unshift(name);
|
||||
});
|
||||
|
||||
var wrapper = document.createElement('div');
|
||||
wrapper.className = 'sys-todo-grid-people-editor';
|
||||
wrapper.setAttribute('role', 'dialog');
|
||||
wrapper.setAttribute('aria-label', '选择' + label);
|
||||
wrapper.setAttribute('data-sys-todo-grid-people-editor', field);
|
||||
|
||||
var options = document.createElement('div');
|
||||
options.className = 'sys-todo-grid-people-editor__options';
|
||||
var optionInputs = choices.map(function (name) {
|
||||
var option = document.createElement('label');
|
||||
var input = document.createElement('input');
|
||||
input.type = 'checkbox';
|
||||
input.value = name;
|
||||
input.checked = selected.indexOf(name) !== -1;
|
||||
input.setAttribute('data-sys-todo-people-option', field);
|
||||
var text = document.createElement('span');
|
||||
text.textContent = name;
|
||||
option.appendChild(input);
|
||||
option.appendChild(text);
|
||||
options.appendChild(option);
|
||||
return input;
|
||||
});
|
||||
|
||||
var actions = document.createElement('div');
|
||||
actions.className = 'sys-todo-grid-people-editor__actions';
|
||||
var clear = document.createElement('button');
|
||||
clear.type = 'button';
|
||||
clear.textContent = field === 'owner' ? '设为待定' : '清空';
|
||||
var cancel = document.createElement('button');
|
||||
cancel.type = 'button';
|
||||
cancel.textContent = '取消';
|
||||
var save = document.createElement('button');
|
||||
save.type = 'button';
|
||||
save.textContent = '确定';
|
||||
save.setAttribute('data-sys-todo-people-save', field);
|
||||
actions.append(clear, cancel, save);
|
||||
wrapper.append(options, actions);
|
||||
|
||||
var peopleEditor = wrapper;
|
||||
cell.classList.add('is-editing');
|
||||
cell.replaceChildren(peopleEditor);
|
||||
|
||||
function getValue() {
|
||||
var values = optionInputs
|
||||
.filter(function (input) { return input.checked; })
|
||||
.map(function (input) { return input.value; });
|
||||
if (field === 'owner' && values.length === 0) return '待定';
|
||||
return values.join('、');
|
||||
}
|
||||
|
||||
function finish(commit) {
|
||||
if (!closeEditor(commit)) return;
|
||||
cell.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
activeEditor = {
|
||||
cell: cell,
|
||||
editor: peopleEditor,
|
||||
original: original,
|
||||
scope: scope,
|
||||
getValue: getValue
|
||||
};
|
||||
|
||||
clear.addEventListener('click', function () {
|
||||
optionInputs.forEach(function (input) {
|
||||
input.checked = field === 'owner' && input.value === '待定';
|
||||
});
|
||||
});
|
||||
cancel.addEventListener('click', function () {
|
||||
finish(false);
|
||||
});
|
||||
save.addEventListener('click', function () {
|
||||
finish(true);
|
||||
});
|
||||
wrapper.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
finish(false);
|
||||
}
|
||||
});
|
||||
var closeOnOutsidePointer = function (event) {
|
||||
if (!wrapper.contains(event.target)) finish(true);
|
||||
};
|
||||
activeEditor.dismiss = closeOnOutsidePointer;
|
||||
document.addEventListener('pointerdown', closeOnOutsidePointer, true);
|
||||
|
||||
window.setTimeout(function () {
|
||||
var focusTarget = optionInputs.find(function (input) { return input.checked; })
|
||||
|| optionInputs[0];
|
||||
if (focusTarget) focusTarget.focus({ preventScroll: true });
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function nextEditableCell(cell, backwards) {
|
||||
var all = cells();
|
||||
var index = all.indexOf(cell);
|
||||
@ -3129,14 +3241,13 @@
|
||||
return;
|
||||
}
|
||||
var editor;
|
||||
if (field === 'status' || field === 'owner' || field === 'assignee') {
|
||||
if (field === 'owner' || field === 'assignee') {
|
||||
openPeopleEditor(cell, field, original, scope);
|
||||
return;
|
||||
}
|
||||
if (field === 'status') {
|
||||
editor = document.createElement('select');
|
||||
var choices = field === 'status'
|
||||
? ['未完成', '已完成']
|
||||
: (field === 'owner' ? ownerOptions : assigneeOptions).slice();
|
||||
if (field === 'assignee') {
|
||||
choices.unshift('');
|
||||
}
|
||||
var choices = ['未完成', '已完成'];
|
||||
if (original !== '' && choices.indexOf(original) === -1) {
|
||||
choices.unshift(original);
|
||||
}
|
||||
@ -3146,7 +3257,7 @@
|
||||
option.textContent = value || '未指定';
|
||||
editor.appendChild(option);
|
||||
});
|
||||
editor.value = original || (field === 'assignee' ? '' : '待定');
|
||||
editor.value = original || '未完成';
|
||||
} else if (field === 'title' || field === 'progress') {
|
||||
editor = document.createElement('textarea');
|
||||
editor.rows = field === 'title' ? 2 : 3;
|
||||
@ -3172,7 +3283,7 @@
|
||||
cell.classList.add('is-dirty');
|
||||
});
|
||||
editor.addEventListener('change', function () {
|
||||
if (field === 'status' || field === 'owner' || field === 'assignee') closeEditor(true);
|
||||
if (field === 'status') closeEditor(true);
|
||||
});
|
||||
editor.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape') {
|
||||
@ -3863,6 +3974,7 @@
|
||||
event.button !== 0
|
||||
|| event.target.closest('.sys-todo-grid-editor')
|
||||
|| event.target.closest('.sys-todo-grid-date-editor')
|
||||
|| event.target.closest('.sys-todo-grid-people-editor')
|
||||
) return;
|
||||
var cell = event.target.closest('[data-sys-todo-grid-cell]');
|
||||
if (!cell) return;
|
||||
@ -3899,7 +4011,10 @@
|
||||
});
|
||||
|
||||
table.addEventListener('click', function (event) {
|
||||
if (event.target.closest('.sys-todo-grid-date-editor')) return;
|
||||
if (
|
||||
event.target.closest('.sys-todo-grid-date-editor')
|
||||
|| event.target.closest('.sys-todo-grid-people-editor')
|
||||
) return;
|
||||
var inlineAddButton = event.target.closest('[data-sys-todo-inline-add]');
|
||||
if (inlineAddButton) {
|
||||
event.preventDefault();
|
||||
@ -3948,6 +4063,7 @@
|
||||
if (
|
||||
event.target.closest('.sys-todo-grid-editor')
|
||||
|| event.target.closest('.sys-todo-grid-date-editor')
|
||||
|| event.target.closest('.sys-todo-grid-people-editor')
|
||||
) return;
|
||||
var cell = event.target.closest('[data-sys-todo-grid-cell]');
|
||||
if (!cell) return;
|
||||
|
||||
@ -104,7 +104,11 @@ class SystemizationTodosTest extends FeatureTestCase
|
||||
->assertDontSee('reloadAfterSave', false)
|
||||
->assertSee('var ownerOptions =', false)
|
||||
->assertSee('var assigneeOptions =', false)
|
||||
->assertSee("field === 'status' || field === 'owner' || field === 'assignee'", false)
|
||||
->assertSee("field === 'owner' || field === 'assignee'", false)
|
||||
->assertSee("wrapper.className = 'sys-todo-grid-people-editor'", false)
|
||||
->assertSee('data-sys-todo-grid-people-editor', false)
|
||||
->assertSee('data-sys-todo-people-save', false)
|
||||
->assertSee("event.target.closest('.sys-todo-grid-people-editor')", false)
|
||||
->assertSee('var activeTodoFilters =', false)
|
||||
->assertSee('withCurrentFilters(createUrl)', false)
|
||||
->assertSee('payload.clear_filters || []', false)
|
||||
@ -864,6 +868,13 @@ class SystemizationTodosTest extends FeatureTestCase
|
||||
'original' => '晨曦',
|
||||
'scope' => 'row',
|
||||
],
|
||||
[
|
||||
'id' => $first->id,
|
||||
'field' => 'assignee',
|
||||
'value' => '秋香、常仪',
|
||||
'original' => '栎阳',
|
||||
'scope' => 'row',
|
||||
],
|
||||
[
|
||||
'id' => $first->id,
|
||||
'field' => 'start_date',
|
||||
@ -896,7 +907,7 @@ class SystemizationTodosTest extends FeatureTestCase
|
||||
])->assertOk()
|
||||
->assertJson([
|
||||
'ok' => true,
|
||||
'updated_cells' => 7,
|
||||
'updated_cells' => 8,
|
||||
'updated_rows' => 2,
|
||||
]);
|
||||
|
||||
@ -907,6 +918,7 @@ class SystemizationTodosTest extends FeatureTestCase
|
||||
$this->assertSame('成本', $other->fresh()->category);
|
||||
$this->assertSame('核对收入 A(已更新)', $first->title);
|
||||
$this->assertSame('晨曦、人参', $first->owner);
|
||||
$this->assertSame('秋香、常仪', $first->assignee);
|
||||
$this->assertSame('2026-10-28', $first->start_date?->format('Y-m-d'));
|
||||
$this->assertSame('2026-11-15', $first->due_date?->format('Y-m-d'));
|
||||
$this->assertSame(SystemizationTodo::STATUS_COMPLETED, $first->status);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user