Commit 8241fe61 authored by xwq's avatar xwq

接口

parent 8ff0b38d
// import { from } from "form-data";
// pages/displayAnswers/displayAnswers.js // pages/displayAnswers/displayAnswers.js
import UploadFileManager from "../../jade/UploadFileManager"; import UploadFileManager from "../../jade/UploadFileManager";
import {hosts} from "../../utils/index"
Page({ Page({
/** /**
...@@ -34,7 +37,7 @@ Page({ ...@@ -34,7 +37,7 @@ Page({
}, },
fail: (e) => reject(e), fail: (e) => reject(e),
}); });
}); }).catch(()=>{});
}, },
detectAnswer: (tempPath) => { detectAnswer: (tempPath) => {
// tempPath -> url // tempPath -> url
...@@ -63,7 +66,7 @@ Page({ ...@@ -63,7 +66,7 @@ Page({
(params) => (params) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
wx.request({ wx.request({
url: `https://test.xinya.me/api/arithmetic_ocr`, url: `${hosts}/api/arithmetic_ocr`,
method: "POST", method: "POST",
data: params, data: params,
success: (res) => { success: (res) => {
...@@ -73,13 +76,15 @@ Page({ ...@@ -73,13 +76,15 @@ Page({
reject(e); reject(e);
}, },
}); });
}).catch(()=>{
}) })
) )
.then( .then(
(res) => (res) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
console.log("]]]]]]]",res) // console.log("]]]]]]]",res)
wx.request({ wx.request({
url: "https://ocr.tencentcloudapi.com", url: "https://ocr.tencentcloudapi.com",
method: "POST", method: "POST",
...@@ -96,7 +101,7 @@ Page({ ...@@ -96,7 +101,7 @@ Page({
} else { } else {
resolve({ resolve({
...ocrRes.data, ...ocrRes.data,
exercise_ocr_record_id: res.exercise_ocr_record_id, ocr_record_id: res.ocr_record_id,
}); });
} }
}, },
...@@ -104,7 +109,7 @@ Page({ ...@@ -104,7 +109,7 @@ Page({
reject(e); reject(e);
}, },
}); });
}) }).catch(()=>{})
); );
}, },
/** /**
...@@ -116,12 +121,12 @@ Page({ ...@@ -116,12 +121,12 @@ Page({
}); });
}, },
confirm: function (e) { confirm: function (e) {
const ret = JSON.parse(wx.getStorageSync("result")); // const ret = JSON.parse(wx.getStorageSync("result"));
ret.errors = this.data.errors != null ? this.data.errors : 0; // ret.errors = this.data.errors != null ? this.data.errors : 0;
ret.errorItems = ret.errors; // ret.errorItems = ret.errors;
const r = Object.keys(ret).reduce((acc, key) => { // const r = Object.keys(ret).reduce((acc, key) => {
return acc + key + "=" + ret[key] + "&"; // return acc + key + "=" + ret[key] + "&";
}, ""); // }, "");
// const opts = { // const opts = {
// ctitle: options.ctitle, // ctitle: options.ctitle,
// answerSrc: options.answerSrc, // answerSrc: options.answerSrc,
...@@ -139,12 +144,13 @@ Page({ ...@@ -139,12 +144,13 @@ Page({
}); });
}, },
onLoad: function (options) { onLoad: function (options) {
// console.log(options.photo);
const context = wx.createCanvasContext("photo_answer");
let radio;
wx.showLoading({ wx.showLoading({
title: "结果加载中", title: "结果加载中",
}); });
console.log(options.photo,"=====",hosts);
const context = wx.createCanvasContext("photo_answer");
let radio;
this.getImageInfopromised(options.photo) this.getImageInfopromised(options.photo)
.then((resPhoto) => { .then((resPhoto) => {
// draw用户拍摄的图片 // draw用户拍摄的图片
...@@ -171,6 +177,7 @@ Page({ ...@@ -171,6 +177,7 @@ Page({
this.setData({ this.setData({
corrects, corrects,
errors: ret.Response.TextDetections.length - corrects, errors: ret.Response.TextDetections.length - corrects,
imgResults:ret.Response
}); });
// console.warn("Res sys", radio); // console.warn("Res sys", radio);
ret.Response.TextDetections.forEach((t, index) => { ret.Response.TextDetections.forEach((t, index) => {
...@@ -206,9 +213,13 @@ Page({ ...@@ -206,9 +213,13 @@ Page({
(ret) => (ret) =>
new Promise((resolve, reject) => new Promise((resolve, reject) =>
setTimeout(() => { setTimeout(() => {
wx.showLoading({
title: "结果加载中",
});
wx.hideLoading(); wx.hideLoading();
wx.canvasToTempFilePath({ wx.canvasToTempFilePath({
canvasId: context.canvasId, canvasId: context.canvasId,
fileType: "jpg",
success: (pic) => { success: (pic) => {
const tempFilePath = pic.tempFilePath; const tempFilePath = pic.tempFilePath;
console.log(tempFilePath); console.log(tempFilePath);
...@@ -223,8 +234,8 @@ Page({ ...@@ -223,8 +234,8 @@ Page({
) )
.then((res) => { .then((res) => {
resolve({ resolve({
exercise_ocr_result: { Response: ret.Response }, ocr_result: { Response: ret.Response },
exercise_ocr_record_id: ret.exercise_ocr_record_id, ocr_record_id: ret.ocr_record_id,
ocr_photo_id: JSON.parse(res.data).id, ocr_photo_id: JSON.parse(res.data).id,
}); });
}) })
...@@ -243,7 +254,7 @@ Page({ ...@@ -243,7 +254,7 @@ Page({
(res) => (res) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
wx.request({ wx.request({
url: "https://xinya.me/api/arithmetic_ocr_result", url: `${hosts}/api/arithmetic_ocr_result`,
method: "POST", method: "POST",
data: res, data: res,
success: (res) => { success: (res) => {
...@@ -257,6 +268,9 @@ Page({ ...@@ -257,6 +268,9 @@ Page({
) )
.catch((e) => { .catch((e) => {
console.error(e); console.error(e);
wx.showLoading({
title: "结果加载中",
});
wx.hideLoading(); wx.hideLoading();
wx.showToast({ wx.showToast({
title: "检查答案出错,请重新拍照检查", title: "检查答案出错,请重新拍照检查",
......
...@@ -139,8 +139,15 @@ const convertURLToJSON = function (url, params = {}) { ...@@ -139,8 +139,15 @@ const convertURLToJSON = function (url, params = {}) {
// wx.miniProgram.navigateTo({ url: url }) // wx.miniProgram.navigateTo({ url: url })
// }) // })
// } // }
// }
const hosts="https://test.xinya.me"
// const hosts="https://xinya.me"
// const request=function(url){
// } // }
module.exports = { module.exports = {
hosts,
getUrl, getUrl,
getCurrentPage, getCurrentPage,
Jade, Jade,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment