Y33com.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import React, { useCallback, useEffect, useMemo, useState } from 'react'
  2. import { Button, Checkbox, Popconfirm } from 'antd'
  3. import MyTable from '@/components/MyTable'
  4. import { Y33tableC } from '@/utils/tableData'
  5. import ImageLazy from '@/components/ImageLazy'
  6. import MyPopconfirm from '@/components/MyPopconfirm'
  7. import Y33setType, { infoType } from '../Y2look/Y33setType'
  8. import YtableVideo from '@/components/YtableVideo'
  9. import { GoodFileType } from '@/pages/B_enterTibet/B3goodsTable/B3GaddNew/type'
  10. import { selectObj } from '@/utils/select'
  11. import { fileImgArr, fileVideoArr } from '@/store/action/layout'
  12. import { downFileFu, resJiLianFu } from '@/utils/history'
  13. import { API_C2dels, API_C2downS, API_goodFileList } from '@/store/action/C2files'
  14. import { MessageFu } from '@/utils/message'
  15. import { useSelector } from 'react-redux'
  16. import { RootState } from '@/store'
  17. type Props = {
  18. isLook?: boolean
  19. sId: number
  20. }
  21. function Y33com({ isLook, sId }: Props) {
  22. const [fileList, setFileList] = useState<GoodFileType[]>([])
  23. const getListFu = useCallback(async () => {
  24. const res = await API_goodFileList(sId)
  25. if (res.code === 0) {
  26. setFileList(res.data || [])
  27. setCheckArr([])
  28. }
  29. }, [sId])
  30. useEffect(() => {
  31. getListFu()
  32. }, [getListFu])
  33. // 附件表格对象
  34. const tableObj = useMemo(() => {
  35. let obj: any = {
  36. '': fileList
  37. }
  38. fileList.forEach(v => {
  39. if (obj[v.type]) obj[v.type].push(v)
  40. else obj[v.type] = [v]
  41. })
  42. return obj
  43. }, [fileList])
  44. const [btnAc, setBtnAc] = useState('')
  45. // 多选
  46. const [checkArr, setCheckArr] = useState<number[]>([])
  47. const checkFu = useCallback(
  48. (id: number) => {
  49. if (checkArr.includes(id)) setCheckArr(checkArr.filter(v => v !== id))
  50. else setCheckArr([...checkArr, id])
  51. },
  52. [checkArr]
  53. )
  54. const startBtn = useMemo(() => {
  55. let arr: any = []
  56. if (isLook)
  57. arr.push({
  58. title: '选择',
  59. width: 50,
  60. render: (item: any) => (
  61. <Checkbox checked={checkArr.includes(item.id)} onChange={() => checkFu(item.id)} />
  62. )
  63. })
  64. return [
  65. ...arr,
  66. {
  67. width: 100,
  68. title: '缩略图/视频',
  69. render: (item: GoodFileType) => {
  70. const fileNameArr = item.fileName.split('.')
  71. const fileNameLast = fileNameArr[fileNameArr.length - 1]
  72. return fileImgArr.includes(fileNameLast) ? (
  73. <div className='tableImgAuto'>
  74. <ImageLazy width={60} height={60} srcBig={item.filePath} src={item.thumb} />
  75. </div>
  76. ) : fileVideoArr.includes(fileNameLast) ? (
  77. <YtableVideo src={item.filePath} />
  78. ) : (
  79. ' - '
  80. )
  81. }
  82. },
  83. {
  84. title: '附件类型',
  85. render: (item: GoodFileType) =>
  86. selectObj['附件类型'].find(v => v.value === item.type)?.label
  87. },
  88. {
  89. title: '附件用途',
  90. render: (item: GoodFileType) => (item.effect ? resJiLianFu(item.effect) : '(空)')
  91. }
  92. ]
  93. }, [checkArr, checkFu, isLook])
  94. // 点击删除
  95. const delFu = useCallback(
  96. async (data: number[]) => {
  97. const res = await API_C2dels(data)
  98. if (res.code === 0) {
  99. MessageFu.success('删除成功')
  100. getListFu()
  101. }
  102. },
  103. [getListFu]
  104. )
  105. // 获取下载权限
  106. const downImg = useSelector((state: RootState) => state.A0Layout.downImg)
  107. const tableLastBtn = useMemo(() => {
  108. return [
  109. {
  110. title: '操作',
  111. render: (item: GoodFileType) => {
  112. const fileNameArr = item.fileName.split('.')
  113. const fileNameLast = fileNameArr[fileNameArr.length - 1]
  114. return (
  115. <>
  116. {downImg['图片'] === '原图和缩略图' && fileImgArr.includes(fileNameLast) ? (
  117. <Popconfirm
  118. title='请选择图片规格'
  119. onConfirm={() => downFileFu(item.filePath)}
  120. onCancel={() => downFileFu(item.thumb)}
  121. okText='原图'
  122. cancelText='缩略图'
  123. >
  124. <Button size='small' type='text'>
  125. 下载
  126. </Button>
  127. </Popconfirm>
  128. ) : (
  129. <Button
  130. size='small'
  131. type='text'
  132. onClick={() => downFileFu(item.thumb || item.filePath)}
  133. >
  134. 下载
  135. </Button>
  136. )}
  137. {isLook ? (
  138. <>
  139. <Button
  140. size='small'
  141. type='text'
  142. onClick={() =>
  143. setTypeMo({
  144. ids: [item.id],
  145. type: item.type,
  146. effect: item.effect,
  147. flag: '单个'
  148. })
  149. }
  150. >
  151. 设置
  152. </Button>
  153. <MyPopconfirm txtK='删除' onConfirm={() => delFu([item.id])} />
  154. </>
  155. ) : null}
  156. </>
  157. )
  158. }
  159. }
  160. ]
  161. }, [delFu, downImg, isLook])
  162. const [typeMo, setTypeMo] = useState({} as infoType)
  163. // 点击批量下载
  164. const downsFu = useCallback(
  165. async (type: 1 | 2) => {
  166. const res = await API_C2downS(checkArr, type)
  167. if (res.code === 0) {
  168. MessageFu.success('下载成功')
  169. downFileFu(res.data, () => {
  170. setCheckArr([])
  171. })
  172. }
  173. },
  174. [checkArr]
  175. )
  176. return (
  177. <div className='Y33com'>
  178. {downImg['可见'] === '可见' ? (
  179. <>
  180. <div className='Y33top'>
  181. <div className='Y33topll'>
  182. {[{ label: '全部', value: '' }, ...selectObj['附件类型']].map(v => (
  183. <Button
  184. key={v.value}
  185. onClick={() => {
  186. setBtnAc(v.value)
  187. setCheckArr([])
  188. }}
  189. type={btnAc === v.value ? 'primary' : 'default'}
  190. >
  191. {v.label}
  192. </Button>
  193. ))}
  194. </div>
  195. {isLook ? (
  196. <div className='Y33toprr'>
  197. {downImg['图片'] === '原图和缩略图' ? (
  198. <Popconfirm
  199. title='请选择图片规格'
  200. onConfirm={() => downsFu(1)}
  201. onCancel={() => downsFu(2)}
  202. okText='原图'
  203. cancelText='缩略图'
  204. >
  205. <Button type='primary' disabled={checkArr.length === 0}>
  206. 批量下载
  207. </Button>
  208. </Popconfirm>
  209. ) : (
  210. <Button
  211. type='primary'
  212. disabled={checkArr.length === 0}
  213. onClick={() => downsFu(2)}
  214. >
  215. 批量下载
  216. </Button>
  217. )}
  218. &emsp;
  219. <Button
  220. type='primary'
  221. disabled={checkArr.length === 0}
  222. onClick={() =>
  223. setTypeMo({
  224. ids: checkArr,
  225. type: '',
  226. effect: '',
  227. flag: '多个'
  228. })
  229. }
  230. >
  231. 批量设置
  232. </Button>
  233. </div>
  234. ) : null}
  235. </div>
  236. {/* 表格 */}
  237. <MyTable
  238. classKey='Y33comTable'
  239. yHeight={isLook ? 640 : 666}
  240. list={tableObj[btnAc] || []}
  241. columnsTemp={Y33tableC}
  242. lastBtn={tableLastBtn}
  243. startBtn={startBtn}
  244. pagingInfo={false}
  245. />
  246. {typeMo.flag ? (
  247. <Y33setType
  248. succFu={getListFu}
  249. info={typeMo}
  250. closeFu={() => setTypeMo({} as infoType)}
  251. />
  252. ) : null}
  253. </>
  254. ) : (
  255. <div className='Y33no'>没有权限</div>
  256. )}
  257. </div>
  258. )
  259. }
  260. const MemoY33com = React.memo(Y33com)
  261. export default MemoY33com