ocr和后端对接

This commit is contained in:
539943419 committed 2023-12-01 00:26:59 +08:00
1 parent 93c9df5600
commit 0c62d232b8
1 file changed
+81 -80
+81 -80
View File
@@ -1089,89 +1089,90 @@ 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 => {
// session_key:this.data.session_key // console.log('data:image/png;base64,' + res.data)
// }, const imgBase64 = res.data
success:res=>{ console.log(res.data)
const data = res.data wx.request({
wx.hideLoading(); url: '' + serverAddr + '/api/ocr', //仅为示例,并非真实的接口地址
var nowdate = new Date(); data: {
var nowyear = nowdate.getFullYear(); imgBase64: imgBase64,
var nowmonth = nowdate.getMonth() + 1; // session_key:this.data.session_key
var nowday = nowdate.getDate(); },
var dateStr = nowyear + '.' + nowmonth + '.' + nowday method: "POST",
if (!this.data.data_history[dateStr]) { header: {
this.data.data_history[dateStr] = [] 'content-type': 'application/json' // 默认值
} },
var historyTemp = success: res => {
{ var data = res.data
id: data.id, console.log(res.data)
imgUrl: data.imgUrl, wx.hideLoading();
res: data.res, var nowdate = new Date();
hasCollect: false,//目前全是false。。。 var nowyear = nowdate.getFullYear();
} var nowmonth = nowdate.getMonth() + 1;
this.data.data_history[dateStr].push(historyTemp) var nowday = nowdate.getDate();
this.setData({ var dateStr = nowyear + '.' + nowmonth + '.' + nowday
data_history: this.data.data_history 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()
// }
// })
}, },
// 向云发送历史记录和收藏记录数据 // 向云发送历史记录和收藏记录数据