feat: QR 预览 + 导出面板(PNG/SVG/复制) + 文本/URL 模式
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useQrState } from '../store/qrContext';
|
||||
import { useQrEncode } from '../hooks/useQrEncode';
|
||||
|
||||
export default function TextMode() {
|
||||
const { state, dispatch } = useQrState();
|
||||
const { encode } = useQrEncode();
|
||||
|
||||
const handleChange = (text: string) => {
|
||||
dispatch({ type: 'SET_FORM_DATA', payload: { text } });
|
||||
encode(text);
|
||||
};
|
||||
|
||||
return (
|
||||
<textarea
|
||||
placeholder="输入任意文本..."
|
||||
value={state.formData.text || ''}
|
||||
onChange={e => handleChange(e.target.value)}
|
||||
rows={3}
|
||||
className="w-full h-full resize-none px-4 py-2 text-sm bg-transparent outline-none placeholder-gray-400 dark:placeholder-gray-600"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useQrState } from '../store/qrContext';
|
||||
import { useQrEncode } from '../hooks/useQrEncode';
|
||||
|
||||
export default function UrlMode() {
|
||||
const { state, dispatch } = useQrState();
|
||||
const { encode } = useQrEncode();
|
||||
|
||||
const handleChange = (url: string) => {
|
||||
dispatch({ type: 'SET_FORM_DATA', payload: { url } });
|
||||
encode(url);
|
||||
};
|
||||
|
||||
const handleBlur = () => {
|
||||
const url = state.formData.url || '';
|
||||
if (url && !/^https?:\/\//i.test(url)) {
|
||||
const corrected = `https://${url}`;
|
||||
dispatch({ type: 'SET_FORM_DATA', payload: { url: corrected } });
|
||||
encode(corrected);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<input
|
||||
type="url"
|
||||
placeholder="https://example.com"
|
||||
value={state.formData.url || ''}
|
||||
onChange={e => handleChange(e.target.value)}
|
||||
onBlur={handleBlur}
|
||||
className="w-full h-full px-4 text-sm bg-transparent outline-none placeholder-gray-400 dark:placeholder-gray-600"
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user