sanmu
authored
|
1
2
3
4
5
6
7
8
9
|
import { getCategoryList } from './../service'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { Category, CategoryRootType } from '@/type'
export const useCategoryStore = defineStore('category', () => {
const list = ref<CategoryRootType[]>([])
const selectedCategory = ref('') // 选中的一级类别
const selectedSubCategory = ref('') // 选中的二级类别
|
sanmu
authored
|
10
|
const selectedFuncCategory = ref('')
|
sanmu
authored
|
11
|
const categoryVisible = ref(true)
|
sanmu
authored
|
12
13
|
let resetFuncValue = ''
let resetCategoryValue = ''
|
sanmu
authored
|
14
15
16
17
18
|
const getList = () => {
getCategoryList().then((res) => {
const rootList = res.data?.data?.rootCategoryList
list.value = rootList || []
|
sanmu
authored
|
19
|
resetCategoryValue = selectedCategory.value = rootList[0].categoryDisplayName
|
sanmu
authored
|
20
|
selectedSubCategory.value = rootList[0].list[0].id
|
sanmu
authored
|
21
|
resetFuncValue = selectedFuncCategory.value = rootList[0].productFunctions[0].id
|
sanmu
authored
|
22
23
24
25
26
|
})
}
const updateCategory = (value: string) => {
selectedCategory.value = value
|
sanmu
authored
|
27
|
updateFuncCategory(value === resetCategoryValue ? resetFuncValue : '')
|
sanmu
authored
|
28
29
30
31
32
33
|
}
const updateSubCategory = (value: string) => {
selectedSubCategory.value = value
}
|
sanmu
authored
|
34
35
36
37
|
const updateFuncCategory = (value?: string) => {
selectedFuncCategory.value = value || ''
}
|
sanmu
authored
|
38
39
40
41
|
const updateDisplay = (visible: boolean) => {
categoryVisible.value = visible
}
|
sanmu
authored
|
42
43
44
45
46
47
|
return {
list,
selectedCategory,
selectedSubCategory,
selectedFuncCategory,
resetCategoryValue,
|
sanmu
authored
|
48
|
categoryVisible,
|
sanmu
authored
|
49
50
51
|
getList,
updateCategory,
updateSubCategory,
|
sanmu
authored
|
52
53
|
updateFuncCategory,
updateDisplay
|
sanmu
authored
|
54
|
}
|
sanmu
authored
|
55
|
})
|