index.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import A1look from './A1look'
  4. import { useDispatch, useSelector } from 'react-redux'
  5. import { A1_APIdel, A1_APIgetList } from '@/store/action/A1record'
  6. import { RootState } from '@/store'
  7. import { MessageFu } from '@/utils/message'
  8. import { Button, Checkbox, Input, Table } from 'antd'
  9. import MyPopconfirm from '@/components/MyPopconfirm'
  10. import { A1ListType, jiGuanFu, LookInfoType } from './data'
  11. import A1add from './A1add'
  12. import ImageLazy from '@/components/ImageLazy'
  13. const baseFromData = {
  14. pageNum: 1,
  15. pageSize: 10,
  16. searchKey: '',
  17. display: ''
  18. }
  19. function A1record() {
  20. const dispatch = useDispatch()
  21. const [fromData, setFromData] = useState(baseFromData)
  22. const getListFu = useCallback(() => {
  23. dispatch(A1_APIgetList(fromData))
  24. }, [dispatch, fromData])
  25. useEffect(() => {
  26. getListFu()
  27. }, [getListFu])
  28. // 作品名称的输入
  29. const timeRef = useRef(-1)
  30. const [inputKey, setInputKey] = useState(0)
  31. const fromKeyChangeFu = useCallback(
  32. (e: React.ChangeEvent<HTMLInputElement>, key: 'searchKey') => {
  33. clearTimeout(timeRef.current)
  34. timeRef.current = window.setTimeout(() => {
  35. setFromData({ ...fromData, [key]: e.target.value, pageNum: 1 })
  36. }, 500)
  37. },
  38. [fromData]
  39. )
  40. const tableInfo = useSelector((state: RootState) => state.A1record.tableInfo)
  41. // 点击重置
  42. const resetSelectFu = useCallback(() => {
  43. setInputKey(Date.now())
  44. setFromData({ ...baseFromData })
  45. }, [])
  46. // 点击查看
  47. const [lookInfo, setLookInfo] = useState<LookInfoType>({
  48. id: 0,
  49. txt: ''
  50. })
  51. const delTableFu = useCallback(
  52. async (id: number) => {
  53. const res = await A1_APIdel(id)
  54. if (res.code === 0) {
  55. MessageFu.success('删除成功!')
  56. getListFu()
  57. }
  58. },
  59. [getListFu]
  60. )
  61. // 表格相关
  62. const columns = useMemo(() => {
  63. const arr: any = [
  64. { title: 'ID', dataIndex: 'num', width: 100 },
  65. {
  66. title: '封面图',
  67. width: 80,
  68. render: (item: A1ListType) => (
  69. <div className='tableImgAuto'>
  70. <ImageLazy
  71. width={60}
  72. height={60}
  73. src={item.thumb || item.thumbPc}
  74. srcBig={item.thumbPc || item.thumb}
  75. />
  76. </div>
  77. )
  78. },
  79. { title: '姓名', render: (item: A1ListType) => item.name, width: 100 },
  80. {
  81. title: '性别',
  82. width: 100,
  83. render: (item: A1ListType) => (item.gender === 1 ? '男' : '女')
  84. },
  85. { title: '民族', width: 100, render: (item: A1ListType) => item.nation || '(空)' },
  86. { title: '番号', render: (item: A1ListType) => item.intro || '(空)' },
  87. {
  88. title: '籍贯',
  89. render: (item: A1ListType) => jiGuanFu(item)
  90. },
  91. {
  92. title: '生卒',
  93. width: 200,
  94. render: (item: A1ListType) =>
  95. (item.dateStart || '(空)') + ' ~ ' + (item.dateEnd || '(空)')
  96. },
  97. {
  98. title: '备注',
  99. render: (item: A1ListType) =>
  100. item.remark ? (
  101. item.remark.length >= 50 ? (
  102. <span style={{ cursor: 'pointer' }} title={item.remark}>
  103. {item.remark.substring(0, 50) + '...'}
  104. </span>
  105. ) : (
  106. item.remark
  107. )
  108. ) : (
  109. '(空)'
  110. )
  111. },
  112. { title: '编辑时间', width: 150, render: (item: A1ListType) => item.updateTime },
  113. { title: '编辑人', width: 100, render: (item: A1ListType) => item.creatorName },
  114. {
  115. title: '操作',
  116. fixed: 'right',
  117. width: 150,
  118. render: (item: A1ListType) => (
  119. <>
  120. <Button
  121. size='small'
  122. type='text'
  123. onClick={() => setLookInfo({ id: item.id, txt: '查看' })}
  124. >
  125. 查看
  126. </Button>
  127. <Button
  128. size='small'
  129. type='text'
  130. onClick={() => setLookInfo({ id: item.id, txt: '编辑' })}
  131. >
  132. 编辑
  133. </Button>
  134. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
  135. </>
  136. )
  137. }
  138. ]
  139. return arr
  140. }, [delTableFu])
  141. return (
  142. <div className={styles.A1record}>
  143. <div className='pageTitle'>
  144. 烈士档案{lookInfo.txt ? ` - ${lookInfo.txt}` : ''}{' '}
  145. {lookInfo.txt === '查看' ? (
  146. <div onClick={() => setLookInfo({ id: 0, txt: '' })} className='A1LookBack'>
  147. <Button>返回</Button>
  148. </div>
  149. ) : null}
  150. </div>
  151. {/* 顶部筛选 */}
  152. <div className='A1top'>
  153. <div className='A1topLeft'>
  154. <div>
  155. <Input
  156. key={inputKey}
  157. maxLength={30}
  158. showCount
  159. style={{ width: 300 }}
  160. placeholder='请输入ID/姓名/番号/籍贯'
  161. allowClear
  162. onChange={e => fromKeyChangeFu(e, 'searchKey')}
  163. />
  164. </div>
  165. <div>
  166. <Checkbox
  167. onChange={e => {
  168. const val: any = e.target.checked ? 1 : ''
  169. setFromData({ ...fromData, display: val, pageNum: 1 })
  170. }}
  171. >
  172. 寻亲烈士
  173. </Checkbox>
  174. </div>
  175. </div>
  176. <div>
  177. <Button onClick={resetSelectFu}>重置</Button>
  178. &emsp;
  179. <Button type='primary' onClick={() => setLookInfo({ id: -1, txt: '新增' })}>
  180. 新增
  181. </Button>
  182. </div>
  183. </div>
  184. {/* 表格主体 */}
  185. <div className='A1tableBox'>
  186. <Table
  187. scroll={{ x: 'max-content', y: 645 }}
  188. columns={columns}
  189. dataSource={tableInfo.list}
  190. rowKey='id'
  191. pagination={{
  192. showQuickJumper: true,
  193. position: ['bottomCenter'],
  194. showSizeChanger: true,
  195. current: fromData.pageNum,
  196. pageSize: fromData.pageSize,
  197. total: tableInfo.total,
  198. onChange: (pageNum, pageSize) => setFromData({ ...fromData, pageNum, pageSize })
  199. }}
  200. />
  201. </div>
  202. {['新增', '编辑'].includes(lookInfo.txt) ? (
  203. <A1add
  204. sId={lookInfo.id}
  205. closeFu={() => setLookInfo({ id: 0, txt: '' })}
  206. addTableFu={resetSelectFu}
  207. upTableFu={getListFu}
  208. />
  209. ) : null}
  210. {lookInfo.txt === '查看' ? <A1look sId={lookInfo.id} /> : null}
  211. </div>
  212. )
  213. }
  214. const MemoA1record = React.memo(A1record)
  215. export default MemoA1record