优化重命名操作和新建文件夹操作

This commit is contained in:
jmal 2020-02-16 14:01:38 +08:00
parent 80075e7feb
commit e97dbd5ac3

View File

@ -10,7 +10,6 @@
v-if="index===pathList.length-1" v-if="index===pathList.length-1"
v-model="isShowNewFolder" v-model="isShowNewFolder"
placement="bottom" placement="bottom"
trigger="click"
@click="showNewFolderClick" @click="showNewFolderClick"
@after-leave="hideNewFolderName" @after-leave="hideNewFolderName"
> >
@ -28,21 +27,21 @@
</li> </li>
<li @click.prevent="newFolder"> <li @click.prevent="newFolder">
<a href="#" class="menuitem"><svg-icon icon-class="folder-add" /><span class="menuitem text">新建文件夹</span> <a href="#" class="menuitem"><svg-icon icon-class="folder-add" /><span class="menuitem text">新建文件夹</span>
<div v-show="showNewFolder" class="folder-name-form">
<el-input v-model="newFolderName" placeholder="请输入文件夹名称" :clearable="true" @change="newFolderNameClick">
<el-button
slot="append"
v-loading="newFolderLoading"
element-loading-spinner="el-icon-loading"
element-loading-background="#f6f7fa88"
class="el-icon-right"
@click="newFolderNameClick"
>
</el-button>
</el-input>
</div>
</a> </a>
</li> </li>
<div v-show="showNewFolder" class="folder-name-form">
<el-input v-focus v-model="newFolderName" placeholder="请输入文件夹名称" :clearable="true" @keyup.enter.native="newFolderNameClickEnter">
<el-button
slot="append"
v-loading="newFolderLoading"
element-loading-spinner="el-icon-loading"
element-loading-background="#f6f7fa88"
class="el-icon-right"
@click="newFolderNameClick"
>
</el-button>
</el-input>
</div>
</ul> </ul>
</div> </div>
<el-button slot="reference" icon="el-icon-plus add-file-button" circle /> <el-button slot="reference" icon="el-icon-plus add-file-button" circle />
@ -70,6 +69,7 @@
<label class="menuitem"><svg-icon :icon-class="item.iconClass" /><span class="menuitem text">{{ item.label }}</span> <label class="menuitem"><svg-icon :icon-class="item.iconClass" /><span class="menuitem text">{{ item.label }}</span>
</label> </label>
</li> </li>
</ul> </ul>
</e-vue-contextmenu> </e-vue-contextmenu>
@ -129,7 +129,23 @@
<el-table-column v-if="index === 2" :key="index" :show-overflow-tooltip="true" min-width="200" :index="index" :prop="item.name" :label="item.label" :sortable="item.sortable" @click.stop="fileClick(scope.row)"> <el-table-column v-if="index === 2" :key="index" :show-overflow-tooltip="true" min-width="200" :index="index" :prop="item.name" :label="item.label" :sortable="item.sortable" @click.stop="fileClick(scope.row)">
<template slot-scope="scope"> <template slot-scope="scope">
<el-col v-if="scope.row.index === editingIndex" :span="10"> <el-col v-if="scope.row.index === editingIndex" :span="10">
<el-input v-model="scope.row.name" placeholder="" size="small" @change="rowRename(scope.row)"></el-input> <el-input v-focus v-model="renameFileName" placeholder="" size="small" :clearable="true" @keyup.enter.native="rowRename(renameFileName, scope.row)">
</el-input>
<el-button
v-loading="renameLoading"
element-loading-spinner="el-icon-loading"
element-loading-background="#f6f7fa88"
class="el-icon-check"
@click="rowRename(renameFileName, scope.row)"
>
</el-button>
<el-button
element-loading-spinner="el-icon-loading"
element-loading-background="#f6f7fa88"
class="el-icon-close"
@click="editingIndex = -1"
>
</el-button>
</el-col> </el-col>
<span v-else>{{ scope.row.name }}</span> <span v-else>{{ scope.row.name }}</span>
</template> </template>
@ -220,6 +236,7 @@ export default {
showNewFolder: false, showNewFolder: false,
isShowNewFolder: false, isShowNewFolder: false,
newFolderName: '新建文件夹', newFolderName: '新建文件夹',
renameFileName: '',
pathList: [ pathList: [
{ 'folder': '', index: 0 }, { 'folder': '', index: 0 },
{ 'folder': '+', index: 1 } { 'folder': '+', index: 1 }
@ -278,6 +295,7 @@ export default {
selectRowData: [], selectRowData: [],
tableLoading: false, tableLoading: false,
newFolderLoading: false, newFolderLoading: false,
renameLoading: false,
menuTriangle: '', menuTriangle: '',
cellMouseIndex: -1, cellMouseIndex: -1,
editingIndex: -1 editingIndex: -1
@ -322,6 +340,16 @@ export default {
destroyed() { destroyed() {
removePath() removePath()
}, },
directives: {
// 注册一个局部的自定义指令 v-focus
focus: {
// 指令的定义
inserted: function (el) {
// 聚焦元素
el.querySelector('input').focus()
}
}
},
methods: { methods: {
// 行拖拽 // 行拖拽
rowDrop() { rowDrop() {
@ -359,7 +387,6 @@ export default {
if (number === 0) { if (number === 0) {
this.path = '' this.path = ''
} else if (number === this.pathList.length - 1) { } else if (number === this.pathList.length - 1) {
// console.log('this.path' + this.path)
} else { } else {
this.path += '/' + this.pathList[number].folder this.path += '/' + this.pathList[number].folder
} }
@ -368,6 +395,17 @@ export default {
this.getFileList() this.getFileList()
}, },
newFolder() { newFolder() {
console.log(879)
this.newFolderName = '新建文件夹'
let append = 0
let filenameList = []
this.fileList.forEach(file => {
filenameList.push(file.name)
})
while(filenameList.includes(this.newFolderName)){
append += 1
this.newFolderName = '新建文件夹' + append
}
this.showNewFolder = true this.showNewFolder = true
}, },
hideNewFolderName() { hideNewFolderName() {
@ -377,28 +415,45 @@ export default {
showNewFolderClick() { showNewFolderClick() {
this.isShowNewFolder = true this.isShowNewFolder = true
}, },
newFolderNameClickEnter() {
this.newFolderNameClick()
},
// 新建文件夹 // 新建文件夹
newFolderNameClick() { newFolderNameClick() {
console.log(68790) this.newFolderLoading = true
this.newFolderLoading = true if(this.newFolderName){
api.uploadFolder({ api.uploadFolder({
isFolder: true, isFolder: true,
filename: this.newFolderName, filename: this.newFolderName,
currentDirectory: this.path, currentDirectory: this.path,
username: this.$store.state.user.username, username: this.$store.state.user.name,
userId: this.$store.state.user.userId userId: this.$store.state.user.userId
}).then(() => { }).then((res) => {
console.log('新建文件夹' + this.newFolderName + '成功!') if(res.data === 1){
this.getFileList() this.newFolderLoading = false
this.newFolderLoading = false this.$message({
this.showNewFolder = false message: '该文件夹已存在',
this.isShowNewFolder = false type: 'warning'
this.$notify({ });
title: '新建文件夹成功', } else {
type: 'success', this.newFolderLoading = false
duration: 1000 this.showNewFolder = false
this.isShowNewFolder = false
this.$notify({
title: '新建文件夹成功',
type: 'success',
duration: 1000
})
this.getFileList()
}
}) })
}) }else{
this.newFolderLoading = false
this.$message({
message: '请输入文件夹名称',
type: 'warning'
});
}
}, },
getFileList() { getFileList() {
this.tableLoading = true this.tableLoading = true
@ -514,14 +569,14 @@ export default {
}, },
// cell-style通过返回值可以实现样式变换利用传递过来的数组index循环改变样式 // cell-style通过返回值可以实现样式变换利用传递过来的数组index循环改变样式
rowRed({ row, column, rowIndex, columnIndex }) { rowRed({ row, column, rowIndex, columnIndex }) {
if (this.indexList.length < 1 && columnIndex === 2 && this.cellMouseIndex === rowIndex) { if (this.indexList.length < 1 && columnIndex === 2 && this.cellMouseIndex === rowIndex) {
return { cursor: 'pointer', color: "#19ACF9" } return { cursor: 'pointer', color: "#19ACF9" }
} }
for (let i = 0; i < this.indexList.length; i++) { for (let i = 0; i < this.indexList.length; i++) {
if (rowIndex === this.indexList[i]) { if (rowIndex === this.indexList[i]) {
return { backgroundColor: '#EBEEF5', color: '#b7b5b6', cursor: 'default' } return { backgroundColor: '#EBEEF5', color: '#b7b5b6', cursor: 'default' }
}
} }
}
}, },
// 动态添加index到row里面去 // 动态添加index到row里面去
tableRowClassName({ row, rowIndex }) { tableRowClassName({ row, rowIndex }) {
@ -537,8 +592,10 @@ export default {
}, },
// 单元格hover进入时时间 // 单元格hover进入时时间
cellMouseEnter(row) { cellMouseEnter(row) {
if (this.indexList.length < 1) { if(this.editingIndex === -1){
this.cellMouseIndex = row.index if (this.indexList.length < 1) {
this.cellMouseIndex = row.index
}
} }
}, },
// 单元格hover退出时时间 // 单元格hover退出时时间
@ -547,48 +604,75 @@ export default {
}, },
// 单元格点击事件 // 单元格点击事件
cellClick(row, column) { cellClick(row, column) {
const columnIndex = column.index if(this.editingIndex === -1) {
if (columnIndex === 0) { const columnIndex = column.index
// 点击选中 if (columnIndex === 0) {
this.$refs.fileListTable.toggleRowSelection(row) // 点击选中
} this.$refs.fileListTable.toggleRowSelection(row)
if (columnIndex === 2) { }
if (this.indexList.length < 1) { if (columnIndex === 2) {
if (row.index !== this.editingIndex) { if (this.indexList.length < 1) {
this.fileClick(row) if (row.index !== this.editingIndex) {
this.editingIndex = -1 this.fileClick(row)
this.editingIndex = -1
}
} }
} }
} if (columnIndex === 4) {
if (columnIndex === 4) { // // 单个操作
// // 单个操作 }
} if (this.indexList.length > 0) {
if (this.indexList.length > 0) { this.$refs.fileListTable.toggleRowSelection(row)
this.$refs.fileListTable.toggleRowSelection(row) }
} }
}, },
// 重命名 // 重命名
rowRename(row) { rowRename(newFileName, row) {
let newFileName = row.name
if (newFileName) { if (newFileName) {
if (!row.isFolder) { if (!row.isFolder) {
const ext = '.' + row.suffix const ext = '.' + row.suffix
if (!newFileName.endsWith(ext)) { if (!newFileName.endsWith(ext)) {
newFileName += ext newFileName += ext
} }
} }
console.log('newFileName', this.$store.state.user)
console.log('newFileName', newFileName)
this.renameLoading = true
const findIndex = this.fileList.findIndex(item => {
if(newFileName === item.name){
return item;
}
})
console.log(findIndex)
if(findIndex > -1){
let msg = '该文件已存在'
if(row.isFolder){
msg = '该文件夹已存在'
}
this.$message({
message: msg,
type: 'warning'
});
this.renameLoading = false
return
}
api.rename({ api.rename({
newFileName: newFileName, newFileName: newFileName,
username: this.$store.state.user.name, username: this.$store.state.user.name,
id: row.id id: row.id
}).then(res => { }).then(res => {
if (res.data) { if (res.data) {
this.renameLoading = false
row.name = newFileName row.name = newFileName
this.fileList[row.index] = row this.fileList[row.index] = row
this.editingIndex = -1 this.editingIndex = -1
} }
}) })
} else {
this.editingIndex = -1
} }
}, },
// 更多操作(多选) // 更多操作(多选)
@ -717,16 +801,8 @@ export default {
break break
case 'rename': case 'rename':
console.log('重命名') console.log('重命名')
this.renameFileName = this.rowContextData.name
this.editingIndex = this.rowContextData.index this.editingIndex = this.rowContextData.index
// if (!this.rowContextData.isFolder) {
// this.editingIndex = this.rowContextData.index
// } else {
// this.$notify({
// title: '暂不支持文件夹重命名',
// type: 'warning',
// duration: 2000
// })
// }
break break
case 'copy': case 'copy':
console.log('移动或复制') console.log('移动或复制')
@ -806,10 +882,10 @@ export default {
console.log(row) console.log(row)
if (row.isFolder) { if (row.isFolder) {
// 打开文件 // 打开文件
this.path += '/' + row.pathname this.path += '/' + row.name
const item1 = {} const item1 = {}
item1['folder'] = row.pathname item1['folder'] = row.name
item1['index'] = this.pathList.length - 1 item1['index'] = this.pathList.length - 1
const item2 = {} const item2 = {}
@ -905,12 +981,17 @@ export default {
cursor: pointer; cursor: pointer;
font-size: 20px; font-size: 20px;
} }
.menuitem /deep/ .el-loading-spinner { /deep/ .el-input-group__append /deep/ .el-loading-spinner {
top: 0; top: 0;
margin-top: 0.75rem; margin-top: 0.75rem;
width: 100%; }
text-align: center; /deep/ .cell /deep/ .el-loading-spinner {
position: absolute; top: 0;
margin-top: 0.54rem;
}
/deep/ .cell /deep/ .el-button {
padding: 8px 16px;
margin-left: 10px;
} }
/deep/ .el-checkbox { /deep/ .el-checkbox {
cursor: default; cursor: default;