|
|
@@ -13,6 +13,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|
|
import { toast } from 'sonner';
|
|
|
import { DataTablePagination } from '@/client/admin-shadcn/components/DataTablePagination';
|
|
|
import AvatarSelector from '@/client/admin-shadcn/components/AvatarSelector';
|
|
|
+import AdvertisementTypeSelector from '@/client/admin-shadcn/components/AdvertisementTypeSelector';
|
|
|
import { advertisementClient } from '@/client/api';
|
|
|
import type { InferRequestType, InferResponseType } from 'hono/client';
|
|
|
import { CreateAdvertisementDto, UpdateAdvertisementDto } from '@/server/modules/advertisements/advertisement.schema';
|
|
|
@@ -53,15 +54,7 @@ export const AdvertisementsPage = () => {
|
|
|
defaultValues: {}
|
|
|
});
|
|
|
|
|
|
- // 获取广告类型列表
|
|
|
- const { data: advertisementTypes } = useQuery({
|
|
|
- queryKey: ['advertisement-types'],
|
|
|
- queryFn: async () => {
|
|
|
- const res = await advertisementClient.types.$get();
|
|
|
- if (res.status !== 200) throw new Error('获取广告类型失败');
|
|
|
- return await res.json();
|
|
|
- }
|
|
|
- });
|
|
|
+ // 获取广告类型列表 - 现在由 AdvertisementTypeSelector 内部处理
|
|
|
|
|
|
// 数据查询
|
|
|
const { data, isLoading, refetch } = useQuery({
|
|
|
@@ -284,7 +277,7 @@ export const AdvertisementsPage = () => {
|
|
|
<TableCell>{advertisement.id}</TableCell>
|
|
|
<TableCell>{advertisement.title || '-'}</TableCell>
|
|
|
<TableCell>
|
|
|
- {advertisementTypes?.data.find(t => t.id === advertisement.typeId)?.name || '-'}
|
|
|
+ {advertisement.advertisementType?.name || '-'}
|
|
|
</TableCell>
|
|
|
<TableCell>
|
|
|
<code className="text-xs bg-muted px-1 rounded">{advertisement.code || '-'}</code>
|
|
|
@@ -343,10 +336,10 @@ export const AdvertisementsPage = () => {
|
|
|
)}
|
|
|
|
|
|
<DataTablePagination
|
|
|
- current={searchParams.page}
|
|
|
+ currentPage={searchParams.page}
|
|
|
pageSize={searchParams.limit}
|
|
|
- total={data?.pagination.total || 0}
|
|
|
- onChange={(page, limit) => setSearchParams(prev => ({ ...prev, page, limit }))}
|
|
|
+ totalCount={data?.pagination.total || 0}
|
|
|
+ onPageChange={(page, limit) => setSearchParams(prev => ({ ...prev, page, limit }))}
|
|
|
/>
|
|
|
</CardContent>
|
|
|
</Card>
|
|
|
@@ -391,17 +384,11 @@ export const AdvertisementsPage = () => {
|
|
|
广告类型 <span className="text-red-500 ml-1">*</span>
|
|
|
</FormLabel>
|
|
|
<FormControl>
|
|
|
- <select
|
|
|
- {...field}
|
|
|
- className="h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
|
|
|
- value={field.value || ''}
|
|
|
- onChange={(e) => field.onChange(parseInt(e.target.value))}
|
|
|
- >
|
|
|
- <option value="">请选择广告类型</option>
|
|
|
- {advertisementTypes?.data.map(type => (
|
|
|
- <option key={type.id} value={type.id}>{type.name}</option>
|
|
|
- ))}
|
|
|
- </select>
|
|
|
+ <AdvertisementTypeSelector
|
|
|
+ value={field.value}
|
|
|
+ onChange={field.onChange}
|
|
|
+ placeholder="请选择广告类型"
|
|
|
+ />
|
|
|
</FormControl>
|
|
|
<FormMessage />
|
|
|
</FormItem>
|
|
|
@@ -570,17 +557,10 @@ export const AdvertisementsPage = () => {
|
|
|
广告类型 <span className="text-red-500 ml-1">*</span>
|
|
|
</FormLabel>
|
|
|
<FormControl>
|
|
|
- <select
|
|
|
- {...field}
|
|
|
- className="h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
|
|
|
- value={field.value || ''}
|
|
|
- onChange={(e) => field.onChange(parseInt(e.target.value))}
|
|
|
- >
|
|
|
- <option value="">请选择广告类型</option>
|
|
|
- {advertisementTypes?.data.map(type => (
|
|
|
- <option key={type.id} value={type.id}>{type.name}</option>
|
|
|
- ))}
|
|
|
- </select>
|
|
|
+ <AdvertisementTypeSelector
|
|
|
+ value={field.value}
|
|
|
+ onChange={field.onChange}
|
|
|
+ />
|
|
|
</FormControl>
|
|
|
<FormMessage />
|
|
|
</FormItem>
|