Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:新增文件批量删除和批量恢复的功能 #147

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

* 修复多次上传的BUG

* 文件批量上传

* 文件批量删除

## 2024-03-27

### ✨ Features | 新功能
Expand Down
3 changes: 2 additions & 1 deletion src/views/personal/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="files-box">
<Option
class="option"
v-if="isShowOptions"
v-show="isShowOptions"
:style="{left: optionLeft + 'px', top: optionTop + 'px'}"
@sendOptions="optionType"
></Option>
Expand Down Expand Up @@ -412,6 +412,7 @@ const sliceFileName = (name: string) => {

.option {
position: absolute;
z-index: 2000;
}

.files-contents {
Expand Down
105 changes: 104 additions & 1 deletion src/views/personal/recycle.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<template>
<div class="recycle-box">
<div class="recycle-box" @click="cancelShowPop($event)">
<div
class="options"
v-show="isShowOptions"
:style="{left: optionsLeft + 'px', top: optionsTop + 'px'}"
>
<button @click="recoverFiles">恢复</button>
<button @click="deleteFiles">删除</button>
</div>
<div
class="recycle-file-content"
v-for="(file, index) of recycleFilesList.files"
:key="index"
@click="chooseFile(file)"
@contextmenu="openRecycleOptions($event, index)"
>
<div class="name-box">
<div class="checkbox" v-if="!file.isChoose"></div>
Expand Down Expand Up @@ -34,7 +43,13 @@
import { ref, onMounted } from 'vue'
import { getRecycleFilesList } from './utils'
import type { responseRecycleFilesList } from './utils'
import { post } from '@/utils/request'

const ctxIndex = ref(-1)
const optionsTop = ref(0)
const optionsLeft = ref(0)
const ctxTarget = ref()
const isShowOptions = ref(false)
const recycleFilesList = ref<responseRecycleFilesList>({
files: [
{
Expand Down Expand Up @@ -66,6 +81,66 @@ onMounted(async() => {
})
})

const cancelShowPop = (e: MouseEvent) => {
isShowOptions.value = false
const target = e.target as HTMLElement
if (target.className !== ctxTarget.value.className && ctxTarget.value) {
ctxIndex.value = -1
ctxTarget.value = null
}
}

const deleteFiles = () => {
const fileIds = getFilesId()
post('/content/deleteFile', {
fileIds,
deleteType: 3
})
.then(async() => {
recycleFilesList.value = await getRecycleFilesList({
limit: 100,
backward: true,
offset: 0
})
})
}
const recoverFiles = () => {
const fileIds = getFilesId()
post('/content/recoverRecycleBinFile', {
fileIds
})
.then(async() => {
recycleFilesList.value = await getRecycleFilesList({
limit: 100,
backward: true,
offset: 0
})
})
}

const getFilesId = () => {
let fileId: string[] = []
recycleFilesList.value.files.forEach(file => {
if (file.isChoose) {
fileId.push(file.fileId)
}
})
if (ctxIndex.value !== -1) {
fileId.push(recycleFilesList.value.files[ctxIndex.value].fileId)
}
return fileId
}

const openRecycleOptions = (e: MouseEvent, index: number) => {
e.preventDefault()
isShowOptions.value = true
optionsLeft.value = e.clientX
optionsTop.value = e.clientY
if (!recycleFilesList.value.files[index].isChoose) {
ctxIndex.value = index
ctxTarget.value = e.target
}
}
const chooseFile = (file: any) => {
file.isChoose = !file.isChoose
}
Expand All @@ -77,12 +152,40 @@ const chooseFile = (file: any) => {
height: 100%;
padding: 10px 10px;

.options {
position: absolute;
width: 120px;
height: 60px;
background-color: #fff;
box-shadow: 0 0 10px 1px rgb(214, 214, 214);
border-radius: 10px;
display: flex;
flex-direction: column;
justify-content: space-around;

button {
width: 100%;
height: 30px;
background-color: #fff;
border: none;
cursor: pointer;
text-align: center;
}
button:hover {
background-color: #f5f5f5;
}
button:last-child {
color: red;
}
}

.recycle-file-content {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #e5e5e5;
cursor: pointer;

.name-box {
width: 77%;
Expand Down
Loading