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;
|
const rows = keyData ? data[keyData] : data;
|
||||||
resetData(rows);
|
resetData(rows);
|
||||||
emit('onFetch', rows);
|
emit('onFetch', rows);
|
||||||
if ($props.insertOnLoad) {
|
$props.insertOnLoad && await insert();
|
||||||
await insert();
|
|
||||||
}
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +229,7 @@ async function insert(pushData = { ...$props.dataRequired, ...$props.dataDefault
|
||||||
const lastRow = formData.value.at(-1);
|
const lastRow = formData.value.at(-1);
|
||||||
const isLastRowEmpty = lastRow ? isRowEmpty(lastRow) : false;
|
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 $index = formData.value.length ? formData.value.at(-1).$index + 1 : 0;
|
||||||
|
|
||||||
const nRow = Object.assign({ $index }, pushData);
|
const nRow = Object.assign({ $index }, pushData);
|
||||||
|
@ -335,34 +333,22 @@ function removeIndexField(data) {
|
||||||
|
|
||||||
async function handleTab(event) {
|
async function handleTab(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const { shiftKey, target } = event;
|
||||||
const focusableSelector = `tbody tr td:not(:first-child) :is(a, button, input, textarea, select, details):not([disabled])`;
|
const focusableSelector = `tbody tr td:not(:first-child) :is(a, button, input, textarea, select, details):not([disabled])`;
|
||||||
const focusableElements = rowsContainer.value?.querySelectorAll(focusableSelector);
|
const focusableElements = rowsContainer.value?.querySelectorAll(focusableSelector);
|
||||||
const currentIndex = Array.prototype.indexOf.call(focusableElements, event.target);
|
const currentIndex = Array.prototype.indexOf.call(focusableElements, target);
|
||||||
const isLast = event.target === focusableElements[focusableElements.length - 1];
|
const index = shiftKey ? currentIndex - 1 : currentIndex + 1;
|
||||||
|
const isLast = target === focusableElements[focusableElements.length - 1];
|
||||||
const isFirst = currentIndex === 0;
|
const isFirst = currentIndex === 0;
|
||||||
|
|
||||||
if (event.shiftKey) {
|
if ((shiftKey && !isFirst) || (!shiftKey && !isLast))
|
||||||
if (!isFirst) {
|
focusableElements[index]?.focus();
|
||||||
focusableElements[currentIndex - 1].focus();
|
else if (isLast) {
|
||||||
} else {
|
await insert();
|
||||||
const prevRow = event.target.closest('tr')?.previousElementSibling;
|
await nextTick();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function reload(params) {
|
async function reload(params) {
|
||||||
const data = await vnPaginateRef.value.fetch(params);
|
const data = await vnPaginateRef.value.fetch(params);
|
||||||
fetch(data);
|
fetch(data);
|
||||||
|
|
Loading…
Reference in New Issue