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

142 lines
3.7 KiB
Vue
Raw Normal View History

2026-06-09 17:49:15 +08:00
<template>
2026-06-10 16:23:47 +08:00
<view>
2026-06-11 20:48:30 +08:00
<view v-if="maxCount > 1" class="video-list">
<view v-for="(item, index) in currentList" :key="index" class="video-wrapper">
<video :src="item" class="preview-video" controls />
<view class="delete-btn" @click="deleteVideo(index)">
<text class="delete-icon">&times;</text>
</view>
</view>
<ali-oss-uploader v-if="currentList.length < maxCount" :key="currentList.length"
:max-count="maxCount - currentList.length"
:max-size="maxSize" accept="video/*" :userId="uploadUserId" :type="ossType" :kind="2" width="200rpx"
@input="onMultiInput" @change="onChange" />
</view>
<view v-else>
<ali-oss-uploader v-if="!currentValue" :max-count="1" :max-size="maxSize" accept="video/*"
:userId="uploadUserId" :type="ossType" :kind="2" width="100%" :file-string="currentValue" @input="onInput"
@change="onChange" @success="onInput" @delete="deleteSingleVideo" />
<view v-else class="video-wrapper">
<video :src="currentValue" class="preview-video" controls />
<view class="delete-btn" @click="deleteSingleVideo">
<text class="delete-icon">&times;</text>
</view>
2026-06-09 17:49:15 +08:00
</view>
</view>
</view>
</template>
<script>
2026-06-10 16:23:47 +08:00
import AliOssUploader from '../ali-oss-uploader/ali-oss-uploader.vue'
2026-06-09 17:49:15 +08:00
export default {
2026-06-10 10:15:10 +08:00
name: 'FormItemVideo',
2026-06-10 16:23:47 +08:00
components: { AliOssUploader },
2026-06-09 17:49:15 +08:00
props: {
2026-06-11 20:48:30 +08:00
value: { type: [String, Array], default: '' },
maxSize: { type: Number, default: 100 },
maxCount: { type: Number, default: 1 },
userId: { type: [Number, String], default: null }
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-11 20:48:30 +08:00
currentValue: '',
currentList: []
2026-06-09 17:49:15 +08:00
};
},
2026-06-10 16:23:47 +08:00
computed: {
2026-06-11 20:48:30 +08:00
uploadUserId: function () {
if (this.userId) return this.userId;
2026-06-10 16:23:47 +08:00
return this.$store && this.$store.state && this.$store.state.sjInfo
? this.$store.state.sjInfo.id : null;
},
ossType: function () {
var artisanType = getApp().globalData ? getApp().globalData.artisanType : 0;
return (artisanType || 0) + 1;
}
},
2026-06-09 17:49:15 +08:00
watch: {
value: {
2026-06-10 10:15:10 +08:00
handler: function (val) {
2026-06-11 20:48:30 +08:00
if (this.maxCount > 1) {
if (Array.isArray(val)) {
this.currentList = val.filter(function (v) { return !!v; });
} else if (val) {
this.currentList = [val];
} else {
this.currentList = [];
}
} else {
this.currentValue = Array.isArray(val) ? (val[0] || '') : (val || '');
}
2026-06-09 17:49:15 +08:00
},
immediate: true
}
},
methods: {
2026-06-10 16:23:47 +08:00
onInput: function (val) {
this.currentValue = val;
this.$emit('input', val);
},
2026-06-11 20:48:30 +08:00
onMultiInput: function (val) {
var arr = Array.isArray(val) ? val : [val];
var list = this.currentList.concat(arr).slice(0, this.maxCount);
this.currentList = list;
this.$emit('input', list);
},
2026-06-10 16:23:47 +08:00
onChange: function (val) {
this.$emit('change', val);
2026-06-09 17:49:15 +08:00
},
2026-06-11 20:48:30 +08:00
deleteSingleVideo: function () {
2026-06-10 16:23:47 +08:00
this.currentValue = '';
2026-06-10 10:15:10 +08:00
this.$emit('input', '');
2026-06-11 20:48:30 +08:00
},
deleteVideo: function (index) {
this.currentList.splice(index, 1);
this.$emit('input', this.currentList);
2026-06-09 17:49:15 +08:00
}
}
};
</script>
<style scoped>
2026-06-11 20:48:30 +08:00
.video-list {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
2026-06-10 16:23:47 +08:00
.video-wrapper {
position: relative;
2026-06-10 10:15:10 +08:00
width: 200rpx;
height: 200rpx;
2026-06-09 17:49:15 +08:00
}
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 16:23:47 +08:00
top: -10rpx;
right: -10rpx;
2026-06-10 10:15:10 +08:00
width: 40rpx;
height: 40rpx;
2026-06-10 16:23:47 +08:00
background-color: #ff4d4f;
color: white;
2026-06-09 17:49:15 +08:00
border-radius: 50%;
display: flex;
justify-content: center;
2026-06-10 16:23:47 +08:00
align-items: center;
font-size: 32rpx;
z-index: 1;
2026-06-09 17:49:15 +08:00
}
2026-06-10 10:15:10 +08:00
2026-06-09 17:49:15 +08:00
.delete-icon {
color: #ffffff;
font-size: 32rpx;
}
</style>