feat(ai): 完善知识库接口

This commit is contained in:
v-zhangjc9
2025-05-16 19:00:55 +08:00
parent be976290b6
commit 5d49c82190
22 changed files with 800 additions and 128 deletions

View File

@@ -0,0 +1,176 @@
import React from 'react'
import {useNavigate} from 'react-router'
import {amisRender, crudCommonOptions, mappingField, mappingItem} from '../../../util/amis.tsx'
const strategyMapping = [
mappingItem('文本', 'Cosine'),
mappingItem('图片', 'Euclid'),
]
const statusMapping = [
mappingItem('正常', 'Green', 'label-success'),
mappingItem('优化中', 'Yellow', 'label-warning'),
mappingItem('错误', 'Red', 'label-danger'),
mappingItem('等待中', 'Grey', 'label-primary'),
]
const Knowledge: React.FC = () => {
const navigate = useNavigate()
return (
<div className="knowledge">
{amisRender(
{
type: 'page',
title: '知识库',
body: [
{
type: 'crud',
api: {
url: 'http://127.0.0.1:8080/knowledge/list',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
},
...crudCommonOptions(),
headerToolbar: [
'reload',
{
type: 'action',
label: '',
icon: 'fa fa-plus',
actionType: 'dialog',
dialog: {
title: '新增知识库',
size: 'md',
body: {
type: 'form',
api: {
url: 'http://127.0.0.1:8080/knowledge/add',
dataType: 'form',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
},
body: [
{
type: 'input-text',
name: 'name',
label: '名称',
},
{
type: 'select',
name: 'strategy',
label: '类型',
value: 'Cosine',
options: [
{
label: '文本',
value: 'Cosine',
},
{
label: '图片',
value: 'Euclid',
disabled: true,
},
],
},
],
},
},
},
],
columns: [
{
name: 'name',
label: '名称',
},
{
label: '类型',
width: 80,
align: 'center',
...mappingField('strategy', strategyMapping),
},
{
name: 'points',
label: '文本数',
width: 80,
align: 'center',
},
{
label: '状态',
width: 80,
align: 'center',
...mappingField('status', statusMapping),
},
{
type: 'operation',
label: '操作',
width: 150,
buttons: [
{
type: 'action',
label: '详情',
level: 'link',
size: 'xs',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(`/ai/knowledge/detail/${context.props.data['name']}`)
},
},
],
},
},
},
{
type: 'action',
label: '导入',
level: 'link',
size: 'xs',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(`/ai/knowledge/import/${context.props.data['name']}`)
},
},
],
},
},
},
{
type: 'action',
label: '删除',
className: 'text-danger hover:text-red-600',
level: 'link',
size: 'xs',
actionType: 'ajax',
api: {
method: 'get',
url: 'http://127.0.0.1:8080/knowledge/delete?name=${name}',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},
},
confirmText: '确认删除',
confirmTitle: '删除',
},
],
},
],
},
],
},
)}
</div>
)
}
export default Knowledge