system-copyright-react/src/components/menu/MenuWithTopButton.tsx

131 lines
5.3 KiB
TypeScript
Raw Normal View History

2024-03-12 18:53:51 +08:00
import './menu-with-top-button.css'
2024-05-28 18:00:42 +08:00
import { IMenuListItem, IMenuWithTopButton } from "../../interfaces/menu/IMenuWithTopButton.ts";
2024-04-29 17:22:26 +08:00
import objImg from '../../static/left/obj.png'
import newImg from '../../static/left/new.png'
2024-08-22 16:33:01 +08:00
import refunimg from '../../static/refun.png'
2024-08-26 18:03:35 +08:00
import correctionImg from '../../static/correction.png'
2024-05-07 17:00:32 +08:00
import { useNavigate } from 'react-router-dom';
2024-04-29 17:22:26 +08:00
import {
RightOutlined
} from '@ant-design/icons';
2024-05-28 18:00:42 +08:00
import { getMenuActive, setMenuActive } from './../../util/cache'
import { useEffect, useState } from 'react'
2024-03-12 18:53:51 +08:00
export default function MenuWithTopButton(props: IMenuWithTopButton) {
2024-05-07 17:00:32 +08:00
const navugate = useNavigate()
2024-05-28 18:00:42 +08:00
const [menuItem, setMenuItem] = useState<IMenuListItem[]>([])
useEffect(() => {
setMenuItem(
props.list.map((m) => {
if (getMenuActive()) {
if (getMenuActive() == m.id) {
m['active'] = true
} else {
m['active'] = false
}
}
return m
})
)
2024-06-19 14:18:16 +08:00
}, [getMenuActive()])
2024-04-29 17:22:26 +08:00
2024-05-28 18:00:42 +08:00
const list = menuItem.map((item, index) => (
2024-04-28 11:04:03 +08:00
// 创建项目下三个选项
2024-04-01 20:39:22 +08:00
<li className={item.active ? 'active' : ''} key={item.id} onClick={(e) => {
2024-03-12 18:53:51 +08:00
props.handleListItem(e, index, item);
2024-05-28 18:00:42 +08:00
setMenuActive(item.id)
2024-08-22 16:33:01 +08:00
if (props.button.name == '项目') {
// props.enableBelongpeople()
navugate('/home', {
state: {
keyword: props.keywords,
name: props.type,
chargeAdditionals: props.chargeAdditionals,
tagDataId: props.tagDataId,
authorId: props.authorId
}
})
}
if (props.button.name == '退款') {
// props.disableBelongpeople()
navugate('/refun', {
2024-08-26 18:03:35 +08:00
state: {
type: item.id
}
})
}
if (props.button.name == '补正') {
// props.disableBelongpeople()
navugate('/correction', {
state: {
type: item.id == 'Correction-PENDING' ? 'PENDING' : item.id == 'Correction-APPROVED' ? 'APPROVED' : item.id == 'Correction-REJECTED' ? 'REJECTED' : item.id == 'Correction-CANCELED' ? 'CANCELED' : ''
2024-08-22 16:33:01 +08:00
}
})
}
2024-03-12 18:53:51 +08:00
}}>
2024-04-29 17:22:26 +08:00
{item.icon ? (<img src={item.icon} className="menu-icon" alt="加载失败" />) : <></>}
2024-03-12 18:53:51 +08:00
<span className="menu-name">{item.name}</span>
2024-04-29 17:22:26 +08:00
<span className='topIcon'><RightOutlined /></span>
2024-03-12 18:53:51 +08:00
</li>
));
return (
<div className="menu-with-top-button">
2024-04-28 11:04:03 +08:00
{/* button 是三个黄色按钮 */}
2024-04-29 17:22:26 +08:00
<div className='top'>
<div className='top-lift'>
2024-08-26 18:03:35 +08:00
<img src={objImg} alt="" style={{ display: props.button.name == '项目' ? 'block' : 'none' }} />
<img src={refunimg} alt="" style={{ display: props.button.name == '退款' ? 'block' : 'none', width: 16 }} />
<img src={correctionImg} alt="" style={{ display: props.button.name == '补正' ? 'block' : 'none', width: 16 }} />
2024-08-22 16:33:01 +08:00
2024-04-29 17:22:26 +08:00
<div> {props.button.name}</div>
</div>
<div className='top-right' onClick={(e) => {
props.button.handle(e);
2024-05-07 17:00:32 +08:00
// 当点击创建时其他按钮默认为不被选中
// props.list.forEach(item => item.active = false);
// console.log(props.list);
2024-06-19 14:18:16 +08:00
// setMenuActive('ALL')
2024-08-26 18:03:35 +08:00
if (props.button.name == '项目') {
// setMenuActive('ALL')
}
if (props.button.name == '退款' ){
setMenuActive('PENDING')
navugate('/refun', {
state: {
type: 'PENDING'
}
})
}
if (props.button.name == '补正' ){
setMenuActive('Correction-PENDING')
navugate('/correction', {
state: {
type: 'PENDING'
}
})
}
2024-04-29 17:22:26 +08:00
}}>
2024-08-22 16:33:01 +08:00
{/* refunimg */}
2024-08-26 18:03:35 +08:00
<img src={newImg} alt="" />
<div style={{ display: props.button.name == '项目' ? 'block' : 'none' }}></div>
<div style={{ display: props.button.name == '退款' ? 'block' : 'none' }}></div>
<div style={{ display: props.button.name == '补正' ? 'block' : 'none' }}></div>
2024-04-29 17:22:26 +08:00
</div>
</div>
{/* <button className="btn btn-orange top-button"
2024-03-12 18:53:51 +08:00
onClick={(e) => {
props.button.handle(e);
2024-04-29 17:22:26 +08:00
console.log(e);
2024-03-12 18:53:51 +08:00
}}
>
{props.button.name}
2024-04-29 17:22:26 +08:00
</button> */}
2024-06-03 14:56:19 +08:00
<ul style={{}}>{list}</ul>
2024-03-12 18:53:51 +08:00
</div>
)
}