Files
peiwan-uniapp/pages/tabbar/components/trend/formVideo.vue
2025-01-21 01:46:34 +08:00

71 lines
1.5 KiB
Vue

<template>
<view>
<htz-image-upload :dataType="1" :max="1" mediaType="video" name="file" :chooseNum="1" v-model="imageDataType1" @chooseSuccess="ceshiChooseSuccessDataType1"></htz-image-upload>
</view>
</template>
<script>
import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
import FileApi from '@/sheep/api/infra/file';
export default {
components: {
htzImageUpload,
},
props: {
modelValue: {
type: String,
default: ''
},
},
data() {
return {
imageDataType1: [],
}
},
created() {
},
computed: {
},
methods: {
ceshiChooseSuccessDataType1(tempFilePaths, e) {
tempFilePaths.forEach(path => {
uni.getFileInfo({
filePath: path,
success: (infoRes) => {
const fileSize = infoRes.size; // 获取文件大小(字节)
if (fileSize > 1024 * 1024 * 10) { // 假设设置的文件大小限制为5MB
uni.showToast({
title: '文件大小限制为10MB',
icon: 'none'
});
return;
}
// 文件大小符合要求,可以执行上传操作
this.uploadVoice(e, path);
},
fail: (err) => {
console.log('获取文件信息失败', err);
}
});
})
},
async uploadVoice(e, path) {
var res = await FileApi.uploadFile(path);
this.$emit('update:modelValue', res.data);
var thisData = {
type: e,
url: path
};
this.imageDataType1.push(thisData);
},
}
}
</script>
<style lang="scss" scoped>
</style>