import { useDrag } from "ahooks";
import { Col, Row, Space, Tabs, Typography } from "antd";
import React, { useState, useImperativeHandle, forwardRef, useRef, useCallback } from "react";
import styles from './index.less'
import { useModel } from "@umijs/max";
import { useToken } from "@ant-design/pro-components";
const DragItem = ({ children }: any) => {
const dragRef = useRef(null);
const [dragging, setDragging] = useState(false);
useDrag(children.key, dragRef, {
onDragStart: () => {
console.log(children.key)
setDragging(true);
},
onDragEnd: () => {
setDragging(false);
},
});
return (
{children}
);
};
type Item = {
componentName: string,//组件名称 也是type
defaultComponentConfigList: any[],//组件配置
enabled: boolean,//是否可编辑
enabledAppTypes: number[]//支持的小程序
id: number,//组件id
remark: string,//备注 一般为中文名称
pagePath: string,//所在页面地址
disabled: boolean,//是否看使用,在已经添加进页面后禁止使用
}
const Comp = ({ item }: { item: Item }) => {
let { token } = useToken()
return item.disabled ?
{item.remark || item.componentName}
:
{item.remark || item.componentName}
}
// 定义组件的 Props 类型
interface Props {
data: any[]
}
// 使用 forwardRef 以支持传递 ref
const PageList = forwardRef((props: Props, ref) => {
let { initialState } = useModel("@@initialState")
let { state, dispatch } = useModel('appPageConifg')
let { data } = props
// 使用 useImperativeHandle 暴露方法给父组件
useImperativeHandle(ref, () => ({
}));
return {
dispatch({ type: "setAll", params: { activePage: activeKey } })
}}
activeKey={state.activePage}
items={data?.map(item => {
return {
label: item.pageName,
key: item.pagePath,
disabled: !item.enabledComponent,
children: item.pagePath === state.activePage ?
顶部组件
{
item?.appComponentList?.filter((i: Item) => i.componentName === 'banners')?.map((comp: Item) => {
let newComp = { ...comp, pagePath: item.pagePath }
let appType = initialState?.selectApp?.appType || 0
let pageConfig = state.pageConfigList.find(page => page.pageUrl === item.pagePath)
let thePage = pageConfig?.workDirectionListDTOS?.find(page => page.workDirection == state.tabs)
let list = thePage?.componentConfigList || []
newComp.disabled = !!list.find(i => i.appComponentId == newComp.id)
if (newComp.enabledAppTypes.includes(appType)) {
return
}
})
}
内容组件
{
item?.appComponentList?.filter((i: Item) => i.componentName !== 'banners')?.map((comp: Item) => {
let newComp = { ...comp, pagePath: item.pagePath }
let appType = initialState?.selectApp?.appType || 0
let pageConfig = state.pageConfigList.find((page: { pageUrl: any; }) => page.pageUrl === item.pagePath)
let thePage = pageConfig?.workDirectionListDTOS?.find(page => page.workDirection == state.tabs)
let list = thePage?.componentConfigList || []
newComp.disabled = !!list.find(i => i.appComponentId == newComp.id)
if (newComp.enabledAppTypes.includes(appType)) {
return
}
})
}
: <>无组件>,
}
})} />
});
export default PageList;