card: кнопка «Добавить в контакты» + надёжное открытие vCard на iOS
This commit is contained in:
@@ -55,15 +55,21 @@ export function CardPage() {
|
|||||||
if (b64 && b64.length < 60000) lines.push(`PHOTO;ENCODING=b;TYPE=${type}:${b64}`);
|
if (b64 && b64.length < 60000) lines.push(`PHOTO;ENCODING=b;TYPE=${type}:${b64}`);
|
||||||
}
|
}
|
||||||
lines.push('END:VCARD');
|
lines.push('END:VCARD');
|
||||||
|
const vcard = lines.join('\r\n');
|
||||||
try {
|
try {
|
||||||
const blob = new Blob([lines.join('\r\n')], { type: 'text/vcard;charset=utf-8' });
|
const isIOS = /iP(hone|ad|od)/.test(navigator.userAgent);
|
||||||
const url = URL.createObjectURL(blob);
|
if (isIOS) {
|
||||||
const a = document.createElement('a');
|
window.location.href = 'data:text/vcard;charset=utf-8,' + encodeURIComponent(vcard);
|
||||||
a.href = url; a.download = `${card.slug}.vcf`;
|
} else {
|
||||||
document.body.appendChild(a); a.click(); a.remove();
|
const blob = new Blob([vcard], { type: 'text/vcard;charset=utf-8' });
|
||||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
const url = URL.createObjectURL(blob);
|
||||||
toast('Контакт сохранён ✓');
|
const a = document.createElement('a');
|
||||||
} catch { toast('Откройте на телефоне для сохранения'); }
|
a.href = url; a.download = `${card.slug}.vcf`;
|
||||||
|
document.body.appendChild(a); a.click(); a.remove();
|
||||||
|
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||||
|
}
|
||||||
|
toast('Открываю карточку контакта…');
|
||||||
|
} catch { toast('Не удалось открыть'); }
|
||||||
}
|
}
|
||||||
function toast(msg: string) {
|
function toast(msg: string) {
|
||||||
const t = document.getElementById('cp-toast');
|
const t = document.getElementById('cp-toast');
|
||||||
@@ -120,7 +126,7 @@ export function CardPage() {
|
|||||||
|
|
||||||
<button className="save reveal d5" onClick={saveContact}>
|
<button className="save reveal d5" onClick={saveContact}>
|
||||||
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /><circle cx="12" cy="7" r="4" /></svg>
|
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" /><circle cx="12" cy="7" r="4" /></svg>
|
||||||
Сохранить контакт
|
Добавить в контакты
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{card.product_title && (
|
{card.product_title && (
|
||||||
|
|||||||
Reference in New Issue
Block a user