feat(rider): 实现水票核销页面自动扫描功能
- 在水票核销页面添加自动扫描模式支持 - 添加路由参数检测实现自动开启扫码功能 - 添加首次展示时自动触发扫码逻辑 - 修改用户卡片组件显示实际水票总数而非礼品卡数量 - 添加独立的水票总数刷新机制 - 在用户登录和信息刷新时同步更新水票总数
This commit is contained in:
@@ -242,7 +242,7 @@ const DealerIndex: React.FC = () => {
|
||||
</View>
|
||||
</Grid.Item>
|
||||
|
||||
<Grid.Item text={'水票核销'} onClick={() => navigateToPage('/rider/ticket/verification/index')}>
|
||||
<Grid.Item text={'水票核销'} onClick={() => navigateToPage('/rider/ticket/verification/index?auto=1')}>
|
||||
<View className="text-center">
|
||||
<View className="w-12 h-12 bg-cyan-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
||||
<Scan color="#06b6d4" size="20" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useMemo, useState } from 'react'
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { View, Text } from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import Taro, { useDidShow, useRouter } from '@tarojs/taro'
|
||||
import { Button, Card, ConfigProvider } from '@nutui/nutui-react-taro'
|
||||
import { Scan, Success, Failure, Tips } from '@nutui/icons-react-taro'
|
||||
|
||||
@@ -29,11 +29,14 @@ type VerifyRecord = {
|
||||
|
||||
const RiderTicketVerificationPage: React.FC = () => {
|
||||
const { hasRole, isAdmin } = useUser()
|
||||
const router = useRouter()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [lastTicket, setLastTicket] = useState<GltUserTicket | null>(null)
|
||||
const [lastQty, setLastQty] = useState<number>(1)
|
||||
const [records, setRecords] = useState<VerifyRecord[]>([])
|
||||
|
||||
const autoScanOnceRef = useRef(false)
|
||||
|
||||
const canVerify = useMemo(() => {
|
||||
return (
|
||||
hasRole('rider') ||
|
||||
@@ -44,6 +47,11 @@ const RiderTicketVerificationPage: React.FC = () => {
|
||||
)
|
||||
}, [hasRole, isAdmin])
|
||||
|
||||
const autoScanEnabled = useMemo(() => {
|
||||
const p: any = router?.params || {}
|
||||
return p.auto === '1' || p.auto === 'true'
|
||||
}, [router])
|
||||
|
||||
const addRecord = (rec: Omit<VerifyRecord, 'id' | 'time'>) => {
|
||||
const item: VerifyRecord = {
|
||||
id: Date.now(),
|
||||
@@ -162,6 +170,25 @@ const RiderTicketVerificationPage: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// If navigated in "auto" mode, open scan on first show when user has permission.
|
||||
useDidShow(() => {
|
||||
// Reset the flag when user manually re-enters the page via navigation again.
|
||||
// (This runs on every show; only the first show with auto enabled will trigger scan.)
|
||||
if (!autoScanEnabled) autoScanOnceRef.current = false
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoScanEnabled) return
|
||||
if (autoScanOnceRef.current) return
|
||||
if (!canVerify) return
|
||||
autoScanOnceRef.current = true
|
||||
// Defer to ensure page is fully mounted before opening camera.
|
||||
setTimeout(() => {
|
||||
handleScan().catch(() => {})
|
||||
}, 80)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [autoScanEnabled, canVerify])
|
||||
|
||||
return (
|
||||
<ConfigProvider>
|
||||
<View className="min-h-screen bg-gray-50 p-4">
|
||||
|
||||
Reference in New Issue
Block a user