diff --git a/api/ocr.js b/api/ocr.js new file mode 100644 index 0000000..025c223 --- /dev/null +++ b/api/ocr.js @@ -0,0 +1,65 @@ +export const getOcr = (url) => { + return new Promise((resolve, reject) => { + wx.request({ + url: 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', + method: 'POST', + dataType: 'json', // 微信官方文档中介绍会对数据进行一次JSON.parse + header: { + 'Authorization': 'Bearer sk-52414b887aee47e4883caf16cbf801bd', + 'Content-Type': 'application/json' + }, + data: { + "model": "qwen-vl-ocr-latest", + "messages": [{ + "role": "user", + "content": [{ + "type": "image_url", + "image_url": { + "url": url + }, + "min_pixels": 3136, + "max_pixels": 6422528 + }, + { + "type": "text", + "text": "要求准确无误的提取上述关键信息、不要遗漏和捏造虚假信息,模糊或者强光遮挡的单个文字可以用英文问号?代替。返回数据格式以MD方式输出" + } + ] + }] + }, + success(res) { + const data = parseMarkdownTable(res.data.choices[0].message.content) + resolve(data); + }, + fail(err) { + console.log(err) + // 断网、服务器挂了都会fail回调,直接reject即可 + reject(err); + }, + }); + }) +} + +function parseMarkdownTable(md) { + // 拆分行,去掉空行 + const lines = md.split('\n').filter(line => line.trim().length > 0); + + // 找到表头和数据行 + const headerLine = lines[0]; + const header = headerLine.split('|').map(h => h.trim()).filter(Boolean); + + // 数据行从第三行开始(第二行为分隔符) + const dataLines = lines.slice(2); + + // 解析每一行 + const result = dataLines.map(line => { + const cells = line.split('|').map(cell => cell.trim()).filter(Boolean); + const obj = {}; + header.forEach((key, idx) => { + obj[key] = cells[idx]; + }); + return obj; + }); + + return result; +} \ No newline at end of file diff --git a/api/request.js b/api/request.js index d857bd4..fd2d794 100644 --- a/api/request.js +++ b/api/request.js @@ -11,7 +11,7 @@ export function resetTokenInvalid() { function request(url, method = 'GET', data = {}) { // 如果 token 已失效,直接中断请求 - if (isTokenInvalid) { + if (isTokenInvalid && wx.getStorageSync('access_token')) { return Promise.reject({ code: 10103, message: '登录已失效,请重新登录' }); } const header = { diff --git a/pages/followUp/index.js b/pages/followUp/index.js index 7267880..40144b5 100644 --- a/pages/followUp/index.js +++ b/pages/followUp/index.js @@ -1,4 +1,6 @@ import request from '~/api/request'; + +import { getOcr } from '~/api/ocr'; Page({ /** @@ -313,6 +315,7 @@ Page({ wx.showToast({ title: '上传失败!', icon: 'none' }); console.error('上传失败:', error); // 输出具体的错误信息 } else { + // getOcr(data) wx.showToast({ title: '上传成功!', icon: 'success' }); const { mode } = e.currentTarget.dataset; let arr = this.data.form[mode] @@ -320,7 +323,7 @@ Page({ this.setData({ [`form.${mode}`]: arr }) - + getOcr(data) console.log('上传成功:', data); // 输出上传成功后的数据 } }); diff --git a/pages/loginCode/loginCode.less b/pages/loginCode/loginCode.less index 4811273..232ad12 100644 --- a/pages/loginCode/loginCode.less +++ b/pages/loginCode/loginCode.less @@ -1,8 +1,6 @@ .page { background-color: rgba(255,255,255,1.000000); position: relative; - width: 750rpx; - height: 1624rpx; overflow: hidden; display: flex; flex-direction: column; @@ -83,7 +81,7 @@ font-size: 40rpx; margin-right: 8rpx; width: 50rpx; - transform: translateY(4rpx); + // transform: translateY(4rpx); } .text-group_2 { overflow-wrap: break-word; @@ -133,7 +131,7 @@ height: 32rpx; display: flex; flex-direction: column; - margin: 2rpx 0 0 0; + margin: 6rpx 0 0 0; } .text_3 { overflow-wrap: break-word; @@ -145,6 +143,7 @@ white-space: nowrap; line-height: 32rpx; margin: 2rpx 0 0 34rpx; + transform: translateY(4rpx); } .text-wrapper_1 { background-color: rgba(0,91,162,1.000000); diff --git a/pages/loginCode/loginCode.wxml b/pages/loginCode/loginCode.wxml index 1f0c534..63e470d 100644 --- a/pages/loginCode/loginCode.wxml +++ b/pages/loginCode/loginCode.wxml @@ -1,9 +1,6 @@ - - - diff --git a/pages/message/index.js b/pages/message/index.js index e86beef..9f9790d 100644 --- a/pages/message/index.js +++ b/pages/message/index.js @@ -108,10 +108,10 @@ Page({ }) }, goQuestionnaire(e) { - const data = this.data.dataList - const target = data.find(item => item.questionnaire_id === 0 && item.status === 2); + // const data = this.data.dataList + // const target = data.find(item => item.questionnaire_id == 0 && item.status == 2); wx.navigateTo({ - url: `/pages/followUp/index?planId=${target.id}&name=&time=&questionnaire_id=0` , + url: `/pages/followUp/index?planId=0&name=&time=&questionnaire_id=0` , }) }, toRegister() { diff --git a/pages/my/index.less b/pages/my/index.less index 1a3883b..9e4b28d 100644 --- a/pages/my/index.less +++ b/pages/my/index.less @@ -220,15 +220,18 @@ // margin: -76rpx 170rpx 0 88rpx; } .group_1 { - width: 270rpx; + margin-top: 22rpx; + // width: 270rpx; // background-color: rgba(208,15,22,0.100000); border-radius: 28rpx; border: 1px solid rgba(255,255,255,1); padding-left: 20rpx; - flex-direction: row; - display: flex; + // flex-direction: row; + width: 300rpx; + display: inline-flex; + // width: auto; justify-content: space-between; - margin: 22rpx 82rpx 0 0; + // margin: 22rpx 82rpx 0 0; } .success{ background-color: rgba(43, 164, 113, 0.1); @@ -268,32 +271,29 @@ } .image-text_4 { - width: 188rpx; - flex-direction: row; - display: flex; - justify-content: space-between; - margin: 14rpx 0 14rpx 0; + // width: 188rpx; + margin: 8rpx 0 8rpx 0; } .thumbnail_1 { color: rgba(212,48,48,1); transform: translateY(-2rpx); + margin-right: 8rpx; } .text-group_5 { - overflow-wrap: break-word; color: rgba(212,48,48,1); font-size: 24rpx; font-family: Alibaba-PuHuiTi-R; - font-weight: normal; - text-align: left; - white-space: nowrap; - line-height: 24rpx; + line-height: 26rpx; } .text-wrapper_2 { border-radius: 28rpx; border: 1px solid rgba(255,255,255,1); display: flex; - flex-direction: column; - padding: 12rpx 22rpx 12rpx 22rpx; + width: 80rpx; + // height: 60rpx; + align-items: center; + justify-content: center; + margin-left: 12rpx; } .text_6 { diff --git a/pages/my/index.wxml b/pages/my/index.wxml index e7741f9..b1d28b3 100644 --- a/pages/my/index.wxml +++ b/pages/my/index.wxml @@ -38,7 +38,7 @@ 中危 - + 高危