t-file-manager
FileManager 文件管理
组件介绍
文件管理选择上传组件,用于便捷上传、管理和分享文件,支持返回文件md5,用于服务端判断重复上传,上传逻辑需要自己实现。
平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
基础用法
vue
<template>
<t-file-manager v-model="fileList" :count="5" fileType="image" @change="handleChange">
<!-- 自定义选择按钮 -->
<template #menu>
<t-button type="primary" size="medium">选择图片</t-button>
</template>
<!-- 自定义文件列表 -->
<template #default="{ files }">
<view class="file-list">
<t-row v-for="(item, index) in files" :key="index" class="file-item">
<t-image :src="item.path" mode="aspectFill" class="file-image"></t-image>
<t-text class="file-name">{{ item.name }}</t-text>
<t-icon type="error" name="close-circle-line" @click="removeFile(index)"></t-icon>
</t-row>
</view>
</template>
</t-file-manager>
<t-text class="mt-20">已选择 {{ fileList.length }} 个文件</t-text>
</template>
<script setup>
const fileList = ref([]);
function handleChange(files) {
console.log('文件列表变化:', files);
// 这里可以实现文件上传逻辑
}
function removeFile(index) {
fileList.value.splice(index, 1);
}
</script>
<style scoped>
.file-list {
margin-top: 20rpx;
}
.file-item {
display: flex;
align-items: center;
padding: 10rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.file-image {
width: 100rpx;
height: 100rpx;
border-radius: 10rpx;
margin-right: 20rpx;
}
.file-name {
flex: 1;
font-size: 28rpx;
color: #333;
}
.mt-20 {
margin-top: 20rpx;
padding: 0 20rpx;
}
</style>Props
| 属性名 | 类型 | 默认值 | 说明 | 可选值 |
|---|---|---|---|---|
| size | String | "medium" | 组件尺寸 | large, medium, small, mini |
| type | String | "primary" | 组件类型 | info, primary, error, warning, success |
| disabled | Boolean | false | 组件是否禁用 | true, false |
| hover | Boolean | false | 是否有点击效果 | true, false |
| path | String | "" | 点击组件后跳转的页面路径 | - |
| effect | String | "normal" | 组件显示主题 | normal, dark, light, plain |
| count | Number | 9 | 最大选择数量 | - |
| modelValue | Array | [] | 选择的文件列表 | - |
| fileType | String | "all" | 选择文件的类型 | all, image, video, audio |
| sizeType | Array | ["original", "compressed"] | 图片尺寸类型 | original, compressed |
| sourceType | Array | ["album", "camera"] | 文件来源 | album, camera |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| change | 选择文件列表发生变化时触发 | 文件列表 |
| click | 点击时触发 | - |
| transitionend | 动画结束时触发 | - |
| initFinished | 组件初始化完成触发 | 组件的节点信息 |
| touchstart | 触摸开始时触发 | 触摸事件对象 |
| touchend | 触摸结束时触发 | 触摸事件对象 |
| touchmove | 触摸移动时触发 | 触摸事件对象 |
| touchcancel | 触摸取消时触发 | 触摸事件对象 |
Slots
| 插槽名 | 说明 |
|---|---|
| menu | 自定义选择按钮插槽 |
| default | 自定义文件列表插槽,接收files参数 |