|
@@ -4,6 +4,9 @@ import React, { useState, useImperativeHandle, forwardRef, useRef, useMemo } fro
|
|
|
import styles from './index.less'
|
|
|
import { Banners } from "../components/banners";
|
|
|
import { useModel } from "@umijs/max";
|
|
|
+import { HotBooks } from "../components/hot_books";
|
|
|
+import { HotCategory } from "../components/hot_category";
|
|
|
+import { Config } from "@/models/appPageConifg";
|
|
|
|
|
|
// 使用 forwardRef 以支持传递 ref
|
|
|
const DragItem = () => {
|
|
@@ -11,32 +14,87 @@ const DragItem = () => {
|
|
|
const [isHovering, setIsHovering] = useState(false);
|
|
|
const dropRef = useRef(null);
|
|
|
const list = useMemo(() => {
|
|
|
- return state.tabs === 0 ? state.manList : state.womanList
|
|
|
+ let pageConfig = state.pageConfigList.find(page => page.pageUrl === state.activePage)
|
|
|
+ let list: {
|
|
|
+ appComponentId: number | string;
|
|
|
+ componentType: string;
|
|
|
+ showRightButton?: boolean;
|
|
|
+ componentName?: string;
|
|
|
+ remark?: string;
|
|
|
+ configs?: Config[];
|
|
|
+ }[] = []
|
|
|
+ if (state.isWorkDirection) {
|
|
|
+ let thePage = pageConfig?.workDirectionListDTOS?.find(page => page.workDirection == state.tabs)
|
|
|
+ list = thePage?.componentConfigList || []
|
|
|
+ } else {
|
|
|
+ list = pageConfig?.workDirectionListDTOS?.[0].componentConfigList || []
|
|
|
+ }
|
|
|
+ return list
|
|
|
}, [state])
|
|
|
useDrop(dropRef, {
|
|
|
// 接收到组件拖拽到手机内容内,添加进入数据
|
|
|
onDom: (content: string, e) => {
|
|
|
- console.log(11111)
|
|
|
- let arr = content?.split('_')
|
|
|
+ let arr = content?.split('-')
|
|
|
let appComponentId = arr[0]
|
|
|
let componentType = arr[1]
|
|
|
- let pageUrl = arr[2]
|
|
|
- let newConfig = { appComponentId, componentType, pageUrl, configs: [] }
|
|
|
- let { tabs, manList, womanList } = state
|
|
|
+ let newConfig: {
|
|
|
+ appComponentId: number | string,//组件ID
|
|
|
+ componentType: string,//组件类型
|
|
|
+ showRightButton?: boolean,//是否展示左侧按钮
|
|
|
+ componentName?: string,//组件名称
|
|
|
+ remark?: string,//备注
|
|
|
+ configs?: Config[],//组件内的配置
|
|
|
+ } = { appComponentId, componentType, configs: [] }
|
|
|
switch (componentType) {
|
|
|
- case "banners":
|
|
|
- dispatch({
|
|
|
- type: 'setAll', params: tabs === 0 ? {
|
|
|
- manList: [...state.manList, newConfig]
|
|
|
- } : {
|
|
|
- womanList: [...state.womanList, newConfig]
|
|
|
+ case 'hot_books':
|
|
|
+ newConfig.configs = [
|
|
|
+ {}, {}, {}, {}, {}
|
|
|
+ ]
|
|
|
+ newConfig.componentName = "今日热书"
|
|
|
+ newConfig.showRightButton = true
|
|
|
+ break;
|
|
|
+ case "hot_category":
|
|
|
+ newConfig.configs = []
|
|
|
+ newConfig.componentName = "热门分类"
|
|
|
+ newConfig.showRightButton = true
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ let { tabs, pageConfigList, activePage, isWorkDirection } = state
|
|
|
+ let pageConfig = pageConfigList.find(page => page.pageUrl === activePage)
|
|
|
+ // 首次添加页面基础数据
|
|
|
+ if (!pageConfig) {
|
|
|
+ pageConfigList.push({
|
|
|
+ pageUrl: activePage,
|
|
|
+ workDirectionListDTOS: isWorkDirection ? [
|
|
|
+ {
|
|
|
+ workDirection: 0,
|
|
|
+ componentConfigList: []
|
|
|
+ },
|
|
|
+ {
|
|
|
+ workDirection: 1,
|
|
|
+ componentConfigList: []
|
|
|
+ },
|
|
|
+ ] : [
|
|
|
+ {
|
|
|
+ componentConfigList: []
|
|
|
}
|
|
|
- })
|
|
|
- break
|
|
|
- default:
|
|
|
- break
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ pageConfig = pageConfigList.find(page => page.pageUrl === activePage)
|
|
|
}
|
|
|
- console.log(`custom: ${content} dropped`);
|
|
|
+ // 存在男女频页面
|
|
|
+ if (isWorkDirection && pageConfig?.workDirectionListDTOS) {
|
|
|
+ for (let page of pageConfig?.workDirectionListDTOS) {
|
|
|
+ if (page.workDirection == tabs) {
|
|
|
+ page.componentConfigList = [...page.componentConfigList, newConfig]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (pageConfig?.workDirectionListDTOS) {// 不存在男女频页面
|
|
|
+ pageConfig.workDirectionListDTOS[0].componentConfigList = [...pageConfig.workDirectionListDTOS[0].componentConfigList, newConfig]
|
|
|
+ }
|
|
|
+ dispatch({
|
|
|
+ type: 'setAll', params: { pageConfigList, index: state.index + 1 }
|
|
|
+ })
|
|
|
},
|
|
|
onDragOver: (e) => {
|
|
|
// console.log("拖拽中",e)
|
|
@@ -47,9 +105,20 @@ const DragItem = () => {
|
|
|
return <div ref={dropRef} style={{ minHeight: '100%' }} >
|
|
|
{
|
|
|
list?.map(item => {
|
|
|
- return <div key={item.appComponentId} className={`${styles.comp} ${state.compAc === item.componentType ? styles.ac : ""}`} onClick={() => { dispatch({ type: "setAll", params: { compAc: item.componentType } }) }}>
|
|
|
- <Banners data={item.configs} />
|
|
|
- </div>
|
|
|
+ return <React.Fragment key={item.appComponentId}>
|
|
|
+ <div
|
|
|
+ className={`${styles.comp} ${state.compAc === item.componentType ? styles.ac : ""}`}
|
|
|
+ onClick={() => { dispatch({ type: "setAll", params: { compAc: item.componentType } }) }}
|
|
|
+ >
|
|
|
+ {/* banners */}
|
|
|
+ {item.componentType === 'banners' && <Banners data={item.configs || []} />}
|
|
|
+ {/* 热门书籍*/}
|
|
|
+ {item.componentType === "hot_books" && <HotBooks data={item} />}
|
|
|
+ {/* 热门分类 */}
|
|
|
+ {item.componentType === "hot_category" && <HotCategory data={item} />}
|
|
|
+ </div>
|
|
|
+ <div className={styles.compBoxM} />
|
|
|
+ </React.Fragment>
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -60,7 +129,7 @@ interface Props {
|
|
|
}
|
|
|
const Content = forwardRef((props: Props, ref) => {
|
|
|
const { state, dispatch } = useModel("appPageConifg")
|
|
|
- // 使用 useImperativeHandle 暴露方法给父组件
|
|
|
+ // 使用 useImperativeHandle 暴露方法给父组件
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
}));
|
|
|
return <div className={styles.phone}>
|
|
@@ -82,8 +151,11 @@ const Content = forwardRef((props: Props, ref) => {
|
|
|
}
|
|
|
|
|
|
</Space>
|
|
|
- {/* 内容 */}
|
|
|
- <DragItem />
|
|
|
+ <div className={styles.content_box}>
|
|
|
+ {/* 内容 */}
|
|
|
+ <DragItem />
|
|
|
+ </div>
|
|
|
+
|
|
|
</div>
|
|
|
</div>
|
|
|
})
|