34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
import { defineAsyncComponent } from 'vue';
|
|
import { defineStore } from 'pinia';
|
|
import { useStateStore } from 'stores/useStateStore';
|
|
|
|
export const useDescriptorStore = defineStore('descriptorStore', () => {
|
|
const { descriptors, setDescriptors } = useStateStore();
|
|
function get() {
|
|
if (Object.keys(descriptors).length) return descriptors;
|
|
|
|
const currentDescriptors = {};
|
|
const files = import.meta.glob(`/src/**/*DescriptorProxy.vue`);
|
|
const moduleParser = {
|
|
account: 'user',
|
|
client: 'customer',
|
|
};
|
|
for (const file in files) {
|
|
const name = file.split('/').at(-1).slice(0, -19).toLowerCase();
|
|
const descriptor = moduleParser[name] ?? name;
|
|
currentDescriptors[descriptor + 'Fk'] = defineAsyncComponent(files[file]);
|
|
}
|
|
setDescriptors(currentDescriptors);
|
|
return currentDescriptors;
|
|
}
|
|
|
|
function has(name) {
|
|
return get()[name];
|
|
}
|
|
|
|
return {
|
|
has,
|
|
get,
|
|
};
|
|
});
|