index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { useCallback, useRef } from 'react'
  2. import styles from './index.module.scss'
  3. import { useParams } from 'react-router-dom'
  4. import { Button } from 'antd'
  5. import MyPopconfirm from '@/components/MyPopconfirm'
  6. import history from '@/utils/history'
  7. import { MessageFu } from '@/utils/message'
  8. import B3aTop from './B3aTop'
  9. export const B3TiaoObjUrl = {
  10. 1: '/entering',
  11. 2: '/enterTibet',
  12. 3: '/register',
  13. 4: '/delete'
  14. }
  15. export const B3TitObjKey = {
  16. '1': '入馆',
  17. '2': '入藏',
  18. '3': '登记',
  19. '4': '删除'
  20. }
  21. function B3add() {
  22. const { key } = useParams<any>()
  23. // 待完善,各种功能
  24. // 点击下方按钮
  25. const btnClickFu = useCallback(
  26. (val: number) => {
  27. // 从顶部组件中拿到数据
  28. const resData = topRef.current?.resData()
  29. console.log('从子组件获取数据', resData)
  30. if (val === 2) {
  31. // 存草稿 当前页保存 不跳转
  32. MessageFu.success('草稿保存成功')
  33. } else {
  34. const url = Reflect.get(B3TiaoObjUrl, key)
  35. history.push(`${url}_edit/${key}/${99}`)
  36. }
  37. },
  38. [key]
  39. )
  40. // 点击按钮调用子组件的方法获取数据
  41. const topRef = useRef<any>(null)
  42. return (
  43. <div className={styles.B3add}>
  44. <div className='pageTitle'>藏品{Reflect.get(B3TitObjKey, key)}-新增</div>
  45. <B3aTop info='xx' pageSta='新增' ref={topRef} />
  46. {/* 底部按钮 */}
  47. <div className='B3aBtn'>
  48. <Button type='primary' onClick={() => btnClickFu(1)}>
  49. 添加藏品
  50. </Button>
  51. <Button type='primary' onClick={() => btnClickFu(1)}>
  52. 创建
  53. </Button>
  54. <Button type='primary' onClick={() => btnClickFu(2)}>
  55. 存草稿
  56. </Button>
  57. <MyPopconfirm txtK='取消' onConfirm={() => history.go(-1)} />
  58. </div>
  59. </div>
  60. )
  61. }
  62. const MemoB3add = React.memo(B3add)
  63. export default MemoB3add