refactor: refs #6897 update VnTable components for improved value handling and UI adjustments
gitea/salix-front/pipeline/pr-test This commit looks good
Details
gitea/salix-front/pipeline/pr-test This commit looks good
Details
This commit is contained in:
parent
b611430d7a
commit
4354fc2293
|
@ -91,7 +91,6 @@ const components = {
|
|||
event: updateEvent,
|
||||
attrs: {
|
||||
...defaultAttrs,
|
||||
style: 'min-width: 150px',
|
||||
},
|
||||
forceAttrs,
|
||||
},
|
||||
|
|
|
@ -31,6 +31,8 @@ import VnLv from 'components/ui/VnLv.vue';
|
|||
import VnTableOrder from 'src/components/VnTable/VnOrder.vue';
|
||||
import VnTableFilter from './VnTableFilter.vue';
|
||||
import { getColAlign } from 'src/composables/getColAlign';
|
||||
import RightMenu from '../common/RightMenu.vue';
|
||||
import { QItemSection } from 'quasar';
|
||||
|
||||
const arrayData = useArrayData(useAttrs()['data-key']);
|
||||
const $props = defineProps({
|
||||
|
@ -414,20 +416,13 @@ async function renderInput(rowId, field, clickedElement) {
|
|||
eventHandlers: {
|
||||
'update:modelValue': async (value) => {
|
||||
if (isSelect && value) {
|
||||
row[column.name] = value[column.attrs?.optionValue ?? 'id'];
|
||||
row[column?.name + 'TextValue'] =
|
||||
value[column.attrs?.optionLabel ?? 'name'];
|
||||
await column?.cellEvent?.['update:modelValue']?.(
|
||||
value,
|
||||
oldValue,
|
||||
row,
|
||||
);
|
||||
await updateSelectValue(value, column, row, oldValue);
|
||||
} else row[column.name] = value;
|
||||
await column?.cellEvent?.['update:modelValue']?.(value, oldValue, row);
|
||||
},
|
||||
keyup: async (event) => {
|
||||
if (event.key === 'Enter')
|
||||
await destroyInput(rowIndex, field, clickedElement);
|
||||
await destroyInput(rowId, field, clickedElement);
|
||||
},
|
||||
keydown: async (event) => {
|
||||
switch (event.key) {
|
||||
|
@ -458,6 +453,17 @@ async function renderInput(rowId, field, clickedElement) {
|
|||
node.el?.querySelector('span > div > div').focus();
|
||||
}
|
||||
|
||||
async function updateSelectValue(value, column, row, oldValue) {
|
||||
row[column.name] = value[column.attrs?.optionValue ?? 'id'];
|
||||
|
||||
row[column?.name + 'VnTableTextValue'] = value[column.attrs?.optionLabel ?? 'name'];
|
||||
|
||||
if (column?.attrs?.find?.label)
|
||||
row[column?.attrs?.find?.label] = value[column.attrs?.optionLabel ?? 'name'];
|
||||
|
||||
await column?.cellEvent?.['update:modelValue']?.(value, oldValue, row);
|
||||
}
|
||||
|
||||
async function destroyInput(rowIndex, field, clickedElement) {
|
||||
if (!clickedElement)
|
||||
clickedElement = document.querySelector(
|
||||
|
@ -520,9 +526,9 @@ function getToggleIcon(value) {
|
|||
}
|
||||
|
||||
function formatColumnValue(col, row, dashIfEmpty) {
|
||||
if (col?.format || row[col?.name + 'TextValue']) {
|
||||
if (selectRegex.test(col?.component) && row[col?.name + 'TextValue']) {
|
||||
return dashIfEmpty(row[col?.name + 'TextValue']);
|
||||
if (col?.format || row[col?.name + 'VnTableTextValue']) {
|
||||
if (selectRegex.test(col?.component) && row[col?.name + 'VnTableTextValue']) {
|
||||
return dashIfEmpty(row[col?.name + 'VnTableTextValue']);
|
||||
} else {
|
||||
return col.format(row, dashIfEmpty);
|
||||
}
|
||||
|
@ -555,19 +561,33 @@ function formatColumnValue(col, row, dashIfEmpty) {
|
|||
}
|
||||
return dashIfEmpty(row[col?.name]);
|
||||
}
|
||||
|
||||
function cardClick(_, row) {
|
||||
if ($props.redirect) router.push({ path: `/${$props.redirect}/${row.id}` });
|
||||
}
|
||||
|
||||
function removeTextValue(data, getChanges) {
|
||||
let changes = data.updates;
|
||||
if (!changes) return data;
|
||||
|
||||
for (const change of changes) {
|
||||
for (const key in change.data) {
|
||||
if (key.endsWith('VnTableTextValue')) {
|
||||
delete change.data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.updates = changes.filter((change) => Object.keys(change.data).length > 0);
|
||||
|
||||
if ($attrs?.beforeSaveFn) data = $attrs.beforeSaveFn(data, getChanges);
|
||||
|
||||
return data;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<QDrawer
|
||||
v-if="$props.rightSearch"
|
||||
v-model="stateStore.rightDrawer"
|
||||
side="right"
|
||||
:width="256"
|
||||
:overlay="$props.overlay"
|
||||
>
|
||||
<QScrollArea class="fit">
|
||||
<RightMenu v-if="$props.rightSearch">
|
||||
<template #right-panel>
|
||||
<VnTableFilter
|
||||
:data-key="$attrs['data-key']"
|
||||
:columns="columns"
|
||||
|
@ -581,8 +601,8 @@ function cardClick(_, row) {
|
|||
<slot :name="slotName" v-bind="slotData ?? {}" :key="slotName" />
|
||||
</template>
|
||||
</VnTableFilter>
|
||||
</QScrollArea>
|
||||
</QDrawer>
|
||||
</template>
|
||||
</RightMenu>
|
||||
<CrudModel
|
||||
v-bind="$attrs"
|
||||
:class="$attrs['class'] ?? 'q-px-md'"
|
||||
|
@ -591,6 +611,7 @@ function cardClick(_, row) {
|
|||
@on-fetch="(...args) => emit('onFetch', ...args)"
|
||||
:search-url="searchUrl"
|
||||
:disable-infinite-scroll="isTableMode"
|
||||
:before-save-fn="removeTextValue"
|
||||
@save-changes="reload"
|
||||
:has-sub-toolbar="$props.hasSubToolbar ?? isEditable"
|
||||
:auto-load="hasParams || $attrs['auto-load']"
|
||||
|
@ -635,20 +656,13 @@ function cardClick(_, row) {
|
|||
:skip="columnsVisibilitySkipped"
|
||||
/>
|
||||
<QBtnToggle
|
||||
v-if="!tableModes.some((mode) => mode.disable)"
|
||||
v-model="mode"
|
||||
toggle-color="primary"
|
||||
class="bg-vn-section-color"
|
||||
dense
|
||||
:options="tableModes.filter((mode) => !mode.disable)"
|
||||
/>
|
||||
|
||||
<QBtn
|
||||
v-if="showRightIcon"
|
||||
icon="filter_alt"
|
||||
class="bg-vn-section-color q-ml-sm"
|
||||
dense
|
||||
@click="stateStore.toggleRightDrawer()"
|
||||
/>
|
||||
</template>
|
||||
<template #header-cell="{ col }">
|
||||
<QTh
|
||||
|
|
|
@ -639,7 +639,7 @@ onMounted(() => {
|
|||
'flex-wrap': 'wrap',
|
||||
gap: '16px',
|
||||
position: 'relative',
|
||||
height: '450px',
|
||||
height: '500px',
|
||||
},
|
||||
columnGridStyle: {
|
||||
'max-width': '50%',
|
||||
|
@ -650,7 +650,7 @@ onMounted(() => {
|
|||
:is-editable="editableMode"
|
||||
:without-header="!editableMode"
|
||||
:with-filters="editableMode"
|
||||
:right-search="true"
|
||||
:right-search="editableMode"
|
||||
:right-search-icon="true"
|
||||
:row-click="false"
|
||||
:columns="columns"
|
||||
|
|
|
@ -274,7 +274,7 @@ onBeforeMount(async () => {
|
|||
:array-data-props="{
|
||||
url: 'Entries/filter',
|
||||
order: 'landed DESC',
|
||||
userFilter: EntryFilter,
|
||||
userFilter: entryQueryFilter,
|
||||
}"
|
||||
>
|
||||
<template #advanced-menu>
|
||||
|
|
|
@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { useSummaryDialog } from 'src/composables/useSummaryDialog';
|
||||
import { useQuasar } from 'quasar';
|
||||
import { dashIfEmpty, toDate, toHour } from 'src/filters';
|
||||
import { toDate, toHour } from 'src/filters';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { usePrintService } from 'src/composables/usePrintService';
|
||||
|
||||
|
|
Loading…
Reference in New Issue