perf: 优化文件重命名,支持按esc取消编辑
This commit is contained in:
parent
c5f1c95f7b
commit
223fb540b1
@ -1,8 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="quick-edit" :class="[alwaysIcon ? 'quick-always' : '']">
|
<div class="quick-edit" :class="[alwaysIcon ? 'quick-always' : '']">
|
||||||
<div v-if="isEdit" v-clickoutside="onClickOut" class="quick-input">
|
<div v-if="isEdit" v-clickoutside="onClickOut" class="quick-input">
|
||||||
<TagInput v-if="isTag" ref="input" v-model="content" :disabled="isLoad" @on-enter="onEnter" @on-blur="onBlur"/>
|
<TagInput
|
||||||
<Input v-else ref="input" v-model="content" :disabled="isLoad" @on-enter="onEnter" @on-blur="onBlur"/>
|
v-if="isTag"
|
||||||
|
ref="input"
|
||||||
|
v-model="content"
|
||||||
|
:disabled="isLoad"
|
||||||
|
@on-keyup="onKeyup"
|
||||||
|
@on-blur="onBlur"/>
|
||||||
|
<Input
|
||||||
|
v-else
|
||||||
|
ref="input"
|
||||||
|
v-model="content"
|
||||||
|
:disabled="isLoad"
|
||||||
|
@on-keyup="onKeyup"
|
||||||
|
@on-blur="onBlur"/>
|
||||||
<div v-if="isLoad" class="quick-loading"><Loading/></div>
|
<div v-if="isLoad" class="quick-loading"><Loading/></div>
|
||||||
</div>
|
</div>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@ -54,9 +66,6 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
isEdit(val) {
|
|
||||||
this.$emit("on-edit-change", val);
|
|
||||||
},
|
|
||||||
autoEdit(val) {
|
autoEdit(val) {
|
||||||
if (val === true) {
|
if (val === true) {
|
||||||
setTimeout(this.onEdit, 0)
|
setTimeout(this.onEdit, 0)
|
||||||
@ -65,9 +74,14 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
onEditChange(val) {
|
||||||
|
this.isEdit = val;
|
||||||
|
this.$emit("on-edit-change", val);
|
||||||
|
},
|
||||||
|
|
||||||
onEdit() {
|
onEdit() {
|
||||||
this.content = this.value;
|
this.content = this.value;
|
||||||
this.isEdit = true;
|
this.onEditChange(true);
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.input.focus({
|
this.$refs.input.focus({
|
||||||
cursor: 'all'
|
cursor: 'all'
|
||||||
@ -75,9 +89,18 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onKeyup(e) {
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
this.onEnter();
|
||||||
|
} else if (e.keyCode === 27) {
|
||||||
|
this.isEdit = false;
|
||||||
|
this.isLoad = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onEnter() {
|
onEnter() {
|
||||||
if (this.content == this.value) {
|
if (this.content == this.value) {
|
||||||
this.isEdit = false;
|
this.onEditChange(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.isLoad) {
|
if (this.isLoad) {
|
||||||
@ -86,7 +109,7 @@ export default {
|
|||||||
this.isLoad = true;
|
this.isLoad = true;
|
||||||
this.$emit("input", this.content);
|
this.$emit("input", this.content);
|
||||||
this.$emit("on-update", this.content, () => {
|
this.$emit("on-update", this.content, () => {
|
||||||
this.isEdit = false;
|
this.onEditChange(false);
|
||||||
this.isLoad = false;
|
this.isLoad = false;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -99,7 +122,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onBlur() {
|
onBlur() {
|
||||||
if (this.clickOutSide) {
|
if (this.clickOutSide || !this.isEdit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.onEnter();
|
this.onEnter();
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
:placeholder="tis || placeholderText"
|
:placeholder="tis || placeholderText"
|
||||||
@keydown.enter="downEnter($event)"
|
@keydown.enter="downEnter($event)"
|
||||||
@keydown.delete="delTag(false)"
|
@keydown.delete="delTag(false)"
|
||||||
@keyup="addTag($event, content)"
|
@keyup="onKeyup"
|
||||||
@focus="onFocus"
|
@focus="onFocus"
|
||||||
@blur="onBlur"
|
@blur="onBlur"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
@ -158,19 +158,22 @@
|
|||||||
this.addTag(false, this.content)
|
this.addTag(false, this.content)
|
||||||
this.$emit("on-blur", e)
|
this.$emit("on-blur", e)
|
||||||
},
|
},
|
||||||
|
onKeyup(e) {
|
||||||
|
this.addTag(e, this.content);
|
||||||
|
//
|
||||||
|
this.$emit("on-keyup", e)
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$emit("on-enter", e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
addTag(e, content) {
|
addTag(e, content) {
|
||||||
|
|
||||||
if (e === false || e.keyCode === 13) {
|
if (e === false || e.keyCode === 13) {
|
||||||
if (content.trim() != '' && this.disSource.indexOf(content.trim()) === -1) {
|
if (content.trim() != '' && this.disSource.indexOf(content.trim()) === -1) {
|
||||||
this.disSource.push(content.trim());
|
this.disSource.push(content.trim());
|
||||||
}
|
}
|
||||||
this.content = '';
|
this.content = '';
|
||||||
//
|
|
||||||
if (e.keyCode === 13) {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.$emit("on-enter", e)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.max > 0 && this.disSource.length >= this.max) {
|
if (this.max > 0 && this.disSource.length >= this.max) {
|
||||||
|
@ -87,9 +87,9 @@
|
|||||||
<li
|
<li
|
||||||
v-for="item in fileList"
|
v-for="item in fileList"
|
||||||
:class="{
|
:class="{
|
||||||
shear: shearIds.includes(item.id),
|
shear: shearIds.includes(item.id),
|
||||||
highlight: selectIds.includes(item.id),
|
highlight: selectIds.includes(item.id),
|
||||||
}"
|
}"
|
||||||
@contextmenu.prevent.stop="handleRightClick($event, item)"
|
@contextmenu.prevent.stop="handleRightClick($event, item)"
|
||||||
@click="openFile(item)">
|
@click="openFile(item)">
|
||||||
<div class="file-check" :class="{'file-checked':selectIds.includes(item.id)}" @click.stop="dropFile(item, 'select')">
|
<div class="file-check" :class="{'file-checked':selectIds.includes(item.id)}" @click.stop="dropFile(item, 'select')">
|
||||||
@ -121,7 +121,7 @@
|
|||||||
size="small"
|
size="small"
|
||||||
:disabled="!!item._load"
|
:disabled="!!item._load"
|
||||||
@on-blur="onBlur(item)"
|
@on-blur="onBlur(item)"
|
||||||
@on-enter="onEnter(item)"/>
|
@on-keyup="onKeyup($event, item)"/>
|
||||||
<div v-if="item._load" class="file-load"><Loading/></div>
|
<div v-if="item._load" class="file-load"><Loading/></div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="file-name" :title="item.name">{{formatName(item)}}</div>
|
<div v-else class="file-name" :title="item.name">{{formatName(item)}}</div>
|
||||||
@ -959,7 +959,6 @@ export default {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'rename':
|
case 'rename':
|
||||||
this.$set(item, 'newname', item.name);
|
|
||||||
this.setEdit(item.id, true)
|
this.setEdit(item.id, true)
|
||||||
this.autoBlur(item.id)
|
this.autoBlur(item.id)
|
||||||
break;
|
break;
|
||||||
@ -1154,9 +1153,21 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onBlur(item) {
|
onBlur(item) {
|
||||||
|
if (this.files.find(({id, _edit}) => id == item.id && !_edit)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.onEnter(item);
|
this.onEnter(item);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onKeyup(e, item) {
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
this.onEnter(item);
|
||||||
|
} else if (e.keyCode === 27) {
|
||||||
|
this.setLoad(item.id, false)
|
||||||
|
this.setEdit(item.id, false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onEnter(item) {
|
onEnter(item) {
|
||||||
let isCreate = !/^\d+$/.test(item.id);
|
let isCreate = !/^\d+$/.test(item.id);
|
||||||
if (!item.newname) {
|
if (!item.newname) {
|
||||||
@ -1204,6 +1215,9 @@ export default {
|
|||||||
let item = this.$store.state.files.find(({id}) => id == fileId)
|
let item = this.$store.state.files.find(({id}) => id == fileId)
|
||||||
if (item) {
|
if (item) {
|
||||||
this.$set(item, '_edit', is);
|
this.$set(item, '_edit', is);
|
||||||
|
if (is) {
|
||||||
|
this.$set(item, 'newname', item.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user