This commit is contained in:
539943419 committed 2023-11-29 15:36:15 +08:00
1 parent a1f11d317f
commit 93c9df5600
5 files changed
+163 -97

No files matched your search

+144 -85
View File
@@ -1047,12 +1047,7 @@ Page({
})
},
// 检查session是否过期
// checkSession() {
// return new Promise((resolve, reject) => {
// this
// })
// },
// 上传照片并展示收到的结果
uploadImg(tempImagePath: any) {
@@ -1060,88 +1055,123 @@ Page({
title: "查询中喵",
mask: true //开启蒙版遮罩
});
return setTimeout(()=>{
wx.hideLoading();
var fake_data = {
id:70582140,
imgUrl:"./static/icons/history.svg",
res:{
scores: 93,
arr: ["生牛乳"],
}
}
var data = fake_data
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()
},3000)
wx.getFileSystemManager().readFile({
// return setTimeout(()=>{
// wx.hideLoading();
// var fake_data = {
// id:70582140,
// imgUrl:"./static/icons/history.svg",
// res:{
// scores: 93,
// arr: ["生牛乳"],
// }
// }
// var data = fake_data
// 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,
// }
// 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()
// },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', //仅为示例,并非真实的接口地址
filePath: tempImagePath,
encoding: 'base64',
success: res => {
// console.log('data:image/png;base64,' + res.data)
const imgBase64 = res.data
wx.request({
url: '' + serverAddr + '/rcvImg', //仅为示例,并非真实的接口地址
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)
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)
}
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()
}
})
})
},
// 向云发送历史记录和收藏记录数据
@@ -1444,6 +1474,35 @@ Page({
return res
},
// 文字转语音
text2speech:function(e:any){
var str = e.target.dataset.name
// console.log(e.target.dataset.name)
// 个人小程序做不了
var plugin = requirePlugin("WechatSI")
// plugin.textToSpeech({
// lang: "zh_CN",
// tts: true,
// content: str,
// success: function(res:any) {
// console.log("succ tts", res.filename)
// const innerAudioContext = wx.createInnerAudioContext()
// innerAudioContext.autoplay = true
// innerAudioContext.src = res.filename
// innerAudioContext.onPlay(() => {
// console.log('开始播放')
// })
// innerAudioContext.onError((res) => {
// console.log(res.errMsg)
// console.log(res.errCode)
// })
// },
// fail: function(res:any) {
// console.log("fail tts", res)
// }
// })
},
// 获取用户code,以给服务端换取openId
getCode: async function () {
var code