import { defineStore } from 'pinia'; import { message } from 'ant-design-vue'; import { getList, addToCard } from '@/api/goods'; import { goodsList } from '@/utils/mock'; export const useGoodsStore = defineStore('goods', { state: () => ({ params: { pageNum: 1, pageSize: 24, total: 0, categoryId: '' }, list: [] }), actions: { resetListData() { this.list = []; }, async fetchListData() { // const res = await getList(this.params); // this.list = res.data?.record || []; // this.params.total = res.data?.total || 0; this.list = goodsList; this.params.total = 120; }, async fetchAllData(params) { // const res = await getList(params); // return Promise.resolve(res.data || []); return new Promise(resolve => resolve(goodsList)) }, resetParams() { this.params.pageNum = 1; this.params.total = 0; this.params.categoryId = ''; }, updateParams(object = {}) { Object.keys(object).forEach(key => { if (this.params[key] != undefined) { this.params[key] = object[key]; } }) }, addToCard(params, success, fail) { addToCard(params).then(() => { message.success('添加成功') success && success() }).catch(() => { fail && fail() }) } } })