collect.ts 677 B

123456789101112131415161718192021222324252627
  1. import { computed, ref } from 'vue'
  2. import { defineStore } from 'pinia'
  3. import { useAuthStore } from './auth';
  4. export const useCollectStore = defineStore('collect', () => {
  5. const collectableModules = ref<string[]>([]);
  6. const authStore = useAuthStore();
  7. function setCollectableModules(modules: string[]) {
  8. collectableModules.value = modules;
  9. }
  10. function canCollect(module: string) {
  11. if (authStore.isAdmin)
  12. return true;
  13. return collectableModules.value.includes(module);
  14. }
  15. const isEmpty = computed(() => collectableModules.value.length === 0);
  16. return {
  17. isEmpty,
  18. collectableModules,
  19. setCollectableModules,
  20. canCollect,
  21. }
  22. })