File size: 17,051 Bytes
9eb1c55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
'use client';

import { useState } from 'react';
import Link from 'next/link';

export default function KnowledgeLibrary() {
  const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid');
  const [selectedKnowledgeBases, setSelectedKnowledgeBases] = useState<string[]>([]);

  const knowledgeBases = [
    {
      id: 'kb-001',
      name: '通用知识库',
      description: '包含基础常识和通用信息,适用于大多数场景的问答需求',
      category: '通用',
      items: 1240,
      size: '15.6 MB',
      status: 'active',
      lastUpdated: '2024-01-15',
      creator: '系统默认',
      isDefault: true,
      usage: 856,
      tags: ['通用', '基础', '默认']
    },
    {
      id: 'kb-002',
      name: '技术文档库',
      description: '收录了各种技术文档、API说明和开发指南,为技术问题提供专业解答',
      category: '技术',
      items: 567,
      size: '8.3 MB',
      status: 'active',
      lastUpdated: '2024-01-14',
      creator: '张工程师',
      isDefault: false,
      usage: 423,
      tags: ['技术', 'API', '开发']
    },
    {
      id: 'kb-003',
      name: '产品说明库',
      description: '产品功能介绍、使用手册和操作指南,帮助用户更好地了解产品特性',
      category: '产品',
      items: 892,
      size: '12.1 MB',
      status: 'active',
      lastUpdated: '2024-01-13',
      creator: '李产品经理',
      isDefault: false,
      usage: 678,
      tags: ['产品', '手册', '功能']
    },
    {
      id: 'kb-004',
      name: '客服问答库',
      description: '客服常见问题和标准解答,提升客户服务效率和质量',
      category: '客服',
      items: 345,
      size: '4.2 MB',
      status: 'active',
      lastUpdated: '2024-01-12',
      creator: '王客服主管',
      isDefault: false,
      usage: 234,
      tags: ['客服', '问答', 'FAQ']
    },
    {
      id: 'kb-005',
      name: '法律法规库',
      description: '相关法律条文、政策解读和合规要求,确保业务合规运营',
      category: '法务',
      items: 178,
      size: '6.8 MB',
      status: 'active',
      lastUpdated: '2024-01-11',
      creator: '赵法务',
      isDefault: false,
      usage: 89,
      tags: ['法律', '合规', '政策']
    },
    {
      id: 'kb-006',
      name: '销售话术库',
      description: '销售技巧、话术模板和客户案例,提升销售团队的专业水平',
      category: '销售',
      items: 456,
      size: '5.9 MB',
      status: 'inactive',
      lastUpdated: '2024-01-10',
      creator: '陈销售总监',
      isDefault: false,
      usage: 156,
      tags: ['销售', '话术', '案例']
    }
  ];

  const toggleSelection = (id: string) => {
    setSelectedKnowledgeBases(prev => 
      prev.includes(id) 
        ? prev.filter(kbId => kbId !== id)
        : [...prev, id]
    );
  };

  const selectAll = () => {
    setSelectedKnowledgeBases(knowledgeBases.map(kb => kb.id));
  };

  const clearSelection = () => {
    setSelectedKnowledgeBases([]);
  };

  const getStatusColor = (status: string) => {
    switch (status) {
      case 'active':
        return 'bg-green-100 text-green-800';
      case 'inactive':
        return 'bg-red-100 text-red-800';
      case 'updating':
        return 'bg-yellow-100 text-yellow-800';
      default:
        return 'bg-gray-100 text-gray-800';
    }
  };

  const getStatusText = (status: string) => {
    switch (status) {
      case 'active':
        return '运行中';
      case 'inactive':
        return '已停用';
      case 'updating':
        return '更新中';
      default:
        return '未知';
    }
  };

  return (
    <div className="space-y-6">
      {/* 操作栏 */}
      <div className="bg-white border border-gray-200 rounded-lg p-4">
        <div className="flex items-center justify-between">
          <div className="flex items-center space-x-4">
            <div className="flex items-center space-x-2">
              <input
                type="checkbox"
                checked={selectedKnowledgeBases.length === knowledgeBases.length}
                onChange={(e) => e.target.checked ? selectAll() : clearSelection()}
                className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"
              />
              <span className="text-sm text-gray-600">
                {selectedKnowledgeBases.length > 0 
                  ? `已选择 ${selectedKnowledgeBases.length} 个知识库`
                  : '全选'
                }
              </span>
            </div>
            
            {selectedKnowledgeBases.length > 0 && (
              <div className="flex items-center space-x-2">
                <button className="px-3 py-1 text-sm bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition-colors cursor-pointer whitespace-nowrap">
                  批量启用
                </button>
                <button className="px-3 py-1 text-sm bg-red-100 text-red-700 rounded hover:bg-red-200 transition-colors cursor-pointer whitespace-nowrap">
                  批量停用
                </button>
                <button className="px-3 py-1 text-sm bg-gray-100 text-gray-700 rounded hover:bg-gray-200 transition-colors cursor-pointer whitespace-nowrap">
                  批量删除
                </button>
              </div>
            )}
          </div>
          
          <div className="flex items-center space-x-2">
            <button
              onClick={() => setViewMode('grid')}
              className={`p-2 rounded ${viewMode === 'grid' ? 'bg-blue-100 text-blue-600' : 'text-gray-400 hover:text-gray-600'} transition-colors cursor-pointer`}
            >
              <div className="w-4 h-4 flex items-center justify-center">
                <i className="ri-layout-grid-line"></i>
              </div>
            </button>
            <button
              onClick={() => setViewMode('list')}
              className={`p-2 rounded ${viewMode === 'list' ? 'bg-blue-100 text-blue-600' : 'text-gray-400 hover:text-gray-600'} transition-colors cursor-pointer`}
            >
              <div className="w-4 h-4 flex items-center justify-center">
                <i className="ri-list-unordered"></i>
              </div>
            </button>
          </div>
        </div>
      </div>

      {/* 知识库列表 */}
      {viewMode === 'grid' ? (
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
          {knowledgeBases.map((kb) => (
            <div key={kb.id} className="bg-white border border-gray-200 rounded-lg hover:shadow-md transition-all duration-200">
              <div className="p-6">
                <div className="flex items-start justify-between mb-4">
                  <div className="flex items-center space-x-3">
                    <input
                      type="checkbox"
                      checked={selectedKnowledgeBases.includes(kb.id)}
                      onChange={() => toggleSelection(kb.id)}
                      className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"
                    />
                    <div className="w-12 h-12 bg-gradient-to-br from-blue-500 to-purple-600 rounded-lg flex items-center justify-center">
                      <i className="ri-book-line text-xl text-white"></i>
                    </div>
                    <div className="flex-1">
                      <div className="flex items-center space-x-2">
                        <h3 className="font-semibold text-gray-900">{kb.name}</h3>
                        {kb.isDefault && (
                          <span className="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">默认</span>
                        )}
                      </div>
                      <span className={`inline-block px-2 py-1 text-xs rounded-full mt-1 ${getStatusColor(kb.status)}`}>
                        {getStatusText(kb.status)}
                      </span>
                    </div>
                  </div>
                  
                  <div className="relative">
                    <button className="p-2 text-gray-400 hover:text-gray-600 transition-colors cursor-pointer">
                      <div className="w-4 h-4 flex items-center justify-center">
                        <i className="ri-more-line"></i>
                      </div>
                    </button>
                  </div>
                </div>
                
                <p className="text-gray-600 text-sm mb-4 line-clamp-3">{kb.description}</p>
                
                <div className="space-y-3 mb-4">
                  <div className="flex items-center justify-between text-sm">
                    <span className="text-gray-500">内容条目</span>
                    <span className="font-medium text-gray-900">{kb.items.toLocaleString()}</span>
                  </div>
                  <div className="flex items-center justify-between text-sm">
                    <span className="text-gray-500">存储大小</span>
                    <span className="font-medium text-gray-900">{kb.size}</span>
                  </div>
                  <div className="flex items-center justify-between text-sm">
                    <span className="text-gray-500">使用次数</span>
                    <span className="font-medium text-gray-900">{kb.usage.toLocaleString()}</span>
                  </div>
                  <div className="flex items-center justify-between text-sm">
                    <span className="text-gray-500">最后更新</span>
                    <span className="font-medium text-gray-900">{kb.lastUpdated}</span>
                  </div>
                </div>
                
                <div className="flex flex-wrap gap-1 mb-4">
                  {kb.tags.map((tag, index) => (
                    <span key={index} className="px-2 py-1 bg-gray-100 text-gray-700 text-xs rounded">
                      {tag}
                    </span>
                  ))}
                </div>
                
                <div className="flex items-center justify-between pt-4 border-t border-gray-200">
                  <div className="flex items-center space-x-2">
                    <div className="w-6 h-6 bg-gray-200 rounded-full flex items-center justify-center">
                      <i className="ri-user-line text-xs text-gray-600"></i>
                    </div>
                    <span className="text-xs text-gray-500">{kb.creator}</span>
                  </div>
                  
                  <div className="flex items-center space-x-2">
                    <Link 
                      href={`/knowledge/${kb.id}`}
                      className="px-3 py-1 bg-blue-100 text-blue-700 text-xs rounded hover:bg-blue-200 transition-colors cursor-pointer whitespace-nowrap"
                    >
                      查看详情
                    </Link>
                  </div>
                </div>
              </div>
            </div>
          ))}
        </div>
      ) : (
        <div className="bg-white border border-gray-200 rounded-lg overflow-hidden">
          <div className="overflow-x-auto">
            <table className="w-full">
              <thead className="bg-gray-50 border-b border-gray-200">
                <tr>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                    <input
                      type="checkbox"
                      checked={selectedKnowledgeBases.length === knowledgeBases.length}
                      onChange={(e) => e.target.checked ? selectAll() : clearSelection()}
                      className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"
                    />
                  </th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">名称</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">分类</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">条目数</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">大小</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">使用次数</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">状态</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">最后更新</th>
                  <th className="px-6 py-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">操作</th>
                </tr>
              </thead>
              <tbody className="bg-white divide-y divide-gray-200">
                {knowledgeBases.map((kb) => (
                  <tr key={kb.id} className="hover:bg-gray-50 transition-colors">
                    <td className="px-6 py-4 whitespace-nowrap">
                      <input
                        type="checkbox"
                        checked={selectedKnowledgeBases.includes(kb.id)}
                        onChange={() => toggleSelection(kb.id)}
                        className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"
                      />
                    </td>
                    <td className="px-6 py-4 whitespace-nowrap">
                      <div className="flex items-center">
                        <div className="w-10 h-10 bg-gradient-to-br from-blue-500 to-purple-600 rounded-lg flex items-center justify-center mr-3">
                          <i className="ri-book-line text-white"></i>
                        </div>
                        <div>
                          <div className="flex items-center space-x-2">
                            <div className="text-sm font-medium text-gray-900">{kb.name}</div>
                            {kb.isDefault && (
                              <span className="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">默认</span>
                            )}
                          </div>
                          <div className="text-sm text-gray-500 max-w-xs truncate">{kb.description}</div>
                        </div>
                      </div>
                    </td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{kb.category}</td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{kb.items.toLocaleString()}</td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{kb.size}</td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{kb.usage.toLocaleString()}</td>
                    <td className="px-6 py-4 whitespace-nowrap">
                      <span className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${getStatusColor(kb.status)}`}>
                        {getStatusText(kb.status)}
                      </span>
                    </td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{kb.lastUpdated}</td>
                    <td className="px-6 py-4 whitespace-nowrap text-sm font-medium">
                      <div className="flex items-center space-x-3">
                        <Link 
                          href={`/knowledge/${kb.id}`}
                          className="text-blue-600 hover:text-blue-900 cursor-pointer"
                        >
                          查看
                        </Link>
                        <button className="text-gray-600 hover:text-gray-900 cursor-pointer">编辑</button>
                        <button className="text-red-600 hover:text-red-900 cursor-pointer">删除</button>
                      </div>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </div>
      )}

      {/* 分页 */}
      <div className="flex items-center justify-between">
        <div className="text-sm text-gray-500">
          共 {knowledgeBases.length} 个知识库
        </div>
        <div className="flex items-center space-x-2">
          <button className="px-3 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors cursor-pointer whitespace-nowrap text-sm">
            上一页
          </button>
          <span className="px-3 py-2 bg-blue-600 text-white rounded-lg text-sm">1</span>
          <button className="px-3 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors cursor-pointer whitespace-nowrap text-sm">
            下一页
          </button>
        </div>
      </div>
    </div>
  );
}