|
@@ -1,62 +0,0 @@
|
|
|
-import React from 'react';
|
|
|
|
|
-import { Controller, useFormContext } from 'react-hook-form';
|
|
|
|
|
-import { AreaSelect } from './AreaSelect';
|
|
|
|
|
-import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from '@d8d/shared-ui-components/components/ui/form';
|
|
|
|
|
-
|
|
|
|
|
-interface AreaSelectFieldProps {
|
|
|
|
|
- name: string;
|
|
|
|
|
- label?: string;
|
|
|
|
|
- description?: string;
|
|
|
|
|
- required?: boolean;
|
|
|
|
|
- disabled?: boolean;
|
|
|
|
|
- className?: string;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export const AreaSelectField: React.FC<AreaSelectFieldProps> = ({
|
|
|
|
|
- name,
|
|
|
|
|
- label = '地区选择',
|
|
|
|
|
- description,
|
|
|
|
|
- required = false,
|
|
|
|
|
- disabled = false,
|
|
|
|
|
- className
|
|
|
|
|
-}) => {
|
|
|
|
|
- const { control } = useFormContext();
|
|
|
|
|
-
|
|
|
|
|
- return (
|
|
|
|
|
- <Controller
|
|
|
|
|
- name={name}
|
|
|
|
|
- control={control}
|
|
|
|
|
- render={({ field, fieldState }) => {
|
|
|
|
|
- // 将字段值转换为 AreaSelect 需要的格式
|
|
|
|
|
- const value = {
|
|
|
|
|
- provinceId: field.value?.provinceId || undefined,
|
|
|
|
|
- cityId: field.value?.cityId || undefined,
|
|
|
|
|
- districtId: field.value?.districtId || undefined
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- return (
|
|
|
|
|
- <FormItem className={className}>
|
|
|
|
|
- {label && (
|
|
|
|
|
- <FormLabel>
|
|
|
|
|
- {label}{required && <span className="text-destructive">*</span>}
|
|
|
|
|
- </FormLabel>
|
|
|
|
|
- )}
|
|
|
|
|
- <FormControl>
|
|
|
|
|
- <AreaSelect
|
|
|
|
|
- value={value}
|
|
|
|
|
- onChange={(newValue) => {
|
|
|
|
|
- // 更新表单字段值
|
|
|
|
|
- field.onChange(newValue);
|
|
|
|
|
- }}
|
|
|
|
|
- disabled={disabled}
|
|
|
|
|
- required={required}
|
|
|
|
|
- />
|
|
|
|
|
- </FormControl>
|
|
|
|
|
- {description && <FormDescription>{description}</FormDescription>}
|
|
|
|
|
- <FormMessage>{fieldState.error?.message}</FormMessage>
|
|
|
|
|
- </FormItem>
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
-};
|
|
|