action.js
1.75 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
import LeftmotionApi from '../api/motion/equipments';
export const useActionStore = defineStore(
'action',
() => {
// 1. 原始所有分类(接口拿回来的)
const allCategories = ref([]);
// 2. 隐藏的分类ID(需要持久化)
const hiddenCategories = ref([]);
// 3. 展示的分类 = 全部分类 - 隐藏分类(过滤 ID)
const showCategories = computed(() => {
return allCategories.value.filter((item) => !hiddenCategories.value.includes(item.id));
});
// 获取分类
const getloadCategories = async () => {
if (allCategories.value.length > 0) return;
const response = await LeftmotionApi.getAllCategories();
// 把接口数据存进去
allCategories.value = response.data || [];
// 追加超级组分类(保持原有逻辑)
allCategories.value.push({
id: 'super',
name: '超级组',
});
};
// 隐藏某个分类(传入 ID)
const hideCategory = (categoryId) => {
if (!hiddenCategories.value.includes(categoryId)) {
hiddenCategories.value.push(categoryId);
}
};
// 显示某个分类(取消隐藏,传入 ID)
const showCategory = (categoryId) => {
hiddenCategories.value = hiddenCategories.value.filter((id) => id !== categoryId);
};
return {
allCategories,
showCategories,
hiddenCategories,
getloadCategories,
hideCategory,
showCategory,
};
},
// 持久化配置
{
persist: {
enabled: true,
strategies: [
{
key: 'action-category-store', // 修正 key 名称
paths: ['hiddenCategories'],
},
],
},
},
);