Update App.jsx via upload script - 2026-11-12 15:17:14
This commit is contained in:
parent
0bbc5b5f44
commit
d4f7b138c5
112
App.jsx
112
App.jsx
|
|
@ -1851,6 +1851,15 @@ const Styles = () => (
|
||||||
.jms-spin { animation: jms-spin .8s linear infinite; }
|
.jms-spin { animation: jms-spin .8s linear infinite; }
|
||||||
@keyframes jms-spin { to { transform: rotate(360deg); } }
|
@keyframes jms-spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
.jms-links { display: flex; flex-direction: column; gap: 6px; }
|
||||||
|
.jms-link-row { display: flex; align-items: center; gap: 4px; }
|
||||||
|
.jms-link-name { width: 82px; flex-shrink: 0; font-size: 11.5px; color: var(--ink-soft); border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
|
input.jms-link-name:hover, input.jms-link-name:focus { border-color: var(--line); background: var(--bg); outline: none; }
|
||||||
|
.jms-link-url { flex: 1; min-width: 0; font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--bg); color: var(--ink); }
|
||||||
|
.jms-link-url:focus { outline: none; border-color: var(--ink-soft); background: var(--panel); }
|
||||||
|
.jms-link-btn { padding: 4px 6px; flex-shrink: 0; }
|
||||||
|
.jms-link-add { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-soft); background: none; border: 1px dashed var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
|
||||||
|
.jms-link-add:hover { color: var(--ink); border-color: var(--ink-soft); }
|
||||||
.jms-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
.jms-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||||
.jms-card-actions .btn { flex: 1; justify-content: center; }
|
.jms-card-actions .btn { flex: 1; justify-content: center; }
|
||||||
|
|
||||||
|
|
@ -6370,6 +6379,38 @@ function jmsBuildLink(line) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 主链接:手动填写的优先,留空则按参数自动生成
|
||||||
|
function jmsMainLink(line) {
|
||||||
|
return String(line.link || '').trim() || jmsBuildLink(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 卡片上可直接编辑的链接行:失焦或回车保存,Esc 取消
|
||||||
|
function JmsLinkRow({ label, url, placeholder, onNameChange, onUrlChange, onCopy, onQr, onReset, onRemove }) {
|
||||||
|
const [u, setU] = useState(url || '');
|
||||||
|
const [n, setN] = useState(label || '');
|
||||||
|
useEffect(() => { setU(url || ''); }, [url]);
|
||||||
|
useEffect(() => { setN(label || ''); }, [label]);
|
||||||
|
const commitU = () => { if (u.trim() !== (url || '').trim()) onUrlChange(u.trim()); };
|
||||||
|
const commitN = () => { if (onNameChange && n.trim() !== (label || '').trim()) onNameChange(n.trim()); };
|
||||||
|
const keys = (commit, reset) => (e) => {
|
||||||
|
if (e.key === 'Enter') { e.preventDefault(); e.currentTarget.blur(); }
|
||||||
|
if (e.key === 'Escape') { reset(); setTimeout(() => e.target.blur(), 0); }
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="jms-link-row">
|
||||||
|
{onNameChange
|
||||||
|
? <input className="jms-link-name" value={n} placeholder="名称" onChange={e => setN(e.target.value)} onBlur={commitN} onKeyDown={keys(commitN, () => setN(label || ''))} />
|
||||||
|
: <span className="jms-link-name jms-link-name-fixed">{label}</span>}
|
||||||
|
<input className="jms-link-url" value={u} placeholder={placeholder || '粘贴链接 ss:// vless:// https://…'} spellCheck={false}
|
||||||
|
onChange={e => setU(e.target.value)} onBlur={commitU} onKeyDown={keys(commitU, () => setU(url || ''))} onFocus={e => e.target.select()} />
|
||||||
|
<button className="btn btn-sm btn-ghost jms-link-btn" onClick={() => onCopy(u.trim())} title="复制链接"><Copy size={12} /></button>
|
||||||
|
<button className="btn btn-sm btn-ghost jms-link-btn" onClick={() => onQr(u.trim())} title="二维码"><QrCode size={12} /></button>
|
||||||
|
{onReset && <button className="btn btn-sm btn-ghost jms-link-btn" onClick={onReset} title="恢复为按参数自动生成的链接"><RefreshCw size={12} /></button>}
|
||||||
|
{onRemove && <button className="btn btn-sm btn-ghost btn-danger jms-link-btn" onClick={onRemove} title="删除此链接"><Trash2 size={12} /></button>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function jmsResolveIp(domain) {
|
async function jmsResolveIp(domain) {
|
||||||
const res = await fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=A`, {
|
const res = await fetch(`https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=A`, {
|
||||||
headers: { Accept: 'application/dns-json' },
|
headers: { Accept: 'application/dns-json' },
|
||||||
|
|
@ -6386,11 +6427,16 @@ function jmsCopyText(text, label, onNotify) {
|
||||||
.catch(() => onNotify && onNotify('复制失败,请手动选择'));
|
.catch(() => onNotify && onNotify('复制失败,请手动选择'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function JmsLineCard({ line, idx, ip, dragIdx, onDragStart, onDropCard, onDragEnd, onRefreshIp, onCopy, onQr, onDuplicate, onEdit, onDelete, onNotify }) {
|
function JmsLineCard({ line, idx, ip, dragIdx, onDragStart, onDropCard, onDragEnd, onRefreshIp, onCopy, onQr, onDuplicate, onEdit, onDelete, onPatch, onNotify }) {
|
||||||
const meta = JMS_PROTO_META[line.protocol] || { label: line.protocol };
|
const meta = JMS_PROTO_META[line.protocol] || { label: line.protocol };
|
||||||
const ipDisplay = ip === 'resolving' ? '解析中…' : (ip || '解析中…');
|
const ipDisplay = ip === 'resolving' ? '解析中…' : (ip || '解析中…');
|
||||||
const hasPassword = line.protocol === 'ss' && !!line.password;
|
const hasPassword = line.protocol === 'ss' && !!line.password;
|
||||||
const hasMethod = line.protocol === 'ss' && !!line.method;
|
const hasMethod = line.protocol === 'ss' && !!line.method;
|
||||||
|
const autoLink = line.addr && line.port ? jmsBuildLink(line) : '';
|
||||||
|
const isCustom = !!String(line.link || '').trim();
|
||||||
|
const extras = Array.isArray(line.extraLinks) ? line.extraLinks : [];
|
||||||
|
const setExtra = (i, patch) => onPatch({ extraLinks: extras.map((x, k) => (k === i ? { ...x, ...patch } : x)) });
|
||||||
|
const copyUrl = (url) => jmsCopyText(url, '链接', onNotify);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
@ -6443,6 +6489,30 @@ function JmsLineCard({ line, idx, ip, dragIdx, onDragStart, onDropCard, onDragEn
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="jms-links">
|
||||||
|
<JmsLinkRow
|
||||||
|
label={isCustom ? '订阅链接 · 手动' : '订阅链接'}
|
||||||
|
url={jmsMainLink(line)}
|
||||||
|
placeholder={autoLink ? '' : '填写订阅链接'}
|
||||||
|
onUrlChange={(v) => onPatch({ link: v === autoLink ? '' : v })}
|
||||||
|
onCopy={copyUrl}
|
||||||
|
onQr={(u) => onQr(line, u)}
|
||||||
|
onReset={isCustom && autoLink ? () => onPatch({ link: '' }) : null}
|
||||||
|
/>
|
||||||
|
{extras.map((x, i) => (
|
||||||
|
<JmsLinkRow
|
||||||
|
key={i}
|
||||||
|
label={x.name || ''}
|
||||||
|
url={x.url || ''}
|
||||||
|
onNameChange={(v) => setExtra(i, { name: v })}
|
||||||
|
onUrlChange={(v) => setExtra(i, { url: v })}
|
||||||
|
onCopy={copyUrl}
|
||||||
|
onQr={(u) => onQr(line, u, x.name)}
|
||||||
|
onRemove={() => onPatch({ extraLinks: extras.filter((_, k) => k !== i) })}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<button className="jms-link-add" onClick={() => onPatch({ extraLinks: [...extras, { name: `链接${extras.length + 2}`, url: '' }] })}><Plus size={12} />添加链接</button>
|
||||||
|
</div>
|
||||||
<div className="jms-card-actions">
|
<div className="jms-card-actions">
|
||||||
<button className="btn btn-sm" onClick={() => onCopy(line)}><Copy size={13} />复制链接</button>
|
<button className="btn btn-sm" onClick={() => onCopy(line)}><Copy size={13} />复制链接</button>
|
||||||
<button className="btn btn-sm" onClick={() => onQr(line)}><QrCode size={13} />二维码</button>
|
<button className="btn btn-sm" onClick={() => onQr(line)}><QrCode size={13} />二维码</button>
|
||||||
|
|
@ -6527,17 +6597,19 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
|
||||||
}, [lines]);
|
}, [lines]);
|
||||||
|
|
||||||
function copyLink(line) {
|
function copyLink(line) {
|
||||||
const link = jmsBuildLink(line);
|
const link = jmsMainLink(line);
|
||||||
|
if (!link) { onNotify('没有可复制的链接'); return; }
|
||||||
navigator.clipboard.writeText(link).then(() => onNotify('订阅链接已复制')).catch(() => onNotify('复制失败,请手动选择'));
|
navigator.clipboard.writeText(link).then(() => onNotify('订阅链接已复制')).catch(() => onNotify('复制失败,请手动选择'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openQr(line) {
|
async function openQr(line, url, label) {
|
||||||
setQrLine(line);
|
const link = url !== undefined ? url : jmsMainLink(line);
|
||||||
|
if (!link) { onNotify('链接为空,无法生成二维码'); return; }
|
||||||
|
setQrLine({ ...line, _qrUrl: link, _qrLabel: label });
|
||||||
setQrDataUrl('');
|
setQrDataUrl('');
|
||||||
try {
|
try {
|
||||||
const mod = await import('qrcode');
|
const mod = await import('qrcode');
|
||||||
const QRCode = mod.default || mod;
|
const QRCode = mod.default || mod;
|
||||||
const link = jmsBuildLink(line);
|
|
||||||
const dataUrl = await QRCode.toDataURL(link, { width: 220, margin: 1, color: { dark: '#18233A', light: '#ffffff' } });
|
const dataUrl = await QRCode.toDataURL(link, { width: 220, margin: 1, color: { dark: '#18233A', light: '#ffffff' } });
|
||||||
setQrDataUrl(dataUrl);
|
setQrDataUrl(dataUrl);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -6569,12 +6641,14 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
|
||||||
|
|
||||||
function handleProtocolChange(p) {
|
function handleProtocolChange(p) {
|
||||||
setProtocol(p);
|
setProtocol(p);
|
||||||
setDraft(d => ({ name: d.name, addr: d.addr, port: d.port }));
|
setDraft(d => ({ name: d.name, addr: d.addr, port: d.port, link: d.link, extraLinks: d.extraLinks }));
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
if (!draft.addr || !draft.port) { onNotify('请填写服务器地址和端口'); return; }
|
const hasLink = String(draft.link || '').trim() || (draft.extraLinks || []).some(x => String(x.url || '').trim());
|
||||||
onSave({ ...draft, protocol }, editingId);
|
if ((!draft.addr || !draft.port) && !hasLink) { onNotify('请填写服务器地址和端口,或直接填写订阅链接'); return; }
|
||||||
|
const extraLinks = (draft.extraLinks || []).map(x => ({ name: String(x.name || '').trim(), url: String(x.url || '').trim() })).filter(x => x.url || x.name);
|
||||||
|
onSave({ ...draft, link: String(draft.link || '').trim(), extraLinks, protocol }, editingId);
|
||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6612,6 +6686,7 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
|
||||||
onDuplicate={duplicateLine}
|
onDuplicate={duplicateLine}
|
||||||
onEdit={openEditModal}
|
onEdit={openEditModal}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
onPatch={(patch) => onSave({ ...line, ...patch }, line.id)}
|
||||||
onNotify={onNotify}
|
onNotify={onNotify}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
@ -6639,6 +6714,21 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
|
||||||
<div className="field"><span className="field-label">端口</span><input className="input" value={draft.port || ''} onChange={e => setDraft(d => ({ ...d, port: e.target.value }))} placeholder="8388" /></div>
|
<div className="field"><span className="field-label">端口</span><input className="input" value={draft.port || ''} onChange={e => setDraft(d => ({ ...d, port: e.target.value }))} placeholder="8388" /></div>
|
||||||
</div>
|
</div>
|
||||||
<JmsLineFormFields protocol={protocol} draft={draft} setDraft={setDraft} />
|
<JmsLineFormFields protocol={protocol} draft={draft} setDraft={setDraft} />
|
||||||
|
<div className="field">
|
||||||
|
<span className="field-label">订阅链接(可选 · 留空则按上面参数自动生成)</span>
|
||||||
|
<textarea className="input" rows={2} style={{ fontFamily: "'IBM Plex Mono', monospace", fontSize: 12 }} value={draft.link || ''} onChange={e => setDraft(d => ({ ...d, link: e.target.value }))} placeholder={(draft.addr && draft.port && jmsBuildLink({ ...draft, protocol })) || 'ss:// 或 vless:// 链接'} />
|
||||||
|
</div>
|
||||||
|
<div className="field">
|
||||||
|
<span className="field-label">其他链接</span>
|
||||||
|
{(draft.extraLinks || []).map((x, i) => (
|
||||||
|
<div key={i} style={{ display: 'flex', gap: 6, marginBottom: 6 }}>
|
||||||
|
<input className="input" style={{ width: 110, flexShrink: 0 }} value={x.name || ''} placeholder="名称" onChange={e => setDraft(d => ({ ...d, extraLinks: d.extraLinks.map((y, k) => (k === i ? { ...y, name: e.target.value } : y)) }))} />
|
||||||
|
<input className="input" style={{ flex: 1, fontFamily: "'IBM Plex Mono', monospace", fontSize: 12 }} value={x.url || ''} placeholder="链接" onChange={e => setDraft(d => ({ ...d, extraLinks: d.extraLinks.map((y, k) => (k === i ? { ...y, url: e.target.value } : y)) }))} />
|
||||||
|
<button className="btn btn-sm btn-ghost btn-danger" onClick={() => setDraft(d => ({ ...d, extraLinks: d.extraLinks.filter((_, k) => k !== i) }))}><Trash2 size={12} /></button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<button className="btn btn-sm" style={{ alignSelf: 'flex-start' }} onClick={() => setDraft(d => ({ ...d, extraLinks: [...(d.extraLinks || []), { name: '', url: '' }] }))}><Plus size={12} />添加链接</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-foot"><button className="btn" onClick={closeModal}>取消</button><button className="btn btn-primary" onClick={handleSave}><Save size={13} />保存</button></div>
|
<div className="modal-foot"><button className="btn" onClick={closeModal}>取消</button><button className="btn btn-primary" onClick={handleSave}><Save size={13} />保存</button></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -6649,13 +6739,13 @@ function JmsPage({ lines, onSave, onDelete, onReorder, onNotify }) {
|
||||||
<div className="modal-overlay" onClick={() => setQrLine(null)}>
|
<div className="modal-overlay" onClick={() => setQrLine(null)}>
|
||||||
<div className="modal-box" style={{ maxWidth: 320, textAlign: 'center' }} onClick={e => e.stopPropagation()}>
|
<div className="modal-box" style={{ maxWidth: 320, textAlign: 'center' }} onClick={e => e.stopPropagation()}>
|
||||||
<div className="modal-head">
|
<div className="modal-head">
|
||||||
<div className="panel-title">{qrLine.name || qrLine.addr} 订阅二维码</div>
|
<div className="panel-title">{qrLine.name || qrLine.addr} {qrLine._qrLabel || '订阅'}二维码</div>
|
||||||
<button className="btn btn-ghost btn-sm" onClick={() => setQrLine(null)}><X size={14} /></button>
|
<button className="btn btn-ghost btn-sm" onClick={() => setQrLine(null)}><X size={14} /></button>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-body" style={{ alignItems: 'center' }}>
|
<div className="modal-body" style={{ alignItems: 'center' }}>
|
||||||
{qrDataUrl ? <img src={qrDataUrl} alt="订阅二维码" style={{ width: 220, height: 220, borderRadius: 8 }} /> : <div style={{ padding: 40 }}>生成中…</div>}
|
{qrDataUrl ? <img src={qrDataUrl} alt="订阅二维码" style={{ width: 220, height: 220, borderRadius: 8 }} /> : <div style={{ padding: 40 }}>生成中…</div>}
|
||||||
<div className="jms-qr-link">{jmsBuildLink(qrLine)}</div>
|
<div className="jms-qr-link">{qrLine._qrUrl}</div>
|
||||||
<button className="btn btn-primary" style={{ width: '100%' }} onClick={() => copyLink(qrLine)}><Copy size={13} />复制订阅链接</button>
|
<button className="btn btn-primary" style={{ width: '100%' }} onClick={() => jmsCopyText(qrLine._qrUrl, '链接', onNotify)}><Copy size={13} />复制链接</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue