文件管理器记录历史路径

4.0
vapao 2023-04-22 23:22:11 +08:00
parent c9f4d7d912
commit 192aa3137c
1 changed files with 18 additions and 14 deletions

View File

@ -18,13 +18,14 @@ import { AuthButton, Action } from 'components';
import { http, uniqueId, X_TOKEN } from 'libs';
import lds from 'lodash';
import styles from './index.module.less'
import moment from 'moment';
class FileManager extends React.Component {
constructor(props) {
super(props);
this.input = null;
this.input2 = null
this.pwdHistoryCaches = new Map()
this.state = {
fetching: false,
showDot: false,
@ -43,8 +44,9 @@ class FileManager extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.id !== prevProps.id) {
this.fetchFiles()
this.setState({objects: []})
let pwd = this.pwdHistoryCaches.get(this.props.id) || []
this.setState({objects: [], pwd})
this.fetchFiles(pwd)
}
}
@ -72,6 +74,7 @@ class FileManager extends React.Component {
}, {
title: '修改时间',
dataIndex: 'date',
sorter: (a, b) => moment(a.date).unix() - moment(b.date).unix(),
width: 190
}, {
title: '属性',
@ -104,6 +107,7 @@ class FileManager extends React.Component {
.then(res => {
const objects = lds.orderBy(res, [this._kindSort, 'name'], ['desc', 'asc']);
this.setState({objects, pwd})
this.pwdHistoryCaches.set(this.props.id, pwd)
this.state.inputPath !== null && this.setState({inputPath: path})
})
.finally(() => this.setState({fetching: false}))
@ -123,19 +127,19 @@ class FileManager extends React.Component {
this.fetchFiles(pwd)
};
handleInputEnter = () => {
if (this.state.inputPath === null) {
if (this.state.pwd.length > 0) {
this.setState({inputPath: `/${this.state.pwd.join('/')}/`})
} else {
this.setState({inputPath: '/'})
handleInputEdit = () => {
let inputPath = '/' + this.state.pwd.join('/')
this.setState({inputPath})
}
setTimeout(() => this.input2.focus(), 100)
} else {
handleInputEnter = () => {
if (this.state.inputPath) {
let pwdStr = this.state.inputPath.replace(/^\/+/, '')
pwdStr = pwdStr.replace(/\/+$/, '')
this.fetchFiles(pwdStr.split('/'))
.then(() => this.setState({inputPath: null}))
} else {
this.setState({inputPath: null})
}
}
@ -220,7 +224,7 @@ class FileManager extends React.Component {
<input style={{display: 'none'}} type="file" ref={ref => this.input = ref}/>
<div className={styles.drawerHeader}>
{this.state.inputPath !== null ? (
<Input ref={ref => this.input2 = ref} size="small" className={styles.input}
<Input size="small" className={styles.input}
suffix={<div style={{color: '#999', fontSize: 12}}>回车确认</div>}
value={this.state.inputPath} onChange={e => this.setState({inputPath: e.target.value})}
onBlur={this.handleInputEnter}
@ -235,7 +239,7 @@ class FileManager extends React.Component {
<span>{item}</span>
</Breadcrumb.Item>
))}
<Breadcrumb.Item onClick={this.handleInputEnter}>
<Breadcrumb.Item onClick={this.handleInputEdit}>
<EditOutlined className={styles.edit}/>
</Breadcrumb.Item>
</Breadcrumb>