refactor: refs #8406 simplified code
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
10d8db6de3
commit
aedcda4799
|
@ -131,9 +131,7 @@ async function fetch(data) {
|
|||
const rows = keyData ? data[keyData] : data;
|
||||
resetData(rows);
|
||||
emit('onFetch', rows);
|
||||
if ($props.insertOnLoad) {
|
||||
await insert();
|
||||
}
|
||||
$props.insertOnLoad && await insert();
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -231,7 +229,7 @@ async function insert(pushData = { ...$props.dataRequired, ...$props.dataDefault
|
|||
const lastRow = formData.value.at(-1);
|
||||
const isLastRowEmpty = lastRow ? isRowEmpty(lastRow) : false;
|
||||
|
||||
if (formData.value.length > 0 && isLastRowEmpty) return;
|
||||
if (formData.value.length && isLastRowEmpty) return;
|
||||
const $index = formData.value.length ? formData.value.at(-1).$index + 1 : 0;
|
||||
|
||||
const nRow = Object.assign({ $index }, pushData);
|
||||
|
@ -335,34 +333,22 @@ function removeIndexField(data) {
|
|||
|
||||
async function handleTab(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const { shiftKey, target } = event;
|
||||
const focusableSelector = `tbody tr td:not(:first-child) :is(a, button, input, textarea, select, details):not([disabled])`;
|
||||
const focusableElements = rowsContainer.value?.querySelectorAll(focusableSelector);
|
||||
const currentIndex = Array.prototype.indexOf.call(focusableElements, event.target);
|
||||
const isLast = event.target === focusableElements[focusableElements.length - 1];
|
||||
const currentIndex = Array.prototype.indexOf.call(focusableElements, target);
|
||||
const index = shiftKey ? currentIndex - 1 : currentIndex + 1;
|
||||
const isLast = target === focusableElements[focusableElements.length - 1];
|
||||
const isFirst = currentIndex === 0;
|
||||
|
||||
if (event.shiftKey) {
|
||||
if (!isFirst) {
|
||||
focusableElements[currentIndex - 1].focus();
|
||||
} else {
|
||||
const prevRow = event.target.closest('tr')?.previousElementSibling;
|
||||
const lastFocusable = prevRow?.querySelector(
|
||||
'td:not(:first-child) :is(input, select, textarea):not([disabled])'
|
||||
);
|
||||
lastFocusable?.focus();
|
||||
}
|
||||
} else {
|
||||
if (isLast) {
|
||||
await insert();
|
||||
await nextTick();
|
||||
} else {
|
||||
focusableElements[currentIndex + 1]?.focus();
|
||||
}
|
||||
if ((shiftKey && !isFirst) || (!shiftKey && !isLast))
|
||||
focusableElements[index]?.focus();
|
||||
else if (isLast) {
|
||||
await insert();
|
||||
await nextTick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function reload(params) {
|
||||
const data = await vnPaginateRef.value.fetch(params);
|
||||
fetch(data);
|
||||
|
|
Loading…
Reference in New Issue