办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
<script setup lang="ts">
import { h, onMounted, reactive, ref } from "vue";
import {
    NButton,
    // NDataTable, // NDataTable 已被移除,可以注释或删除
    DrawerPlacement,
    NDrawer,
    NDrawerContent,
    NForm,
    NFormItem,
    NInput,
    NSpace,
    useMessage,
    NGrid,
    NGi,
    NSwitch,
    NInputNumber,
    NSelect,
    NPagination,
    NCard, // 添加 NCard 导入
} from "naive-ui";
import {
    createKnowledgeReq,
    getKnowledge,
    delKnowledge,
} from "@/api/knowledge";
import { useRouter } from "vue-router";
import { t } from "@/locales";
import { list } from "@/api/model";
 
onMounted(() => {
    fetchData(), getModelList();
});
 
const router = useRouter();
const message = useMessage();
 
// 初始化表单数据对象
const formValue = ref({
    id: "", // 知识库id
    kid: "", // 附件id
    uid: "", // 用户id
    kname: "", // 知识库名称
    share: "0", // 是否分享
    description: "", // 知识库描述
    knowledgeSeparator: "", // 知识分隔符
    questionSeparator: "", // 提问分隔符
    overlapChar: 50, // 重叠字符数
    retrieveLimit: 3, // 知识库中检索的条数
    textBlockSize: 500, // 文本块大小
    vectorModelName: "weaviate", //  向量库
    embeddingModelName: "baai/bge-m3", //  向量模型
});
 
async function submitForm() {
    // 关闭弹框
    active.value = false;
    const result = await createKnowledgeReq(formValue.value);
    if (result.code == 200) {
        message.success("添加成功");
        // 重新获取数据,更新表格
        await fetchData();
    }
}
 
async function delKnowledgeForm(id: string) {
    // 发起一个请求
    const req = {
        id: id, // 附件id
    };
    const result = await delKnowledge(req);
    if (result.code == 200) {
        message.success("删除成功!");
    } else {
        message.error("删除失败!" + result.data.msg);
    }
    // 重新获取数据,更新表格
    await fetchData();
}
 
function handleActionButtonClick(row: any, action1: string): void {
    // 跳转到知识库附件页面
    router.push({ path: "/annex/t", query: { kid: row.id } });
}
 
function handleUpdateValue(value: string) {
    formValue.value.share = value;
}
 
// 定义一个激活抽屉的函数,接受一个 DrawerPlacement 类型的参数
const activate = (place: DrawerPlacement) => {
    active.value = true;
    placement.value = place;
};
 
// 使用 ref 来创建响应式变量
const active = ref(false);
const placement = ref<DrawerPlacement>("right");
 
const getVector = reactive([
    { label: "weaviate", value: "weaviate" },
]);
 
const getVectorModel = ref([]);
 
async function getModelList() {
    try {
        const res = await list('vector');
        getVectorModel.value = res.rows;
    } catch (error) {
        message.error("获取模型列表失败");
    }
}
 
const createColumns = () => {
    return [
        ...(false
            ? [
                {
                    title: "ID",
                    key: "id",
                    width: 80,
                    ellipsis: true,
                },
            ]
            : []),
        {
            title: t("knowledge.number"),
            key: "kid",
            width: 200,
        },
        {
            title: t("knowledge.name"),
            key: "kname",
            width: 200,
        },
        {
            title: t("knowledge.description"),
            key: "description",
            width: 200,
        },
        {
            title: t("knowledge.actions"),
            key: "actions",
            width: 200,
            render: (row: any) => {
                return [
                    h(
                        NButton,
                        {
                            onClick: () => delKnowledgeForm(row.id),
                            style: "margin-left: 8px; color: #FF4500;",
                            class: "table-button",
                            bordered: false,
                        },
                        { default: () => t("knowledge.delete") }
                    ),
 
                    h(
                        NButton,
                        {
                            onClick: () => handleActionButtonClick(row, "action3"),
                            style: "margin-left: 8px; color: #32CD32;",
                            class: "table-button",
                            bordered: false,
                        },
                        { default: () => t("knowledge.attachment") }
                    ),
                ];
            },
        },
    ];
};
 
