视频上传

This commit is contained in:
zmj 2024-04-22 08:38:39 +08:00
parent b22db99e63
commit 8c05ceb8fb
2 changed files with 116 additions and 40 deletions

View File

@ -15,15 +15,24 @@
<text style="font-size:24rpx ; color:#E18C34 ;">上传时应注重真实性清晰度</text> <text style="font-size:24rpx ; color:#E18C34 ;">上传时应注重真实性清晰度</text>
</u-form-item> </u-form-item>
<view class="" style="display: flex;flex-wrap: wrap;"> <view class="" style="display: flex;flex-wrap: wrap;">
<u-upload :fileList="formData.imageList" @afterRead="afterRead" @delete="deletePic" name="6" <view class='uploadimg' @click="show=true">
multiple :maxCount="5"> <u-icon name="plus" color="#777777"></u-icon>
<view class="" style="color: #777777;font-size: 20rpx;">
上传图片/视频
</view>
</view>
<!-- <view class="" style="width: 100rpx;height: 100rpx;background-color: red;" @click="test">
</view> -->
<!-- <u-upload :fileList="formData.imageList" @afterRead="afterRead" @delete="deletePic" name="6"
multiple :maxCount="5" accept="video">
<view class='uploadimg'> <view class='uploadimg'>
<u-icon name="plus" color="#777777"></u-icon> <u-icon name="plus" color="#777777"></u-icon>
<view class="" style="color: #777777;font-size: 24rpx;"> <view class="" style="color: #777777;font-size: 24rpx;">
上传图片 上传图片
</view> </view>
</view> </view>
</u-upload> </u-upload> -->
</view> </view>
</view> </view>
<view class="card"> <view class="card">
@ -98,7 +107,8 @@
</view> </view>
</view> </view>
</u-popup> </u-popup>
<u-picker :show="show" :columns="columns" confirmColor='#33BB3C' @close='show=false' @confirm='choseMedia'
@cancel='show=false'></u-picker>
</view> </view>
@ -131,6 +141,9 @@
}, },
data() { data() {
return { return {
columns: [
['图片', '视频', ]
],
isWholeSale: false, // isWholeSale: false, //
show: false, // show: false, //
showCustom: false, // showCustom: false, //
@ -152,24 +165,6 @@
], ],
selfAttr: "", selfAttr: "",
formData: { formData: {
// // store_name: "",
// imageList: [],
// cate_name: "",
// cate_id: "",
// attrValue: [{
// "price": "",
// "unit_name": "",
// "wholesale_unit_name": "",
// "wholesale_price": '',
// "stock": "",
// open: true,
// spec_type: ''
// }],
// image: '',
// slider_image: [],
// delivery_way: [],
// attr: [],
// // product_attribute: [],
"store_name": "", "store_name": "",
"imageList": [ "imageList": [
@ -240,24 +235,100 @@
message: '请选择', message: '请选择',
trigger: ['blur', 'change'] trigger: ['blur', 'change']
} }
// 'userInfo.name': {
// type: 'string',
// required: true,
// message: '',
// trigger: ['blur', 'change']
// },
// 'userInfo.sex': {
// type: 'string',
// max: 1,
// required: true,
// message: '',
// trigger: ['blur', 'change']
// },
}, },
}; };
}, },
methods: { methods: {
choseMedia(e) {
console.log(e.value)
this.show = false
if (e.value[0] == '图片') {
this.handleChooseImage()
// uni.chooseImage({
// count: 6, //9
// sizeType: ['original', 'compressed'], //
// sourceType: ['album', 'camera'], //
// success: function(res) {
// console.log(JSON.stringify(res.tempFilePaths));
// }
// });
} else {
this.uploadVideo()
// uni.chooseVideo({
// sourceType: ['camera', 'album'],
// success: function(res) {
// self.src = res.tempFilePath;
// }
// });
}
},
//
handleChooseImage() {
let that = this;
that.$util.uploadImageOne('upload/image', function(res) {
// that.setFormData.imageList.push(res.data.path);
});
},
//
uploadVideo() {
uni.chooseVideo({
sourceType: ['camera', 'album'],
success: res => {
console.log(res)
if (Math.ceil(res.size / 1024) < this.upload_max * 1024) {
uni.uploadFile({
url: this.uploadUrl, //
filePath: res.tempFilePath,
name: 'file',
//
// formData: {
// user: 'test'
// },
header: {
// #ifdef MP
'Content-Type': 'multipart/form-data',
// #endif
[TOKENNAME]: 'Bearer ' + store.state.app.token
},
success: uploadFileRes => {
// let data = JSON.parse(uploadFileRes.data);
// this.addGoodsSecoundData.video_link = (data.data.src);
},
complete: a => {
// console.log(a);
}
});
} else {
uni.showModal({
title: '提示',
content: `视频超出限制${this.upload_max}MB,已过滤`
});
}
},
fail: err => {
//
// uni.showModal({
// content: JSON.stringify(err)
// });
console.log(err)
}
});
},
test() {
uni.chooseFile({
count: 6, //100
extension: ['.zip', '.doc'],
success: function(res) {
console.log(JSON.stringify(res.tempFilePaths));
}
});
},
// //
deletePic(event) { deletePic(event) {
this.formData[`imageList`].splice(event.index, 1) this.formData[`imageList`].splice(event.index, 1)

View File

@ -56,8 +56,7 @@
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right" <view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="navgo(`/pages/product/addGoodDetail/goodsAttr?formData=${JSON.stringify(formData)}&&mer_id=${mer_id}`)"> @click="navgo(`/pages/product/addGoodDetail/goodsAttr?formData=${JSON.stringify(formData)}&&mer_id=${mer_id}`)">
<view style="margin-right: 10rpx;line-height: 25rpx;"> <view style="margin-right: 10rpx;line-height: 25rpx;">
{{Object.values(formData.product_attribute).address ?"已设置":"未设置"}} {{isSet(formData.product_attribute)?'已设置':'未设置' }}
<!-- {{Object.values(formData.product_attribute) }} -->
</view> </view>
<u-icon name="arrow-right"></u-icon> <u-icon name="arrow-right"></u-icon>
</view> </view>
@ -285,7 +284,15 @@
}; };
}, },
methods: { methods: {
isSet(obj) {
for (let key in obj) {
if (typeof obj[key] == 'object') this.isSet(obj[key])
else {
if (Boolean(obj[key])) return true;
}
}
},
// //
deletePic1(event) { deletePic1(event) {
this.formData[`imageList`].splice(event.index, 1) this.formData[`imageList`].splice(event.index, 1)
@ -326,8 +333,6 @@
}); });
}) })
}, },
// //
deletePic(event) { deletePic(event) {
this.formData.content.image.splice(event.index, 1) this.formData.content.image.splice(event.index, 1)