|
|
@@ -1,9 +1,241 @@
|
|
|
-import React from 'react'
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
+import { useDispatch, useSelector } from 'react-redux'
|
|
|
+import { fromDataBase } from '../A2video/data'
|
|
|
+import { B2_APIdel, B2_APIgetList } from '@/store/action/B2library'
|
|
|
+import store, { RootState } from '@/store'
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
+import { FileListType } from '@/components/ZupTypes'
|
|
|
+import { Button, Checkbox, Input, Select } from 'antd'
|
|
|
+import { baseURL } from '@/utils/http'
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
+import { B2typeSelectType, downloadFilesAsZip } from './data'
|
|
|
+import MyTable from '@/components/MyTable'
|
|
|
+import { B2tableC } from '@/utils/tableData'
|
|
|
+import ImageLazy from '@/components/ImageLazy'
|
|
|
+import { EyeOutlined } from '@ant-design/icons'
|
|
|
+
|
|
|
function B2library() {
|
|
|
+ const dispatch = useDispatch()
|
|
|
+
|
|
|
+ // 顶部筛选
|
|
|
+ const [fromData, setFromData] = useState(fromDataBase)
|
|
|
+
|
|
|
+ // 封装发送请求的函数
|
|
|
+ const getListFu = useCallback(async () => {
|
|
|
+ dispatch(B2_APIgetList(fromData))
|
|
|
+ }, [dispatch, fromData])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getListFu()
|
|
|
+ }, [getListFu])
|
|
|
+
|
|
|
+ const timeRef = useRef(-1)
|
|
|
+ // 输入框的输入
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
+ (e: React.ChangeEvent<HTMLInputElement>, key: 'searchKey') => {
|
|
|
+ clearTimeout(timeRef.current)
|
|
|
+ timeRef.current = window.setTimeout(() => {
|
|
|
+ setFromData({
|
|
|
+ ...fromData,
|
|
|
+ [key]: e.target.value,
|
|
|
+ pageNum: 1
|
|
|
+ })
|
|
|
+ }, 500)
|
|
|
+ },
|
|
|
+ [fromData]
|
|
|
+ )
|
|
|
+ // 点击重置
|
|
|
+ const [inputKey, setInputKey] = useState(1)
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
+ setInputKey(Date.now())
|
|
|
+ setFromData({ ...fromDataBase })
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 从仓库中获取表格数据
|
|
|
+ const tableInfo = useSelector((state: RootState) => state.B2library.tableInfo)
|
|
|
+
|
|
|
+ const [checkArr, setCheckArr] = useState<FileListType[]>([])
|
|
|
+
|
|
|
+ const checkFlag = useMemo(() => {
|
|
|
+ return tableInfo.list.length <= checkArr.length
|
|
|
+ }, [checkArr.length, tableInfo.list.length])
|
|
|
+
|
|
|
+ // 全选和反选
|
|
|
+ const onChangeAll = useCallback(() => {
|
|
|
+ if (checkFlag) setCheckArr([])
|
|
|
+ else setCheckArr([...tableInfo.list])
|
|
|
+ }, [checkFlag, tableInfo.list])
|
|
|
+
|
|
|
+ // 单个选择
|
|
|
+ const checkOneFu = useCallback(
|
|
|
+ (item: FileListType) => {
|
|
|
+ if (checkArr.map(v => v._id).includes(item._id))
|
|
|
+ setCheckArr(checkArr.filter(v => v._id !== item._id))
|
|
|
+ else setCheckArr([...checkArr, item])
|
|
|
+ },
|
|
|
+ [checkArr]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 点击删除
|
|
|
+ const delTableFu = useCallback(
|
|
|
+ async (id: string) => {
|
|
|
+ const res: any = await B2_APIdel(id)
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success('删除成功')
|
|
|
+ if (checkArr.map(v => v._id).includes(id)) setCheckArr(checkArr.filter(v => v._id !== id))
|
|
|
+ getListFu()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [checkArr, getListFu]
|
|
|
+ )
|
|
|
+
|
|
|
+ const tableLastBtn = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: '查看',
|
|
|
+ render: (item: FileListType) => {
|
|
|
+ if (item.type === 'img') {
|
|
|
+ return (
|
|
|
+ <div className='tableImgAuto'>
|
|
|
+ <ImageLazy
|
|
|
+ width={60}
|
|
|
+ height={60}
|
|
|
+ src={item.compressedUrl || item.originalUrl}
|
|
|
+ srcBig={item.originalUrl || item.compressedUrl}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ } else if (item.type === 'video') {
|
|
|
+ return (
|
|
|
+ <div className='B2lookVideo'>
|
|
|
+ <div
|
|
|
+ className='B2lookBox'
|
|
|
+ onClick={() =>
|
|
|
+ store.dispatch({
|
|
|
+ type: 'layout/lookDom',
|
|
|
+ payload: { src: item.originalUrl, type: 'video' }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <EyeOutlined rev={undefined} />
|
|
|
+
|
|
|
+ <div>预览</div>
|
|
|
+ </div>
|
|
|
+ <video src={baseURL + item.originalUrl} />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ const lastNameArr = item.originalName.split('.')
|
|
|
+ let laseName = lastNameArr[lastNameArr.length - 1]
|
|
|
+ laseName = laseName.toLocaleLowerCase()
|
|
|
+ if (laseName === 'pdf') {
|
|
|
+ return (
|
|
|
+ <Button
|
|
|
+ size='small'
|
|
|
+ type='text'
|
|
|
+ onClick={() => {
|
|
|
+ window.open(baseURL + item.originalUrl)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+ )
|
|
|
+ } else return <div className='tableImgAuto'>-</div>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: (
|
|
|
+ <div>
|
|
|
+ <Checkbox checked={checkFlag} onChange={() => onChangeAll()}>
|
|
|
+ {checkFlag ? '反选' : '全选'}
|
|
|
+ </Checkbox>
|
|
|
+ </div>
|
|
|
+ ),
|
|
|
+ render: (item: FileListType) => (
|
|
|
+ <Checkbox
|
|
|
+ checked={checkArr.map(v => v._id).includes(item._id)}
|
|
|
+ onChange={() => checkOneFu(item)}
|
|
|
+ >
|
|
|
+ <span style={{ opacity: 0 }}>选择</span>{' '}
|
|
|
+ </Checkbox>
|
|
|
+ )
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ render: (item: FileListType) => (
|
|
|
+ <>
|
|
|
+ <Button size='small' type='text'>
|
|
|
+ <a href={baseURL + item.originalUrl} download target='_blank' rel='noreferrer'>
|
|
|
+ 下载
|
|
|
+ </a>
|
|
|
+ </Button>
|
|
|
+ <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item._id)} />
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }, [checkArr, checkFlag, checkOneFu, delTableFu, onChangeAll])
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.B2library}>
|
|
|
- <h1>B2library</h1>
|
|
|
+ <div className='pageTitle'>素材库</div>
|
|
|
+
|
|
|
+ <div className='B2top'>
|
|
|
+ <div className='B2topll'>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={30}
|
|
|
+ showCount
|
|
|
+ style={{ width: 300 }}
|
|
|
+ placeholder='请输入标题'
|
|
|
+ allowClear
|
|
|
+ onChange={e => txtChangeFu(e, 'searchKey')}
|
|
|
+ />
|
|
|
+  
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ style={{ width: 150 }}
|
|
|
+ placeholder='类别'
|
|
|
+ options={B2typeSelectType}
|
|
|
+ value={fromData.type || null}
|
|
|
+ onChange={e => setFromData({ ...fromData, type: e, pageNum: 1 })}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className='B2toprr'>
|
|
|
+ <Button onClick={resetSelectFu}>重置</Button> 
|
|
|
+ <Button
|
|
|
+ type='primary'
|
|
|
+ onClick={() =>
|
|
|
+ downloadFilesAsZip(
|
|
|
+ checkArr.map(v => ({
|
|
|
+ url: baseURL + v.originalUrl,
|
|
|
+ name: v.originalName
|
|
|
+ })),
|
|
|
+ 'download.zip',
|
|
|
+ () => {
|
|
|
+ setCheckArr([])
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 批量下载
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <MyTable
|
|
|
+ yHeight={650}
|
|
|
+ list={tableInfo.list}
|
|
|
+ columnsTemp={B2tableC}
|
|
|
+ lastBtn={tableLastBtn}
|
|
|
+ pageNum={fromData.pageNum}
|
|
|
+ pageSize={fromData.pageSize}
|
|
|
+ total={tableInfo.total}
|
|
|
+ onChange={(pageNum, pageSize) => setFromData({ ...fromData, pageNum, pageSize })}
|
|
|
+ />
|
|
|
</div>
|
|
|
)
|
|
|
}
|