优化重命名
This commit is contained in:
parent
3eb561bcb2
commit
505f19def1
@ -1,5 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<v-contextmenu ref="contextmenu" :theme="lightTheme?'default':'dark'" @contextmenu="contextmenu">
|
||||||
|
<v-contextmenu-item v-for="item of menus" :key="item.operation" @click="contextmenuClick(item.operation)">
|
||||||
|
<svg-icon :icon-class="item.iconClass"></svg-icon>
|
||||||
|
{{item.label}}
|
||||||
|
</v-contextmenu-item>
|
||||||
|
</v-contextmenu>
|
||||||
<div class="dir-tools" style="min-width: 272px;">
|
<div class="dir-tools" style="min-width: 272px;">
|
||||||
<el-button-group>
|
<el-button-group>
|
||||||
<el-button :class="lightTheme?'light-button':'dark-button'" size="small" icon="el-icon-arrow-left" @click="upperLeve">上一级</el-button>
|
<el-button :class="lightTheme?'light-button':'dark-button'" size="small" icon="el-icon-arrow-left" @click="upperLeve">上一级</el-button>
|
||||||
@ -9,12 +15,6 @@
|
|||||||
</el-button-group>
|
</el-button-group>
|
||||||
</div>
|
</div>
|
||||||
<div id="dir-tree" :style="{width: contentsWidth+'px',height: contentsHieght+'px'}">
|
<div id="dir-tree" :style="{width: contentsWidth+'px',height: contentsHieght+'px'}">
|
||||||
<v-contextmenu ref="contextmenu" :theme="lightTheme?'default':'dark'" @contextmenu="contextmenu">
|
|
||||||
<v-contextmenu-item v-for="item of menus" :key="item.operation" @click="contextmenuClick(item.operation)">
|
|
||||||
<svg-icon :icon-class="item.iconClass"></svg-icon>
|
|
||||||
{{item.label}}
|
|
||||||
</v-contextmenu-item>
|
|
||||||
</v-contextmenu>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -57,8 +57,13 @@
|
|||||||
{ iconClass: 'menu-remove', label: '删除', operation: 'remove' }
|
{ iconClass: 'menu-remove', label: '删除', operation: 'remove' }
|
||||||
],
|
],
|
||||||
fileMenus: [
|
fileMenus: [
|
||||||
|
{ iconClass: 'menu-rename', label: '重命名', operation: 'rename' },
|
||||||
{ iconClass: 'menu-remove', label: '删除', operation: 'remove' }
|
{ iconClass: 'menu-remove', label: '删除', operation: 'remove' }
|
||||||
]
|
],
|
||||||
|
newFileMenus: [
|
||||||
|
{ iconClass: 'add-file', label: '新建文件', operation: 'addFile' },
|
||||||
|
{ iconClass: 'folder-add', label: '新建目录', operation: 'addFolder' }
|
||||||
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -84,7 +89,6 @@
|
|||||||
let evObj = document.createEvent('MouseEvents');
|
let evObj = document.createEvent('MouseEvents');
|
||||||
evObj.initMouseEvent('click',true,true,window,1,12,345,7,220,false,false,true,false,0,null);
|
evObj.initMouseEvent('click',true,true,window,1,12,345,7,220,false,false,true,false,0,null);
|
||||||
vnode.dispatchEvent(evObj);
|
vnode.dispatchEvent(evObj);
|
||||||
|
|
||||||
if(this.contextData.isFolder){
|
if(this.contextData.isFolder){
|
||||||
this.menus = this.folderMenus
|
this.menus = this.folderMenus
|
||||||
}else{
|
}else{
|
||||||
@ -102,6 +106,10 @@
|
|||||||
console.log('remove',this.contextData)
|
console.log('remove',this.contextData)
|
||||||
this.delFile(this.contextData)
|
this.delFile(this.contextData)
|
||||||
break
|
break
|
||||||
|
case 'rename':
|
||||||
|
console.log('rename',this.contextData)
|
||||||
|
this.tree.getActiveNode().editStart()
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
console.log('default',this.contextData)
|
console.log('default',this.contextData)
|
||||||
break
|
break
|
||||||
@ -109,7 +117,8 @@
|
|||||||
},
|
},
|
||||||
// 删除文件/文件夹
|
// 删除文件/文件夹
|
||||||
delFile(data){
|
delFile(data){
|
||||||
this.$confirm('此操作将永久删除' + data.name + ', 是否继续?', '提示', {
|
this.$confirm('此操作将永久删除' + data.name + ',' +
|
||||||
|
'\n 是否继续?', '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
@ -197,6 +206,7 @@
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
initTree(treeData){
|
initTree(treeData){
|
||||||
|
const that = this
|
||||||
this.tree = fancytree.createTree('#dir-tree', {
|
this.tree = fancytree.createTree('#dir-tree', {
|
||||||
extensions: ["edit"],
|
extensions: ["edit"],
|
||||||
icon: (event,data)=> this.icon(event,data),
|
icon: (event,data)=> this.icon(event,data),
|
||||||
@ -230,7 +240,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
save: function(event, data){
|
save: function(event, data){
|
||||||
console.log(event.type, data);
|
console.log(event.type, data , data.input.val());
|
||||||
|
that.nodeRename(data.input.val(), data.node.data, data.node)
|
||||||
// Save data.input.val() or return false to keep editor open
|
// Save data.input.val() or return false to keep editor open
|
||||||
// Simulate to start a slow ajax request...
|
// Simulate to start a slow ajax request...
|
||||||
// setTimeout(function(){
|
// setTimeout(function(){
|
||||||
@ -256,6 +267,42 @@
|
|||||||
});
|
});
|
||||||
console.log(this.tree.getActiveNode(),fancytree._extensions)
|
console.log(this.tree.getActiveNode(),fancytree._extensions)
|
||||||
},
|
},
|
||||||
|
// 重命名
|
||||||
|
nodeRename(newFileName, row, node) {
|
||||||
|
if (newFileName) {
|
||||||
|
if(/[\/\\"<>\?\*]/gi.test(newFileName)){
|
||||||
|
this.$message({
|
||||||
|
message: '文件名不能包含以下字字符:<,>,|,*,?,,/',
|
||||||
|
type: 'warning'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let strFileName = newFileName.replace(/(.*\/)*([^.]+).*/ig,"$2");
|
||||||
|
let newExt = newFileName.replace(/.+\./,"");
|
||||||
|
if (!row.isFolder) {
|
||||||
|
if (row.suffix !== newExt) {
|
||||||
|
this.$confirm(`您确定要将扩展名“.${row.suffix}”更改为“.${newExt}”吗?`,'提示',{
|
||||||
|
type: 'warning',
|
||||||
|
confirmButtonText: `保持.${row.suffix}`,
|
||||||
|
cancelButtonText: `使用.${newExt}`,
|
||||||
|
}).then(()=>{
|
||||||
|
newFileName = strFileName + '.' + row.suffix
|
||||||
|
}).catch(()=>{
|
||||||
|
}).then(()=>{
|
||||||
|
this.rename(row,newFileName,node)
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
this.rename(row,newFileName,node)
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
this.rename(row,newFileName,node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rename(row,newFileName,node){
|
||||||
|
// 重命名
|
||||||
|
node.setTitle(newFileName);
|
||||||
|
},
|
||||||
icon(event,data) {
|
icon(event,data) {
|
||||||
return { html: this.loadSvg(this.findIconClass(data.node.data)) }
|
return { html: this.loadSvg(this.findIconClass(data.node.data)) }
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1852,49 +1852,69 @@
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let strFileName = newFileName.replace(/(.*\/)*([^.]+).*/ig,"$2");
|
||||||
|
let newExt = newFileName.replace(/.+\./,"");
|
||||||
if (!row.isFolder) {
|
if (!row.isFolder) {
|
||||||
const ext = '.' + row.suffix
|
if (row.suffix !== newExt) {
|
||||||
if (!newFileName.endsWith(ext)) {
|
this.$confirm(`您确定要将扩展名“.${row.suffix}”更改为“.${newExt}”吗?`,'提示',{
|
||||||
newFileName += ext
|
type: 'warning',
|
||||||
|
confirmButtonText: `保持.${row.suffix}`,
|
||||||
|
cancelButtonText: `使用.${newExt}`,
|
||||||
|
}).then(()=>{
|
||||||
|
newFileName = strFileName + '.' + row.suffix
|
||||||
|
}).catch(()=>{
|
||||||
|
}).then(()=>{
|
||||||
|
this.rename(row,newFileName)
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
this.rename(row,newFileName)
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
this.rename(row,newFileName)
|
||||||
}
|
}
|
||||||
this.renameLoading = true
|
|
||||||
const findIndex = this.fileList.findIndex(item => {
|
|
||||||
if(newFileName === item.name){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if(findIndex > -1){
|
|
||||||
let msg = '该文件已存在'
|
|
||||||
if(row.isFolder){
|
|
||||||
msg = '该文件夹已存在'
|
|
||||||
}
|
|
||||||
this.$message({
|
|
||||||
message: msg,
|
|
||||||
type: 'warning'
|
|
||||||
});
|
|
||||||
this.renameLoading = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
api.rename({
|
|
||||||
newFileName: newFileName,
|
|
||||||
username: this.$store.state.user.name,
|
|
||||||
id: row.id
|
|
||||||
}).then(res => {
|
|
||||||
if (res.data) {
|
|
||||||
this.renameLoading = false
|
|
||||||
row.name = newFileName
|
|
||||||
this.fileList[row.index] = row
|
|
||||||
this.editingIndex = -1
|
|
||||||
}
|
|
||||||
}).then(()=>{
|
|
||||||
this.$refs.fileListTable.clearSelection()
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
this.editingIndex = -1
|
this.editingIndex = -1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
rename(row,newFileName){
|
||||||
|
if(row.name === newFileName){
|
||||||
|
this.editingIndex = -1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.renameLoading = true
|
||||||
|
const findIndex = this.fileList.findIndex(item => {
|
||||||
|
if(newFileName === item.name){
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(findIndex > -1){
|
||||||
|
let msg = '该文件已存在'
|
||||||
|
if(row.isFolder){
|
||||||
|
msg = '该文件夹已存在'
|
||||||
|
}
|
||||||
|
this.$message({
|
||||||
|
message: msg,
|
||||||
|
type: 'warning'
|
||||||
|
});
|
||||||
|
this.renameLoading = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
api.rename({
|
||||||
|
newFileName: newFileName,
|
||||||
|
username: this.$store.state.user.name,
|
||||||
|
id: row.id
|
||||||
|
}).then(res => {
|
||||||
|
if (res.data) {
|
||||||
|
this.renameLoading = false
|
||||||
|
row.name = newFileName
|
||||||
|
row.suffix = newFileName.replace(/.+\./,"")
|
||||||
|
this.fileList[row.index] = row
|
||||||
|
this.editingIndex = -1
|
||||||
|
}
|
||||||
|
}).then(()=>{
|
||||||
|
this.$refs.fileListTable.clearSelection()
|
||||||
|
})
|
||||||
|
},
|
||||||
// 更多操作(多选)
|
// 更多操作(多选)
|
||||||
moreOperation(event) {
|
moreOperation(event) {
|
||||||
this.menusIsMultiple = true
|
this.menusIsMultiple = true
|
||||||
|
|||||||
@ -743,7 +743,6 @@
|
|||||||
|
|
||||||
.dir-tools {
|
.dir-tools {
|
||||||
background: #ececec;
|
background: #ececec;
|
||||||
border-right: 5px solid #fff;
|
|
||||||
.el-button--small {
|
.el-button--small {
|
||||||
padding: 9px 10px;
|
padding: 9px 10px;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user