feat:【antd】【ai】知识库的 knowledge segment、document 优化
This commit is contained in:
@@ -26,10 +26,12 @@ export function getKnowledgeDocumentPage(params: PageParam) {
|
|||||||
export function getKnowledgeDocument(id: number) {
|
export function getKnowledgeDocument(id: number) {
|
||||||
return requestClient.get(`/ai/knowledge/document/get?id=${id}`);
|
return requestClient.get(`/ai/knowledge/document/get?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增知识库文档(单个)
|
// 新增知识库文档(单个)
|
||||||
export function createKnowledge(data: any) {
|
export function createKnowledge(data: any) {
|
||||||
return requestClient.post('/ai/knowledge/document/create', data);
|
return requestClient.post('/ai/knowledge/document/create', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增知识库文档(多个)
|
// 新增知识库文档(多个)
|
||||||
export function createKnowledgeDocumentList(data: any) {
|
export function createKnowledgeDocumentList(data: any) {
|
||||||
return requestClient.post('/ai/knowledge/document/create-list', data);
|
return requestClient.post('/ai/knowledge/document/create-list', data);
|
||||||
@@ -44,6 +46,7 @@ export function updateKnowledgeDocument(data: any) {
|
|||||||
export function updateKnowledgeDocumentStatus(data: any) {
|
export function updateKnowledgeDocumentStatus(data: any) {
|
||||||
return requestClient.put('/ai/knowledge/document/update-status', data);
|
return requestClient.put('/ai/knowledge/document/update-status', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除知识库文档
|
// 删除知识库文档
|
||||||
export function deleteKnowledgeDocument(id: number) {
|
export function deleteKnowledgeDocument(id: number) {
|
||||||
return requestClient.delete(`/ai/knowledge/document/delete?id=${id}`);
|
return requestClient.delete(`/ai/knowledge/document/delete?id=${id}`);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export function getKnowledge(id: number) {
|
|||||||
`/ai/knowledge/get?id=${id}`,
|
`/ai/knowledge/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增知识库
|
// 新增知识库
|
||||||
export function createKnowledge(data: AiKnowledgeKnowledgeApi.Knowledge) {
|
export function createKnowledge(data: AiKnowledgeKnowledgeApi.Knowledge) {
|
||||||
return requestClient.post('/ai/knowledge/create', data);
|
return requestClient.post('/ai/knowledge/create', data);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export function getKnowledgeSegment(id: number) {
|
|||||||
`/ai/knowledge/segment/get?id=${id}`,
|
`/ai/knowledge/segment/get?id=${id}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增知识库分段
|
// 新增知识库分段
|
||||||
export function createKnowledgeSegment(
|
export function createKnowledgeSegment(
|
||||||
data: AiKnowledgeSegmentApi.KnowledgeSegment,
|
data: AiKnowledgeSegmentApi.KnowledgeSegment,
|
||||||
@@ -47,9 +48,13 @@ export function updateKnowledgeSegment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改知识库分段状态
|
// 修改知识库分段状态
|
||||||
export function updateKnowledgeSegmentStatus(data: any) {
|
export function updateKnowledgeSegmentStatus(id: number, status: number) {
|
||||||
return requestClient.put('/ai/knowledge/segment/update-status', data);
|
return requestClient.put('/ai/knowledge/segment/update-status', {
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除知识库分段
|
// 删除知识库分段
|
||||||
export function deleteKnowledgeSegment(id: number) {
|
export function deleteKnowledgeSegment(id: number) {
|
||||||
return requestClient.delete(`/ai/knowledge/segment/delete?id=${id}`);
|
return requestClient.delete(`/ai/knowledge/segment/delete?id=${id}`);
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { AiKnowledgeDocumentApi } from '#/api/ai/knowledge/document';
|
||||||
|
|
||||||
import { AiModelTypeEnum, CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
import { AiModelTypeEnum, CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
import { getModelSimpleList } from '#/api/ai/model/model';
|
import { getModelSimpleList } from '#/api/ai/model/model';
|
||||||
|
|
||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
@@ -92,12 +94,17 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'name',
|
fieldName: 'name',
|
||||||
label: '文件名称',
|
label: '文件名称',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入文件名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'status',
|
fieldName: 'status',
|
||||||
label: '是否启用',
|
label: '是否启用',
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
placeholder: '请选择是否启用',
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||||
},
|
},
|
||||||
@@ -106,45 +113,66 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
export function useGridColumns(
|
||||||
|
onStatusChange?: (
|
||||||
|
newStatus: number,
|
||||||
|
row: AiKnowledgeDocumentApi.KnowledgeDocument,
|
||||||
|
) => PromiseLike<boolean | undefined>,
|
||||||
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '文档编号',
|
title: '文档编号',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
title: '文件名称',
|
title: '文件名称',
|
||||||
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'contentLength',
|
field: 'contentLength',
|
||||||
title: '字符数',
|
title: '字符数',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'tokens',
|
field: 'tokens',
|
||||||
title: 'Token 数',
|
title: 'Token 数',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'segmentMaxTokens',
|
field: 'segmentMaxTokens',
|
||||||
title: '分片最大 Token 数',
|
title: '分片最大 Token 数',
|
||||||
|
minWidth: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'retrievalCount',
|
field: 'retrievalCount',
|
||||||
title: '召回次数',
|
title: '召回次数',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'status',
|
field: 'status',
|
||||||
title: '是否启用',
|
title: '是否启用',
|
||||||
slots: { default: 'status' },
|
minWidth: 100,
|
||||||
|
align: 'center',
|
||||||
|
cellRender: {
|
||||||
|
attrs: { beforeChange: onStatusChange },
|
||||||
|
name: 'CellSwitch',
|
||||||
|
props: {
|
||||||
|
checkedValue: CommonStatusEnum.ENABLE,
|
||||||
|
unCheckedValue: CommonStatusEnum.DISABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: '上传时间',
|
title: '上传时间',
|
||||||
|
minWidth: 180,
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 150,
|
minWidth: 150,
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
slots: { default: 'actions' },
|
slots: { default: 'actions' },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import type { AxiosProgressEvent } from '#/api/infra/file';
|
|||||||
import { computed, getCurrentInstance, inject, onMounted, ref } from 'vue';
|
import { computed, getCurrentInstance, inject, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
import { $t } from '@vben/locales';
|
|
||||||
import { generateAcceptedFileTypes } from '@vben/utils';
|
import { generateAcceptedFileTypes } from '@vben/utils';
|
||||||
|
|
||||||
import { Button, Form, message, UploadDragger } from 'ant-design-vue';
|
import { Button, Form, message, UploadDragger } from 'ant-design-vue';
|
||||||
@@ -124,7 +123,7 @@ async function customRequest(info: UploadRequestOption<any>) {
|
|||||||
};
|
};
|
||||||
const res = await httpRequest(info.file as File, progressEvent);
|
const res = await httpRequest(info.file as File, progressEvent);
|
||||||
info.onSuccess!(res);
|
info.onSuccess!(res);
|
||||||
message.success($t('ui.upload.uploadSuccess'));
|
message.success('上传成功');
|
||||||
ensureListExists();
|
ensureListExists();
|
||||||
emit('update:modelValue', {
|
emit('update:modelValue', {
|
||||||
...props.modelValue,
|
...props.modelValue,
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import type { AiKnowledgeDocumentApi } from '#/api/ai/knowledge/document';
|
|||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { useAccess } from '@vben/access';
|
|
||||||
import { confirm, Page } from '@vben/common-ui';
|
import { confirm, Page } from '@vben/common-ui';
|
||||||
import { CommonStatusEnum } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
import { getDictLabel } from '@vben/hooks';
|
||||||
|
|
||||||
import { message, Switch } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
@@ -21,18 +21,18 @@ import { $t } from '#/locales';
|
|||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
/** AI 知识库文档 列表 */
|
/** AI 知识库文档列表 */
|
||||||
defineOptions({ name: 'AiKnowledgeDocument' });
|
defineOptions({ name: 'AiKnowledgeDocument' });
|
||||||
const { hasAccessByCodes } = useAccess();
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
/** 刷新表格 */
|
/** 刷新表格 */
|
||||||
function handleRefresh() {
|
function handleRefresh() {
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建 */
|
/** 创建知识库文档 */
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
router.push({
|
router.push({
|
||||||
name: 'AiKnowledgeDocumentCreate',
|
name: 'AiKnowledgeDocumentCreate',
|
||||||
@@ -40,7 +40,7 @@ function handleCreate() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑 */
|
/** 编辑知识库文档 */
|
||||||
function handleEdit(id: number) {
|
function handleEdit(id: number) {
|
||||||
router.push({
|
router.push({
|
||||||
name: 'AiKnowledgeDocumentUpdate',
|
name: 'AiKnowledgeDocumentUpdate',
|
||||||
@@ -48,7 +48,7 @@ function handleEdit(id: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除 */
|
/** 删除知识库文档 */
|
||||||
async function handleDelete(row: AiKnowledgeDocumentApi.KnowledgeDocument) {
|
async function handleDelete(row: AiKnowledgeDocumentApi.KnowledgeDocument) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||||
@@ -56,14 +56,13 @@ async function handleDelete(row: AiKnowledgeDocumentApi.KnowledgeDocument) {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteKnowledgeDocument(row.id as number);
|
await deleteKnowledgeDocument(row.id as number);
|
||||||
message.success({
|
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
|
||||||
});
|
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 跳转到知识库分段页面 */
|
/** 跳转到知识库分段页面 */
|
||||||
function handleSegment(id: number) {
|
function handleSegment(id: number) {
|
||||||
router.push({
|
router.push({
|
||||||
@@ -71,33 +70,38 @@ function handleSegment(id: number) {
|
|||||||
query: { documentId: id },
|
query: { documentId: id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/** 修改是否发布 */
|
|
||||||
|
/** 更新文档状态 */
|
||||||
async function handleStatusChange(
|
async function handleStatusChange(
|
||||||
|
newStatus: number,
|
||||||
row: AiKnowledgeDocumentApi.KnowledgeDocument,
|
row: AiKnowledgeDocumentApi.KnowledgeDocument,
|
||||||
) {
|
): Promise<boolean | undefined> {
|
||||||
try {
|
return new Promise((resolve, reject) => {
|
||||||
// 修改状态的二次确认
|
confirm({
|
||||||
const text = row.status ? '启用' : '禁用';
|
content: `你要将${row.name}的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`,
|
||||||
await confirm(`确认要"${text}"${row.name}文档吗?`).then(async () => {
|
})
|
||||||
|
.then(async () => {
|
||||||
|
// 更新文档状态
|
||||||
await updateKnowledgeDocumentStatus({
|
await updateKnowledgeDocumentStatus({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
status: row.status,
|
status: newStatus,
|
||||||
|
});
|
||||||
|
// 提示并返回成功
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
reject(new Error('取消操作'));
|
||||||
});
|
});
|
||||||
handleRefresh();
|
|
||||||
});
|
});
|
||||||
} catch {
|
|
||||||
row.status =
|
|
||||||
row.status === CommonStatusEnum.ENABLE
|
|
||||||
? CommonStatusEnum.DISABLE
|
|
||||||
: CommonStatusEnum.ENABLE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(),
|
columns: useGridColumns(handleStatusChange),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
@@ -114,6 +118,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
keyField: 'id',
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
@@ -121,6 +126,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
} as VxeTableGridOptions<AiKnowledgeDocumentApi.KnowledgeDocument>,
|
} as VxeTableGridOptions<AiKnowledgeDocumentApi.KnowledgeDocument>,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 初始化 */
|
/** 初始化 */
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 如果知识库 ID 不存在,显示错误提示并关闭页面
|
// 如果知识库 ID 不存在,显示错误提示并关闭页面
|
||||||
@@ -148,15 +154,6 @@ onMounted(() => {
|
|||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #status="{ row }">
|
|
||||||
<Switch
|
|
||||||
v-model:checked="row.status"
|
|
||||||
:checked-value="0"
|
|
||||||
:un-checked-value="1"
|
|
||||||
@change="handleStatusChange(row)"
|
|
||||||
:disabled="!hasAccessByCodes(['ai:knowledge:update'])"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<template #actions="{ row }">
|
<template #actions="{ row }">
|
||||||
<TableAction
|
<TableAction
|
||||||
:actions="[
|
:actions="[
|
||||||
@@ -178,6 +175,8 @@ onMounted(() => {
|
|||||||
{
|
{
|
||||||
label: $t('common.delete'),
|
label: $t('common.delete'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
|
danger: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
auth: ['ai:knowledge:delete'],
|
auth: ['ai:knowledge:delete'],
|
||||||
popConfirm: {
|
popConfirm: {
|
||||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { AiKnowledgeSegmentApi } from '#/api/ai/knowledge/segment';
|
||||||
|
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
|
|
||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
@@ -43,12 +44,17 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'documentId',
|
fieldName: 'documentId',
|
||||||
label: '文档编号',
|
label: '文档编号',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入文档编号',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'status',
|
fieldName: 'status',
|
||||||
label: '是否启用',
|
label: '是否启用',
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
placeholder: '请选择是否启用',
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||||
},
|
},
|
||||||
@@ -57,11 +63,17 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
export function useGridColumns(
|
||||||
|
onStatusChange?: (
|
||||||
|
newStatus: number,
|
||||||
|
row: AiKnowledgeSegmentApi.KnowledgeSegment,
|
||||||
|
) => PromiseLike<boolean | undefined>,
|
||||||
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '分段编号',
|
title: '分段编号',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'expand',
|
type: 'expand',
|
||||||
@@ -76,23 +88,36 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
{
|
{
|
||||||
field: 'contentLength',
|
field: 'contentLength',
|
||||||
title: '字符数',
|
title: '字符数',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'tokens',
|
field: 'tokens',
|
||||||
title: 'token 数量',
|
title: 'token 数量',
|
||||||
|
minWidth: 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'retrievalCount',
|
field: 'retrievalCount',
|
||||||
title: '召回次数',
|
title: '召回次数',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'status',
|
field: 'status',
|
||||||
title: '是否启用',
|
title: '状态',
|
||||||
slots: { default: 'status' },
|
minWidth: 100,
|
||||||
|
align: 'center',
|
||||||
|
cellRender: {
|
||||||
|
attrs: { beforeChange: onStatusChange },
|
||||||
|
name: 'CellSwitch',
|
||||||
|
props: {
|
||||||
|
checkedValue: CommonStatusEnum.ENABLE,
|
||||||
|
unCheckedValue: CommonStatusEnum.DISABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
|
minWidth: 180,
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import type { AiKnowledgeSegmentApi } from '#/api/ai/knowledge/segment';
|
|||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import { useAccess } from '@vben/access';
|
|
||||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { CommonStatusEnum } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
import { getDictLabel } from '@vben/hooks';
|
||||||
|
|
||||||
import { message, Switch } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +23,7 @@ import { useGridColumns, useGridFormSchema } from './data';
|
|||||||
import Form from './modules/form.vue';
|
import Form from './modules/form.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { hasAccessByCodes } = useAccess();
|
|
||||||
const [FormModal, formModalApi] = useVbenModal({
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
connectedComponent: Form,
|
connectedComponent: Form,
|
||||||
destroyOnClose: true,
|
destroyOnClose: true,
|
||||||
@@ -34,17 +34,17 @@ function handleRefresh() {
|
|||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建 */
|
/** 创建知识库片段 */
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
formModalApi.setData({ documentId: route.query.documentId }).open();
|
formModalApi.setData({ documentId: route.query.documentId }).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑 */
|
/** 编辑知识库片段 */
|
||||||
function handleEdit(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
function handleEdit(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除 */
|
/** 删除知识库片段 */
|
||||||
async function handleDelete(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
async function handleDelete(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||||
@@ -52,21 +52,41 @@ async function handleDelete(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteKnowledgeSegment(row.id as number);
|
await deleteKnowledgeSegment(row.id as number);
|
||||||
message.success({
|
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
|
||||||
});
|
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 更新知识库片段状态 */
|
||||||
|
async function handleStatusChange(
|
||||||
|
newStatus: number,
|
||||||
|
row: AiKnowledgeSegmentApi.KnowledgeSegment,
|
||||||
|
): Promise<boolean | undefined> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
confirm({
|
||||||
|
content: `你要将片段 ${row.id} 的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`,
|
||||||
|
})
|
||||||
|
.then(async () => {
|
||||||
|
// 更新片段状态
|
||||||
|
await updateKnowledgeSegmentStatus(row.id!, newStatus);
|
||||||
|
// 提示并返回成功
|
||||||
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
reject(new Error('取消操作'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(),
|
columns: useGridColumns(handleStatusChange),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
@@ -82,6 +102,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
keyField: 'id',
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
@@ -90,26 +111,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
} as VxeTableGridOptions<AiKnowledgeSegmentApi.KnowledgeSegment>,
|
} as VxeTableGridOptions<AiKnowledgeSegmentApi.KnowledgeSegment>,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 修改是否发布 */
|
/** 初始化 */
|
||||||
async function handleStatusChange(row: AiKnowledgeSegmentApi.KnowledgeSegment) {
|
|
||||||
try {
|
|
||||||
// 修改状态的二次确认
|
|
||||||
const text = row.status ? '启用' : '禁用';
|
|
||||||
await confirm(`确认要"${text}"该分段吗?`).then(async () => {
|
|
||||||
await updateKnowledgeSegmentStatus({
|
|
||||||
id: row.id,
|
|
||||||
status: row.status,
|
|
||||||
});
|
|
||||||
gridApi.reload();
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
row.status =
|
|
||||||
row.status === CommonStatusEnum.ENABLE
|
|
||||||
? CommonStatusEnum.DISABLE
|
|
||||||
: CommonStatusEnum.ENABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
gridApi.formApi.setFieldValue('documentId', route.query.documentId);
|
gridApi.formApi.setFieldValue('documentId', route.query.documentId);
|
||||||
});
|
});
|
||||||
@@ -132,15 +134,6 @@ onMounted(() => {
|
|||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #status="{ row }">
|
|
||||||
<Switch
|
|
||||||
v-model:checked="row.status"
|
|
||||||
:checked-value="0"
|
|
||||||
:un-checked-value="1"
|
|
||||||
@change="handleStatusChange(row)"
|
|
||||||
:disabled="!hasAccessByCodes(['ai:knowledge:update'])"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<template #expand_content="{ row }">
|
<template #expand_content="{ row }">
|
||||||
<div
|
<div
|
||||||
class="whitespace-pre-wrap border-l-4 border-blue-500 px-2.5 py-5 leading-5"
|
class="whitespace-pre-wrap border-l-4 border-blue-500 px-2.5 py-5 leading-5"
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
// 加载数据
|
// 加载数据
|
||||||
const data = modalApi.getData<AiKnowledgeSegmentApi.KnowledgeSegment>();
|
const data = modalApi.getData<AiKnowledgeSegmentApi.KnowledgeSegment>();
|
||||||
if (!data || !data.id) {
|
if (!data || !data.id) {
|
||||||
await formApi.setValues(data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
|
|||||||
Reference in New Issue
Block a user