feat(knowledge): 完成知识库基本功能开发

This commit is contained in:
v-zhangjc9
2025-05-28 15:06:30 +08:00
parent f7ed3bd270
commit 3ee6303cf5
30 changed files with 1787 additions and 273 deletions

View File

@@ -1,30 +1,85 @@
import React from 'react'
import {useParams} from 'react-router'
import {amisRender, crudCommonOptions} from '../../../util/amis.tsx'
import {useNavigate, useParams} from 'react-router'
import {amisRender, crudCommonOptions, mappingField, mappingItem} from '../../../util/amis.tsx'
const statusMapping = [
mappingItem('解析中', 'RUNNING', 'bg-warning'),
mappingItem('使用中', 'FINISHED', 'bg-success'),
]
const DataDetail: React.FC = () => {
const {name} = useParams()
const {knowledge_id} = useParams()
const navigate = useNavigate()
return (
<div className="import-detail h-full">
{amisRender(
{
className: 'h-full',
type: 'page',
title: `数据详情 (知识库:${name}`,
title: {
type: 'wrapper',
size: 'none',
body: [
'数据详情 (知识库:',
{
type: 'service',
className: 'inline',
api: {
method: 'get',
url: 'http://127.0.0.1:8080/knowledge/name',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
data: {
id: knowledge_id,
},
},
body: {
type: 'tpl',
tpl: '${name}',
},
},
'',
],
},
size: 'lg',
actions: [],
body: [
{
type: 'crud',
api: {
url: 'http://127.0.0.1:8080/knowledge/list_points?name=${name}',
method: 'get',
url: 'http://127.0.0.1:8080/group/list',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
data: {
knowledge_id,
},
},
...crudCommonOptions(),
headerToolbar: [
'reload',
{
type: 'action',
icon: 'fa fa-plus',
label: '',
tooltip: '新增',
tooltipPlacement: 'top',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(`/ai/knowledge/import/${knowledge_id}`)
},
},
],
},
},
},
],
columns: [
{
@@ -32,8 +87,15 @@ const DataDetail: React.FC = () => {
hidden: true,
},
{
name: 'text',
label: '内容',
name: 'name',
label: '文件名',
},
{
name: 'status',
label: '状态',
width: 50,
align: 'center',
...mappingField('status', statusMapping),
},
{
type: 'operation',
@@ -42,30 +104,17 @@ const DataDetail: React.FC = () => {
buttons: [
{
type: 'action',
label: '编辑',
label: '查看',
level: 'link',
size: 'lg',
actionType: 'dialog',
dialog: {
title: '编辑文段',
size: 'md',
body: {
type: 'form',
body: [
size: 'sm',
onEvent: {
click: {
actions: [
{
type: 'input-text',
name: 'id',
disabled: true,
label: '文段ID',
},
{
type: 'editor',
label: '内容',
name: 'text',
language: 'plaintext',
options: {
lineNumbers: 'off',
wordWrap: 'bounded',
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(`/ai/knowledge/detail/${knowledge_id}/segment/${context.props.data['id']}`)
},
},
],
@@ -77,13 +126,17 @@ const DataDetail: React.FC = () => {
label: '删除',
className: 'text-danger hover:text-red-600',
level: 'link',
size: 'xs',
size: 'sm',
actionType: 'ajax',
api: {
method: 'get',
url: 'http://127.0.0.1:8080/group/delete',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
data: {
id: '${id}',
},
},
confirmText: '确认删除',
confirmTitle: '删除',