| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { computed, ref } from 'vue'
- import { defineStore } from 'pinia'
- import { useAuthStore } from './auth';
- const CollectableModulesNameMapping : Record<string, string> = {
- 'overview': '村落概况',
- 'distribution': '建筑分布',
- 'building': '传统建筑',
- 'folk_culture': '民俗文化',
- 'food_product': '美食物产',
- 'route': '旅游路线',
- 'travel_guide': '旅游导览',
- 'element': '环境要素',
- 'environment': '环境格局',
- 'relic': '文物古迹',
- 'cultural': '历史文化',
- 'figure': '历史人物',
- 'ich': '非遗',
- 'story': '掌故轶事',
- 'village': '风景名胜',
- 'speaker': '口述者',
- 'collect': '随手记',
- }
- export const useCollectStore = defineStore('collect', () => {
- const collectableModules = ref(new Map<string, number>());
- const authStore = useAuthStore();
- function setCollectableModules(modules: Map<string, number>) {
- collectableModules.value = modules;
- console.log(modules);
-
- }
- function canCollect(module: string) {
- if (authStore.isAdmin)
- return true;
- if (collectableModules.value.has(CollectableModulesNameMapping[module]))
- return true;
- return collectableModules.value.has(module);
- }
- function getCollectModuleId(module: string) {
- if (collectableModules.value.has(CollectableModulesNameMapping[module]))
- return collectableModules.value.get(CollectableModulesNameMapping[module]);
- return collectableModules.value.get(module);
- }
- function getCollectModuleInternalNameById(id: number) {
- for (const [key, value] of collectableModules.value) {
- if (value == id) {
- for (const k2 in CollectableModulesNameMapping) {
- if (CollectableModulesNameMapping[k2] == key) {
- return k2;
- }
- }
- }
- }
- return '';
- }
-
- const isEmpty = computed(() => collectableModules.value.size === 0);
- return {
- isEmpty,
- collectableModules,
- setCollectableModules,
- getCollectModuleInternalNameById,
- getCollectModuleId,
- canCollect,
- }
- })
|