import React, { useState } from "react"; import { Switch, Form, Input, Space, Tag, InputNumber, Radio, Tooltip, } from 'antd'; import Styles from './web.module.less'; import EditorRegexs from "./editorRegexs"; export default function Password(props) { const { passport, t, changeEnabled, updateConfig } = props; const { id, type, enabled, stateColor } = passport; const config = passport.config || {}; const [min, setMin] = useState(config?.min || 8); const [max, setMax] = useState(config?.max || 24); const [regexs, setRegexs] = useState(config?.regexs || []); const [tip, setTip] = useState(config?.tip || ''); const [mode, setMode] = useState(config?.mode || 'all'); // useEffect(() => { // const newMin = config?.min || 8; // const newMax = config?.max || 24; // const newRegexs = config?.regexs || []; // const newTip = config?.tip || ''; // const newMode = config?.mode || 'all'; // if (min !== newMin) setMin(newMin); // if (max !== newMax) setMax(newMax); // if (JSON.stringify(regexs) !== JSON.stringify(newRegexs)) setRegexs(newRegexs); // if (tip !== newTip) setTip(newTip); // if (mode !== newMode) setMode(newMode); // }, [config?.min, config?.max, config?.regexs, config?.tip, config?.mode, config?.verify]); return (
{t(`passport:v.type.${type}`)} { changeEnabled(checked); }} disabled={!enabled}/>
{enabled &&
updateConfig(id, config, 'mode', e.target.value, 'password')} value={mode}> 明文与SHA1加密 仅明文 仅SHA1加密 { updateConfig(id, config, 'min', value, 'password'); }}/>
~
{ updateConfig(id, config, 'max', value, 'password'); }}/>
{ updateConfig(id, config, 'verify', checked, 'password'); }}/> <> {!!config?.verify ? (<> { updateConfig(id, config, 'regexs', regexs, 'password'); }}/> ) : (
暂未启用正则校验,无需设置
)}
{ setTip(e.target.value); }} onBlur={() => { if (tip && tip !== config?.tip) { updateConfig(id, config, 'tip', tip, 'password'); } }}/>
}
); }