文件上传组件

This commit is contained in:
田岩
2025-06-25 14:19:51 +08:00
parent c8c4e3285a
commit 49e51eabe3
19 changed files with 92 additions and 4 deletions
@@ -0,0 +1,67 @@
<template>
<view class="components_custom_file_upload_div pic-cell">
<view v-for="(item,index) in fileList">
<image-preview :imgId="item.fileId"></image-preview>
</view>
<view @tap="upload">
<view class="img-width-height add_icon wh_100">+</view>
</view>
</view>
</template>
<script setup>
import { ref, defineProps, defineEmits, onMounted } from 'vue'
import common from '@/common/common'
import { uploadFile } from '@/api/common'
// 定义props
const props = defineProps({
modelValue: {
type: String,
default: ''
},
limit: {
type: Number,
default: 9
},
mark: {
type: [String, Number],
default: ''
}
})
// 定义emits
const emits = defineEmits(['upload_success'])
// 状态管理
const fileList = ref([])
// 生命周期钩子
onMounted(() => {
// 初始化逻辑
})
// 方法
const upload = () => {
uni.chooseImage({
count: props.limit,
sizeType: ['original', 'compressed'],
sourceType: ['camera', 'album'],
success: async ({ tempFilePaths }) => {
for (const file of tempFilePaths) {
try {
// 修正:data变量未定义问题
const data = { bizScen: 'S3005' }
const res = await uploadFile(file, data)
console.log('res', res);
fileList.value.push(res)
} catch (error) {
console.error('文件上传失败', error)
}
}
// emits('upload_success', fileList.value)
}
})
}
</script>