ocr和后端对接

This commit is contained in:
539943419 committed 2023-12-01 00:26:59 +08:00
1 parent 93c9df5600
commit 0c62d232b8
1 file changed
+57 -56
+57 -56
View File
@@ -1089,64 +1089,26 @@ Page({
// this.show_result_byId(data.id) // this.show_result_byId(data.id)
// this.save2storage() // this.save2storage()
// },3000) // },3000)
// wx.getFileSystemManager().readFile({ 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', //仅为示例,并非真实的接口地址
filePath: tempImagePath, filePath: tempImagePath,
name: 'file', encoding: 'base64',
// formData: { 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 // session_key:this.data.session_key
// }, },
success:res=>{ method: "POST",
const data = res.data header: {
'content-type': 'application/json' // 默认值
},
success: res => {
var data = res.data
console.log(res.data)
wx.hideLoading(); wx.hideLoading();
var nowdate = new Date(); var nowdate = new Date();
var nowyear = nowdate.getFullYear(); var nowyear = nowdate.getFullYear();
@@ -1170,8 +1132,47 @@ Page({
this.sortHistory() this.sortHistory()
this.show_result_byId(data.id) this.show_result_byId(data.id)
this.save2storage() this.save2storage()
},
fail: res => {
console.log(res)
} }
}) })
}
})
// 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()
// }
// })
}, },
// 向云发送历史记录和收藏记录数据 // 向云发送历史记录和收藏记录数据