import React from 'react'; import { View, StyleSheet, Text } from 'react-native'; import Form from '../index'; import Button from '../../Button'; import { ScrollView } from 'react-native'; import BottomSafeArea from '../../BottomSafeArea'; import { Fill, Toast } from '@xrnjs/ui'; import Card from '_global/Card'; type FormData = { city: string[]; category: string[]; level: string[]; department: string[]; priority: string[]; status: string[]; region: string[]; skill: string[]; language: string[]; experience: string[]; education: string[]; gender: string[]; }; // 模拟数据 const cityOptions = [ { label: '北京', value: 'beijing' }, { label: '上海', value: 'shanghai' }, { label: '广州', value: 'guangzhou' }, { label: '深圳', value: 'shenzhen' }, { label: '杭州', value: 'hangzhou' }, { label: '南京', value: 'nanjing' }, { label: '武汉', value: 'wuhan' }, { label: '成都', value: 'chengdu' }, { label: '西安', value: 'xian' }, { label: '重庆', value: 'chongqing' }, ]; const categoryOptions = [ { label: '技术开发', value: 'tech' }, { label: '产品设计', value: 'design' }, { label: '市场营销', value: 'marketing' }, { label: '销售管理', value: 'sales' }, { label: '人力资源', value: 'hr' }, { label: '财务会计', value: 'finance' }, { label: '运营管理', value: 'operation' }, { label: '客户服务', value: 'service' }, ]; const levelOptions = [ { label: '初级', value: 'junior' }, { label: '中级', value: 'middle' }, { label: '高级', value: 'senior' }, { label: '专家', value: 'expert' }, { label: '架构师', value: 'architect' }, ]; const departmentOptions = [ { label: '研发部', value: 'rd' }, { label: '产品部', value: 'product' }, { label: '设计部', value: 'design' }, { label: '市场部', value: 'marketing' }, { label: '销售部', value: 'sales' }, { label: '人事部', value: 'hr' }, { label: '财务部', value: 'finance' }, { label: '运营部', value: 'operation' }, ]; const priorityOptions = [ { label: '低', value: 'low' }, { label: '中', value: 'medium' }, { label: '高', value: 'high' }, { label: '紧急', value: 'urgent' }, ]; const statusOptions = [ { label: '待处理', value: 'pending' }, { label: '进行中', value: 'processing' }, { label: '已完成', value: 'completed' }, { label: '已取消', value: 'cancelled' }, { label: '已暂停', value: 'paused' }, ]; // 级联选择数据 const regionOptions = [ { label: '华北地区', value: 'north', children: [ { label: '北京市', value: 'beijing' }, { label: '天津市', value: 'tianjin' }, { label: '河北省', value: 'hebei' }, { label: '山西省', value: 'shanxi' }, { label: '内蒙古', value: 'neimenggu' }, ], }, { label: '华东地区', value: 'east', children: [ { label: '上海市', value: 'shanghai' }, { label: '江苏省', value: 'jiangsu' }, { label: '浙江省', value: 'zhejiang' }, { label: '安徽省', value: 'anhui' }, { label: '福建省', value: 'fujian' }, { label: '江西省', value: 'jiangxi' }, { label: '山东省', value: 'shandong' }, ], }, { label: '华南地区', value: 'south', children: [ { label: '广东省', value: 'guangdong' }, { label: '广西省', value: 'guangxi' }, { label: '海南省', value: 'hainan' }, ], }, { label: '华中地区', value: 'central', children: [ { label: '湖北省', value: 'hubei' }, { label: '湖南省', value: 'hunan' }, { label: '河南省', value: 'henan' }, ], }, ]; const skillOptions = [ { label: 'JavaScript', value: 'javascript' }, { label: 'TypeScript', value: 'typescript' }, { label: 'React', value: 'react' }, { label: 'React Native', value: 'react-native' }, { label: 'Vue.js', value: 'vue' }, { label: 'Angular', value: 'angular' }, { label: 'Node.js', value: 'nodejs' }, { label: 'Python', value: 'python' }, { label: 'Java', value: 'java' }, { label: 'Go', value: 'go' }, { label: 'Swift', value: 'swift' }, { label: 'Kotlin', value: 'kotlin' }, ]; const languageOptions = [ { label: '中文', value: 'zh' }, { label: 'English', value: 'en' }, { label: '日本語', value: 'ja' }, { label: '한국어', value: 'ko' }, { label: 'Français', value: 'fr' }, { label: 'Deutsch', value: 'de' }, { label: 'Español', value: 'es' }, { label: 'Русский', value: 'ru' }, ]; const experienceOptions = [ { label: '应届毕业生', value: 'fresh' }, { label: '1年以下', value: 'less-1' }, { label: '1-3年', value: '1-3' }, { label: '3-5年', value: '3-5' }, { label: '5-10年', value: '5-10' }, { label: '10年以上', value: 'more-10' }, ]; const educationOptions = [ { label: '高中及以下', value: 'high-school' }, { label: '大专', value: 'college' }, { label: '本科', value: 'bachelor' }, { label: '硕士', value: 'master' }, { label: '博士', value: 'doctor' }, ]; const genderOptions = [ { label: '男', value: 'male' }, { label: '女', value: 'female' }, { label: '不便透露', value: 'other' }, ]; const PickerExamplesDemo: React.FC = () => { const form = Form.useForm({ defaultValues: { city: [], priority: ['medium'], // 默认选中中等优先级 language: ['zh'], // 默认选中中文 }, }); const [cityFixed, setCityFixed] = React.useState<(string | number)[]>([ 'shanghai', ]); const onSubmit = (data: FormData) => { console.log('Form submitted:', data); // 获取选中项的标签文本用于显示 const getLabel = (options: any[], value: string[]) => { return ( options.find((option) => value.includes(option.value))?.label || value ); }; const cityLabel = getLabel(cityOptions, data.city); const categoryLabel = getLabel(categoryOptions, data.category); const priorityLabel = getLabel(priorityOptions, data.priority); Toast( `提交成功!\n城市: ${cityLabel || '未选择'}\n职业类别: ${ categoryLabel || '未选择' }\n优先级: ${priorityLabel || '未选择'}` ); }; const onError = (errors: Record) => { console.log('Form errors:', errors); }; return ( {/* 基础单选示例 */} { const category = form.getValues('category'); if (category.includes('tech') && value === 'junior') { return '技术开发岗位要求中级以上技能等级'; } return true; }, }} message="选择您的技能等级" /> {/* 带默认值和验证的示例 */} { const category = form.getValues('category'); if ( category.includes('tech') && !['rd', 'product'].includes(value) ) { return '技术开发类别应选择研发部或产品部'; } return true; }, }} message="选择您所属的部门" /> {/* 级联选择示例 */} { if (!value || value.length < 2) { return '请选择完整的地区信息'; } return true; }, }} > {/* 高级配置示例 */} { const category = form.getValues('category'); if ( category.includes('tech') && ![ 'javascript', 'typescript', 'react', 'react-native', 'vue', 'angular', 'nodejs', ].includes(value) ) { return '技术开发类别请选择前端或后端相关技能'; } return true; }, }} message="选择您最擅长的技能" confirmButtonText="确认技能" cancelButtonText="重新选择" title="选择技能" /> { const level = form.getValues('level'); if ( level.includes('senior') && ['fresh', 'less-1', '1-3'].includes(value) ) { return '高级技能等级需要3年以上工作经验'; } if ( level.includes('expert') && !['5-10', 'more-10'].includes(value) ) { return '专家级别需要5年以上工作经验'; } return true; }, }} message="选择您的工作经验年限" /> {/* 不同样式配置示例 */} {/* 禁用状态示例 */} {/* 自定义验证示例 */} { const { category, level, experience, education } = form.getValues(); // 技术岗位的复合验证 if (category.includes('tech')) { if ( level.includes('expert') && education.includes('high-school') ) { return '技术专家级别通常需要大专以上学历'; } if ( level.includes('architect') && !['bachelor', 'master', 'doctor'].some((ed) => education.includes(ed) ) ) { return '架构师级别通常需要本科以上学历'; } if ( level.includes('senior') && experience.includes('fresh') ) { return '高级技术人员不能是应届毕业生'; } } return true; }, }} > 当前值:{cityFixed} setCityFixed(v)} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, scrollContainer: { flex: 1, padding: 20, paddingBottom: 0, }, cardStyle: { marginBottom: 16, }, fixedButtonContainer: { backgroundColor: '#fff', paddingHorizontal: 20, paddingTop: 16, paddingBottom: 30, borderTopWidth: 1, borderTopColor: '#e5e5e5', flexDirection: 'row', justifyContent: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: -2, }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 8, }, buttonSpacer: { width: 20, }, }); export default PickerExamplesDemo;