From e2d28f5e80737c133adf446badc62ea05e4f9a08 Mon Sep 17 00:00:00 2001 From: xuan Date: Mon, 13 Mar 2023 15:28:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(ID1001459):=20=E3=80=90?= =?UTF-8?q?=E5=86=85=E9=83=A8=E5=95=86=E5=9F=8E=E3=80=91-=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=A2=E6=88=B7A=E7=9A=84=E9=9D=A2=E6=96=99?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E8=B7=B3=E8=BD=AC=E5=88=B0=E5=AE=A2=E6=88=B7?= =?UTF-8?q?B=E7=9A=84=E8=B4=AD=E7=89=A9=E8=BD=A6=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【内部商城】-删除客户A的面料后,跳转到客户B的购物车页面】 https://www.tapd.cn/53459131/bugtrace/bugs/view/1153459131001001459 --- src/common/constant.ts | 4 +- .../components/shoppingCartItem/index.tsx | 55 +++++++++++++++---- src/pages/shopping/index.tsx | 4 +- src/pages/user/index.tsx | 17 +++--- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/common/constant.ts b/src/common/constant.ts index 93a0f48..c305c85 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -4,7 +4,7 @@ // export const BASE_URL = `http://10.0.0.5:50001/lymarket` // export const BASE_URL = `http://192.168.0.89:40001/lymarket` // export const BASE_URL = `http://192.168.1.165:40001/lymarket` // 王霞 -// export const BASE_URL = `https://test.zzfzyc.com/lymarket` // 测试环境 +// export const BASE_URL = 'https://test.zzfzyc.com/lymarket' // 测试环境 export const BASE_URL = 'https://pre.zzfzyc.com/lymarket' // 预发布 // export const BASE_URL = `http://192.168.1.9:40001/lymarket` // 发 // export const BASE_URL = `http://192.168.1.9:50005/lymarket` // 发 @@ -15,7 +15,7 @@ export const BASE_URL = 'https://pre.zzfzyc.com/lymarket' // 预发布 // export const BASE_URL = 'http://192.168.1.7:50002/lymarket' // 添 // export const BASE_URL = 'http://192.168.1.42:50002/lymarket' // 杰 // export const BASE_URL = `http://192.168.1.95:40001/lymarket` // 华 -// export const BASE_URL = 'http://192.168.1.28:50001/lymarket' // 婷 +// export const BASE_URL = 'http://192.168.1.28:50002/lymarket' // 婷 // CDN // 生成密钥 diff --git a/src/pages/shopping/components/shoppingCartItem/index.tsx b/src/pages/shopping/components/shoppingCartItem/index.tsx index 2e5c9cb..3abf4dc 100644 --- a/src/pages/shopping/components/shoppingCartItem/index.tsx +++ b/src/pages/shopping/components/shoppingCartItem/index.tsx @@ -23,11 +23,16 @@ import LoadingCard from '@/components/loadingCard' import { ShoppingCartListApi } from '@/api' import { usePropsValue } from '@/use/useCommon' -enum BackEndSaleModeListFieldMap { +export enum BackEndSaleModeListFieldMap { bulk_color_list = 0, length_cut_color_list = 1, weight_cut_color_list = 2, } +export const BackEndSaleModeListField: BackEndSaleModeListFieldMap[] = [ + BackEndSaleModeListFieldMap.bulk_color_list, + BackEndSaleModeListFieldMap.length_cut_color_list, + BackEndSaleModeListFieldMap.weight_cut_color_list, +] interface ButtonPropsType { isActive: boolean onClick?: Function @@ -63,9 +68,10 @@ interface GoodsListPropType { selected: EnumSaleMode isPending: boolean startTransition: React.TransitionStartFunction + onSelectOrderType: (type: EnumSaleMode) => void } const GoodsList = (props: GoodsListPropType) => { - const { itemData, selected, isPending, startTransition, multipleSelection } = props + const { itemData, selected, isPending, startTransition, multipleSelection, onSelectOrderType } = props console.log('rerender component GoodsList', props, props.itemData?.purchaser_name) // const prevMultipleSelection = useRef(multipleSelection) const currentSelected = useRef(null) @@ -87,7 +93,6 @@ const GoodsList = (props: GoodsListPropType) => { 暂无数据 ), ) - // prevMultipleSelection.current = multipleSelection } useEffect(() => { @@ -251,16 +256,21 @@ const ShoppingCartItem: FC = (props) => { const updatePurchaserMultipleSelection = (purchaserId: number, payload: Goods, operationType: OperationType, goodsId: number) => { console.log('delete', colorStore, purchaserId) if (operationType === 'add') { + const multipleSelection = { + ...colorStore?.[purchaserId]?.multipleSelection, + [goodsId]: payload, + } dispatch({ type: ShoppingDispatchType.UPDATE_CHANGED_CHECKBOX, data: { purchaserId, - multipleSelection: { - ...colorStore?.[purchaserId]?.multipleSelection, - [goodsId]: payload, - }, + multipleSelection, }, }) + // 全选标识 + if (currentItemData.current?.purchaser_id === purchaserId && currentItemData.current?.[BackEndSaleModeListFieldMap[selected]].length === Object.keys(multipleSelection).length) { + dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: true }) + } } else if (operationType === 'delete') { const temp = { ...colorStore?.[purchaserId]?.multipleSelection } @@ -272,8 +282,30 @@ const ShoppingCartItem: FC = (props) => { multipleSelection: temp, }, }) + dispatch({ type: ShoppingDispatchType.UPDATE_MULTIPLE_SELECTION_STATUS, data: false }) } } + + const handleOtherHighLight = (purchaserId: number) => { + console.log('handleOtherHighLight', purchaserId, currentCheckedPurchaserId) + if (purchaserId === currentCheckedPurchaserId) { + for (let i = 0; i < BackEndSaleModeListField.length; i++) { + if (itemData?.[BackEndSaleModeListFieldMap[i]].length !== 0) { + // 控制高亮 + onSelectOrderType(i) + return + } + } + } + } + + useEffect(() => { + events.on('handleOtherHighLight', handleOtherHighLight) + return () => { + events.off('handleOtherHighLight', handleOtherHighLight) + } + }, [handleOtherHighLight]) + // 发布订阅 useEffect(() => { events.on('updatePurchaserMultipleSelection', updatePurchaserMultipleSelection) @@ -418,6 +450,7 @@ const ShoppingCartItem: FC = (props) => { selected={selected} isPending={isPending} startTransition={startTransition} + onSelectOrderType={onSelectOrderType} /> @@ -429,7 +462,7 @@ const ShoppingCartItem: FC = (props) => { // State 分割组件 思路就是把 context 直接通过 props 的形式传给组件,这样的话就解决了 context 强制刷新 memo 的问题了 // 那么当 context 内的 value 被更新的时候,react 只会强制渲染 Wrapper -const withStateSlice = (comp, slice) => { +const withStateSlice = (comp, slice: (state: ShoppingStateContextValue, props: PropsType) => any) => { const MemoComp = memo(comp, (prevProps, nextProps) => { let needMemo = true if (JSON.stringify(prevProps.itemData) !== JSON.stringify(nextProps.itemData)) { @@ -461,7 +494,7 @@ const withStateSlice = (comp, slice) => { } return needMemo }) - const Wrapper = (props, ref) => { + const Wrapper = (props: PropsType, ref) => { const state = useShoppingState() // console.log('Wrapper colorStore', state.colorStore) return @@ -469,9 +502,9 @@ const withStateSlice = (comp, slice) => { return memo(forwardRef(Wrapper)) } -const ShoppingCartItemWithStateSlice = withStateSlice(ShoppingCartItem, (state: ShoppingStateContextValue, props) => ({ +const ShoppingCartItemWithStateSlice = withStateSlice(ShoppingCartItem, (state: ShoppingStateContextValue, props: PropsType) => ({ colorStore: state.colorStore, - multipleSelection: state.colorStore?.[props.itemData.purchaser_id]?.multipleSelection, + multipleSelection: state.colorStore?.[props.itemData!.purchaser_id]?.multipleSelection, currentCheckedPurchaserId: state.currentCheckedPurchaserId, Observer: state.Observer, })) diff --git a/src/pages/shopping/index.tsx b/src/pages/shopping/index.tsx index a7928e8..90a7f03 100644 --- a/src/pages/shopping/index.tsx +++ b/src/pages/shopping/index.tsx @@ -4,12 +4,13 @@ import type { FC } from 'react' import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useTransition } from 'react' import classnames from 'classnames' import styles from './index.module.scss' -import ItemList from './components/shoppingCartItem/index' +import ItemList, { BackEndSaleModeListField, BackEndSaleModeListFieldMap } from './components/shoppingCartItem/index' import BottomSettleBar from './components/bottomSettleBar' import BottomEditBar from './components/bottomEditBar' import { ShoppingProvider } from './components/shoppingCart/index' import type { Goods } from './context' import { ShoppingDispatchType, useShoppingDispatch, useShoppingState } from './context' +import { events } from './context/shoppingStore' import { dataLoadingStatus, debounce, getFilterData } from '@/common/util' import { ShoppingCartDeleteApi, ShoppingCartListApi } from '@/api/index' import { formatPriceDiv } from '@/common/format' @@ -162,6 +163,7 @@ const ShoppingCartContainer: FC = () => { }, }) fetchData(searchOptions) + events.trigger('handleOtherHighLight', currentCheckedPurchaserId) // Observer.notify(currentCheckedPurchaserId) } else { diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx index e2ec780..19e954a 100644 --- a/src/pages/user/index.tsx +++ b/src/pages/user/index.tsx @@ -193,6 +193,7 @@ const UserInfo: FC = () => { console.log(err, 'err') } } + return ( <> @@ -260,16 +261,16 @@ const UserInfo: FC = () => { // 我的 const User = () => { + const [current_env, _] = useState(CURRENT_ENV) + const [current_version, __] = useState(CURRENT_VERSION) return ( - <> - - + + - {/* 测试暂时添加 */} - {CURRENT_VERSION} - {CURRENT_ENV !== 'production' && {BASE_URL}} - - + {/* 测试暂时添加 */} + {current_version} + {current_env !== 'production' && {BASE_URL}} + ) }