|
@@ -1,6 +1,6 @@
|
|
import { useDrop } from "ahooks";
|
|
import { useDrop } from "ahooks";
|
|
import { Col, Row, Space } from "antd";
|
|
import { Col, Row, Space } from "antd";
|
|
-import React, { useState, useImperativeHandle, forwardRef, useRef, useMemo } from "react";
|
|
|
|
|
|
+import React, { useState, useImperativeHandle, forwardRef, useRef, useMemo, useEffect } from "react";
|
|
import styles from './index.less'
|
|
import styles from './index.less'
|
|
import { Banners } from "../components/banners";
|
|
import { Banners } from "../components/banners";
|
|
import { useModel } from "@umijs/max";
|
|
import { useModel } from "@umijs/max";
|
|
@@ -19,6 +19,8 @@ const DragItem = () => {
|
|
const { state, dispatch } = useModel("appPageConifg")
|
|
const { state, dispatch } = useModel("appPageConifg")
|
|
const [isHovering, setIsHovering] = useState(false);
|
|
const [isHovering, setIsHovering] = useState(false);
|
|
const dropRef = useRef(null);
|
|
const dropRef = useRef(null);
|
|
|
|
+ // 创建一个 ref 数组,存储每个组件的引用
|
|
|
|
+ const componentRefs = useRef<any>([]);
|
|
const list = useMemo(() => {
|
|
const list = useMemo(() => {
|
|
let pageConfig = state.pageConfigList?.find(page => page.pageUrl === state.activePage)
|
|
let pageConfig = state.pageConfigList?.find(page => page.pageUrl === state.activePage)
|
|
let list: {
|
|
let list: {
|
|
@@ -37,6 +39,10 @@ const DragItem = () => {
|
|
}
|
|
}
|
|
return list
|
|
return list
|
|
}, [state])
|
|
}, [state])
|
|
|
|
+ const handleClick = (item: { componentType: any; }, index: string | number) => {
|
|
|
|
+ dispatch({ type: "setAll", params: { compAc: item.componentType } });
|
|
|
|
+ // 滚动到对应元素
|
|
|
|
+ };
|
|
useDrop(dropRef, {
|
|
useDrop(dropRef, {
|
|
// 接收到组件拖拽到手机内容内,添加进入数据
|
|
// 接收到组件拖拽到手机内容内,添加进入数据
|
|
onDom: (content: string, e) => {
|
|
onDom: (content: string, e) => {
|
|
@@ -141,7 +147,7 @@ const DragItem = () => {
|
|
pageConfig.workDirectionList[0].componentConfigList = [...pageConfig.workDirectionList[0].componentConfigList, newConfig]
|
|
pageConfig.workDirectionList[0].componentConfigList = [...pageConfig.workDirectionList[0].componentConfigList, newConfig]
|
|
}
|
|
}
|
|
dispatch({
|
|
dispatch({
|
|
- type: 'setAll', params: { pageConfigList, index: state.index + 1 }
|
|
|
|
|
|
+ type: 'setAll', params: { pageConfigList, index: state.index + 1 ,compAc: componentType}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
onDragOver: (e) => {
|
|
onDragOver: (e) => {
|
|
@@ -150,13 +156,20 @@ const DragItem = () => {
|
|
onDragEnter: () => setIsHovering(true),
|
|
onDragEnter: () => setIsHovering(true),
|
|
onDragLeave: () => setIsHovering(false),
|
|
onDragLeave: () => setIsHovering(false),
|
|
});
|
|
});
|
|
|
|
+ useEffect(()=>{
|
|
|
|
+ let index = list?.findIndex(i=>i.componentType === state.compAc)
|
|
|
|
+ if(index !== -1){
|
|
|
|
+ componentRefs.current[index].scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
|
|
+ }
|
|
|
|
+ },[state.compAc,list])
|
|
return <div ref={dropRef} style={{ minHeight: '100%' }} >
|
|
return <div ref={dropRef} style={{ minHeight: '100%' }} >
|
|
{
|
|
{
|
|
- list?.map(item => {
|
|
|
|
|
|
+ list?.map((item,index) => {
|
|
return <React.Fragment key={item.appComponentId}>
|
|
return <React.Fragment key={item.appComponentId}>
|
|
<div
|
|
<div
|
|
className={`${styles.comp} ${state.compAc === item.componentType ? styles.ac : ""}`}
|
|
className={`${styles.comp} ${state.compAc === item.componentType ? styles.ac : ""}`}
|
|
- onClick={() => { dispatch({ type: "setAll", params: { compAc: item.componentType } }) }}
|
|
|
|
|
|
+ onClick={() => handleClick(item, index)}
|
|
|
|
+ ref={el => componentRefs.current[index] = el} // 将每个元素的引用存储在 refs 数组中
|
|
>
|
|
>
|
|
{/* banners */}
|
|
{/* banners */}
|
|
{item.componentType === 'banners' && <Banners data={item.configs || []} />}
|
|
{item.componentType === 'banners' && <Banners data={item.configs || []} />}
|