|
|
@@ -1,10 +1,10 @@
|
|
|
-import { useState, useEffect } from 'react'
|
|
|
-import { View, Text, ScrollView, Input, Button as TaroButton } from '@tarojs/components'
|
|
|
+import { useState } from 'react'
|
|
|
+import { View, Text, ScrollView } from '@tarojs/components'
|
|
|
import Taro from '@tarojs/taro'
|
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
|
import { Navbar } from '@/components/ui/navbar'
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
-import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
|
|
+import { Card, CardContent } from '@/components/ui/card'
|
|
|
import { Input as ShadcnInput } from '@/components/ui/input'
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
|
@@ -12,17 +12,10 @@ import { Label } from '@/components/ui/label'
|
|
|
import { useAuth } from '@/utils/auth'
|
|
|
import { passengerClient } from '@/api'
|
|
|
import { IdType } from '@/types/passenger.types'
|
|
|
+import type { InferResponseType } from 'hono/client'
|
|
|
|
|
|
-interface Passenger {
|
|
|
- id: number
|
|
|
- name: string
|
|
|
- idType: IdType
|
|
|
- idNumber: string
|
|
|
- phone: string
|
|
|
- isDefault: boolean
|
|
|
- createdAt: string
|
|
|
- updatedAt: string
|
|
|
-}
|
|
|
+// 使用RPC方式提取类型
|
|
|
+type Passenger = InferResponseType<typeof passengerClient.$get, 200>['data'][0]
|
|
|
|
|
|
const PassengersPage: React.FC = () => {
|
|
|
const { user } = useAuth()
|
|
|
@@ -43,8 +36,14 @@ const PassengersPage: React.FC = () => {
|
|
|
const { data: passengers = [], isLoading } = useQuery({
|
|
|
queryKey: ['passengers'],
|
|
|
queryFn: async () => {
|
|
|
- const response = await passengerClient.$get()
|
|
|
- return await response.json()
|
|
|
+ const response = await passengerClient.$get({ query: { page: 1, pageSize: 100 } })
|
|
|
+ const result = await response.json()
|
|
|
+ // 检查响应是否包含data字段
|
|
|
+ if ('data' in result) {
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ // 如果响应是错误格式,返回空数据
|
|
|
+ return { data: [], total: 0, page: 1, pageSize: 100 }
|
|
|
},
|
|
|
enabled: !!user
|
|
|
})
|
|
|
@@ -70,8 +69,8 @@ const PassengersPage: React.FC = () => {
|
|
|
// 更新乘客
|
|
|
const updateMutation = useMutation({
|
|
|
mutationFn: async ({ id, data }: { id: number; data: Partial<Passenger> }) => {
|
|
|
- const response = await passengerClient[':id'].$patch({
|
|
|
- param: { id: id.toString() },
|
|
|
+ const response = await passengerClient[':id'].$put({
|
|
|
+ param: { id },
|
|
|
json: data
|
|
|
})
|
|
|
return await response.json()
|
|
|
@@ -91,7 +90,7 @@ const PassengersPage: React.FC = () => {
|
|
|
// 删除乘客
|
|
|
const deleteMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
- await passengerClient[':id'].$delete({ param: { id: id.toString() } })
|
|
|
+ await passengerClient[':id'].$delete({ param: { id } })
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
queryClient.invalidateQueries({ queryKey: ['passengers'] })
|
|
|
@@ -107,7 +106,7 @@ const PassengersPage: React.FC = () => {
|
|
|
const setDefaultMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
const response = await passengerClient[':id']['set-default'].$post({
|
|
|
- param: { id: id.toString() }
|
|
|
+ param: { id }
|
|
|
})
|
|
|
return await response.json()
|
|
|
},
|
|
|
@@ -219,12 +218,6 @@ const PassengersPage: React.FC = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // 跳转到独立添加页面
|
|
|
- const navigateToAddPage = () => {
|
|
|
- Taro.navigateTo({
|
|
|
- url: '/pages/passengers/add-passenger?from=management'
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
if (!user) {
|
|
|
return (
|
|
|
@@ -272,7 +265,7 @@ const PassengersPage: React.FC = () => {
|
|
|
<ShadcnInput
|
|
|
placeholder="输入姓名、手机号或证件号"
|
|
|
value={searchKeyword}
|
|
|
- onChange={(e) => setSearchKeyword(e.target.value)}
|
|
|
+ onChange={(value) => setSearchKeyword(value)}
|
|
|
className="w-full"
|
|
|
/>
|
|
|
</View>
|
|
|
@@ -399,7 +392,7 @@ const PassengersPage: React.FC = () => {
|
|
|
id="name"
|
|
|
placeholder="请输入姓名"
|
|
|
value={formData.name}
|
|
|
- onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
|
+ onChange={(value) => setFormData({ ...formData, name: value })}
|
|
|
/>
|
|
|
</View>
|
|
|
|
|
|
@@ -428,7 +421,7 @@ const PassengersPage: React.FC = () => {
|
|
|
id="idNumber"
|
|
|
placeholder="请输入证件号码"
|
|
|
value={formData.idNumber}
|
|
|
- onChange={(e) => setFormData({ ...formData, idNumber: e.target.value })}
|
|
|
+ onChange={(value) => setFormData({ ...formData, idNumber: value })}
|
|
|
/>
|
|
|
</View>
|
|
|
|
|
|
@@ -438,9 +431,7 @@ const PassengersPage: React.FC = () => {
|
|
|
id="phone"
|
|
|
placeholder="请输入手机号"
|
|
|
value={formData.phone}
|
|
|
- onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
|
|
|
- type="number"
|
|
|
- maxLength={11}
|
|
|
+ onChange={(value) => setFormData({ ...formData, phone: value })}
|
|
|
/>
|
|
|
</View>
|
|
|
</View>
|