拍照支持裁剪

This commit is contained in:
2025-09-22 09:48:37 +08:00
parent d4f357d624
commit ad4d9323ad
4 changed files with 49 additions and 18 deletions

View File

@@ -29,7 +29,7 @@
<view class="th" style="width: 25%; text-align: center; justify-content: center; display: flex; align-items: center;"> <view class="th" style="width: 25%; text-align: center; justify-content: center; display: flex; align-items: center;">
<van-icon name="edit" size="40rpx" bind:tap="handleUpdate" data-data="{{item}}" color="#15755e" /> <van-icon name="edit" size="40rpx" bind:tap="handleUpdate" data-data="{{item}}" color="#15755e" />
<van-icon name="delete" size="40rpx" bind:tap="handleDelete" data-data="{{item}}" color="#15755e" custom-style="margin-left: 20rpx" /> <van-icon wx:if="{{item.isDelete}}" name="delete" size="40rpx" bind:tap="handleDelete" data-data="{{item}}" color="#15755e" custom-style="margin-left: 20rpx" />
</view> </view>
</view> </view>
</view> </view>

View File

@@ -32,8 +32,20 @@ Component({
success: async function(res) { success: async function(res) {
// console.log(res.tempFiles[0].tempFilePath) // console.log(res.tempFiles[0].tempFilePath)
// console.log(res.tempFiles[0].size) // console.log(res.tempFiles[0].size)
wx.cropImage({
src: res.tempFiles[0].tempFilePath, // 图片路径
cropScale: '16:9', // 裁剪比例
success: function (res) {
if (!/(\.jpg|\.png|\.jpeg)$/.test(res.tempFilePath.toLowerCase())) {
wx.showToast({
title: '请上传jpg、png或jpeg格式的图片',
icon: 'none',
});
return;
}
var tempFilePaths = res.tempFilePath;
loadingFunc(async () => { loadingFunc(async () => {
const { code, message, data } = await uploadOcrFile(res.tempFiles[0].tempFilePath) const { code, message, data } = await uploadOcrFile(tempFilePaths)
if (code !== OK) { if (code !== OK) {
alertError(message) alertError(message)
return return
@@ -44,6 +56,21 @@ Component({
}) })
} }
})
// loadingFunc(async () => {
// const { code, message, data } = await uploadOcrFile(res.tempFiles[0].tempFilePath)
// if (code !== OK) {
// alertError(message)
// return
// }
// setTimeout(() => {
// that.triggerEvent("finish", { number: data?.integer, success: data?.integer != null && data?.integer !== "" })
// }, 100)
// })
}
}) })
} }
} }

View File

@@ -53,7 +53,7 @@ Component({
this.setData({ this.setData({
currentNumber: e.detail, currentNumber: e.detail,
calcNumber: isNaN(Number(e.detail)) ? 0 : Number(e.detail), calcNumber: isNaN(Number(e.detail)) ? 0 : Number(e.detail),
diff: isNaN(Number(e.detail)) ? "-" : Number(e.detail) - this.data.meterInfo?.overall diff: isNaN(Number(e.detail)) ? "-" : (Number(e.detail) - this.data.meterInfo?.overall).toFixed(2)
}) })
}, },
handleClear() { handleClear() {
@@ -82,7 +82,7 @@ Component({
}) })
alertSuccess("获取成功") alertSuccess("获取成功")
} else { } else {
alertInfo("未能获取到") alertInfo("未能识别数字")
} }
}, },
async onSubmit() { async onSubmit() {
@@ -98,6 +98,11 @@ Component({
alertError(message) alertError(message)
return return
} }
this.setData({
currentNumber: null,
calcNumber: null,
diff: "-"
})
alertSuccess("录入成功") alertSuccess("录入成功")
const that = this; const that = this;
setTimeout(async () => { setTimeout(async () => {
@@ -115,11 +120,11 @@ Component({
if (res.confirm) { if (res.confirm) {
// await that.changeEndStatus() // await that.changeEndStatus()
wx.navigateBack() wx.navigateBack()
const pages = getCurrentPages(); // const pages = getCurrentPages();
const prevPage = pages[pages.length - 2]; // const prevPage = pages[pages.length - 2];
if (prevPage.init){ // if (prevPage.init){
prevPage.init() // prevPage.init()
} // }
} }
} }
}) })

View File

@@ -19,7 +19,6 @@ Page({
*/ */
onLoad(options) { onLoad(options) {
const { id } = options; const { id } = options;
this.getMeterList(id) this.getMeterList(id)
}, },
async getMeterList(id) { async getMeterList(id) {
@@ -52,7 +51,7 @@ Page({
newIndex = meterList?.length - 1 newIndex = meterList?.length - 1
} }
this.setData({ this.setData({
active: newIndex active: newIndex,
}) })
}, },
handlePrev() { handlePrev() {