const tableData = ref([]);
 
const pagination = reactive({
    page: 1,
    pageSize: 12,
    itemCount: 0,
    pageSizes: [12, 24, 36, 48],
    onUpdatePage: (page: number) => {
        pagination.page = page;
        fetchData();
    },
    onUpdatePageSize: (pageSize: number) => {
        pagination.pageSize = pageSize;
        pagination.page = 1;
        fetchData();
    },
});
 
const fetchData = async () => {
    // 发起一个请求
    const result = await getKnowledge(pagination.page, pagination.pageSize);
    if (result.code == 200) {
        tableData.value = result.rows;
        console.log('Knowledge data:', result);
        pagination.itemCount = result.total; // 根据后端返回的数据结构,使用 total 作为总数
    }
};
 
 
</script>
 
<template>
    <div class="page-container">
        <div class="create-app-panel">
            <n-button type="primary" @click="activate('right')">
                创建知识库
            </n-button>
        </div>
 
        <div class="content-panel">
            <div class="knowledge-card-list">
                <n-grid :x-gap="8" :y-gap="8" :cols="4" item-responsive responsive="screen">
                    <n-gi v-for="item in tableData" :key="item.id">
                        <n-card :title="item.kname" hoverable class="knowledge-card">
                            <!-- Add icon and subtitle similar to the image -->
                            <template #cover>
                                <!-- Placeholder for an icon, e.g., using an NIcon component or an img tag -->
                            </template>
                            <div class="card-meta">
                                <span class="card-author">{{ item.id || 'N/A2' }}</span> - <span class="card-date">{{ item.createTime || 'N/A1' }}</span>
                            </div>
                            <p class="card-description">{{ item.description }}</p>
                            <template #action>
                                <n-space justify="end">
                                    <n-button size="small" @click="handleActionButtonClick(item, 'action3')" type="primary" ghost>
                                        {{ $t("knowledge.attachment") }}
                                    </n-button>
                                    <n-button size="small" @click="delKnowledgeForm(item.id)" type="error" ghost>
                                        {{ $t("knowledge.delete") }}
                                    </n-button>
                                </n-space>
                            </template>
                        </n-card>
                    </n-gi>
                </n-grid>
            </div>
 
            <div class="pagination-wrapper">
                <n-pagination
                    v-model:page="pagination.page"
                    :item-count="pagination.itemCount"
                    v-model:page-size="pagination.pageSize"
                    :page-sizes="pagination.pageSizes"
                    show-size-picker
                    @update:page="pagination.onUpdatePage"
                    @update:page-size="pagination.onUpdatePageSize"
                />
            </div>
        </div>
    </div>
 
    <n-drawer class="knowledge-drawer" v-model:show="active" :width="800" :placement="placement"
        display-directive="show" :mask-closable="false">
        <n-drawer-content :title="$t('knowledge.createKnowledgeBase')" class="drawer-content" closable>
            <n-space vertical>
                <n-form ref="formRef" :label-width="100" :model="formValue" class="knowledge-form"
                    label-placement="left">
                    <n-grid :cols="24" :x-gap="24" :y-gap="16">
                        <n-gi :span="12">
                            <n-form-item label="知识库名称" required>
                                <n-input v-model:value="formValue.kname" placeholder="请输入知识库名称" clearable />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="分隔符">
                                <n-input v-model:value="formValue.knowledgeSeparator" placeholder="请输入知识分隔符"
                                    clearable />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="检索条数" required>
                                <n-input-number v-model:value="formValue.retrieveLimit" placeholder="请输入检索条数" :min="1"
                                    :max="10" class="full-width" />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="文本块大小" required>
                                <n-input-number v-model:value="formValue.textBlockSize" placeholder="请输入文本块大小"
                                    :min="100" :max="2000" class="full-width" />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="重叠字符">
                                <n-input-number v-model:value="formValue.overlapChar" placeholder="请输入重叠字符数" :min="0"
                                    :max="200" class="full-width" />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="向量库" required>
                                <n-select :options="getVector" v-model:value="formValue.vectorModelName"
                                    placeholder="请选择向量库" clearable></n-select>
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="提问分割符">
                                <n-input v-model:value="formValue.questionSeparator" placeholder="请输入提问分割符" clearable />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="12">
                            <n-form-item label="向量模型" required>
                                <n-select :options="getVectorModel" v-model:value="formValue.embeddingModelName"
                                    value-field="modelDescribe" label-field="modelName" placeholder="请选择向量模型"
                                    clearable></n-select>
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="24">
                            <n-form-item :label="$t('knowledge.knowledgeDescription')">
                                <n-input maxlength="1000" type="textarea" v-model:value="formValue.description"
                                    :placeholder="$t('knowledge.enterKnowledgeDescription')"
                                    :autosize="{ minRows: 3, maxRows: 5 }" show-count />
                            </n-form-item>
                        </n-gi>
 
                        <n-gi :span="24">
                            <n-form-item label="是否公开" label-placement="left">
                                <n-switch size="large" checked-value="1" unchecked-value="0"
                                    @update:value="handleUpdateValue">
                                    <template #checked>是</template>
                                    <template #unchecked>否</template>
                                </n-switch>
                            </n-form-item>
                        </n-gi>
                    </n-grid>
                </n-form>
            </n-space>
 
            <template #footer>
                <div>
                    <n-button @click="active = false" :bordered="true" style="margin-right: 10px">
                        取消
                    </n-button>
                    <n-button @click="submitForm" :bordered="false" type="primary">
                        {{ $t("knowledge.add") }}
                    </n-button>
                </div>
            </template>
        </n-drawer-content>
    </n-drawer>
