wangzhibo
2026-07-16 e0eb5808fe1ecb4e8a0e15cd9c6a0c77e30679bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const DataStore = {
  categories: [],
  items: [],
  categoryMap: {},
 
  async load() {
    const [catRes, itemRes] = await Promise.all([
      fetch('config/categories.json'),
      fetch('config/items.json')
    ]);
    this.categories = await catRes.json();
    this.items = await itemRes.json();
    this.categoryMap = {};
    this.categories.forEach(c => { this.categoryMap[c.id] = c; });
  },
 
  getCategory(id) {
    return this.categoryMap[id];
  },
 
  getItemsByCategory(categoryId) {
    return this.items.filter(i => i.categoryId === categoryId);
  },
 
  getLocalizedName(item) {
    return I18n.t(item.nameKey);
  },
 
  getAllItemsLocalized() {
    return this.items.map(item => ({
      ...item,
      localName: this.getLocalizedName(item),
      category: this.getCategory(item.categoryId)
    }));
  },
 
  getCategoryName(categoryId) {
    const cat = this.getCategory(categoryId);
    return cat ? I18n.t(cat.nameKey) : '';
  },
 
  getCategoryColorClass(categoryId) {
    const map = {
      recyclable: 'text-recyclable',
      hazardous: 'text-hazardous',
      wet: 'text-wet',
      dry: 'text-dry'
    };
    return map[categoryId] || '';
  }
};