fix: polish forum navigation and interface states
This commit is contained in:
1 parent
0933220c70
commit
6947cdaf36
33 files changed
+1615
-360
No files matched your search
@@ -2,10 +2,14 @@
|
||||
|
||||
// 管理后台 - 友情链接管理
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API } from '@/lib/api';
|
||||
import { Icon } from '../Icons';
|
||||
import { useToast } from '../Toast';
|
||||
|
||||
export default function AdminLinks() {
|
||||
const { t } = useTranslation();
|
||||
const { toast, confirmAction } = useToast();
|
||||
const [links, setLinks] = useState([]);
|
||||
const [title, setTitle] = useState('');
|
||||
const [url, setUrl] = useState('');
|
||||
@@ -14,24 +18,24 @@ export default function AdminLinks() {
|
||||
useEffect(load, []);
|
||||
|
||||
const handleAdd = async () => {
|
||||
if (!title.trim() || !url.trim()) { alert('请填写完整信息'); return; }
|
||||
if (!title.trim() || !url.trim()) { toast(t('admin.link.incomplete'), 'warning'); return; }
|
||||
try {
|
||||
await API.addLink(title.trim(), url.trim());
|
||||
setTitle('');
|
||||
setUrl('');
|
||||
load();
|
||||
} catch (err) {
|
||||
alert('添加失败:' + err.message);
|
||||
toast(t('admin.link.addFailed', { msg: err.message }), 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id) => {
|
||||
if (!confirm('确定删除该链接吗?')) return;
|
||||
if (!await confirmAction(t('admin.link.confirmDelete'))) return;
|
||||
try {
|
||||
await API.deleteLink(id);
|
||||
load();
|
||||
} catch (err) {
|
||||
alert('删除失败:' + err.message);
|
||||
toast(t('admin.common.deleteFailed', { msg: err.message }), 'error');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,26 +43,26 @@ export default function AdminLinks() {
|
||||
<>
|
||||
<div style={{ marginBottom: 16, display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
<input
|
||||
type="text" placeholder="链接名称"
|
||||
type="text" placeholder={t('admin.link.namePlaceholder')}
|
||||
style={{ flex: 1, minWidth: 120, padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--bg)', color: 'var(--text)' }}
|
||||
value={title} onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
type="url" placeholder="链接地址"
|
||||
type="url" placeholder={t('admin.link.urlPlaceholder')}
|
||||
style={{ flex: 2, minWidth: 160, padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--bg)', color: 'var(--text)' }}
|
||||
value={url} onChange={(e) => setUrl(e.target.value)}
|
||||
/>
|
||||
<button className="btn-primary" style={{ padding: '8px 16px' }} onClick={handleAdd}>添加</button>
|
||||
<button className="btn-primary" style={{ padding: '8px 16px' }} onClick={handleAdd}>{t('admin.link.add')}</button>
|
||||
</div>
|
||||
<div id="linkList">
|
||||
{links.length === 0 ? (
|
||||
<div style={{ color: '#94a3b8', fontSize: 13 }}>暂无友情链接</div>
|
||||
<div style={{ color: '#94a3b8', fontSize: 13 }}>{t('admin.link.empty')}</div>
|
||||
) : (
|
||||
links.map((l) => (
|
||||
<div key={l.id} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '8px 0', borderBottom: '1px solid #f1f5f9' }}>
|
||||
<span><a href={l.url} target="_blank" rel="noreferrer" style={{ color: '#6366f1', textDecoration: 'none' }}>{l.title}</a></span>
|
||||
<button className="btn-sm btn-danger" onClick={() => handleDelete(l.id)}>
|
||||
<Icon name="trash" size={12} /> 删除
|
||||
<Icon name="trash" size={12} /> {t('admin.common.delete')}
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
|
||||
Reference in new issue
Block a user