</template>
 
<style scoped>
.page-container {
  min-height: 100vh;
  background-color: var(--n-color-body);
  padding: 20px;
  padding-top: 80px;
}
 
.create-app-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 10;
}
 
.panel-title {
    font-size: 16px;
    color: #888;
    margin-bottom: 15px;
    font-weight: bold;
}
 
.panel-button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 15px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #333;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}
 
.panel-button:hover {
    background-color: #f0f2f5;
}
 
.content-panel {
    flex: 1; /* Takes the remaining space */
}
 
 
.knowledge-card {
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    margin: 10px; /* 添加上下左右 10px 边距 */
}
 
.knowledge-card:hover {
    transform: translateY(-5px); /* 更明显的悬停效果 */
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}
 
.card-meta {
    font-size: 12px;
    color: #999;
    margin-top: 5px;
    margin-bottom: 10px;
}
 
.card-author,
.card-date {
    color: #666;
}
 
.card-description {
    font-size: 14px;
    color: #666;
    min-height: 60px; /* 确保描述区域有最小高度 */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 限制描述显示3行 */
    -webkit-box-orient: vertical;
}
 
.pagination-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}
 
.knowledge-drawer {
    --n-body-padding: 24px;
}
 
.drawer-content {
    padding: 0;
}
 
.drawer-header {
    padding: 16px 24px;
    border-bottom: 1px solid #f0f0f0;
}
 
.drawer-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}
 
.drawer-description {
    color: #666;
    margin: 16px 24px;
    font-size: 14px;
    line-height: 1.6;
}
 
.drawer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #f0f0f0;
}
 
.knowledge-form {
    padding: 0 24px 24px;
}
 
.knowledge-form :deep(.n-form-item-label) {
    font-weight: 500;
    /* color: #333; */
}
 
