PluginTable.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // src/components/admin/plugins/PluginTable.tsx
  2. 'use client';
  3. import {
  4. History,
  5. Plus,
  6. Zap,
  7. Edit2,
  8. Trash2,
  9. FileCode,
  10. CheckCircle2,
  11. XCircle,
  12. Calendar,
  13. Layers,
  14. } from 'lucide-react';
  15. import { PluginItem } from '@/types';
  16. interface PluginTableProps {
  17. plugins: PluginItem[];
  18. loading: boolean;
  19. onOpenVersions: (plugin: PluginItem) => void;
  20. onOpenPublishVersion: (plugin: PluginItem) => void;
  21. onQuickDispatchUpgrade: (plugin: PluginItem) => void;
  22. onOpenEdit: (plugin: PluginItem) => void;
  23. onDelete: (plugin: PluginItem) => void;
  24. }
  25. export default function PluginTable({
  26. plugins,
  27. loading,
  28. onOpenVersions,
  29. onOpenPublishVersion,
  30. onQuickDispatchUpgrade,
  31. onOpenEdit,
  32. onDelete,
  33. }: PluginTableProps) {
  34. if (loading) {
  35. return (
  36. <div className="bg-white rounded-2xl border border-slate-200 p-12 text-center shadow-sm">
  37. <div className="inline-block animate-spin rounded-full h-8 w-8 border-4 border-blue-600 border-t-transparent mb-3" />
  38. <p className="text-sm font-medium text-slate-500">正在加载插件列表...</p>
  39. </div>
  40. );
  41. }
  42. if (plugins.length === 0) {
  43. return (
  44. <div className="bg-white rounded-2xl border border-slate-200 p-12 text-center shadow-sm">
  45. <div className="w-12 h-12 rounded-2xl bg-blue-50 text-blue-600 flex items-center justify-center mx-auto mb-3">
  46. <Layers size={24} />
  47. </div>
  48. <h3 className="text-base font-bold text-slate-800">暂无任何插件</h3>
  49. <p className="text-xs text-slate-500 mt-1 max-w-sm mx-auto">
  50. 尚未发布任何自动化插件。点击右上角的“发布新插件”上传首发版本代码。
  51. </p>
  52. </div>
  53. );
  54. }
  55. return (
  56. <div className="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
  57. <div className="overflow-x-auto">
  58. <table className="w-full text-left border-collapse">
  59. <thead>
  60. <tr className="bg-slate-50/80 border-b border-slate-200 text-[11px] font-bold text-slate-500 uppercase tracking-wider">
  61. <th className="py-4 px-5">插件名称 / 标识</th>
  62. <th className="py-4 px-4">生效版本</th>
  63. <th className="py-4 px-4">运行状态</th>
  64. <th className="py-4 px-4">功能描述</th>
  65. <th className="py-4 px-4">更新时间</th>
  66. <th className="py-4 px-5 text-right">操作</th>
  67. </tr>
  68. </thead>
  69. <tbody className="divide-y divide-slate-100 text-sm">
  70. {plugins.map((plugin) => (
  71. <tr
  72. key={plugin.id || plugin.name}
  73. className="hover:bg-slate-50/60 transition-colors group"
  74. >
  75. {/* 插件名称 / 英文标识 */}
  76. <td className="py-4 px-5">
  77. <div className="flex items-start gap-3">
  78. <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">
  79. <FileCode size={18} />
  80. </div>
  81. <div>
  82. <div className="font-bold text-slate-900 flex items-center gap-2">
  83. <span>{plugin.display_name || plugin.name}</span>
  84. </div>
  85. <div className="flex items-center gap-2 mt-0.5">
  86. <span className="text-xs font-mono font-medium px-1.5 py-0.5 rounded bg-slate-100 text-slate-600">
  87. {plugin.name}
  88. </span>
  89. <span className="text-[11px] font-mono text-slate-400">
  90. {plugin.filename || `${plugin.name}.py`}
  91. </span>
  92. </div>
  93. </div>
  94. </div>
  95. </td>
  96. {/* 生效版本 */}
  97. <td className="py-4 px-4 whitespace-nowrap">
  98. <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">
  99. v{plugin.latest_version}
  100. </span>
  101. </td>
  102. {/* 状态 */}
  103. <td className="py-4 px-4 whitespace-nowrap">
  104. {plugin.status === 1 ? (
  105. <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">
  106. <CheckCircle2 size={12} className="text-emerald-600" />
  107. 已启用
  108. </span>
  109. ) : (
  110. <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">
  111. <XCircle size={12} className="text-slate-400" />
  112. 已停用
  113. </span>
  114. )}
  115. </td>
  116. {/* 描述 */}
  117. <td className="py-4 px-4 max-w-xs">
  118. <p className="text-xs text-slate-600 line-clamp-2" title={plugin.description}>
  119. {plugin.description || <span className="text-slate-400 italic">无描述</span>}
  120. </p>
  121. </td>
  122. {/* 更新时间 */}
  123. <td className="py-4 px-4 whitespace-nowrap text-xs text-slate-500">
  124. <div className="flex items-center gap-1">
  125. <Calendar size={13} className="text-slate-400" />
  126. <span>{plugin.updated_at || plugin.created_at || '—'}</span>
  127. </div>
  128. </td>
  129. {/* 操作列 */}
  130. <td className="py-4 px-5 whitespace-nowrap text-right">
  131. <div className="inline-flex items-center gap-1">
  132. {/* 版本管理 (抽屉) */}
  133. <button
  134. onClick={() => onOpenVersions(plugin)}
  135. 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"
  136. title="查看全部历史版本及回滚"
  137. >
  138. <History size={14} />
  139. 版本管理
  140. </button>
  141. {/* 快捷下发升级 */}
  142. <button
  143. onClick={() => onQuickDispatchUpgrade(plugin)}
  144. className="p-1.5 text-purple-600 hover:text-purple-700 hover:bg-purple-50 rounded-lg transition"
  145. title="快捷推送此插件升级给节点"
  146. >
  147. <Zap size={15} />
  148. </button>
  149. {/* 发布新版本 */}
  150. <button
  151. onClick={() => onOpenPublishVersion(plugin)}
  152. className="p-1.5 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50 rounded-lg transition"
  153. title="为此插件上传新版本"
  154. >
  155. <Plus size={15} />
  156. </button>
  157. {/* 编辑元数据 */}
  158. <button
  159. onClick={() => onOpenEdit(plugin)}
  160. className="p-1.5 text-slate-500 hover:text-slate-700 hover:bg-slate-100 rounded-lg transition"
  161. title="编辑插件基础信息与启停状态"
  162. >
  163. <Edit2 size={15} />
  164. </button>
  165. {/* 删除整套插件 */}
  166. <button
  167. onClick={() => onDelete(plugin)}
  168. className="p-1.5 text-slate-400 hover:text-rose-600 hover:bg-rose-50 rounded-lg transition"
  169. title="删除此插件及其全部版本"
  170. >
  171. <Trash2 size={15} />
  172. </button>
  173. </div>
  174. </td>
  175. </tr>
  176. ))}
  177. </tbody>
  178. </table>
  179. </div>
  180. </div>
  181. );
  182. }