购物车逻辑调整
This commit is contained in:
@@ -4,18 +4,19 @@ import { getCompanyId } from '@/utils';
|
||||
|
||||
const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
state: (): { shoppingCartList: GoodsBean[] } => ({
|
||||
shoppingCartList: []
|
||||
shoppingCartList: uni.getStorageSync(`shoppingCart_${getCompanyId()}`) as GoodsBean[]
|
||||
}),
|
||||
|
||||
persist: {
|
||||
// 修改存储中使用的键名称,默认为当前 Store的 id
|
||||
key: 'shoppingCartState_' + getCompanyId(),
|
||||
key: 'shoppingCartState',
|
||||
storage: {
|
||||
setItem(key, value) {
|
||||
uni.setStorageSync(key, value); // [!code warning]
|
||||
uni.setStorageSync(key, value || []); // [!code warning]
|
||||
uni.setStorageSync(`shoppingCart_${getCompanyId()}`, JSON.parse(value).shoppingCartList);
|
||||
},
|
||||
getItem(key) {
|
||||
return uni.getStorageSync(key); // [!code warning]
|
||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)); // [!code warning]
|
||||
}
|
||||
},
|
||||
// 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
||||
@@ -23,11 +24,11 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
},
|
||||
|
||||
getters: {
|
||||
getShoppingCartList(): any[] {
|
||||
getShoppingCartList(): GoodsBean[] {
|
||||
return this.shoppingCartList;
|
||||
},
|
||||
|
||||
getTotalCount(): number {
|
||||
totalCount(): number {
|
||||
return this.shoppingCartList.length;
|
||||
},
|
||||
|
||||
@@ -57,6 +58,10 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
this.shoppingCartList = this.shoppingCartList.filter(res => res.checked == undefined || res.checked === false);
|
||||
},
|
||||
|
||||
resetData() {
|
||||
this.shoppingCartList = uni.getStorageSync(`shoppingCart_${getCompanyId()}`);
|
||||
},
|
||||
|
||||
clearAll() {
|
||||
this.shoppingCartList = [];
|
||||
}
|
||||
|
Reference in New Issue
Block a user