Skip to content

Commit

Permalink
refactor: refactor stat
Browse files Browse the repository at this point in the history
  • Loading branch information
rayadaschn committed Nov 7, 2023
1 parent 0897aa5 commit 64a5d40
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/pages/question/stat/components/StatContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from 'react'
import StatContainerLeft from './StatContainerLeft'
import StatContainerCenter from './StatContainerCenter'
import StatContainerRight from './StatContainerRight'
import StatContainerLeft from './leftPanel'
import StatContainerCenter from './centerPanel'
import StatContainerRight from './rightPanel'

const StatContainer: FC = () => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FC } from 'react'

const ComponentLayer: FC = () => {
return <>ComponentLayer</>
}

export default ComponentLayer
64 changes: 64 additions & 0 deletions src/pages/question/stat/components/leftPanel/ComponentLib.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
ComponentConfType,
componentConfGroup,
} from '@/components/QuestionComponents'
import { addComponent } from '@/store/modules/componentsReducer'
import { nanoid } from '@reduxjs/toolkit'
import { Typography } from 'antd'
import { FC } from 'react'
import { useDispatch } from 'react-redux'

const { Title } = Typography

const genComponent = (c: ComponentConfType) => {
const { title, type, Component, defaultProps } = c
const dispatch = useDispatch()

const handleClick = useCallback(() => {
dispatch(
addComponent({
fe_id: nanoid(),
title,
type,
props: defaultProps,
}),
)
}, [])

return (
<div
key={type}
onClick={handleClick}
className="mb-3 cursor-pointer rounded border-solid bg-white p-3 hover:border-cyan"
>
<div className="pointer-events-none">
<Component />
</div>
</div>
)
}

const ComponentLib: FC = () => {
return (
<>
{componentConfGroup.map((group, index) => {
const { groupId, groupName, components } = group

return (
<div key={groupId}>
<Title
level={3}
style={{ fontSize: '16px', marginTop: index > 0 ? '20px' : '0' }}
>
{groupName}
</Title>

<div>{components.map((c) => genComponent(c))}</div>
</div>
)
})}
</>
)
}

export default ComponentLib
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FC } from 'react'
import { Tabs } from 'antd'
import { AppstoreOutlined, BarsOutlined } from '@ant-design/icons'
import ComponentLib from './ComponentLib'
import ComponentLayer from './ComponentLayer'

const StatContainerLeft: FC = () => {
const tabsItems = [
Expand All @@ -12,7 +14,7 @@ const StatContainerLeft: FC = () => {
组件库
</span>
),
children: <div>子组件</div>,
children: <ComponentLib />,
},
{
key: 'layers',
Expand All @@ -22,7 +24,7 @@ const StatContainerLeft: FC = () => {
图层
</span>
),
children: <div>图层</div>,
children: <ComponentLayer />,
},
]

Expand Down

0 comments on commit 64a5d40

Please sign in to comment.