index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import React, { useCallback, useEffect, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { Button, Input, Select } from 'antd'
  4. import { useDispatch, useSelector } from 'react-redux'
  5. import { A1EditInfoType } from './data'
  6. import { A6_APIdel, A6_APIgetList, A6_APIpublish } from '@/store/action/A6exhibition'
  7. import { RootState } from '@/store'
  8. import { MessageFu } from '@/utils/message'
  9. import { A6tableType } from '@/types/api/A6exhibition'
  10. import MyPopconfirm from '@/components/MyPopconfirm'
  11. import MyTable from '@/components/MyTable'
  12. import { A6tableC } from '@/utils/tableData'
  13. import A6add from './A6add'
  14. import { handleCopyClick } from '@/utils/copyTxt'
  15. import { editPreview } from '@/store/action/layout'
  16. const pageDataBase = {
  17. pageNum: 1,
  18. pageSize: 10
  19. }
  20. function A6exhibition() {
  21. const dispatch = useDispatch()
  22. const [pageData, setPageData] = useState(pageDataBase)
  23. const [title, setTitle] = useState('')
  24. const [type, setType] = useState(0)
  25. const getListFu = useCallback(
  26. (title?: string) => {
  27. // status: -1 全部 0 未发布 1 已发布
  28. dispatch(A6_APIgetList({ ...pageData, status: -1, title, type }))
  29. },
  30. [dispatch, pageData, type]
  31. )
  32. useEffect(() => {
  33. getListFu()
  34. }, [getListFu])
  35. // 点击重置
  36. const resetSelectFu = useCallback(() => {
  37. setPageData({ ...pageDataBase })
  38. }, [])
  39. const tableInfo = useSelector((state: RootState) => state.A6exhibition.tableInfo)
  40. const delTableFu = useCallback(
  41. async (id: number) => {
  42. const res = await A6_APIdel(id)
  43. if (res.code === 0) {
  44. MessageFu.success('删除成功!')
  45. getListFu()
  46. }
  47. },
  48. [getListFu]
  49. )
  50. const publishFu = useCallback(
  51. async (id: number) => {
  52. const res = await A6_APIpublish(id)
  53. if (res.code === 0) {
  54. MessageFu.success('发布成功!')
  55. getListFu()
  56. }
  57. },
  58. [getListFu]
  59. )
  60. const tableLastBtn = useMemo(() => {
  61. return [
  62. {
  63. title: '操作',
  64. render: (item: A6tableType) => (
  65. <>
  66. <Button
  67. size='small'
  68. type='text'
  69. onClick={() =>
  70. handleCopyClick(
  71. item.status === 1
  72. ? `https://sit-kelamayi.4dage.com/mini/#/allDetailsShow?id=${item.exhibitId}&type=exhibition&isFrom=weixin`
  73. : `https://sit-kelamayi.4dage.com/mini/#/allDetailsShow?id=${item.exhibitId}&type=exhibition&preview=1&isFromPage=indexPage/exhibition`
  74. )
  75. }
  76. >
  77. 复制地址
  78. </Button>
  79. {item.status === 0 && (
  80. <Button
  81. size='small'
  82. type='text'
  83. onClick={() =>
  84. dispatch(
  85. editPreview({
  86. isOpenPreview: true,
  87. src: `/allDetailsShow?id=${item.exhibitId}&type=exhibition&preview=1&isFromPage=exhibition`
  88. })
  89. )
  90. }
  91. >
  92. 预览
  93. </Button>
  94. )}
  95. <Button
  96. size='small'
  97. type='text'
  98. onClick={() => setEditInfo({ id: item.exhibitId, txt: '编辑' })}
  99. >
  100. 编辑
  101. </Button>
  102. {item.status === 0 && (
  103. <Button size='small' type='text' onClick={() => publishFu(item.exhibitId)}>
  104. 发布
  105. </Button>
  106. )}
  107. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.exhibitId)} />
  108. </>
  109. )
  110. }
  111. ]
  112. }, [delTableFu, dispatch, publishFu])
  113. //新增、编辑
  114. const [editInfo, setEditInfo] = useState<A1EditInfoType>({
  115. id: 0,
  116. txt: ''
  117. })
  118. return (
  119. <div className={styles.A6exhibition}>
  120. <div className='pageTitle'>克博展览 {editInfo.id ? ` - ${editInfo.txt}` : ''}</div>
  121. {/* 顶部筛选 */}
  122. <div className='A6top'>
  123. <div className='A6topLeft'>
  124. <Input
  125. style={{ width: 200 }}
  126. placeholder='请输入标题'
  127. onChange={e => setTitle(e.target.value)}
  128. value={title}
  129. maxLength={10}
  130. />
  131. <Button type='primary' onClick={() => getListFu(title)}>
  132. 搜索
  133. </Button>
  134. <Button
  135. type='primary'
  136. onClick={() => {
  137. resetSelectFu()
  138. setTitle('')
  139. }}
  140. >
  141. 重置
  142. </Button>
  143. <div className='rowItem'>
  144. 展览类型:
  145. <Select
  146. style={{ width: 120 }}
  147. defaultValue={0}
  148. options={[
  149. { label: '全部', value: 0 },
  150. { label: '室内', value: 1 },
  151. { label: '室外', value: 2 }
  152. ]}
  153. onChange={value => setType(value)}
  154. />
  155. </div>
  156. </div>
  157. <Button type='primary' onClick={() => setEditInfo({ id: -1, txt: '新增' })}>
  158. 新增
  159. </Button>
  160. </div>
  161. {/* 表格主体 */}
  162. <div className='A6tableBox'>
  163. <MyTable
  164. myKey='exhibitId'
  165. yHeight={625}
  166. list={tableInfo.list}
  167. columnsTemp={A6tableC}
  168. lastBtn={tableLastBtn}
  169. pageNum={pageData.pageNum}
  170. pageSize={pageData.pageSize}
  171. total={tableInfo.total}
  172. onChange={(pageNum, pageSize) => setPageData({ ...pageData, pageNum, pageSize })}
  173. />
  174. </div>
  175. {/* 新增 / 编辑 */}
  176. {editInfo.id ? (
  177. <A6add
  178. editInfo={editInfo}
  179. closeFu={() => setEditInfo({ id: 0, txt: '新增' })}
  180. addTableFu={resetSelectFu}
  181. editTableFu={getListFu}
  182. />
  183. ) : null}
  184. </div>
  185. )
  186. }
  187. const MemoA6exhibition = React.memo(A6exhibition)
  188. export default MemoA6exhibition