import * as React from 'react'; import { Form, Input, Select, Cascader, Tag, InputNumber, ColorPicker, Button, Space, message } from 'antd'; import { PlusCircleOutlined, MinusCircleOutlined, CloseCircleOutlined, LinkOutlined } from '@ant-design/icons'; import * as AllIcons from '@ant-design/icons'; import IconPicker from './IconPicker'; import VipSelector from './VipSelector'; import './style.scss'; interface Step1BasicProps { form: any; appTypeList: any[]; appVisibleList: any[]; appProjectList: any[]; isAppPro: boolean; visibleFlag: string | number; vipList: any[]; userInfo: any; onAppChange: (typeId: number) => void; onVisibleChange: (value: any) => void; onRemoveVip: (userId: string) => void; onVipConfirm: (users: any[]) => void; onNext: () => void; onBack: () => void; } interface InputItem { id: number; value: string; } const Step1Basic: React.FC = (props) => { const { form, appTypeList, appVisibleList, appProjectList, isAppPro, visibleFlag, vipList, userInfo, onAppChange, onVisibleChange, onAddVip, onRemoveVip, onNext, onBack, } = props; const [inputs, setInputs] = React.useState([{ id: 1, value: '' }]); const [iconPickerVisible, setIconPickerVisible] = React.useState(false); const [vipSelectorVisible, setVipSelectorVisible] = React.useState(false); const [selectedIcon, setSelectedIcon] = React.useState(null); const [previewBg, setPreviewBg] = React.useState('#005D80'); const getContrastColor = (hex: string) => { const c = hex.replace('#', ''); const r = parseInt(c.substring(0, 2), 16); const g = parseInt(c.substring(2, 4), 16); const b = parseInt(c.substring(4, 6), 16); const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255; return luminance > 0.6 ? '#000' : '#fff'; }; const presetColors = ['#1677ff', '#52c41a', '#fa8c16', '#f5222d', '#722ed1', '#ffffff', '#f0f0f0']; const presetItems = [{ label: '', colors: presetColors }]; const addInput = () => { const newId = inputs.length + 1; setInputs([...inputs, { id: newId, value: '' }]); }; const delInput = (id: number) => { if (inputs.length <= 1) { message.warning("至少保留 1 个预设问题"); return; } setInputs(inputs.filter(input => input.id !== id)); }; const handleChange = (id: number, value: string) => { setInputs(inputs.map(input => (input.id === id ? { ...input, value } : input))); form.setFieldValue('questionList', inputs.map(input => input.value)); }; const handleNext = () => { form.validateFields(['name', 'desc', 'appProId', 'iconType']).then((values) => { form.setFieldValue('questionList', inputs.map(input => input.value)); onNext(); }).catch((error) => { console.error(error); }); }; return (
{selectedIcon ? (() => { const C = (AllIcons as any)[selectedIcon]; const iconColor = getContrastColor(previewBg); return C ? : {selectedIcon}; })() : 预览}
setIconPickerVisible(true)} style={{ fontSize: 13, color: '#1677ff', cursor: 'pointer' }}> 选择图标
背景色:
{ const hex = color.toHexString?.() || color?.toString?.() || previewBg; setPreviewBg(hex); form.setFieldValue('iconColor', hex); }} />
{isAppPro && ( )} {userInfo?.tenantId === '000000' && (visibleFlag === '0' || visibleFlag === 0) && ( handleChange(input.id, e.target.value)} />
delInput(input.id)} />
))}
); }; export default Step1Basic;