| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- // src/components/admin/plugins/PluginTable.tsx
- 'use client';
- import {
- History,
- Plus,
- Zap,
- Edit2,
- Trash2,
- FileCode,
- CheckCircle2,
- XCircle,
- Calendar,
- Layers,
- } from 'lucide-react';
- import { PluginItem } from '@/types';
- interface PluginTableProps {
- plugins: PluginItem[];
- loading: boolean;
- onOpenVersions: (plugin: PluginItem) => void;
- onOpenPublishVersion: (plugin: PluginItem) => void;
- onQuickDispatchUpgrade: (plugin: PluginItem) => void;
- onOpenEdit: (plugin: PluginItem) => void;
- onDelete: (plugin: PluginItem) => void;
- }
- export default function PluginTable({
- plugins,
- loading,
- onOpenVersions,
- onOpenPublishVersion,
- onQuickDispatchUpgrade,
- onOpenEdit,
- onDelete,
- }: PluginTableProps) {
- if (loading) {
- return (
- <div className="bg-white rounded-2xl border border-slate-200 p-12 text-center shadow-sm">
- <div className="inline-block animate-spin rounded-full h-8 w-8 border-4 border-blue-600 border-t-transparent mb-3" />
- <p className="text-sm font-medium text-slate-500">正在加载插件列表...</p>
- </div>
- );
- }
- if (plugins.length === 0) {
- return (
- <div className="bg-white rounded-2xl border border-slate-200 p-12 text-center shadow-sm">
- <div className="w-12 h-12 rounded-2xl bg-blue-50 text-blue-600 flex items-center justify-center mx-auto mb-3">
- <Layers size={24} />
- </div>
- <h3 className="text-base font-bold text-slate-800">暂无任何插件</h3>
- <p className="text-xs text-slate-500 mt-1 max-w-sm mx-auto">
- 尚未发布任何自动化插件。点击右上角的“发布新插件”上传首发版本代码。
- </p>
- </div>
- );
- }
- return (
- <div className="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
- <div className="overflow-x-auto">
- <table className="w-full text-left border-collapse">
- <thead>
- <tr className="bg-slate-50/80 border-b border-slate-200 text-[11px] font-bold text-slate-500 uppercase tracking-wider">
- <th className="py-4 px-5">插件名称 / 标识</th>
- <th className="py-4 px-4">生效版本</th>
- <th className="py-4 px-4">运行状态</th>
- <th className="py-4 px-4">功能描述</th>
- <th className="py-4 px-4">更新时间</th>
- <th className="py-4 px-5 text-right">操作</th>
- </tr>
- </thead>
- <tbody className="divide-y divide-slate-100 text-sm">
- {plugins.map((plugin) => (
- <tr
- key={plugin.id || plugin.name}
- className="hover:bg-slate-50/60 transition-colors group"
- >
- {/* 插件名称 / 英文标识 */}
- <td className="py-4 px-5">
- <div className="flex items-start gap-3">
- <div className="w-9 h-9 rounded-xl bg-blue-50 text-blue-600 flex items-center justify-center flex-shrink-0 mt-0.5 group-hover:bg-blue-600 group-hover:text-white transition">
- <FileCode size={18} />
- </div>
- <div>
- <div className="font-bold text-slate-900 flex items-center gap-2">
- <span>{plugin.display_name || plugin.name}</span>
- </div>
- <div className="flex items-center gap-2 mt-0.5">
- <span className="text-xs font-mono font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-600">
- {plugin.name}
- </span>
- <span className="text-[11px] font-mono text-slate-400">
- {plugin.filename || `${plugin.name}.py`}
- </span>
- </div>
- </div>
- </div>
- </td>
- {/* 生效版本 */}
- <td className="py-4 px-4 whitespace-nowrap">
- <span className="inline-flex items-center gap-1 font-mono font-bold text-xs px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700 border border-blue-200/60">
- v{plugin.latest_version}
- </span>
- </td>
- {/* 状态 */}
- <td className="py-4 px-4 whitespace-nowrap">
- {plugin.status === 1 ? (
- <span className="inline-flex items-center gap-1 text-xs font-medium text-emerald-700 bg-emerald-50 border border-emerald-200/60 px-2.5 py-0.5 rounded-full">
- <CheckCircle2 size={12} className="text-emerald-600" />
- 已启用
- </span>
- ) : (
- <span className="inline-flex items-center gap-1 text-xs font-medium text-slate-500 bg-slate-100 border border-slate-200 px-2.5 py-0.5 rounded-full">
- <XCircle size={12} className="text-slate-400" />
- 已停用
- </span>
- )}
- </td>
- {/* 描述 */}
- <td className="py-4 px-4 max-w-xs">
- <p className="text-xs text-slate-600 line-clamp-2" title={plugin.description}>
- {plugin.description || <span className="text-slate-400 italic">无描述</span>}
- </p>
- </td>
- {/* 更新时间 */}
- <td className="py-4 px-4 whitespace-nowrap text-xs text-slate-500">
- <div className="flex items-center gap-1">
- <Calendar size={13} className="text-slate-400" />
- <span>{plugin.updated_at || plugin.created_at || '—'}</span>
- </div>
- </td>
- {/* 操作列 */}
- <td className="py-4 px-5 whitespace-nowrap text-right">
- <div className="inline-flex items-center gap-1">
- {/* 版本管理 (抽屉) */}
- <button
- onClick={() => onOpenVersions(plugin)}
- className="px-2.5 py-1.5 text-xs font-semibold text-blue-600 hover:text-blue-700 hover:bg-blue-50 rounded-lg transition flex items-center gap-1"
- title="查看全部历史版本及回滚"
- >
- <History size={14} />
- 版本管理
- </button>
- {/* 快捷下发升级 */}
- <button
- onClick={() => onQuickDispatchUpgrade(plugin)}
- className="p-1.5 text-purple-600 hover:text-purple-700 hover:bg-purple-50 rounded-lg transition"
- title="快捷推送此插件升级给节点"
- >
- <Zap size={15} />
- </button>
- {/* 发布新版本 */}
- <button
- onClick={() => onOpenPublishVersion(plugin)}
- className="p-1.5 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50 rounded-lg transition"
- title="为此插件上传新版本"
- >
- <Plus size={15} />
- </button>
- {/* 编辑元数据 */}
- <button
- onClick={() => onOpenEdit(plugin)}
- className="p-1.5 text-slate-500 hover:text-slate-700 hover:bg-slate-100 rounded-lg transition"
- title="编辑插件基础信息与启停状态"
- >
- <Edit2 size={15} />
- </button>
- {/* 删除整套插件 */}
- <button
- onClick={() => onDelete(plugin)}
- className="p-1.5 text-slate-400 hover:text-rose-600 hover:bg-rose-50 rounded-lg transition"
- title="删除此插件及其全部版本"
- >
- <Trash2 size={15} />
- </button>
- </div>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- </div>
- );
- }
|