mrr.sj.front/components/dynamic-form/FormItemVideo.vue

105 lines
1.8 KiB
Vue
Raw Normal View History

2026-06-09 17:49:15 +08:00
<template>
<view class="form-video">
<view v-if="videoUrl" class="video-preview">
2026-06-10 10:15:10 +08:00
<video :src="videoUrl" class="preview-video" controls />
2026-06-09 17:49:15 +08:00
<view class="delete-btn" @click="deleteVideo">
<text class="delete-icon">&times;</text>
</view>
</view>
2026-06-10 10:15:10 +08:00
<view v-else class="upload-btn" @click="chooseVideo">
<text class="plus-icon">+</text>
2026-06-09 17:49:15 +08:00
</view>
</view>
</template>
<script>
export default {
2026-06-10 10:15:10 +08:00
name: 'FormItemVideo',
2026-06-09 17:49:15 +08:00
props: {
2026-06-10 10:15:10 +08:00
value: { type: String, default: '' }
2026-06-09 17:49:15 +08:00
},
2026-06-10 10:15:10 +08:00
data: function () {
2026-06-09 17:49:15 +08:00
return {
2026-06-10 10:15:10 +08:00
videoUrl: ''
2026-06-09 17:49:15 +08:00
};
},
watch: {
value: {
2026-06-10 10:15:10 +08:00
handler: function (val) {
this.videoUrl = val || '';
2026-06-09 17:49:15 +08:00
},
immediate: true
}
},
methods: {
2026-06-10 10:15:10 +08:00
chooseVideo: function () {
2026-06-09 17:49:15 +08:00
var self = this;
uni.chooseVideo({
2026-06-10 10:15:10 +08:00
sourceType: ['album', 'camera'],
2026-06-09 17:49:15 +08:00
maxDuration: 60,
2026-06-10 10:15:10 +08:00
success: function (res) {
2026-06-09 17:49:15 +08:00
self.videoUrl = res.tempFilePath;
2026-06-10 10:15:10 +08:00
self.$emit('input', self.videoUrl);
2026-06-09 17:49:15 +08:00
}
});
},
2026-06-10 10:15:10 +08:00
deleteVideo: function () {
this.videoUrl = '';
this.$emit('input', '');
2026-06-09 17:49:15 +08:00
}
}
};
</script>
<style scoped>
.form-video {
width: 100%;
}
2026-06-10 10:15:10 +08:00
2026-06-09 17:49:15 +08:00
.video-preview {
2026-06-10 10:15:10 +08:00
width: 200rpx;
height: 200rpx;
2026-06-09 17:49:15 +08:00
position: relative;
}
2026-06-10 10:15:10 +08:00
.preview-video {
width: 200rpx;
height: 200rpx;
2026-06-09 17:49:15 +08:00
border-radius: 8rpx;
}
2026-06-10 10:15:10 +08:00
2026-06-09 17:49:15 +08:00
.delete-btn {
position: absolute;
2026-06-10 10:15:10 +08:00
top: -20rpx;
right: -20rpx;
width: 40rpx;
height: 40rpx;
background-color: rgba(0, 0, 0, 0.5);
2026-06-09 17:49:15 +08:00
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
2026-06-10 10:15:10 +08:00
2026-06-09 17:49:15 +08:00
.delete-icon {
color: #ffffff;
font-size: 32rpx;
}
2026-06-10 10:15:10 +08:00
.upload-btn {
width: 200rpx;
height: 200rpx;
background-color: #ffffff;
border: 2rpx dashed #dddddd;
2026-06-09 17:49:15 +08:00
border-radius: 8rpx;
display: flex;
justify-content: center;
2026-06-10 10:15:10 +08:00
align-items: center;
2026-06-09 17:49:15 +08:00
}
2026-06-10 10:15:10 +08:00
.plus-icon {
2026-06-09 17:49:15 +08:00
font-size: 60rpx;
color: #999999;
}
</style>