feat: QR 预览 + 导出面板(PNG/SVG/复制) + 文本/URL 模式

This commit is contained in:
2026-06-17 00:23:23 +08:00
parent 8aacd3bea2
commit 1a4af38bac
5 changed files with 200 additions and 9 deletions
+22
View File
@@ -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"
/>
);
}
+32
View File
@@ -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"
/>
);
}