diff --git a/miniprogram/pages/index/index.ts b/miniprogram/pages/index/index.ts index 749a54b..9258551 100644 --- a/miniprogram/pages/index/index.ts +++ b/miniprogram/pages/index/index.ts @@ -1089,89 +1089,90 @@ Page({ // this.show_result_byId(data.id) // this.save2storage() // },3000) - // wx.getFileSystemManager().readFile({ - // filePath: tempImagePath, - // // encoding: 'base64', - // success: res => { - // // console.log('data:image/png;base64,' + res.data) - // const imgBase64 = res.data - // wx.request({ - // url: '' + serverAddr + '/api/ocr', //仅为示例,并非真实的接口地址 - // data: { - // file: imgBase64, - // session_key:this.data.session_key - // }, - // method: "POST", - // header: { - // 'content-type': 'application/json' // 默认值 - // }, - // success: res => { - // var data = res.data - // console.log(res.data) - // wx.hideLoading(); - // var nowdate = new Date(); - // var nowyear = nowdate.getFullYear(); - // var nowmonth = nowdate.getMonth() + 1; - // var nowday = nowdate.getDate(); - // var dateStr = nowyear + '.' + nowmonth + '.' + nowday - // if (!this.data.data_history[dateStr]) { - // this.data.data_history[dateStr] = [] - // } - // var historyTemp = - // { - // id: data.id, - // imgUrl: data.imgUrl, - // res: data.res, - // hasCollect: false,//目前全是false。。。 - // } - // this.data.data_history[dateStr].push(historyTemp) - // this.setData({ - // data_history: this.data.data_history - // }) - // this.sortHistory() - // this.show_result_byId(data.id) - // this.save2storage() - // }, - // fail: res => { - // console.log(res) - // } - // }) - // } - // }) - wx.uploadFile({ - url: '' + serverAddr + '/api/ocr', //仅为示例,并非真实的接口地址 + wx.getFileSystemManager().readFile({ filePath: tempImagePath, - name: 'file', - // formData: { - // session_key:this.data.session_key - // }, - success:res=>{ - const data = res.data - wx.hideLoading(); - var nowdate = new Date(); - var nowyear = nowdate.getFullYear(); - var nowmonth = nowdate.getMonth() + 1; - var nowday = nowdate.getDate(); - var dateStr = nowyear + '.' + nowmonth + '.' + nowday - if (!this.data.data_history[dateStr]) { - this.data.data_history[dateStr] = [] - } - var historyTemp = - { - id: data.id, - imgUrl: data.imgUrl, - res: data.res, - hasCollect: false,//目前全是false。。。 - } - this.data.data_history[dateStr].push(historyTemp) - this.setData({ - data_history: this.data.data_history + encoding: 'base64', + success: res => { + // console.log('data:image/png;base64,' + res.data) + const imgBase64 = res.data + console.log(res.data) + wx.request({ + url: '' + serverAddr + '/api/ocr', //仅为示例,并非真实的接口地址 + data: { + imgBase64: imgBase64, + // session_key:this.data.session_key + }, + method: "POST", + header: { + 'content-type': 'application/json' // 默认值 + }, + success: res => { + var data = res.data + console.log(res.data) + wx.hideLoading(); + var nowdate = new Date(); + var nowyear = nowdate.getFullYear(); + var nowmonth = nowdate.getMonth() + 1; + var nowday = nowdate.getDate(); + var dateStr = nowyear + '.' + nowmonth + '.' + nowday + if (!this.data.data_history[dateStr]) { + this.data.data_history[dateStr] = [] + } + var historyTemp = + { + id: data.id, + imgUrl: data.imgUrl, + res: data.res, + hasCollect: false,//目前全是false。。。 + } + this.data.data_history[dateStr].push(historyTemp) + this.setData({ + data_history: this.data.data_history + }) + this.sortHistory() + this.show_result_byId(data.id) + this.save2storage() + }, + fail: res => { + console.log(res) + } }) - this.sortHistory() - this.show_result_byId(data.id) - this.save2storage() } - }) + }) + // wx.uploadFile({ + // url: '' + serverAddr + '/api/ocr', //仅为示例,并非真实的接口地址 + // filePath: tempImagePath, + // name: 'file', + // // formData: { + // // session_key:this.data.session_key + // // }, + // success:res=>{ + // const data = res.data + // wx.hideLoading(); + // var nowdate = new Date(); + // var nowyear = nowdate.getFullYear(); + // var nowmonth = nowdate.getMonth() + 1; + // var nowday = nowdate.getDate(); + // var dateStr = nowyear + '.' + nowmonth + '.' + nowday + // if (!this.data.data_history[dateStr]) { + // this.data.data_history[dateStr] = [] + // } + // var historyTemp = + // { + // id: data.id, + // imgUrl: data.imgUrl, + // res: data.res, + // hasCollect: false,//目前全是false。。。 + // } + // this.data.data_history[dateStr].push(historyTemp) + // this.setData({ + // data_history: this.data.data_history + // }) + // this.sortHistory() + // this.show_result_byId(data.id) + // this.save2storage() + // } + // }) }, // 向云发送历史记录和收藏记录数据