2022-11-16 10:26:39 +08:00
|
|
|
<template>
|
2022-11-21 18:40:28 +08:00
|
|
|
<div class="fileDirectory" style="width: 100% !important;transform: scale(1) !important;">
|
2022-11-18 00:18:59 +08:00
|
|
|
<div class="file-directory-header">
|
2022-11-23 18:38:00 +08:00
|
|
|
<span style="color: #fff">
|
|
|
|
|
{{$t('terminal.sftp')}}
|
|
|
|
|
<span style="color: #B7B7B7;margin-left: 10px">
|
|
|
|
|
<span @click="getSftpPath('/')" class="breadcrumb-item breadcrumb-action"><i class="nz-icon nz-icon-Computer"/></span>
|
|
|
|
|
<span v-for="(item,index) in breadcrumb" :key="index" class="breadcrumb-item">
|
|
|
|
|
/<span class="breadcrumb-action" @click="gotoPath(item,index)">{{item}}</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
<span style="color: #fff" class="header-option">
|
2022-11-18 00:18:59 +08:00
|
|
|
<i class="nz-icon nz-icon-a-newfolder" @click="newFolderBoxShow = true"></i>
|
|
|
|
|
<i class="nz-icon nz-icon-upload" @click="uploadFile"></i>
|
|
|
|
|
<i class="nz-icon nz-icon-close" @click="$emit('close')"></i>
|
2022-11-16 10:26:39 +08:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2022-11-21 18:40:28 +08:00
|
|
|
<div class="file-directory-content" v-my-loading="fileDirectoryLoading">
|
2022-11-22 16:28:39 +08:00
|
|
|
<div v-if="fileDirectory !== '/'" @click="backFileDirectory" class="file-item"><i class="nz-icon nz-icon-a-upperlevel" style="margin-right: 10px"/>{{$t('terminal.back')}}</div>
|
2022-11-18 00:18:59 +08:00
|
|
|
<div v-for="(item,index) in fileList" :key="index" class="file-item" @click="selectFile(item)">
|
2022-11-21 18:40:28 +08:00
|
|
|
<div class="text-ellipsis file-name">
|
2022-11-18 00:18:59 +08:00
|
|
|
<i class="nz-icon" :class="selIcon(item)"/>
|
|
|
|
|
{{item.name}}
|
2022-11-21 18:40:28 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="file-feature" v-if="!item.isDir">
|
2022-11-18 00:18:59 +08:00
|
|
|
<i class="nz-icon nz-icon-download1" v-if="!item.isDir" @click="downloadFile(item)"></i>
|
|
|
|
|
<i class="nz-icon nz-icon-delete" v-if="!item.isDir" @click="delFile(item)"></i>
|
2022-11-21 18:40:28 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="file-date">
|
|
|
|
|
<span>{{momentTz(item.cts * 1000)}}</span>
|
|
|
|
|
<span v-if="!item.isDir">{{bytes(item.size, 0, 0)}}</span>
|
|
|
|
|
</div>
|
2022-11-16 10:26:39 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-11-18 00:18:59 +08:00
|
|
|
<el-dialog
|
2022-11-23 18:38:00 +08:00
|
|
|
class="nz-dialog snapshot-dialog"
|
|
|
|
|
width="472px"
|
2022-11-22 10:00:08 +08:00
|
|
|
:title='$t("overall.newFolder")'
|
2022-11-23 18:38:00 +08:00
|
|
|
destroy-on-close
|
|
|
|
|
:modal-append-to-body="false"
|
|
|
|
|
:close-on-click-modal="false"
|
2022-11-18 00:18:59 +08:00
|
|
|
:visible.sync="newFolderBoxShow"
|
2022-11-23 18:38:00 +08:00
|
|
|
@close="newFolder(false)"
|
|
|
|
|
>
|
2022-11-22 10:00:08 +08:00
|
|
|
<div style="display: flex; align-items: center">
|
|
|
|
|
<div style="width: 100px;flex-shrink: 1">{{$t('overall.folderName')}}</div>
|
|
|
|
|
<el-input v-model="folder" size="small" style="flex: 1"/>
|
2022-11-18 00:18:59 +08:00
|
|
|
</div>
|
2022-11-23 18:38:00 +08:00
|
|
|
<div slot="footer">
|
|
|
|
|
<div class="el-message-box__btns">
|
|
|
|
|
<button class="nz-btn el-button el-button--small el-button--default" @click="newFolder(false)">
|
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button class="nz-btn el-button--small nz-btn-style-normal" @click="newFolder(true)">
|
|
|
|
|
<span style="text-transform:Capitalize">{{$t('overall.create')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-11-18 00:18:59 +08:00
|
|
|
</el-dialog>
|
2022-11-16 10:26:39 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-11-21 18:40:28 +08:00
|
|
|
import chartDataFormat from '@/components/chart/chartDataFormat'
|
2022-11-16 10:26:39 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'fileDirectory',
|
2022-11-18 00:18:59 +08:00
|
|
|
props: {
|
2022-11-21 18:40:28 +08:00
|
|
|
uuid: {},
|
|
|
|
|
fileDirectoryShow: {}
|
2022-11-18 00:18:59 +08:00
|
|
|
},
|
2022-11-16 10:26:39 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
fileDirectory: '/',
|
2022-11-23 18:38:00 +08:00
|
|
|
breadcrumb: [],
|
2022-11-18 00:18:59 +08:00
|
|
|
fileList: [],
|
|
|
|
|
newFolderBoxShow: false,
|
2022-11-21 18:40:28 +08:00
|
|
|
folder: '',
|
2022-11-22 16:28:39 +08:00
|
|
|
fileDirectoryLoading: false,
|
|
|
|
|
timer: ''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
updateUuid () {
|
|
|
|
|
return this.$store.getters.getUpdateUuid
|
|
|
|
|
},
|
|
|
|
|
updateIndex () {
|
|
|
|
|
return this.$store.getters.getUpdateIndex
|
2022-11-16 10:26:39 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-11-18 00:18:59 +08:00
|
|
|
mounted () {
|
2022-11-21 18:40:28 +08:00
|
|
|
// this.init()
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
fileDirectoryShow (n) {
|
|
|
|
|
if (n) {
|
|
|
|
|
this.init()
|
|
|
|
|
}
|
2022-11-22 16:28:39 +08:00
|
|
|
},
|
|
|
|
|
updateIndex (n) {
|
|
|
|
|
if (this.updateUuid == this.uuid) {
|
|
|
|
|
if (this.timer) {
|
|
|
|
|
clearTimeout(this.timer)
|
|
|
|
|
}
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
this.getSftpPath(this.fileDirectory)
|
|
|
|
|
this.timer = null
|
|
|
|
|
}, 200)
|
|
|
|
|
}
|
2022-11-21 18:40:28 +08:00
|
|
|
}
|
2022-11-18 00:18:59 +08:00
|
|
|
},
|
2022-11-16 10:26:39 +08:00
|
|
|
methods: {
|
2022-11-21 18:40:28 +08:00
|
|
|
bytes: chartDataFormat.getUnit(7).compute,
|
2022-11-18 00:18:59 +08:00
|
|
|
init () {
|
|
|
|
|
this.getSftpPath(this.fileDirectory)
|
|
|
|
|
},
|
|
|
|
|
selectFile (item) {
|
|
|
|
|
if (item.isDir) {
|
|
|
|
|
const path = this.fileDirectory == '/' ? '' : this.fileDirectory
|
|
|
|
|
this.getSftpPath(path + '/' + item.name)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
newFolder (flag) {
|
|
|
|
|
if (!flag) {
|
|
|
|
|
this.newFolderBoxShow = false
|
|
|
|
|
this.folder = ''
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const path = this.fileDirectory == '/' ? '' : this.fileDirectory
|
|
|
|
|
const params = {
|
|
|
|
|
uuid: this.uuid,
|
|
|
|
|
path: path + '/' + this.folder
|
2022-11-16 10:26:39 +08:00
|
|
|
}
|
2022-11-18 00:18:59 +08:00
|
|
|
this.$post('/terminal/sftp/mkdir', params).then(res => {
|
|
|
|
|
this.newFolderBoxShow = false
|
|
|
|
|
this.getSftpPath(this.fileDirectory)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
backFileDirectory () {
|
|
|
|
|
const arr = this.fileDirectory.split('/')
|
|
|
|
|
arr.pop()
|
|
|
|
|
const path = arr.join('/')
|
|
|
|
|
this.getSftpPath(path || '/')
|
|
|
|
|
},
|
2022-11-23 18:38:00 +08:00
|
|
|
gotoPath (item, index) {
|
|
|
|
|
console.log(item, index, this.breadcrumb.slice(0, index + 1))
|
|
|
|
|
const path = '/' + this.breadcrumb.slice(0, index + 1).join('/')
|
|
|
|
|
console.log(path)
|
|
|
|
|
this.getSftpPath(path || '/')
|
|
|
|
|
},
|
2022-11-18 00:18:59 +08:00
|
|
|
getSftpPath (path) {
|
2022-11-23 18:38:00 +08:00
|
|
|
this.breadcrumb = path.split('/').filter(item => item)
|
2022-11-18 00:18:59 +08:00
|
|
|
const params = {
|
|
|
|
|
uuid: this.uuid,
|
|
|
|
|
path: path
|
|
|
|
|
}
|
2022-11-21 18:40:28 +08:00
|
|
|
this.fileDirectoryLoading = true
|
2022-11-18 00:18:59 +08:00
|
|
|
this.$post('/terminal/sftp/ls', params).then(res => {
|
2022-11-21 18:40:28 +08:00
|
|
|
this.fileDirectoryLoading = false
|
2022-11-18 00:18:59 +08:00
|
|
|
this.fileDirectory = res.data.path
|
|
|
|
|
this.fileList = res.data.list
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
uploadFile () {
|
|
|
|
|
const params = {
|
|
|
|
|
uuid: this.uuid,
|
|
|
|
|
path: this.fileDirectory,
|
|
|
|
|
myId: 'upload' + this.uuid + new Date().getTime(),
|
|
|
|
|
type: 'upload',
|
|
|
|
|
isStart: false,
|
|
|
|
|
isFinish: false,
|
|
|
|
|
importFileList: [],
|
|
|
|
|
total: '',
|
|
|
|
|
speed: '',
|
|
|
|
|
fileLength: '',
|
|
|
|
|
startTime: '',
|
|
|
|
|
cancel: '',
|
2022-11-21 18:40:28 +08:00
|
|
|
axios: '',
|
|
|
|
|
timer: '',
|
|
|
|
|
done: 0
|
2022-11-18 00:18:59 +08:00
|
|
|
}
|
|
|
|
|
this.$store.dispatch('uploadFile', params)
|
|
|
|
|
},
|
|
|
|
|
downloadFile (item) {
|
2022-11-21 18:40:28 +08:00
|
|
|
if (item.timer) {
|
|
|
|
|
clearTimeout(item.timer)
|
2022-11-18 00:18:59 +08:00
|
|
|
}
|
2022-11-21 18:40:28 +08:00
|
|
|
item.timer = setTimeout(() => {
|
|
|
|
|
const path = this.fileDirectory == '/' ? '' : this.fileDirectory
|
|
|
|
|
const params = {
|
|
|
|
|
...item,
|
|
|
|
|
uuid: this.uuid,
|
|
|
|
|
path: path + '/' + item.name,
|
|
|
|
|
myId: 'download' + this.uuid + new Date().getTime(),
|
|
|
|
|
type: 'download',
|
|
|
|
|
isStart: false,
|
|
|
|
|
isFinish: false,
|
|
|
|
|
total: '',
|
|
|
|
|
speed: '',
|
|
|
|
|
fileLength: '',
|
|
|
|
|
startTime: '',
|
|
|
|
|
cancel: '',
|
|
|
|
|
axios: ''
|
|
|
|
|
}
|
|
|
|
|
this.$store.dispatch('dispatchAddFileList', params)
|
|
|
|
|
}, 300)
|
2022-11-18 00:18:59 +08:00
|
|
|
},
|
|
|
|
|
delFile (item) {
|
|
|
|
|
const params = {
|
|
|
|
|
uuid: this.uuid,
|
|
|
|
|
path: this.fileDirectory + '/' + item.name
|
|
|
|
|
}
|
|
|
|
|
this.$post('/terminal/sftp/rm', params).then(res => {
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
this.getSftpPath(this.fileDirectory)
|
|
|
|
|
} else {
|
2022-11-22 16:28:39 +08:00
|
|
|
this.getSftpPath(this.fileDirectory)
|
2022-11-18 00:18:59 +08:00
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
selIcon (item) {
|
|
|
|
|
// console.log(item)
|
|
|
|
|
const hz = item.name.split('.')[1]
|
|
|
|
|
if (item.isDir) {
|
|
|
|
|
return 'nz-icon-Folder colorFA901C'
|
|
|
|
|
}
|
|
|
|
|
if (item.isReg) {
|
|
|
|
|
return 'nz-icon-File'
|
|
|
|
|
}
|
|
|
|
|
return 'nz-icon-File'
|
2022-11-16 10:26:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2022-11-18 00:18:59 +08:00
|
|
|
<style scoped lang="scss">
|
2022-11-21 18:40:28 +08:00
|
|
|
|
2022-11-16 10:26:39 +08:00
|
|
|
</style>
|