#8113 create arrayDataStore map #979

Closed
jorgep wants to merge 17 commits from 8113-preventDuplicateRecords into dev
3 changed files with 9 additions and 4 deletions
Showing only changes of commit d1684b4ae6 - Show all commits

View File

@ -74,8 +74,11 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
mapKey: {
type: String,
default: 'id',
},
}); });
const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']); const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']);
const isLoading = ref(false); const isLoading = ref(false);
const mounted = ref(false); const mounted = ref(false);
@ -84,7 +87,6 @@ const pagination = ref({
rowsPerPage: props.limit, rowsPerPage: props.limit,
page: 1, page: 1,
}); });
const arrayData = useArrayData(props.dataKey, { const arrayData = useArrayData(props.dataKey, {
url: props.url, url: props.url,
filter: props.filter, filter: props.filter,
@ -96,9 +98,10 @@ const arrayData = useArrayData(props.dataKey, {
exprBuilder: props.exprBuilder, exprBuilder: props.exprBuilder,
keepOpts: props.keepOpts, keepOpts: props.keepOpts,
searchUrl: props.searchUrl, searchUrl: props.searchUrl,
mapKey: props.mapKey,
}); });
const store = arrayData.store; const store = arrayData.store;
console.log('store', store);
onMounted(async () => { onMounted(async () => {
if (props.autoLoad && !store.data?.length) await fetch(); if (props.autoLoad && !store.data?.length) await fetch();
mounted.value = true; mounted.value = true;

View File

@ -49,6 +49,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
'exprBuilder', 'exprBuilder',
'searchUrl', 'searchUrl',
'navigate', 'navigate',
'mapKey',
]; ];
if (typeof userOptions === 'object') { if (typeof userOptions === 'object') {
for (const option in userOptions) { for (const option in userOptions) {
@ -294,7 +295,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
function mapData(data) { function mapData(data) {
data.forEach((row) => { data.forEach((row) => {
const key = row.id; const key = row[store.mapKey];
const val = { ...row, key }; const val = { ...row, key };
if (store.map.has(key)) { if (store.map.has(key)) {

View File

@ -17,6 +17,7 @@ export const useArrayDataStore = defineStore('arrayDataStore', () => {
searchUrl: 'params', searchUrl: 'params',
navigate: null, navigate: null,
page: 1, page: 1,
mapKey: 'id',
}; };
function get(key) { function get(key) {