Commit 8241fe61 authored by xwq's avatar xwq

接口

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