✨ feat(购物页面): 已完成购物页面的调整条数米数功能并计算预估金额
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { EnumSaleMode } from '@/common/Enumerate'
|
||||
import React, { Dispatch } from 'react'
|
||||
import { useContext } from 'react'
|
||||
import { ShoppingStore } from './shoppingStore'
|
||||
|
||||
/**
|
||||
* 456: {
|
||||
@@ -8,7 +9,13 @@ import { useContext } from 'react'
|
||||
* colorKind: {
|
||||
* 4562: {
|
||||
* id: 4562,
|
||||
* checked: false
|
||||
* ...
|
||||
* }
|
||||
* },
|
||||
* multipleSelection: {
|
||||
* 4562: {
|
||||
* id: 4562,
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* },
|
||||
@@ -17,7 +24,7 @@ import { useContext } from 'react'
|
||||
* colorKind: {
|
||||
* 4562: {
|
||||
* id: 4562,
|
||||
* checked: false
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
@@ -40,9 +47,7 @@ export interface GoodsMeta {
|
||||
goodsKind?: {
|
||||
[id: Goods['id']]: Goods
|
||||
}
|
||||
multipleSelection: {
|
||||
[id: Goods['id']]: Goods
|
||||
}
|
||||
multipleSelection?: GoodsMeta['goodsKind']
|
||||
}
|
||||
|
||||
export interface ShoppingStateContextValue {
|
||||
@@ -52,6 +57,7 @@ export interface ShoppingStateContextValue {
|
||||
currentCheckedSaleMode: EnumSaleMode
|
||||
colorStore: ColorStore
|
||||
selectedAmount: number
|
||||
Observer: ShoppingStore
|
||||
}
|
||||
|
||||
export enum ShoppingDispatchType {
|
||||
@@ -63,7 +69,7 @@ export enum ShoppingDispatchType {
|
||||
UPDATE_SELECTED_AMOUNT = 'UPDATE_SELECTED_AMOUNT',
|
||||
UPDATE_CHANGED_CHECKBOX = 'UPDATE_CHANGED_CHECKBOX',
|
||||
}
|
||||
// UPDATE_MultipleSelection
|
||||
|
||||
export interface ShoppingDispatchContextValue {
|
||||
[ShoppingDispatchType.UPDATE_MANAGE_STATUS]: (isManageStatus: ShoppingStateContextValue['isManageStatus']) => void
|
||||
[ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION]: (isMultipleSelection: ShoppingStateContextValue['isMultipleSelection']) => void
|
||||
@@ -109,7 +115,7 @@ export function shoppingReducer(state: ShoppingStateContextValue, action: Shoppi
|
||||
[data.purchaserId as number]: {
|
||||
purchaserId: data.purchaserId,
|
||||
goodsKind: { ...state.colorStore[data.purchaserId]?.goodsKind, ...data.goodsKind },
|
||||
multipleSelection: { ...data.multipleSelection },
|
||||
multipleSelection: data?.multipleSelection ? data.multipleSelection : state.colorStore[data.purchaserId]?.multipleSelection,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { GoodsMeta, ColorStore } from '.'
|
||||
|
||||
// 用于优化数据流 结合发布订阅 更新组件内部状态可以组件自己处理
|
||||
|
||||
export type SubscribeCallback = (changedGoods: GoodsMeta) => void
|
||||
import { ColorStore } from "."
|
||||
|
||||
export type SubscribeCallback = (changedGoods: any) => void
|
||||
|
||||
export class ShoppingStore {
|
||||
// 全局缓存
|
||||
@@ -9,7 +11,7 @@ export class ShoppingStore {
|
||||
// 监听器数组
|
||||
private observers: SubscribeCallback[] = []
|
||||
|
||||
constructor(initialValue: ColorStore) {
|
||||
constructor(initialValue?: any) {
|
||||
initialValue && this.updateStore(initialValue)
|
||||
}
|
||||
// 更新全局缓存
|
||||
@@ -27,9 +29,9 @@ export class ShoppingStore {
|
||||
}
|
||||
}
|
||||
// 通知
|
||||
notify(changedGoods: GoodsMeta) {
|
||||
notify(changedGoods: any) {
|
||||
// 循环调用
|
||||
this.observers.forEach((callback) => {
|
||||
this.observers.forEach(callback => {
|
||||
callback(changedGoods)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user