| | |
| | | /** 表单类型 */ |
| | | export type FormType = 'create' | 'update' | 'detail'; |
| | | |
| | | export interface LocationFormCallbacks { |
| | | onLatitudeChange?: (value?: number) => void; |
| | | onLocationRequiredChange?: (value: boolean) => void; |
| | | onLongitudeChange?: (value?: number) => void; |
| | | onRadiusChange?: (value?: number) => void; |
| | | } |
| | | |
| | | /** 新增/编辑考勤规则的表单 */ |
| | | export function useFormSchema(formType: FormType): VbenFormSchema[] { |
| | | export function useFormSchema( |
| | | formType: FormType, |
| | | locationCallbacks: LocationFormCallbacks = {}, |
| | | ): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | fieldName: 'id', |
| | |
| | | defaultValue: false, |
| | | componentProps: { |
| | | checkedChildren: '启用', |
| | | onChange: locationCallbacks.onLocationRequiredChange, |
| | | unCheckedChildren: '关闭', |
| | | }, |
| | | }, |
| | |
| | | fieldName: 'longitude', |
| | | label: '经度(WGS84)', |
| | | component: 'InputNumber', |
| | | componentProps: { min: -180, max: 180, precision: 7, style: { width: '100%' } }, |
| | | componentProps: { |
| | | min: -180, |
| | | max: 180, |
| | | onChange: locationCallbacks.onLongitudeChange, |
| | | precision: 7, |
| | | style: { width: '100%' }, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['locationRequired'], |
| | | show: (values) => Boolean(values.locationRequired), |
| | |
| | | fieldName: 'latitude', |
| | | label: '纬度(WGS84)', |
| | | component: 'InputNumber', |
| | | componentProps: { min: -90, max: 90, precision: 7, style: { width: '100%' } }, |
| | | componentProps: { |
| | | min: -90, |
| | | max: 90, |
| | | onChange: locationCallbacks.onLatitudeChange, |
| | | precision: 7, |
| | | style: { width: '100%' }, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['locationRequired'], |
| | | show: (values) => Boolean(values.locationRequired), |
| | |
| | | fieldName: 'radiusMeters', |
| | | label: '打卡半径(米)', |
| | | component: 'InputNumber', |
| | | defaultValue: 100, |
| | | componentProps: { min: 10, max: 5000, precision: 0, style: { width: '100%' } }, |
| | | defaultValue: 10, |
| | | componentProps: { |
| | | min: 10, |
| | | max: 5000, |
| | | onChange: locationCallbacks.onRadiusChange, |
| | | precision: 0, |
| | | style: { width: '100%' }, |
| | | }, |
| | | help: '最小可设 10 米;实际精度取决于手机 GPS 与环境', |
| | | dependencies: { |
| | | triggerFields: ['locationRequired'], |