import React, { useEffect, useState, useRef } from 'react'; import { connect } from 'react-redux'; import moment from 'moment'; import { Button, Col, Row, Input, Tree, Table, Space, Tooltip, Spin, Popconfirm, Pagination, DatePicker } from '@douyinfe/semi-ui'; import { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons'; import { getResourceFileList, postResourceFile, delResourceFile, getResourceClassify, postResourceClassify, putResourceClassify, delResourceClassify } from '../actions/resourceRepository'; import FolderModal from '../components/resourceRepository/folder-model'; import ResourceUploadModal from '../components/resourceRepository/upload-modal'; import '../style.less'; const ResourceRepository = (props) => { const { dispatch, clientHeight, apiRoot, user, resourceClassify, resourceFilelist, isRequesting } = props; const [treeData, setTreeData] = useState([]); const [currentSelect, setCurrentSelect] = useState("公司培训资料"); const [defaultExpandedKey, setDefaultExpandedKey] = useState(); const [modelVisiable, setModelVisiable] = useState(false); const [modalData, setModalData] = useState(); const [uploadModalVisiable, setUploadModalVisiable] = useState(false); const [paginationQuery, setPaginatioQuery] = useState({ limit: 10, page: 0 }); //页码信息 const [keyword, setKeyword] = useState();//文件名称过滤 const [dataRange, setDataRange] = useState();//更新时间过滤 const ref = useRef(); useEffect(() => { getClassify(); }, []) const style = { width: 260, height: clientHeight - 294, border: '1px solid var(--semi-color-border)' }; const columns = [ { title: '文件类型', dataIndex: 'fileType', }, { title: '文件名称', dataIndex: 'fileName', }, { title: '大小', dataIndex: 'fileSize', }, { title: '更新时间', dataIndex: 'updateDate', render: (text) => text && moment(text).format('YYYY-MM-DD HH:mm:ss') || '-' }, { title: '操作', dataIndex: 'action', render: (text, record) => { return
删除 }
} } ]; const renderLabel = (label, data) => { const child = data.children ? true : false; const key = data.key.split('/'); return (
{label.length > 7 ? label.substring(0, 7) + '...' : label} {true == data.operation ? handleFolderClick(child ? '编辑' : '编辑子', !child, key[1], key[2] || undefined)} /> handleDel(data.key)} // onCancel={onCancel} > {child ? handleFolderClick('新建子', true, label, undefined)} /> : ''} : ''}
) }; const handleFolderClick = (title, childFolder, departmentName, trainDate) => { setModelVisiable(true); setModalData({ title, childFolder, departmentName, trainDate }); } const handleSelect = (e) => { setCurrentSelect(e); setPaginatioQuery({ limit: 10, page: 0 }); setKeyword(null); setDataRange(null); getFile(e, { limit: 10, page: 0 }, { restSearch: true }); } const handleDataToSave = (add, body) => { setDefaultExpandedKey([]); if (add) { dispatch(postResourceClassify(body)).then(res => { if (res.success) { getClassify(); setModelVisiable(false); } }); } else { dispatch(putResourceClassify(body)).then(res => { if (res.success) { getClassify(); setModelVisiable(false); } }); } } const handleDelFile = (id) => { dispatch(delResourceFile(id)).then(res => { if (res.success) { getFile(currentSelect, { limit: 10, page: 0 }, { restSearch: true }); } }) } const handleDel = (key) => { const arr = key.split('/'); const query = { departmentName: arr[1] } if (arr.length == 3) { query.trainDate = arr[2]; } dispatch(delResourceClassify(query)).then(res => { if (res.success) { getClassify(); setModelVisiable(false); } }); } const handleUploadOk = (data) => { const fileList = data.attachPath && data.attachPath.length && data.attachPath.filter(d => "success" == d.status).map(d => { const { name, size, response } = d; const { uploaded } = response || {}; let index = name.lastIndexOf('.'); return { fileType: name.substring(index), fileName: name.substring(0, index), fileSize: size, attachPath: uploaded } }); dispatch(postResourceFile({ fileList, currentSelect })).then(res => { if (res.success) { getFile(currentSelect); setUploadModalVisiable(false); } }) } const handleSearch = () => { setPaginatioQuery({ limit: 10, page: 0 }); getFile(null, { limit: 10, page: 0 }); } const getFile = (e, pagination, opt) => { const arr = e ? e.split("/") : currentSelect.split("/"); const query = pagination ? { ...pagination, type: arr[0] } : { ...paginationQuery, type: arr[0] }; if (opt && opt.restSearch) { //选中树节点重置 setPaginatioQuery({ limit: 10, page: 0 }); setKeyword(null); setDataRange(null); } else { if (keyword) { query.keyword = keyword; } if (dataRange) { query.startTime = moment(dataRange[0]).format('YYYY-MM-DD HH:mm:ss'); query.endTime = moment(dataRange[1]).format('YYYY-MM-DD HH:mm:ss'); } } if (arr[1]) { query.departmentName = arr[1]; } if (arr[2]) { query.trainDate = arr[2]; } dispatch(getResourceFileList(query)); } const getClassify = () => { dispatch(getResourceClassify()).then(res => { const { success, payload } = res; if (success) { let defaultKey = ""; if (payload.data.length) { if (payload.data[0].children && payload.data[0].children.length) { defaultKey = payload.data[0].children[0].key; setDefaultExpandedKey([payload.data[0].key, payload.data[0].children[0].key]); } else { defaultKey = payload.data[0].key; setDefaultExpandedKey([payload.data[0].key]); } } setCurrentSelect(defaultKey); setTreeData(payload.data); getFile(defaultKey); } }); } return ( <>
培训
/
培训档案
/
培训资源储存库
培训资源储存库
RESOURCE REPOSITORY
{/* 左侧 */}
} showClear onChange={v => ref.current.search(v)} placeholder="请输入"> setDefaultExpandedKey(e)} onSelect={handleSelect} /> {/* 右侧内容 */} 当前文件夹:{currentSelect} {currentSelect && currentSelect.includes("公司培训资料") && currentSelect.split("/").length == 3 ? : null} 关键字 } showClear placeholder="文件名称" value={keyword} onChange={(value) => { setKeyword(value) }} > 更新时间范围 { setDataRange(data) }} onClear={() => { setDataRange(null) }} />
共{resourceFilelist && resourceFilelist.count}条信息 { setPaginatioQuery({ limit: pageSize, page: currentPage - 1 }); getFile(currentSelect, { limit: pageSize, page: currentPage - 1 }); }} />
{modelVisiable ? '公司培训资料' == r.label)} modalData={modalData} onOk={handleDataToSave} onCancel={() => { setModelVisiable(false) }} /> : null } {uploadModalVisiable ? { setUploadModalVisiable(false) }} /> : null } ) } function mapStateToProps(state) { const { auth, global, resourceClassify, resourceFilelist } = state; return { user: auth.user, actions: global.actions, apiRoot: global.apiRoot, clientHeight: global.clientHeight, resourceClassify: resourceClassify.data || [], resourceFilelist: resourceFilelist.data && resourceFilelist.data, isRequesting: resourceClassify.isRequesting || resourceFilelist.isRequesting }; } export default connect(mapStateToProps)(ResourceRepository);