拍照支持裁剪

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;">
<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 File

@@ -32,8 +32,20 @@ Component({
success: async function(res) {
// console.log(res.tempFiles[0].tempFilePath)
// 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 () => {
const { code, message, data } = await uploadOcrFile(res.tempFiles[0].tempFilePath)
const { code, message, data } = await uploadOcrFile(tempFilePaths)
if (code !== OK) {
alertError(message)
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({
currentNumber: 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() {
@@ -82,7 +82,7 @@ Component({
})
alertSuccess("获取成功")
} else {
alertInfo("未能获取到")
alertInfo("未能识别数字")
}
},
async onSubmit() {
@@ -98,6 +98,11 @@ Component({
alertError(message)
return
}
this.setData({
currentNumber: null,
calcNumber: null,
diff: "-"
})
alertSuccess("录入成功")
const that = this;
setTimeout(async () => {
@@ -115,11 +120,11 @@ Component({
if (res.confirm) {
// await that.changeEndStatus()
wx.navigateBack()
const pages = getCurrentPages();
const prevPage = pages[pages.length - 2];
if (prevPage.init){
prevPage.init()
}
// const pages = getCurrentPages();
// const prevPage = pages[pages.length - 2];
// if (prevPage.init){
// prevPage.init()
// }
}
}
})

View File

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