mirror of https://github.com/openspug/spug
修复文件管理器路径输入框报错问题
parent
cdedc648e0
commit
bd07775a26
|
@ -25,7 +25,6 @@ class FileManager extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.input = null;
|
this.input = null;
|
||||||
this.input2 = null
|
|
||||||
this.pwdHistoryCaches = new Map()
|
this.pwdHistoryCaches = new Map()
|
||||||
this.state = {
|
this.state = {
|
||||||
fetching: false,
|
fetching: false,
|
||||||
|
@ -45,8 +44,9 @@ class FileManager extends React.Component {
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.id !== prevProps.id) {
|
if (this.props.id !== prevProps.id) {
|
||||||
this.fetchFiles()
|
let pwd = this.pwdHistoryCaches.get(this.props.id) || []
|
||||||
this.setState({objects: []})
|
this.setState({objects: [], pwd})
|
||||||
|
this.fetchFiles(pwd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +101,7 @@ class FileManager extends React.Component {
|
||||||
|
|
||||||
fetchFiles = (pwd) => {
|
fetchFiles = (pwd) => {
|
||||||
this.setState({ fetching: true });
|
this.setState({ fetching: true });
|
||||||
pwd = pwd || (this.pwdHistoryCaches.get(this.props.id) || []);
|
pwd = pwd || this.state.pwd;
|
||||||
if (this.pwdHistoryCaches.has(this.props.id)) {
|
|
||||||
let pwdCache = this.pwdHistoryCaches.get(this.props.id)
|
|
||||||
pwdCache.push(pwd.length > 0 ? pwd.splice(-1) : null)
|
|
||||||
pwd = pwdCache.filter(x => !!x)
|
|
||||||
}
|
|
||||||
const path = '/' + pwd.join('/');
|
const path = '/' + pwd.join('/');
|
||||||
return http.get('/api/file/', {params: {id: this.props.id, path}})
|
return http.get('/api/file/', {params: {id: this.props.id, path}})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
@ -132,19 +127,19 @@ class FileManager extends React.Component {
|
||||||
this.fetchFiles(pwd)
|
this.fetchFiles(pwd)
|
||||||
};
|
};
|
||||||
|
|
||||||
handleInputEnter = () => {
|
handleInputEdit = () => {
|
||||||
if (this.state.inputPath === null) {
|
let inputPath = '/' + this.state.pwd.join('/')
|
||||||
if (this.state.pwd.length > 0) {
|
this.setState({inputPath})
|
||||||
this.setState({inputPath: `/${this.state.pwd.join('/')}/`})
|
|
||||||
} else {
|
|
||||||
this.setState({inputPath: '/'})
|
|
||||||
}
|
}
|
||||||
setTimeout(() => this.input2.focus(), 100)
|
|
||||||
} else {
|
handleInputEnter = () => {
|
||||||
|
if (this.state.inputPath) {
|
||||||
let pwdStr = this.state.inputPath.replace(/^\/+/, '')
|
let pwdStr = this.state.inputPath.replace(/^\/+/, '')
|
||||||
pwdStr = pwdStr.replace(/\/+$/, '')
|
pwdStr = pwdStr.replace(/\/+$/, '')
|
||||||
this.fetchFiles(pwdStr.split('/'))
|
this.fetchFiles(pwdStr.split('/'))
|
||||||
.then(() => this.setState({inputPath: null}))
|
.then(() => this.setState({inputPath: null}))
|
||||||
|
} else {
|
||||||
|
this.setState({inputPath: null})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +224,7 @@ class FileManager extends React.Component {
|
||||||
<input style={{display: 'none'}} type="file" ref={ref => this.input = ref}/>
|
<input style={{display: 'none'}} type="file" ref={ref => this.input = ref}/>
|
||||||
<div className={styles.drawerHeader}>
|
<div className={styles.drawerHeader}>
|
||||||
{this.state.inputPath !== null ? (
|
{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>}
|
suffix={<div style={{color: '#999', fontSize: 12}}>回车确认</div>}
|
||||||
value={this.state.inputPath} onChange={e => this.setState({inputPath: e.target.value})}
|
value={this.state.inputPath} onChange={e => this.setState({inputPath: e.target.value})}
|
||||||
onBlur={this.handleInputEnter}
|
onBlur={this.handleInputEnter}
|
||||||
|
@ -244,7 +239,7 @@ class FileManager extends React.Component {
|
||||||
<span>{item}</span>
|
<span>{item}</span>
|
||||||
</Breadcrumb.Item>
|
</Breadcrumb.Item>
|
||||||
))}
|
))}
|
||||||
<Breadcrumb.Item onClick={this.handleInputEnter}>
|
<Breadcrumb.Item onClick={this.handleInputEdit}>
|
||||||
<EditOutlined className={styles.edit}/>
|
<EditOutlined className={styles.edit}/>
|
||||||
</Breadcrumb.Item>
|
</Breadcrumb.Item>
|
||||||
</Breadcrumb>
|
</Breadcrumb>
|
||||||
|
|
Loading…
Reference in New Issue