视频和图片压缩上传

test
zhangdi 1 year ago
parent c46bb97428
commit 55ae673aed
  1. 50
      common/betone_components/betone-upload.vue
  2. 5
      utils/request.js
  3. 4
      utils/website.js

@ -80,14 +80,33 @@ export default {
this.$refs.BetLoading.show()
//
const tempFilePaths = res.tempFilePaths;
uni.compressImage({
src: tempFilePaths[0], //
quality: 50, // 0 - 100100
success: (compressRes) => {
const compressedFilePath = compressRes.tempFilePath;
this.uploadFile(compressedFilePath);
// 使uni.getFileInfo
uni.getFileInfo({
filePath: compressedFilePath,
success: (infoRes) => {
//
const size = infoRes.size / 1024 / 1024; // M
if (size > 3) {
uni.showToast({ title: '图片大小不能超过3M', icon: 'none' });
} else {
this.uploadFile(compressedFilePath);
}
},
fail: (err) => {
console.error('获取文件信息失败:', err);
}
});
}
})
},
});
},
@ -97,15 +116,32 @@ export default {
sourceType: ["album", "camera"],
success: (res) => {
this.$refs.BetLoading.show()
const tempFilePaths = res.tempFilePaths;
const tempFilePaths = res.tempFilePath;
//
// this.uploadFile(res.tempFilePath);
uni.compressVideo({ //
src:tempFilePaths,
quality:1,
success:(compressRes)=>{
this.uploadFile(compressRes.tempFilePath);
src: tempFilePaths,
quality: '1',
success: (compressRes) => {
uni.getFileInfo({
filePath: compressRes.tempFilePath,
success: (infoRes) => {
//
const size = infoRes.size / 1024 / 1024; // M
if (size > 50) {
uni.showToast({ title: '视频大小不能超过50M', icon: 'none' });
} else {
this.uploadFile(compressRes.tempFilePath);
}
},
fail: (err) => {
console.error('获取文件信息失败:', err);
}
});
},
fail:(err)=>{
console.log(666,err)
}
})
},
});

@ -56,11 +56,10 @@ const install = (Vue, vm) => {
// 响应拦截,判断状态码是否通过
Vue.prototype.$u.http.interceptor.response = (res) => {
console.log('接口返回拦截',res)
const data = res
let status = res.code || res.status;
const message = res.msg || res.error_description || '未知错误';
console.log(555555555,status)
if (!!res.error_code) {
uni.showToast({
title: res.error_description,
@ -83,7 +82,7 @@ const install = (Vue, vm) => {
// return false;
// }
// // 如果请求为非200否者默认统一处理
if (status !== 200) {
if (status&&status !== 200) {
uni.showToast({
title: message,
icon: 'none'

@ -2,8 +2,8 @@
* 全局配置文件
*/
export default {
// baseUrl: 'http://124.221.142.15:8088/lab',
baseUrl:'http://192.168.0.111:80',
baseUrl: 'http://124.221.142.15:8088/lab',
// baseUrl:'http://192.168.0.111:80',
indexTitle: "科研医疗建筑运维平台",
clientId: "saber", // 客户端id
clientSecret: "saber_secret", // 客户端密钥

Loading…
Cancel
Save