🆕 限制上传文件夹额外的操作
This commit is contained in:
parent
284c7e9398
commit
510e660b17
@ -36,6 +36,7 @@ function listenInput(sftpClient, socket) {
|
|||||||
socket.on('rm_dir', async (path) => {
|
socket.on('rm_dir', async (path) => {
|
||||||
const exists = await sftpClient.exists(path)
|
const exists = await sftpClient.exists(path)
|
||||||
if (!exists) return socket.emit('not_exists_dir', '目录不存在或当前不可访问')
|
if (!exists) return socket.emit('not_exists_dir', '目录不存在或当前不可访问')
|
||||||
|
consola.info('rm_dir: ', path)
|
||||||
try {
|
try {
|
||||||
let res = await sftpClient.rmdir(path, true) // 递归删除
|
let res = await sftpClient.rmdir(path, true) // 递归删除
|
||||||
socket.emit('rm_success', res)
|
socket.emit('rm_success', res)
|
||||||
@ -127,6 +128,7 @@ function listenInput(sftpClient, socket) {
|
|||||||
const exists = await sftpClient.exists(fullPath)
|
const exists = await sftpClient.exists(fullPath)
|
||||||
if (exists) continue
|
if (exists) continue
|
||||||
await sftpClient.mkdir(fullPath, true)
|
await sftpClient.mkdir(fullPath, true)
|
||||||
|
socket.emit('create_remote_dir_progress', fullPath)
|
||||||
consola.info('创建目录:', fullPath)
|
consola.info('创建目录:', fullPath)
|
||||||
}
|
}
|
||||||
socket.emit('create_remote_dir_success')
|
socket.emit('create_remote_dir_success')
|
||||||
|
@ -53,6 +53,11 @@ html.dark {
|
|||||||
background-color: #454242 !important;
|
background-color: #454242 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
section {
|
||||||
|
.left {
|
||||||
|
border: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.info_box {
|
.info_box {
|
||||||
border-right: 1px solid #454242;
|
border-right: 1px solid #454242;
|
||||||
|
@ -108,12 +108,15 @@
|
|||||||
:percentage="upFileProgress"
|
:percentage="upFileProgress"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="showDirProgress">
|
||||||
|
<span>文件夹创建: {{ curUploadDirName }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul
|
<ul
|
||||||
v-if="fileList.length !== 0"
|
v-if="fileList.length !== 0"
|
||||||
ref="childDirRef"
|
ref="childDirRef"
|
||||||
v-loading="childDirLoading"
|
v-loading="childDirLoading"
|
||||||
element-loading-text="加载中..."
|
element-loading-text="操作中..."
|
||||||
class="dir-list"
|
class="dir-list"
|
||||||
>
|
>
|
||||||
<li
|
<li
|
||||||
@ -187,11 +190,16 @@ const curTarget = ref(null)
|
|||||||
const showFileProgress = ref(false)
|
const showFileProgress = ref(false)
|
||||||
const upFileProgress = ref(0)
|
const upFileProgress = ref(0)
|
||||||
const curUploadFileName = ref('')
|
const curUploadFileName = ref('')
|
||||||
|
|
||||||
|
const showDirProgress = ref(false)
|
||||||
|
const curUploadDirName = ref(0)
|
||||||
|
|
||||||
const adjustRef = ref(null)
|
const adjustRef = ref(null)
|
||||||
const sftpTabContainerRef = ref(null)
|
const sftpTabContainerRef = ref(null)
|
||||||
const childDirRef = ref(null)
|
const childDirRef = ref(null)
|
||||||
const uploadFileRef = ref(null)
|
const uploadFileRef = ref(null)
|
||||||
const uploadDirRef = ref(null)
|
const uploadDirRef = ref(null)
|
||||||
|
const forbiddenAction = ref(false)
|
||||||
|
|
||||||
const token = computed(() => $store.token)
|
const token = computed(() => $store.token)
|
||||||
const curPath = computed(() => paths.value.join('/').replace(/\/{2,}/g, '/'))
|
const curPath = computed(() => paths.value.join('/').replace(/\/{2,}/g, '/'))
|
||||||
@ -308,6 +316,7 @@ const listenSftp = () => {
|
|||||||
socket.value.on('rm_success', (res) => {
|
socket.value.on('rm_success', (res) => {
|
||||||
$message.success(res)
|
$message.success(res)
|
||||||
childDirLoading.value = false
|
childDirLoading.value = false
|
||||||
|
forbiddenAction.value = false
|
||||||
handleRefresh()
|
handleRefresh()
|
||||||
})
|
})
|
||||||
socket.value.on('down_file_success', (res) => {
|
socket.value.on('down_file_success', (res) => {
|
||||||
@ -324,6 +333,7 @@ const listenSftp = () => {
|
|||||||
})
|
})
|
||||||
socket.value.on('sftp_error', (res) => {
|
socket.value.on('sftp_error', (res) => {
|
||||||
$message.error(res)
|
$message.error(res)
|
||||||
|
forbiddenAction.value = false
|
||||||
resetFileStatusFlag()
|
resetFileStatusFlag()
|
||||||
})
|
})
|
||||||
socket.value.on('up_file_progress', (res) => {
|
socket.value.on('up_file_progress', (res) => {
|
||||||
@ -336,7 +346,7 @@ const listenSftp = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openRootChild = (item) => {
|
const openRootChild = (item) => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
const { name, type } = item
|
const { name, type } = item
|
||||||
if (isDir(type)) {
|
if (isDir(type)) {
|
||||||
childDirLoading.value = true
|
childDirLoading.value = true
|
||||||
@ -353,7 +363,7 @@ const openRootChild = (item) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openTarget = (item) => {
|
const openTarget = (item) => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
const { name, type, size } = item
|
const { name, type, size } = item
|
||||||
if (isDir(type)) {
|
if (isDir(type)) {
|
||||||
paths.value.push(name)
|
paths.value.push(name)
|
||||||
@ -388,7 +398,7 @@ const selectFile = (item) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleReturn = () => {
|
const handleReturn = () => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
if (paths.value.length === 1) return
|
if (paths.value.length === 1) return
|
||||||
paths.value.pop()
|
paths.value.pop()
|
||||||
openDir()
|
openDir()
|
||||||
@ -399,7 +409,7 @@ const handleRefresh = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleDownload = () => {
|
const handleDownload = () => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
if (curTarget.value === null) return $message.warning('先选择一个文件')
|
if (curTarget.value === null) return $message.warning('先选择一个文件')
|
||||||
const { name, size, type } = curTarget.value
|
const { name, size, type } = curTarget.value
|
||||||
if (isDir(type)) return $message.error('暂不支持下载文件夹')
|
if (isDir(type)) return $message.error('暂不支持下载文件夹')
|
||||||
@ -422,7 +432,7 @@ const handleDownload = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
if (curTarget.value === null) return $message.warning('先选择一个文件(夹)')
|
if (curTarget.value === null) return $message.warning('先选择一个文件(夹)')
|
||||||
const { name, type } = curTarget.value
|
const { name, type } = curTarget.value
|
||||||
$messageBox.confirm(`确认删除:${ name }`, 'Warning', {
|
$messageBox.confirm(`确认删除:${ name }`, 'Warning', {
|
||||||
@ -432,6 +442,7 @@ const handleDelete = () => {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
childDirLoading.value = true
|
childDirLoading.value = true
|
||||||
const path = getPath(name)
|
const path = getPath(name)
|
||||||
|
forbiddenAction.value = true
|
||||||
if (isDir(type)) {
|
if (isDir(type)) {
|
||||||
socket.value.emit('rm_dir', path)
|
socket.value.emit('rm_dir', path)
|
||||||
} else {
|
} else {
|
||||||
@ -441,9 +452,10 @@ const handleDelete = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleUploadFiles = async (event) => {
|
const handleUploadFiles = async (event) => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
let { files } = event.target
|
let { files } = event.target
|
||||||
|
|
||||||
|
forbiddenAction.value = true
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
try {
|
try {
|
||||||
const targetFilePath = getPath(file.name)
|
const targetFilePath = getPath(file.name)
|
||||||
@ -452,12 +464,13 @@ const handleUploadFiles = async (event) => {
|
|||||||
$message.error(`${ file.name }上传失败: ${ error }`)
|
$message.error(`${ file.name }上传失败: ${ error }`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forbiddenAction.value = false
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
uploadFileRef.value = null
|
uploadFileRef.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleUploadDir = async (event) => {
|
const handleUploadDir = async (event) => {
|
||||||
if (showFileProgress.value) return $message.warning('需等待当前任务完成')
|
if (forbiddenAction.value) return $message.warning('需等待当前任务完成')
|
||||||
let { files } = event.target
|
let { files } = event.target
|
||||||
if (files.length === 0) return $message.warning('不允许上传空文件夹')
|
if (files.length === 0) return $message.warning('不允许上传空文件夹')
|
||||||
files = Array.from(files)
|
files = Array.from(files)
|
||||||
@ -467,13 +480,27 @@ const handleUploadDir = async (event) => {
|
|||||||
if (foldersName.length === 0) return $message.warning('不允许上传空文件夹')
|
if (foldersName.length === 0) return $message.warning('不允许上传空文件夹')
|
||||||
// console.log(foldersName)
|
// console.log(foldersName)
|
||||||
let targetDirPath = curPath.value
|
let targetDirPath = curPath.value
|
||||||
|
forbiddenAction.value = true
|
||||||
socket.value.emit('create_remote_dir', { targetDirPath, foldersName })
|
socket.value.emit('create_remote_dir', { targetDirPath, foldersName })
|
||||||
socket.value.once('create_remote_dir_exists', (res) => {
|
socket.value.once('create_remote_dir_exists', (res) => {
|
||||||
$message.error(res)
|
$message.error(res)
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
uploadDirRef.value = null
|
uploadDirRef.value = null
|
||||||
|
forbiddenAction.value = false
|
||||||
})
|
})
|
||||||
|
function computedUploadDirProgress(path) {
|
||||||
|
// $message.success('创建服务器文件夹中...')
|
||||||
|
// console.log(path)
|
||||||
|
showDirProgress.value = true
|
||||||
|
curUploadDirName.value = path
|
||||||
|
}
|
||||||
|
$message.success('创建服务器文件夹中...')
|
||||||
|
socket.value.on('create_remote_dir_progress', computedUploadDirProgress)
|
||||||
socket.value.once('create_remote_dir_success', async () => {
|
socket.value.once('create_remote_dir_success', async () => {
|
||||||
|
socket.value.off('create_remote_dir_progress', computedUploadDirProgress)
|
||||||
|
showDirProgress.value = false
|
||||||
|
curUploadDirName.value = ''
|
||||||
|
$message.success('服务器文件夹创建成功, 开始上传文件')
|
||||||
for (let [index, file,] of files.entries()) {
|
for (let [index, file,] of files.entries()) {
|
||||||
let fullFilePath = getPath(`${ foldersName[index] }/${ file.name }`)
|
let fullFilePath = getPath(`${ foldersName[index] }/${ file.name }`)
|
||||||
console.log('fullFilePath: ', fullFilePath)
|
console.log('fullFilePath: ', fullFilePath)
|
||||||
@ -483,6 +510,7 @@ const handleUploadDir = async (event) => {
|
|||||||
$message.error(`${ file.name }上传失败: ${ error }`)
|
$message.error(`${ file.name }上传失败: ${ error }`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forbiddenAction.value = false
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
uploadDirRef.value = null
|
uploadDirRef.value = null
|
||||||
})
|
})
|
||||||
@ -508,7 +536,6 @@ const uploadFile = (file, targetFilePath) => {
|
|||||||
try {
|
try {
|
||||||
upFileProgress.value = 0
|
upFileProgress.value = 0
|
||||||
showFileProgress.value = true
|
showFileProgress.value = true
|
||||||
// childDirLoading.value = true
|
|
||||||
const totalSliceCount = Math.ceil(size / range)
|
const totalSliceCount = Math.ceil(size / range)
|
||||||
while (end < size) {
|
while (end < size) {
|
||||||
fileIndex++
|
fileIndex++
|
||||||
|
@ -35,7 +35,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
fontSize: {
|
fontSize: {
|
||||||
required: false,
|
required: false,
|
||||||
default: 18,
|
default: 16,
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
|
@ -202,7 +202,7 @@ const themeName = ref(localStorage.getItem('themeName') || 'Afterglow')
|
|||||||
let localTerminalBackground = localStorage.getItem('terminalBackground')
|
let localTerminalBackground = localStorage.getItem('terminalBackground')
|
||||||
const terminalBackground = ref(localTerminalBackground || '/terminal/01.png')
|
const terminalBackground = ref(localTerminalBackground || '/terminal/01.png')
|
||||||
let localTerminalFontSize = localStorage.getItem('terminalFontSize')
|
let localTerminalFontSize = localStorage.getItem('terminalFontSize')
|
||||||
const terminalFontSize = ref(Number(localTerminalFontSize) || 18)
|
const terminalFontSize = ref(Number(localTerminalFontSize) || 16)
|
||||||
|
|
||||||
const terminalTabs = computed(() => props.terminalTabs)
|
const terminalTabs = computed(() => props.terminalTabs)
|
||||||
const terminalTabsLen = computed(() => props.terminalTabs.length)
|
const terminalTabsLen = computed(() => props.terminalTabs.length)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user