Commit ff0f70bf authored by Bill's avatar Bill

fix: 修改品类导航滚动问题

parent 462da585
import React from 'react'; import React, { useEffect } from 'react';
import { SimpleCommodity, CustomizeTag } from '@lingxi-disign/ui'; import { SimpleCommodity, CustomizeTag } from '@lingxi-disign/ui';
import cs from 'classnames'; import cs from 'classnames';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import styles from './simple.less'; import styles from './simple.less';
import Container from '../Container'; import Container from '../Container';
import { useSelector, getIframe, getSelectedNode } from '@lingxi-disign/react';
interface Iprops { interface Iprops {
children: React.ReactElement, children: React.ReactElement,
title: string, title: string,
} }
const scrollNode = (key: string) => {
const iframe=getIframe();
const splitCode = key.split("-");
if (splitCode.length < 3) {
return;
}
const parentNode = getSelectedNode(`${splitCode.slice(0, 2).join("-")}-0`, iframe);
if (!parentNode) {
return;
}
const cardBody = parentNode.querySelector('.ant-card-body');
if (!cardBody) {
return;
}
const selectedNode = getSelectedNode(`${key}-0`, iframe);
if (!selectedNode) {
return
}
const { x, y, width }= selectedNode.getBoundingClientRect();
if (cardBody.scrollWidth > selectedNode.scrollWidth) {
const position:{left?:number,top?:number}={
left: x - 18,
top: 0
};
cardBody.scrollBy({...position,behavior:'smooth'});
}
}
const SimpleCommodityList: React.FC<Iprops> & { Item: typeof SimpleItem } = (props: Iprops) => { const SimpleCommodityList: React.FC<Iprops> & { Item: typeof SimpleItem } = (props: Iprops) => {
// console.log(props);
const { children, title } = props; const { children, title } = props;
const cardProps = { const cardProps = {
title: title || '标题', title: title || '标题',
...@@ -34,8 +64,22 @@ const SimpleCommodityList: React.FC<Iprops> & { Item: typeof SimpleItem } = (pro ...@@ -34,8 +64,22 @@ const SimpleCommodityList: React.FC<Iprops> & { Item: typeof SimpleItem } = (pro
const divProps = { const divProps = {
onClick, onDrag, onDragEnd, onDragEnter, onDragStart, onMouseOver, getOperateState, className onClick, onDrag, onDragEnd, onDragEnter, onDragStart, onMouseOver, getOperateState, className
}; };
const {selectedInfo, hoverKey} = useSelector(['pageConfig', 'shopId', 'selectedInfo', 'hoverKey']);
useEffect(() => {
if (hoverKey !== null) {
scrollNode(hoverKey);
}
}, [hoverKey])
return ( return (
<Container card={true} cardProps={cardProps as any} listStyle={listStyle} itemStyle={itemStyle} {...divProps}> <Container
card={true}
cardProps={cardProps as any}
listStyle={listStyle}
itemStyle={itemStyle}
{...divProps}
>
{ {
children children
} }
......
...@@ -9,7 +9,6 @@ import { context } from '../../../common/context/context'; ...@@ -9,7 +9,6 @@ import { context } from '../../../common/context/context';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
import { getAuth } from '@/utils/auth'; import { getAuth } from '@/utils/auth';
import { usePageStatus } from '@/hooks/usePageStatus'; import { usePageStatus } from '@/hooks/usePageStatus';
import { usePrevious } from '@umijs/hooks';
const { TabPane } = Tabs; const { TabPane } = Tabs;
...@@ -22,7 +21,7 @@ interface Iprops { ...@@ -22,7 +21,7 @@ interface Iprops {
const CustomizeTabs: React.FC<Iprops> & { TabItem: typeof TabItem } = (props: Iprops) => { const CustomizeTabs: React.FC<Iprops> & { TabItem: typeof TabItem } = (props: Iprops) => {
const { children } = props; const { children } = props;
const auth = getAuth(); const auth = getAuth();
const { pageConfig, shopId, selectedInfo, activeKey: currentActiveKey, dom } = useSelector(['pageConfig', 'shopId', 'selectedInfo', 'domKey', 'activeKey']); const { pageConfig, shopId, selectedInfo} = useSelector(['pageConfig', 'shopId', 'selectedInfo']);
const { isSelf } = usePageStatus(); const { isSelf } = usePageStatus();
/** 是否是自营商城 */ /** 是否是自营商城 */
const isSelfMall = useMemo(() => !!isSelf, [isSelf]); const isSelfMall = useMemo(() => !!isSelf, [isSelf]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment