|
|
@@ -1,9 +1,312 @@
|
|
|
-import React from 'react'
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
+import { antdSelectType, selectObj } from '@/utils/dataChange'
|
|
|
+import { useDispatch, useSelector } from 'react-redux'
|
|
|
+import { getKuListByOpenFu } from '@/pages/Zother/data'
|
|
|
+import { ziyuanAcGet, ziyuanAcSet } from '@/utils/storage'
|
|
|
+import { B2_APIdowns, B2_APIgetList } from '@/store/action/Bresource/B2resFile'
|
|
|
+import { RootState } from '@/store'
|
|
|
+import { openLink } from '@/utils/history'
|
|
|
+import { downloadFileByUrl, fileImgArr } from '@/utils'
|
|
|
+import { Button, Checkbox, Input, Select } from 'antd'
|
|
|
+import { FileListType } from '@/components/Z3upFiles/data'
|
|
|
+import ImageLazy from '@/components/ImageLazy'
|
|
|
+import YtableVideo from '@/components/YtableVideo'
|
|
|
+import { baseURL } from '@/utils/http'
|
|
|
+import MyTable from '@/components/MyTable'
|
|
|
+import { fileTableC } from '@/utils/tableData'
|
|
|
+import B2set from './B2set'
|
|
|
+
|
|
|
+export const B2selectTopBase: any = {
|
|
|
+ searchKey: '',
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ type: '',
|
|
|
+ formDefId: ''
|
|
|
+}
|
|
|
+
|
|
|
function A2resFile() {
|
|
|
+ const [kuList, setKuList] = useState<antdSelectType[]>([])
|
|
|
+
|
|
|
+ const [loding, setLoding] = useState(false)
|
|
|
+
|
|
|
+ const dispatch = useDispatch()
|
|
|
+
|
|
|
+ const [formData, setFormData] = useState({ ...B2selectTopBase })
|
|
|
+ const formDataRef = useRef({ ...B2selectTopBase })
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ formDataRef.current = { ...formData }
|
|
|
+ }, [formData])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getKuListByOpenFu(data => {
|
|
|
+ setLoding(true)
|
|
|
+ if (data && data.length) {
|
|
|
+ setKuList(data)
|
|
|
+ const ziyuanAcTxt = ziyuanAcGet()
|
|
|
+ let objRes = data.find(v => v.value === ziyuanAcTxt)
|
|
|
+
|
|
|
+ const resFid = objRes ? ziyuanAcTxt : data[0].value
|
|
|
+ const fId = resFid
|
|
|
+ const obj = { ...B2selectTopBase, formDefId: fId }
|
|
|
+ setFormData(obj)
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, [dispatch])
|
|
|
+
|
|
|
+ // 点击搜索的 时间戳
|
|
|
+ const [timeKey, setTimeKey] = useState(0)
|
|
|
+
|
|
|
+ // 选择
|
|
|
+ const [checkIds, setCheckIds] = useState<number[]>([])
|
|
|
+
|
|
|
+ // 点击搜索
|
|
|
+ const clickSearch = useCallback(() => {
|
|
|
+ setFormData({ ...formData, pageNum: 1 })
|
|
|
+ setCheckIds([])
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ }, [formData])
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const resetSelectFu = useCallback(
|
|
|
+ (formDefId?: number) => {
|
|
|
+ setFormData({ ...B2selectTopBase, formDefId: formDefId || formData.formDefId })
|
|
|
+ setCheckIds([])
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ },
|
|
|
+ [formData.formDefId]
|
|
|
+ )
|
|
|
+ // 封装发送请求的函数
|
|
|
+ const getList = useCallback(async () => {
|
|
|
+ const obj = {
|
|
|
+ ...formDataRef.current
|
|
|
+ }
|
|
|
+ dispatch(B2_APIgetList(obj))
|
|
|
+ }, [dispatch])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (timeKey) getList()
|
|
|
+ }, [getList, timeKey])
|
|
|
+
|
|
|
+ // 页码变化
|
|
|
+ const paginationChange = useCallback(
|
|
|
+ (pageNum: number, pageSize: number) => {
|
|
|
+ setFormData({ ...formData, pageNum, pageSize })
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now())
|
|
|
+ }, 50)
|
|
|
+ },
|
|
|
+ [formData]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 表格数据
|
|
|
+ const tableInfo = useSelector((state: RootState) => state.B2resFile.tableInfo)
|
|
|
+
|
|
|
+ // 点击批量下载
|
|
|
+ const downFu = useCallback(async () => {
|
|
|
+ const res = await B2_APIdowns({ ids: checkIds })
|
|
|
+
|
|
|
+ if (res.code === 0) {
|
|
|
+ downloadFileByUrl(res.data)
|
|
|
+ setCheckIds([])
|
|
|
+ }
|
|
|
+ }, [checkIds])
|
|
|
+
|
|
|
+ // 表格操作按钮
|
|
|
+ const staBtn = useMemo(() => {
|
|
|
+ let arr: any[] = [
|
|
|
+ {
|
|
|
+ title: '选择',
|
|
|
+ width: 70,
|
|
|
+ render: (item: any) => (
|
|
|
+ <div className='tableAuto'>
|
|
|
+ <Checkbox
|
|
|
+ checked={checkIds.includes(item.id)}
|
|
|
+ onChange={() => {
|
|
|
+ setCheckIds(
|
|
|
+ checkIds.includes(item.id)
|
|
|
+ ? checkIds.filter(v => v !== item.id)
|
|
|
+ : [...checkIds, item.id]
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ ></Checkbox>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '缩略图/查看',
|
|
|
+ render: (item: FileListType) => {
|
|
|
+ const lastNameArr = item.fileName.split('.')
|
|
|
+ let lastName = lastNameArr[lastNameArr.length - 1]
|
|
|
+ lastName = lastName.toLocaleLowerCase()
|
|
|
+
|
|
|
+ if (fileImgArr.includes(lastName)) {
|
|
|
+ return (
|
|
|
+ <div className='tableImgAuto'>
|
|
|
+ <ImageLazy
|
|
|
+ width={60}
|
|
|
+ height={60}
|
|
|
+ src={item.thumb || item.filePath}
|
|
|
+ srcBig={item.filePath || item.thumb}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ } else if (item.type === 'video') {
|
|
|
+ return <YtableVideo src={item.filePath} />
|
|
|
+ } else {
|
|
|
+ const lastNameArr = item.fileName.split('.')
|
|
|
+ let laseName = lastNameArr[lastNameArr.length - 1]
|
|
|
+ laseName = laseName.toLocaleLowerCase()
|
|
|
+ if (['pdf', 'txt'].includes(laseName)) {
|
|
|
+ return (
|
|
|
+ <Button
|
|
|
+ size='small'
|
|
|
+ type='text'
|
|
|
+ onClick={() => {
|
|
|
+ window.open(baseURL + item.filePath)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+ )
|
|
|
+ } else return <div className='tableImgAuto'>-</div>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+
|
|
|
+ return arr
|
|
|
+ }, [checkIds])
|
|
|
+
|
|
|
+ const tabBtnArr = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ width: 'auto',
|
|
|
+ render: (item: any) => {
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Button
|
|
|
+ size='small'
|
|
|
+ type='text'
|
|
|
+ onClick={() => openLink(`/goodsLook/${item.moduleId}/${formData.formDefId}`)}
|
|
|
+ >
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ size='small'
|
|
|
+ type='text'
|
|
|
+ onClick={async () => downloadFileByUrl(item.filePath)}
|
|
|
+ >
|
|
|
+ 下载
|
|
|
+ </Button>
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }, [formData.formDefId])
|
|
|
+
|
|
|
+ // 输入框的改变
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
+ (txt: string, key: any) => {
|
|
|
+ setFormData({
|
|
|
+ ...formData,
|
|
|
+ [key]: txt
|
|
|
+ })
|
|
|
+ },
|
|
|
+ [formData]
|
|
|
+ )
|
|
|
+
|
|
|
+ // 复制管理
|
|
|
+ const [fuZhi, setFuZhi] = useState(false)
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.A2resFile}>
|
|
|
- <h1>A2resFile</h1>
|
|
|
+ <div className='pageTitle'>资源附件{fuZhi ? '-复制管理' : ''}</div>
|
|
|
+
|
|
|
+ {formData.formDefId ? (
|
|
|
+ <div className='B2main'>
|
|
|
+ <div className='b2top'>
|
|
|
+ <div className='b2top1'>
|
|
|
+ <div>
|
|
|
+ <Input
|
|
|
+ style={{ width: 300 }}
|
|
|
+ value={formData.searchKey}
|
|
|
+ maxLength={30}
|
|
|
+ showCount
|
|
|
+ placeholder='请输入附件名称/资源编码/资源名称'
|
|
|
+ onChange={e => txtChangeFu(e.target.value, 'searchKey')}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Select
|
|
|
+ placeholder='附件类型'
|
|
|
+ style={{ width: 200 }}
|
|
|
+ options={selectObj['附件类型']}
|
|
|
+ value={formData.type || null}
|
|
|
+ onChange={e => txtChangeFu(e, 'type')}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <Button type='primary' onClick={clickSearch}>
|
|
|
+ 查询
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Button onClick={() => resetSelectFu()}>重置</Button> 
|
|
|
+ <Button type='primary' disabled={checkIds.length === 0} onClick={downFu}>
|
|
|
+ 批量下载
|
|
|
+ </Button>
|
|
|
+   {checkIds.length ? <>已选中 {checkIds.length} 条数据</> : null}
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className='Z0ku'>
|
|
|
+ 资源库:
|
|
|
+ <Select
|
|
|
+ style={{ maxWidth: 200, minWidth: 120 }}
|
|
|
+ value={formData.formDefId}
|
|
|
+ onChange={e => {
|
|
|
+ setFormData({ ...formData, pageNum: 1, formDefId: e })
|
|
|
+ ziyuanAcSet(e)
|
|
|
+ resetSelectFu(e)
|
|
|
+ }}
|
|
|
+ options={kuList}
|
|
|
+ />
|
|
|
+  
|
|
|
+ <Button type='primary' onClick={() => setFuZhi(true)}>
|
|
|
+ 复制管理
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <MyTable
|
|
|
+ yHeight={660}
|
|
|
+ classKey='A2resFile'
|
|
|
+ list={tableInfo.list}
|
|
|
+ columnsTemp={fileTableC(true)}
|
|
|
+ lastBtn={tabBtnArr}
|
|
|
+ pageNum={formData.pageNum}
|
|
|
+ pageSize={formData.pageSize}
|
|
|
+ total={tableInfo.total}
|
|
|
+ staBtn={staBtn}
|
|
|
+ onChange={(pageNum, pageSize) => paginationChange(pageNum, pageSize)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div hidden={!loding} className='Z0null'>
|
|
|
+ 请先在 系统管理-资源库管理 添加数据 或 开启资源库状态
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ {fuZhi ? (
|
|
|
+ <B2set kuList={kuList} formDefId={formData.formDefId} closeFu={() => setFuZhi(false)} />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
)
|
|
|
}
|