Files
crawler-plugin/frontend-vue/src/shared/components/FileUploadZone.vue
T

143 lines
3.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="upload-zone">
<div class="hint">{{ hint }}</div>
<div class="btns">
<button type="button" class="opt-btn" :disabled="disabled" @click="emit('select-files')">
{{ uploading && uploadingLabel ? uploadingLabel : filesLabel }}
</button>
<button v-if="showFolderButton" type="button" class="opt-btn" :disabled="disabled" @click="emit('select-folder')">
{{ folderLabel }}
</button>
</div>
<div class="selected-files" :class="filesClass">
<template v-if="names.length">
<span v-for="name in visibleNames" :key="name" :title="nameTitle ? name : undefined">{{ name }}</span>
<span v-if="names.length > visibleNames.length" class="more-line">
还有 {{ names.length - visibleNames.length }} 个文件未展开显示
</span>
</template>
<span v-else :class="{ 'text-muted': mutedEmpty }">{{ emptyText }}</span>
</div>
<div v-if="footerTip" class="bridge-tip">{{ footerTip }}</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
/**
* 「上传文件」区块:选择 Excel / 文件夹按钮 + 已选文件列表。
*
* 抽自各品牌 Tab 逐字重复的 upload-zone 模板与样式;差异点全部 props 化。
* Tab 保留自己的业务状态与 selectFiles / selectFolder 实现(通常来自
* useExcelFileUpload),组件只负责展示与点击事件。
*/
const props = withDefaults(
defineProps<{
/** 区块顶部提示文案 */
hint: string
/** 已选文件展示列表(完整列表,超出 maxDisplay 时折叠) */
names: string[]
/** 未选择时的占位文案 */
emptyText?: string
/** 「选择 Excel」按钮文案 */
filesLabel?: string
/** 上传中时「选择 Excel」按钮的文案(配合 uploading) */
uploadingLabel?: string
/** 「选择文件夹」按钮文案 */
folderLabel?: string
/** 是否显示「选择文件夹」按钮 */
showFolderButton?: boolean
/** 两个按钮是否禁用 */
disabled?: boolean
/** 上传中状态(配合 uploadingLabel) */
uploading?: boolean
/** 超过该数量折叠展示;不传则全量展示 */
maxDisplay?: number
/** selected-files 容器的附加 class(如 clean-placeholder) */
filesClass?: string
/** 空态文案是否加 text-muted */
mutedEmpty?: boolean
/** 文件名 span 是否带 title 提示完整路径 */
nameTitle?: boolean
/** 区块底部的附加提示(如浏览器环境的桥接提示),空串不显示 */
footerTip?: string
}>(),
{
emptyText: '暂未选择文件',
filesLabel: '选择 Excel',
folderLabel: '选择文件夹',
showFolderButton: true,
disabled: false,
uploading: false,
mutedEmpty: false,
nameTitle: false,
footerTip: '',
},
)
const emit = defineEmits<{
(event: 'select-files'): void
(event: 'select-folder'): void
}>()
const visibleNames = computed(() =>
props.maxDisplay && props.maxDisplay > 0 ? props.names.slice(0, props.maxDisplay) : props.names,
)
</script>
<style scoped>
/* 与多数品牌 Tab 原有的 upload-zone 写法保持一致;个别 Tab 的差异样式由
Tab 自身用 :deep(.upload-zone) 等覆写 */
.upload-zone {
border: 1px dashed #3e4a62;
border-radius: 10px;
padding: 18px;
background: #242424;
margin-bottom: 18px;
}
.hint {
color: #5e6878;
font-size: 12px;
line-height: 1.5;
}
.btns {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.opt-btn {
border: none;
cursor: pointer;
border-radius: 7px;
padding: 8px 14px;
color: #c8d2e2;
background: #242424;
border: 1px solid #3e4a62;
}
.selected-files {
margin-top: 14px;
color: #a0acbe;
font-size: 12px;
word-break: break-all;
}
.selected-files span {
display: block;
margin: 4px 0;
}
.selected-files .more-line {
color: #5e6878;
}
.selected-files .text-muted {
color: #5e6878;
font-style: italic;
}
</style>