improve emblemscanner scanning

This commit is contained in:
Fam Zheng 2025-09-17 07:29:51 +01:00
parent 5a7688cb80
commit 615a01ee8f
7 changed files with 174 additions and 3 deletions

View File

@ -3,6 +3,7 @@
"pages/index/index",
"pages/camera/camera",
"pages/emblemscanner/emblemscanner",
"pages/result_page/result_page",
"pages/productinfo/productinfo",
"pages/test_result_page/test_result_page",
"pages/camentry/camentry",

View File

@ -37,8 +37,8 @@
<!-- Single WeChat native camera for all camera states -->
<camera class="camera"
flash="{{ camera_flash }}"
frame-size="{{ app_state == 'init_camera' ? 'large' : 'medium' }}"
resolution="{{ app_state == 'init_camera' ? 'high' : 'medium' }}"
frame-size="large"
resolution="high"
bindinitdone="onCameraReady"
binderror="onCameraError">
</camera>

View File

@ -129,7 +129,7 @@ Page({
goto_camera: function () {
this.getUserProfile(() => {
wx.navigateTo({
url: '/pages/emblemscanner/emblemscanner?return_page=/pages/productinfo/productinfo'
url: '/pages/emblemscanner/emblemscanner?return_page=/pages/result_page/result_page'
});
});
},

View File

@ -0,0 +1,116 @@
// Result Page - Handle emblemscanner results and navigation
Page({
/**
* Page initial data
*/
data: {
ok: false,
qr_code: '',
serial_code: '',
scan_timestamp: '',
show_verify_failed: false
},
/**
* Lifecycle function--Called when page load
*/
onLoad(options) {
console.log('Result page loaded with options:', options);
const timestamp = new Date().toLocaleString();
const ok = options.ok === '1';
const qr_code = options.qr_code || '';
const serial_code = options.serial_code || '';
this.setData({
ok: ok,
qr_code: decodeURIComponent(qr_code),
serial_code: decodeURIComponent(serial_code),
scan_timestamp: timestamp,
show_verify_failed: !ok
});
console.log('Result page data:', {
ok: ok,
qr_code: qr_code,
serial_code: serial_code
});
// Handle navigation based on result
if (ok && serial_code) {
// Success case: redirect to productinfo page
this.redirectToProductInfo(serial_code);
} else if (!ok) {
// Failure case: show verify failed UI
this.showVerifyFailed();
}
},
/**
* Redirect to product info page with serial code
*/
redirectToProductInfo(serialCode) {
console.log('Redirecting to productinfo with serial_code:', serialCode);
wx.redirectTo({
url: `/pages/productinfo/productinfo?serial_code=${encodeURIComponent(serialCode)}`,
success: () => {
console.log('Successfully redirected to productinfo');
},
fail: (err) => {
console.error('Failed to redirect to productinfo:', err);
// Fallback: show verify failed UI
this.showVerifyFailed();
}
});
},
/**
* Show verify failed UI
*/
showVerifyFailed() {
console.log('Showing verify failed UI');
this.setData({
show_verify_failed: true
});
},
/**
* Handle verifyfailed component back event - rescan
*/
onVerifyFailedBack() {
console.log('Verify failed back event - rescanning');
this.rescan();
},
/**
* Handle verifyfailed component service event
*/
onVerifyFailedService() {
console.log('Verify failed service event - showing service modal');
// You can implement service modal logic here if needed
// For now, just log it
},
/**
* Rescan - go back to emblemscanner
*/
rescan() {
console.log('Rescan button clicked');
wx.redirectTo({
url: '/pages/emblemscanner/emblemscanner',
success: () => {
console.log('Successfully redirected to emblemscanner');
},
fail: (err) => {
console.error('Failed to redirect to emblemscanner:', err);
wx.showToast({
title: 'Navigation failed',
icon: 'error'
});
}
});
},
});

View File

@ -0,0 +1,9 @@
{
"usingComponents": {
"verifyfailed": "/components/verifyfailed/verifyfailed"
},
"navigationBarTitleText": "扫码结果",
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"backgroundColor": "#f5f5f5"
}

View File

@ -0,0 +1,12 @@
<!--pages/result_page/result_page.wxml-->
<view class="container">
<!-- Success Case: Should redirect automatically, this is just fallback -->
<view wx:if="{{ok && !show_verify_failed}}" class="success-container">
<view class="success-icon">✓</view>
<view class="success-text">验证成功</view>
<view class="success-subtext">正在跳转...</view>
</view>
</view>
<!-- Failure Case: Use verifyfailed component -->
<verifyfailed wx:if="{{show_verify_failed}}" bindback="onVerifyFailedBack" bindservice="onVerifyFailedService" />

View File

@ -0,0 +1,33 @@
/* pages/result_page/result_page.wxss */
.container {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f5f5f5;
padding: 40rpx;
}
/* Success state (should be briefly visible before redirect) */
.success-container {
text-align: center;
}
.success-icon {
font-size: 120rpx;
color: #07c160;
margin-bottom: 40rpx;
}
.success-text {
font-size: 48rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
}
.success-subtext {
font-size: 32rpx;
color: #666;
}