diff --git a/common/betone_components/betone-upload.vue b/common/betone_components/betone-upload.vue index e9e2279..d14265e 100644 --- a/common/betone_components/betone-upload.vue +++ b/common/betone_components/betone-upload.vue @@ -80,14 +80,33 @@ export default { this.$refs.BetLoading.show() // 成功选择图片后的回调 const tempFilePaths = res.tempFilePaths; + uni.compressImage({ src: tempFilePaths[0], // 图片路径 quality: 50, // 压缩质量,范围为0 - 100,100为不压缩 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) + } }) }, }); diff --git a/utils/request.js b/utils/request.js index f25083b..4ef8250 100644 --- a/utils/request.js +++ b/utils/request.js @@ -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' diff --git a/utils/website.js b/utils/website.js index 6accd01..299d5ed 100644 --- a/utils/website.js +++ b/utils/website.js @@ -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", // 客户端密钥