.knowledge-form :deep(.n-form-item-feedback-wrapper) {
    min-height: 18px;
}
 
.knowledge-form :deep(.n-input),
.knowledge-form :deep(.n-input-number),
.knowledge-form :deep(.n-select) {
    width: 100%;
    border-radius: 6px;
    height: 40px;
}
 
.knowledge-form :deep(.n-input .n-input__input-el),
.knowledge-form :deep(.n-input-number-input),
.knowledge-form :deep(.n-base-selection) {
    height: 40px;
    font-size: 14px;
.knowledge-form :deep(.n-input:hover),
.knowledge-form :deep(.n-input-number:hover),
.knowledge-form :deep(.n-select:hover) {
    border-color: #18a058;
}
 
.knowledge-form :deep(.n-input:focus),
.knowledge-form :deep(.n-input-number:focus),
.knowledge-form :deep(.n-select:focus) {
    border-color: #18a058;
    box-shadow: 0 0 0 2px rgba(24, 160, 88, 0.2);
}
 
.knowledge-form :deep(.n-input-number) {
    width: 100%;
}
 
 
 
.knowledge-table {
    --n-td-color: transparent;
    --n-td-color-hover: rgba(0, 0, 0, 0.02);
    --n-td-text-color: #333;
    --n-border-color: #f0f0f0;
}
 
.knowledge-card-list {
    margin-top: 20px;
}
 
.knowledge-card {
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
 
.knowledge-card:hover {
    transform: translateY(-5px); /* 更明显的悬停效果 */
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}
 
.card-description {
    font-size: 14px;
    color: #666;
    min-height: 60px; /* 确保描述区域有最小高度 */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 限制描述显示3行 */
    -webkit-box-orient: vertical;
}
 
.pagination-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}
 
.knowledge-drawer {
    --n-body-padding: 24px;
}
 
.drawer-content {
    padding: 0;
}
 
.drawer-header {
    padding: 16px 24px;
    border-bottom: 1px solid #f0f0f0;
}
 
.drawer-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}
 
.drawer-description {
    color: #666;
    margin: 16px 24px;
    font-size: 14px;
    line-height: 1.6;
}
 
.drawer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #f0f0f0;
}
 
.knowledge-form {
    padding: 0 24px 24px;
}
 
.knowledge-form :deep(.n-form-item-label) {
    font-weight: 500;
    /* color: #333; */
}
 
.knowledge-form :deep(.n-form-item-feedback-wrapper) {
    min-height: 18px;
}
 
.knowledge-form :deep(.n-input),
.knowledge-form :deep(.n-input-number),
.knowledge-form :deep(.n-select) {
    width: 100%;
    border-radius: 6px;
    height: 40px;
}
 
.knowledge-form :deep(.n-input .n-input__input-el),
.knowledge-form :deep(.n-input-number-input),
.knowledge-form :deep(.n-base-selection) {
    height: 40px;
    font-size: 14px;
.knowledge-form :deep(.n-input:hover),
.knowledge-form :deep(.n-input-number:hover),
.knowledge-form :deep(.n-select:hover) {
    border-color: #18a058;
}
 
.knowledge-form :deep(.n-input:focus),
.knowledge-form :deep(.n-input-number:focus),
.knowledge-form :deep(.n-select:focus) {
    border-color: #18a058;
    box-shadow: 0 0 0 2px rgba(24, 160, 88, 0.2);
}
 
.knowledge-form :deep(.n-input-number) {
    width: 100%;
}
 
 
    height: 40px;
    font-size: 14px;
}
}
 
.cancel-button {
    padding: 10px 20px;
    border-radius: 6px;
    transition: all 0.3s ease;
    height: 40px;
    min-width: 100px;
    font-size: 14px;
}
 
.draw-button {
    padding: 10px 20px;
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    height: 40px;
    min-width: 100px;
    font-size: 14px;
}
 
.draw-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
</style>