Skip to content

Commit

Permalink
feat: add pageSetting
Browse files Browse the repository at this point in the history
  • Loading branch information
rayadaschn committed Oct 25, 2023
1 parent ad4fb54 commit 7ea4a7b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/hooks/modules/useLoadQuestionData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useParams } from 'react-router-dom'
import { getQuestionService } from '@/api'
import { useDispatch } from 'react-redux'
import store from '@/store'
import { resetPageInfo } from '@/store/modules/pageInfoReducer'
import { resetComponents } from '@/store/modules/componentsReducer'

Expand Down
43 changes: 41 additions & 2 deletions src/pages/question/edit/component/leftPanel/LeftLayers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useGetComponentInfo } from '@/hooks'
import {
changeComponentHidden,
changeComponentTitle,
changeSelectedId,
toggleComponentLocked,
} from '@/store/modules/componentsReducer'
import { Input, message } from 'antd'
import { EyeInvisibleOutlined, LockOutlined } from '@ant-design/icons'
import { Button, Input, Space, message } from 'antd'
import classNames from 'classnames'
import React, { ChangeEvent, FC } from 'react'
import { useDispatch } from 'react-redux'
Expand Down Expand Up @@ -39,6 +42,16 @@ const LeftLayers: FC = () => {
dispatch(changeComponentTitle({ fe_id: selectedId, title: newTitle }))
}

/** 切换显示/隐藏 */
const toggleHidden = (fe_id: string, isHidden: boolean) => {
dispatch(changeComponentHidden({ fe_id, isHidden }))
}

/** 切换锁定/解锁 */
const toggleLocked = (fe_id: string) => {
dispatch(toggleComponentLocked({ fe_id }))
}

return (
<>
{componentList.map((c) => {
Expand All @@ -49,6 +62,13 @@ const LeftLayers: FC = () => {
[titleDefaultClassName]: true,
[selectedClassName]: fe_id === selectedId,
})
const isShowName = 'opacity-20'
const hiddenButtonClassName = classNames({
[isShowName]: isHidden,
})
const clockButtonClassName = classNames({
[isShowName]: isHidden,
})

return (
<div
Expand All @@ -69,7 +89,26 @@ const LeftLayers: FC = () => {
)}
{fe_id !== changingTitleId && title}
</div>
<div className="w-12 text-end">按钮</div>
<div className="w-12 text-end">
<Space>
<Button
size="small"
shape="circle"
className={hiddenButtonClassName}
icon={<EyeInvisibleOutlined />}
type={isHidden ? 'primary' : 'text'}
onClick={() => toggleHidden(fe_id, !isHidden)}
/>
<Button
size="small"
shape="circle"
className={clockButtonClassName}
icon={<LockOutlined />}
type={isLocked ? 'primary' : 'text'}
onClick={() => toggleLocked(fe_id)}
/>
</Space>
</div>
</div>
)
})}
Expand Down
48 changes: 48 additions & 0 deletions src/pages/question/edit/component/rightPanel/RightPageSetting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useGetPageInfo } from '@/hooks'
import { resetPageInfo } from '@/store/modules/pageInfoReducer'
import { Form, Input } from 'antd'
import TextArea from 'antd/es/input/TextArea'
import { FC } from 'react'
import { useDispatch } from 'react-redux'

const RightPageSetting: FC = () => {
const pageInfo = useGetPageInfo()
const [form] = Form.useForm()
const dispatch = useDispatch()

/** 更新表单 */
const handelValuesChange = () => {
dispatch(resetPageInfo(form.getFieldsValue()))
}

return (
<Form
layout="vertical"
initialValues={pageInfo}
onValuesChange={handelValuesChange}
form={form}
>
<Form.Item
name="title"
label="问卷标题"
rules={[{ required: true, message: '请输入标题' }]}
>
<Input placeholder="请输入标题" />
</Form.Item>

<Form.Item name="desc" label="问卷描述">
<TextArea placeholder="问卷描述信息" />
</Form.Item>

<Form.Item name="css" label="样式代码">
<TextArea placeholder="请输入 CSS 样式代码" />
</Form.Item>

<Form.Item name="js" label="脚本代码">
<TextArea placeholder="请输入 JS 脚本代码" />
</Form.Item>
</Form>
)
}

export default RightPageSetting
11 changes: 7 additions & 4 deletions src/pages/question/edit/component/rightPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { FileTextOutlined, SettingOutlined } from '@ant-design/icons'
import React, { FC } from 'react'
import RightComponentProp from './RightComponentProp'
import { Tabs } from 'antd'
import RightPageSetting from './RightPageSetting'

// TS 枚举
enum TAB_KEYS {
PROP_KEY = 'prop',
SETTING_KEY = 'setting',
Expand All @@ -15,8 +15,11 @@ const EditRightPanel: FC = () => {
const { selectedId } = useGetComponentInfo()

useEffect(() => {
if (selectedId) setActiveKey(TAB_KEYS.PROP_KEY)
else setActiveKey(TAB_KEYS.SETTING_KEY)
if (selectedId) {
setActiveKey(TAB_KEYS.PROP_KEY)
} else {
setActiveKey(TAB_KEYS.SETTING_KEY)
}
}, [selectedId])

const tabsItems = [
Expand All @@ -38,7 +41,7 @@ const EditRightPanel: FC = () => {
页面设置
</span>
),
children: <div>页面设置</div>,
children: <RightPageSetting />,
},
]
return <Tabs activeKey={activeKey} items={tabsItems} />
Expand Down
16 changes: 14 additions & 2 deletions src/pages/question/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import EditHeader from './component/header'
import EditLeftPanel from './component/leftPanel'
import EditCenterPanel from './component/centerPanel'
import EditRightPanel from './component/rightPanel'
import { useDispatch } from 'react-redux'
import { changeSelectedId } from '@/store/modules/componentsReducer'

const Edit: FC = () => {
const dispatch = useDispatch()
const { loading } = useLoadQuestionData()

const { title } = useGetPageInfo()
useTitle(`问卷编辑 - ${title}`)
const pageTitle = title ? `问卷编辑 - ${title}` : '问卷调查'
useTitle(pageTitle)

/** 清空选择 */
const clearSelectedId = () => {
dispatch(changeSelectedId(''))
}

return (
<div className="h-screen flex flex-col bg-[#f0f2f5]">
Expand All @@ -20,7 +29,10 @@ const Edit: FC = () => {
<EditLeftPanel />
</div>

<div className="relative flex-1 overflow-hidden">
<div
className="relative flex-1 overflow-hidden"
onClick={clearSelectedId}
>
<div className="absolute left-1/2 top-1/2 h-178 w-150 transform items-center justify-center overflow-auto shadow-2xl -translate-x-1/2 -translate-y-1/2">
<EditCenterPanel loading={loading} />
</div>
Expand Down

0 comments on commit 7ea4a7b

Please sign in to comment.