products.ts
1007 Bytes
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
import { defineStore } from 'pinia'
import { store } from '..'
import type { ProductsDetailWithThingsModelType, Tsl } from '@/api/device/model'
interface ProductsStoreType {
products: Record<string, ProductsDetailWithThingsModelType>
}
export const useProductsStore = defineStore('app-products', {
state: (): ProductsStoreType => {
return {
products: {},
}
},
actions: {
setProducts(products: Record<string, ProductsDetailWithThingsModelType>) {
this.products = products
},
getProductDetailById(id: string) {
return this.products[id]
},
getObjectModelsById(id: string) {
return this.products[id]
},
getObjectModelByIdWithIdentifier(id: string, identifier: string): Nullable<Tsl> {
const product = this.getObjectModelsById(id)
if (!product) return null
return product.tsl.filter(item => item.identifier === identifier)[0]
},
},
})
export function useProductsStoreWithOut() {
return useProductsStore(store)
}