From bd7cf76402ce7666a0bd2c8df95d0afdc13fd491 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Mon, 4 May 2020 23:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A1=E6=A3=80=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant/UrlConstant.js | 6 +- factory/Base64Factory.js | 121 ++++++++++++------ pages/excuteInspection/excuteInspection.vue | 42 +++++- .../excuteOneInspection.vue | 64 ++++----- 4 files changed, 162 insertions(+), 71 deletions(-) diff --git a/constant/UrlConstant.js b/constant/UrlConstant.js index 6a725af..bd59b9e 100644 --- a/constant/UrlConstant.js +++ b/constant/UrlConstant.js @@ -64,6 +64,9 @@ const listInspectionTasks = baseUrl + "app/inspectionTask.listInspectionTasks"; //巡检任务详情 const listInspectionTaskDetails = baseUrl + 'app/inspectionTaskDetail.listInspectionTaskDetails'; +//巡检 +const updateInspectionTaskDetail = baseUrl + 'app/inspectionTaskDetail.updateInspectionTaskDetail' + module.exports = { baseUrl: baseUrl, @@ -96,5 +99,6 @@ module.exports = { listAdvertPhoto: listAdvertPhoto, saveOwnerRepair:saveOwnerRepair, listInspectionTasks:listInspectionTasks, - listInspectionTaskDetails:listInspectionTaskDetails + listInspectionTaskDetails:listInspectionTaskDetails, + updateInspectionTaskDetail:updateInspectionTaskDetail }; \ No newline at end of file diff --git a/factory/Base64Factory.js b/factory/Base64Factory.js index c7852b5..bd6211c 100644 --- a/factory/Base64Factory.js +++ b/factory/Base64Factory.js @@ -4,43 +4,92 @@ * add by wuxw 2020-01-01 美丽的夏都西宁 */ class Base64Factory { - constructor() {} + constructor() {} - static urlTobase64(url) { - return new Promise((resolve, reject) => { - uni.request({ - url: url, - method:'GET', - responseType: 'arraybuffer', - success: ress => { - let base64 = wx.arrayBufferToBase64(ress.data); //把arraybuffer转成base64 - base64 = 'data:image/jpeg;base64,' + base64 //不加上这串字符,在页面无法显示的哦 - console.log(base64); - resolve(base64); - }, - fail: function (e) { - console.log(e); - reject(e); - } - }); - /* wx.getFileSystemManager().readFile({ - filePath: url, - //选择图片返回的相对路径 - encoding: 'base64', - //编码格式 - success: res => { - //成功的回调 - //console.log('data:image/png;base64,' + res.data); - let base64 = 'data:image/png;base64,' + res.data; - resolve(base64); - }, - fail: function (e) { - console.log(e); - reject(e); - } - }); */ - }); - } + static getLocalFilePath(path) { + if (path.indexOf('_www') === 0 || path.indexOf('_doc') === 0 || path.indexOf('_documents') === 0 || path.indexOf( + '_downloads') === 0) { + return path + } + if (path.indexOf('file://') === 0) { + return path + } + if (path.indexOf('/storage/emulated/0/') === 0) { + return path + } + if (path.indexOf('/') === 0) { + var localFilePath = plus.io.convertAbsoluteFileSystem(path) + if (localFilePath !== path) { + return localFilePath + } else { + path = path.substr(1) + } + } + return '_www/' + path + } + + static urlTobase64(url) { + //url = Base64Factory.getLocalFilePath(url); + + return new Promise((resolve, reject) => { + console.log('url', url); + // #ifdef H5 + let imgData; + let reader = new FileReader(); + getImageBlob(url, function(blob) { + reader.readAsDataURL(blob); + }); + reader.onload = function(e) { + imgData = e.target.result; + resolve(imgData); + }; + + function getImageBlob(_url, cb) { + let xhr = new XMLHttpRequest(); + xhr.open("get", _url, true); + xhr.responseType = "blob"; + xhr.onload = function() { + if (this.status == 200) { + if (cb) cb(this.response); + } + }; + xhr.send(); + } + // #endif + // #ifdef APP-PLUS + let _imageBase64List = ''; + plus.io.resolveLocalFileSystemURL(url, + function(entry) { + // 可通过entry对象操作test.html文件 + entry.file(function(file) { + var fileReader = new plus.io.FileReader(); + fileReader.readAsDataURL(file); + fileReader.onloadend = function(evt) { + _imageBase64List = _imageBase64List.concat(evt.target.result); + resolve(_imageBase64List); + } + }) + }); + // #endif + + // #ifdef MP-WEIXIN + wx.getFileSystemManager().readFile({ + filePath: url, //选择图片返回的相对路径 + encoding: 'base64', //编码格式 + success: res => { //成功的回调 + //console.log('data:image/png;base64,' + res.data); + let base64 = 'data:image/png;base64,' + res.data; + resolve(base64); + }, + fail: function(e) { + console.log(e); + reject(e); + } + }) + // #endif + }); + + } } diff --git a/pages/excuteInspection/excuteInspection.vue b/pages/excuteInspection/excuteInspection.vue index 6bb77ca..f041883 100644 --- a/pages/excuteInspection/excuteInspection.vue +++ b/pages/excuteInspection/excuteInspection.vue @@ -11,9 +11,26 @@ + + + + + + + + + + + + + + + + + @@ -27,7 +44,9 @@ communityId:'', userId:'', userName:'', - taskDetails:[] + taskDetails:[], + viewImage:false, + viewImageSrc:'' } }, @@ -38,6 +57,9 @@ let _userInfo = this.java110Context.getUserInfo(); this.userName = _userInfo.userName; this.userId = _userInfo.userId; + + }, + onShow() { this._queryTaskDetail(); }, methods: { @@ -60,7 +82,16 @@ // res.data.inspectionTaskDetails.forEach(function(item, index) { // item.timeStr = item.planInsTime.replace(/:\d{1,2}$/, ' '); // }); - _that.taskDetails = res.data.inspectionTaskDetails; + let _inspectionTaskDetails = res.data.inspectionTaskDetails; + _inspectionTaskDetails.forEach(function(_item){ + if(_item.state == '20200407'){ + _item.photos.forEach(function(_photoTmp) { + _photoTmp.url = _that.java110Constant.url.hcBaseUrl + _photoTmp.url; + }); + } + + }) + _that.taskDetails = _inspectionTaskDetails; } }); }, @@ -73,6 +104,13 @@ uni.navigateTo({ url:'/pages/excuteOneInspection/excuteOneInspection?taskDetailId='+_item.taskDetailId+"&taskId="+_item.taskId+"&inspectionId="+_item.inspectionId+"&inspectionName="+_item.inspectionName }); + }, + preview: function(_src) { + this.viewImage = true; + this.viewImageSrc = _src; + }, + closeViewImage: function() { + this.viewImage = false; } } } diff --git a/pages/excuteOneInspection/excuteOneInspection.vue b/pages/excuteOneInspection/excuteOneInspection.vue index 966309a..1dd4b23 100644 --- a/pages/excuteOneInspection/excuteOneInspection.vue +++ b/pages/excuteOneInspection/excuteOneInspection.vue @@ -19,18 +19,18 @@ 巡检图片 - {{photoList.length}}/4 + {{imgList.length}}/4 - - + + - + @@ -59,7 +59,6 @@ description:'', photos:[], imgList:[], - photoList:[], patrolIndex:0, communityId:'', userId:'', @@ -82,23 +81,27 @@ this.patrolTypeName = this.patrols[e.detail.value]; this.patrolType = this.patrolTypes[e.detail.value]; }, - afterRead: function(event) { - const { - file - } = event.detail; - - let _that = this; - - const { - photoList = [] - } = this; - photoList.push(file); - this.photoList = photoList; - - factory.base64.urlTobase64(file.path).then(function(_baseInfo) { - _that.photos.push(_baseInfo); + removePhoto: function(e) { + console.log(e.detail.index); + let _imgList = []; + this.imgList.forEach(function(item, index) { + if (index != e.detail.index) { + _imgList.push(item); + } }); - console.log("data信息:", this); + let _photos = []; + this.photos.forEach(function(item, index) { + if (index != e.detail.index) { + _photos.push(item); + } + }); + this.photos = _photos; + this.imgList = _imgList; + }, + deleteImage: function(e) { + console.log(e); + let imageArr = this.$data.imgList; + imageArr.splice(e, 1); }, ChooseImage: function(e) { let that = this; @@ -108,19 +111,16 @@ sourceType: ['album'], //从相册选择 success: (res) => { console.log(res); - if (that.$data.photoList.length) { - that.$data.photoList.push(res.tempFilePaths[0]); - } else { - that.$data.photoList = res.tempFilePaths; - } + that.$data.imgList.push(res.tempFilePaths[0]); + let _base64Photo = ''; + that.java110Factory.base64.urlTobase64(res.tempFilePaths[0]).then(function(_res) { + _base64Photo = _res; + console.log('base64', _base64Photo); + that.photos.push(_base64Photo); + }); } }); }, - removePhoto: function(e) { - console.log(e); - let imageArr = this.$data.photoList; - imageArr.splice(e, 1); - }, _submitExcuteInspection: function() { /** * taskId:'', @@ -174,7 +174,7 @@ }); } else { this.java110Context.request({ - url: this.java110Constant.url.saveOwnerRepair, // http://hc.demo.winqi.cn:8012/appApi/ownerRepair.saveOwnerRepair + url: this.java110Constant.url.updateInspectionTaskDetail, // http://hc.demo.winqi.cn:8012/appApi/ownerRepair.saveOwnerRepair header: this.java110Context.getHeaders(), method: "POST", data: obj, //动态数据