diff --git a/pages/6170/deviceControl/index.vue b/pages/6170/deviceControl/index.vue index 3808b74..356e5d3 100644 --- a/pages/6170/deviceControl/index.vue +++ b/pages/6170/deviceControl/index.vue @@ -187,8 +187,12 @@ - - + + + @@ -238,7 +242,11 @@ import { getDeviceId } from '../../../store/BLETools'; - + import { + baseURL, + getToken, + clientid + } from '@/utils/request' export default { data() { return { @@ -278,7 +286,9 @@ showPopupFlag: false, //是否显示弹框 popupMessage: '!', popupConfirmText: '确认', - showUploadPopup: false + showUploadPopup: false, + selectedImage: null, // 添加这个变量来存储选择的图片 + file: '' } }, computed: { @@ -288,9 +298,9 @@ }, methods: { // *******定位****** - gpsPosition(){ + gpsPosition() { uni.navigateTo({ - url:'/pages/common/map/index' + url: '/pages/common/map/index' }) }, // ***********进度条*********** @@ -370,38 +380,75 @@ checkImgUpload() { uni.chooseImage({ count: 1, - sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 - sourceType: ['album', 'camera'], //从相册,相机选择,, - success: function(res) { - uni.navigateTo({ - url: "/pages/6155/ImgCrop", - events: { - ImgCutOver: function(data) { - console.log("我收到裁剪后的图片了,感谢老铁," + data) - uni.showLoading({ - title: "正在发送..." - }); - setTimeout(function() { - processAndSendImageData(data).catch(() => {}); - }, 0) - } - }, - success(ev) { - ev.eventChannel.emit('checkImg', { - data: res.tempFiles[0].path - }) - }, - fail(ex) { - console.log("跳转页面失败" + JSON.stringify(ex)); - } + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success: (res) => { + // 将选择的图片赋值给selectedImage + const file = res.tempFiles[0]; + const fileSize = file.size || 0; + if (fileSize > 2 * 1024 * 1024) { + console.log(`文件过大: ${fileSize} 字节`); // 调试日志 + uni.showToast({ + title: '图片大小不能超过2MB', + icon: 'none', + duration: 3000 + }); + return; + } + this.selectedImage = res.tempFilePaths[0]; + console.log('选择的图片:', res); + this.file = res.tempFiles[0].file + }, + fail: (err) => { + console.error('选择图片失败:', err); + uni.showToast({ + title: '选择图片失败', + icon: 'none' }); - } }); }, // 上传开机画面确认按键 handleupload() { - this.lightModeB = false + uni.uploadFile({ + url: baseURL + '/app/device/uploadLogo', + filePath: this.selectedImage, + name:this.file, + formData: { + deviceId: this.deviceID, + }, + header: { + 'Authorization': 'Bearer ' + getToken(), + 'clientid': clientid(), + }, + complete: (res) => { + console.log(res, 'resss'); + try { + const responseData = JSON.parse(res.data); + if (responseData.code === 200) { + uni.showToast({ + title: responseData.msg, + icon: 'success' + }); + this.selectedImage='' + this.lightModeB = false + } else { + uni.showToast({ + title: responseData.msg, + icon: 'none' + }); + } + } catch (e) { + uni.showToast({ + title: '上传失败', + icon: 'none' + }); + } finally { + uni.hideLoading(); + } + } + }) + }, // 分享 shareUp() { @@ -634,11 +681,11 @@ const statusTopic = `A/${this.itemInfo.deviceImei}`; this.mqttClient.subscribe(statusTopic, (payload) => { console.log(`收到来自 ${statusTopic} 的消息:`, payload); - uni.showModal({ - title: '收到设备消息', - content: payload, - showCancel: false - }); + // uni.showModal({ + // title: '收到设备消息', + // content: payload, + // showCancel: false + // }); }); }); if (this.apiType === 'listA') { @@ -894,7 +941,7 @@ border-radius: 8rpx; background: rgba(58, 58, 58, 1); text-align: center; - line-height:200rpx; + line-height: 200rpx; } .img { diff --git a/pages/common/send/index.vue b/pages/common/send/index.vue index d879326..40534bf 100644 --- a/pages/common/send/index.vue +++ b/pages/common/send/index.vue @@ -189,7 +189,6 @@ .device-content { background-color: rgb(26, 26, 26); border-radius: 16rpx; - margin-bottom: 20rpx; position: relative; /* display: flex; */ align-items: center;