import { listProduct } from '@/api/oa/product'; import { listBomItem } from '@/api/oa/bomItem'; const useProductStore = defineStore('product', { state: () => ({ productMap: {}, bomMap: {}, }), actions: { setProductMap(productMap) { this.productMap = productMap; }, setBomMap(bomMap) { this.bomMap = bomMap; }, async getBomInfo(bomId) { try { if (!this.bomMap[bomId]) { const res = await listBomItem({ bomId }); this.bomMap[bomId] = res.rows; } return this.bomMap[bomId]; } catch (error) { console.error(error); return []; } }, fetchProductMap() { listProduct({ pageNum: 1, pageSize: 10000 }).then(res => { const map = {}; res.rows.forEach(item => { map[item.productId] = item; }); console.log(map, res, 'productMap'); this.productMap = map; }) }, } }) export default useProductStore;