Spaces:
Sleeping
Sleeping
File size: 4,378 Bytes
f0953a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
<template>
<div class="resource-select">
<div class="select-header">
<div class="select-info">
<el-icon><Document /></el-icon>
<span>已选择 {{ selectedCount }} 个文件</span>
<span v-if="totalSize" class="total-size">({{ formattedFileSize(totalSize) }})</span>
</div>
<div class="header-actions">
<el-button type="text" @click="handleSelectAll(!hasSelectedAll)">
{{ hasSelectedAll ? "取消全选" : "全选" }}
</el-button>
</div>
</div>
<div class="file-list">
<div
v-for="file in resourceStore.shareInfo.list"
:key="file.fileId"
class="file-item"
:class="{ 'is-checked': isChecked(file.fileId) }"
@click="toggleSelect(file)"
>
<el-checkbox :model-value="isChecked(file.fileId)" @click.stop>
<div class="file-info">
<el-icon><Document /></el-icon>
<span class="file-name">{{ file.fileName }}</span>
<span v-if="file.fileSize" class="file-size">
{{ formattedFileSize(file.fileSize) }}
</span>
</div>
</el-checkbox>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useResourceStore } from "@/stores/resource";
import { formattedFileSize } from "@/utils/index";
import { computed } from "vue";
import type { ShareInfo } from "@/types";
import { Document } from "@element-plus/icons-vue";
const resourceStore = useResourceStore();
const selectedCount = computed(
() => resourceStore.resourceSelect.filter((x) => x.isChecked).length
);
const totalSize = computed(() =>
resourceStore.resourceSelect
.filter((x) => x.isChecked)
.reduce((sum, item) => sum + (item.fileSize || 0), 0)
);
const totalFiles = computed(() => resourceStore.shareInfo.list.length);
const hasSelectedAll = computed(() => selectedCount.value === totalFiles.value);
const isChecked = (fileId: string) => {
return resourceStore.resourceSelect.find((x) => x.fileId === fileId)?.isChecked;
};
const toggleSelect = (file: ShareInfo) => {
let resourceSelect = [...resourceStore.resourceSelect];
const item = resourceSelect.find((x) => x.fileId === file.fileId);
if (item) {
item.isChecked = !item.isChecked;
resourceStore.setSelectedResource(resourceSelect);
}
};
const handleSelectAll = (checked: boolean) => {
const resourceSelect = resourceStore.shareInfo.list.map((file) => ({
fileId: file.fileId,
fileName: file.fileName,
fileSize: file.fileSize,
isChecked: checked,
}));
resourceStore.setSelectedResource(resourceSelect);
};
</script>
<style lang="scss" scoped>
@import "@/styles/responsive.scss";
.resource-select {
min-height: 200px;
max-height: 500px;
display: flex;
flex-direction: column;
gap: 16px;
.select-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
background: var(--el-fill-color-light);
border-radius: var(--theme-radius);
.select-info {
display: flex;
align-items: center;
gap: 8px;
color: var(--theme-text-regular);
font-size: 14px;
.el-icon {
font-size: 16px;
}
.total-size {
color: var(--theme-text-secondary);
}
}
.header-actions {
display: flex;
gap: 16px;
}
.el-button {
font-size: 13px;
padding: 4px 8px;
&:not(:disabled):hover {
color: var(--theme-primary);
}
}
}
.file-list {
flex: 1;
overflow-y: auto;
padding: 4px;
.file-item {
padding: 12px 16px;
border-radius: var(--theme-radius);
cursor: pointer;
transition: var(--theme-transition);
&:hover {
background: var(--el-fill-color-light);
}
&.is-checked {
background: var(--el-color-primary-light-9);
}
.file-info {
display: flex;
align-items: center;
gap: 8px;
color: var(--theme-text-primary);
font-size: 14px;
.el-icon {
font-size: 16px;
color: var(--theme-text-regular);
}
.file-name {
flex: 1;
@include text-ellipsis;
}
.file-size {
color: var(--theme-text-secondary);
font-size: 13px;
}
}
}
}
}
</style>
|