Compare commits
2 Commits
234b376adb
...
3ac7e69330
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ac7e69330 | |||
| 5685dab1d0 |
@@ -114,7 +114,7 @@ export async function updateAiHistoryBatch(data: { list: AiHistory[] }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除AI审计历史记录表
|
||||
* 批量删除 AI审计历史记录表
|
||||
*/
|
||||
export async function removeAiHistoryBatch(ids: number[]) {
|
||||
const res = await request.delete<ApiResult<unknown>>(
|
||||
@@ -127,3 +127,20 @@ export async function removeAiHistoryBatch(ids: number[]) {
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据接口名称和项目 ID 查询最新的历史记录
|
||||
*/
|
||||
export async function getLatestHistoryByInterface(params: {
|
||||
interfaceName: string;
|
||||
projectId: number;
|
||||
}) {
|
||||
const res = await request.get<ApiResult<AiHistory>>(
|
||||
`${MODULES_API_URL}/ai/history/latest`,
|
||||
{ params }
|
||||
);
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
return null; // 如果没有数据,返回 null
|
||||
}
|
||||
|
||||
|
||||
@@ -183,4 +183,117 @@ export async function generateAuditReportWithEvidences(projectId: number, eviden
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error('文件下载失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据项目 ID、选中的取证单和章节内容生成审计报告并下载
|
||||
* @param projectId 项目 ID
|
||||
* @param evidenceIds 勾选的取证单 ID 列表
|
||||
* @param chapters 章节内容数组(包含 formCommit 和 reportContent)
|
||||
* @param evaluate 总体评价
|
||||
* @param suggestion 审计建议
|
||||
*/
|
||||
export async function generateAuditReportWithContent(
|
||||
projectId: number,
|
||||
evidenceIds: number[],
|
||||
chapters: Array<{
|
||||
formCommit: number;
|
||||
reportContent: string;
|
||||
}>,
|
||||
evaluate?: string,
|
||||
suggestion?: string
|
||||
) {
|
||||
const res = await request.post(
|
||||
MODULES_API_URL + '/ai/auditReport/generateWithContent',
|
||||
{
|
||||
evidenceIds,
|
||||
chapters,
|
||||
evaluate,
|
||||
suggestion
|
||||
},
|
||||
{
|
||||
params: { projectId },
|
||||
responseType: 'blob' // 处理二进制流响应
|
||||
}
|
||||
);
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
return Promise.reject(new Error('文件下载失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 生成默认话术
|
||||
*/
|
||||
export async function generateDefaultText(params: {
|
||||
projectId?: number;
|
||||
formCommit: number;
|
||||
chapterTitle?: string;
|
||||
evidenceIds?: number[]; // 新增:选中的取证单 ID 列表
|
||||
}) {
|
||||
const res = await request.post<ApiResult<string>>(
|
||||
MODULES_API_URL + '/ai/auditReport/generateDefaultText',
|
||||
{
|
||||
projectId: params.projectId,
|
||||
formCommit: params.formCommit,
|
||||
chapterTitle: params.chapterTitle,
|
||||
evidenceIds: params.evidenceIds
|
||||
}
|
||||
);
|
||||
|
||||
if (res.data.code === 0) {
|
||||
// 后端返回的数据在 message 字段中
|
||||
return res.data.message || res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 分析用户自定义输入
|
||||
*/
|
||||
export async function analyzeUserInput(params: {
|
||||
formCommit: number;
|
||||
userQuestion: string;
|
||||
chapterContent?: string;
|
||||
}) {
|
||||
const res = await request.post<ApiResult<string>>(
|
||||
MODULES_API_URL + '/ai/auditReport/analyzeUserInput',
|
||||
null,
|
||||
{
|
||||
params
|
||||
}
|
||||
);
|
||||
|
||||
if (res.data.code === 0) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据取证单生成审计建议
|
||||
*/
|
||||
export async function generateAuditSuggestion(params: {
|
||||
projectId: number;
|
||||
evidenceIds: number[];
|
||||
}) {
|
||||
const res = await request.post<ApiResult<string>>(
|
||||
MODULES_API_URL + '/ai/auditReport/generateAuditSuggestion',
|
||||
{ evidenceIds: params.evidenceIds },
|
||||
{
|
||||
params: {
|
||||
projectId: params.projectId
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (res.data.code === 0) {
|
||||
// 后端返回的数据在 message 字段中
|
||||
return res.data.message || res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
@@ -80,11 +80,12 @@ const props = defineProps<{
|
||||
visible: boolean;
|
||||
interfaceName?: string;
|
||||
projectId?: number;
|
||||
chapter?: any; // 当前章节对象
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
(e: 'select', record: any): void;
|
||||
(e: 'select', record: any, chapter?: any): void;
|
||||
}>();
|
||||
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
@@ -99,7 +100,11 @@ const datasource: DatasourceFunction = async ({ page, limit, orders }) => {
|
||||
if (orders) {
|
||||
Object.assign(params, orders);
|
||||
}
|
||||
console.log(props,'props');
|
||||
|
||||
console.log('===== HistoryModal Props =====', props);
|
||||
console.log('interfaceName:', props.interfaceName);
|
||||
console.log('projectId:', props.projectId);
|
||||
|
||||
// 使用传入的接口名称进行过滤
|
||||
if (props.interfaceName) {
|
||||
params.interfaceName = props.interfaceName;
|
||||
@@ -107,6 +112,8 @@ const datasource: DatasourceFunction = async ({ page, limit, orders }) => {
|
||||
if (props.projectId) {
|
||||
params.projectId = props.projectId;
|
||||
}
|
||||
|
||||
console.log('查询参数 params:', params);
|
||||
|
||||
try {
|
||||
const result = await pageAiHistory(params);
|
||||
@@ -116,14 +123,23 @@ const datasource: DatasourceFunction = async ({ page, limit, orders }) => {
|
||||
let processingTime = '';
|
||||
|
||||
try {
|
||||
// responseData 直接就是 AI 生成的文本内容,不是 JSON 对象
|
||||
// 这里只是为了统计展示信息,不影响主要内容显示
|
||||
if (record.responseData) {
|
||||
const responseData = JSON.parse(record.responseData);
|
||||
if (responseData.data && Array.isArray(responseData.data)) {
|
||||
dataCount = responseData.data.length;
|
||||
} else if (responseData.data?.data && Array.isArray(responseData.data.data)) {
|
||||
dataCount = responseData.data.data.length;
|
||||
// 尝试解析是否为 JSON 格式(兼容旧数据)
|
||||
try {
|
||||
const parsed = JSON.parse(record.responseData);
|
||||
if (parsed.data && Array.isArray(parsed.data)) {
|
||||
dataCount = parsed.data.length;
|
||||
} else if (parsed.data?.data && Array.isArray(parsed.data.data)) {
|
||||
dataCount = parsed.data.data.length;
|
||||
}
|
||||
processingTime = parsed.processing_time || parsed.generated_time || '';
|
||||
} catch (e) {
|
||||
// 如果不是 JSON,说明是纯文本,不需要统计这些数据
|
||||
dataCount = 0;
|
||||
processingTime = '';
|
||||
}
|
||||
processingTime = responseData.processing_time || responseData.generated_time || '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('解析响应数据失败:', error);
|
||||
@@ -258,6 +274,14 @@ const getRequestDataPreview = (record: any) => {
|
||||
const hasValidData = (record: any) => {
|
||||
try {
|
||||
if (record.responseData) {
|
||||
// responseData 可能是纯文本(AI 生成的审计报告内容),也可能是 JSON 对象
|
||||
// 对于纯文本,只要有内容就认为有效
|
||||
if (typeof record.responseData === 'string') {
|
||||
// 如果是字符串,检查是否非空
|
||||
return record.responseData.trim().length > 0;
|
||||
}
|
||||
|
||||
// 如果是对象,尝试解析 JSON
|
||||
const responseData = JSON.parse(record.responseData);
|
||||
const hasData = (responseData.data && Array.isArray(responseData.data) && responseData.data.length > 0) ||
|
||||
(responseData.data?.data && Array.isArray(responseData.data.data) && responseData.data.data.length > 0);
|
||||
@@ -265,13 +289,15 @@ const hasValidData = (record: any) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('检查数据有效性失败:', error);
|
||||
// 如果解析失败,但有 responseData 字符串,也认为有效(说明是纯文本)
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleSelect = (record: any) => {
|
||||
if (!hasValidData(record)) return;
|
||||
emit('select', record);
|
||||
emit('select', record, props.chapter);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -170,45 +170,34 @@
|
||||
<!-- </div>-->
|
||||
<!-- 单内容部分 -->
|
||||
<template v-if="!item.children">
|
||||
<a-textarea
|
||||
v-model:value="item.content"
|
||||
:rows="item.rows || 8"
|
||||
:placeholder="'点击(AI生成)按钮让AI为您生成该部分内容,或直接填入'"
|
||||
class="content-textarea"
|
||||
style="margin-top: 16px; background-color: #f0fdf4"
|
||||
/>
|
||||
|
||||
<div style="margin-top: 12px;">
|
||||
<div class="question-prompt">AI小助手</div>
|
||||
<div class="textarea-with-button" style="width: 600px">
|
||||
<a-textarea
|
||||
v-model:value="item.suggestion"
|
||||
:rows="3"
|
||||
placeholder="请输入您的要求并回车..."
|
||||
class="suggestion-textarea-inner"
|
||||
@pressEnter="generateContent(index)"
|
||||
/>
|
||||
<a-button
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="generateContent(index)"
|
||||
:loading="item.generating"
|
||||
class="send-button-inner"
|
||||
>
|
||||
<template #icon>
|
||||
<RobotOutlined/>
|
||||
</template>
|
||||
发送
|
||||
</a-button>
|
||||
</div>
|
||||
<div class="content-with-ai-button">
|
||||
<a-textarea
|
||||
v-model:value="item.content"
|
||||
:rows="item.rows || 8"
|
||||
:placeholder="'点击 (AI 生成) 按钮让 AI 为您生成该部分内容,或直接填入'"
|
||||
class="content-textarea"
|
||||
style="background-color: #f0fdf4"
|
||||
/>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="large"
|
||||
@click="generateContent(index)"
|
||||
:loading="item.generating"
|
||||
class="ai-generate-btn"
|
||||
>
|
||||
<template #icon>
|
||||
<RobotOutlined/>
|
||||
</template>
|
||||
AI 生成
|
||||
</a-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 多内容部分 -->
|
||||
<template v-else>
|
||||
<div v-for="(child, childIndex) in item.children" :key="childIndex" class="child-section" style="border-left: 3px solid #1890ff; padding-left: 16px; margin-bottom: 20px;">
|
||||
<div class="child-title" style="display: flex; align-items: center; justify-content: space-between;">
|
||||
<span style="font-weight: bold;">{{ child.name }}</span>
|
||||
<template v-if="item.children">
|
||||
<div v-for="(child, childIndex) in item.children" :key="childIndex" class="child-section">
|
||||
<div class="child-header">
|
||||
<span class="child-title">{{ `(${childIndex + 1})${child.name}` }}</span>
|
||||
<a-space>
|
||||
<a-button
|
||||
type="primary"
|
||||
@@ -236,10 +225,10 @@
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
size="small"
|
||||
size="large"
|
||||
@click.stop="generateContent(index, childIndex)"
|
||||
:loading="child.generating"
|
||||
class="child-action-button ai-generate-button"
|
||||
class="ai-generate-btn"
|
||||
>
|
||||
<template #icon>
|
||||
<RobotOutlined/>
|
||||
@@ -253,34 +242,8 @@
|
||||
:rows="child.rows || 6"
|
||||
:placeholder="child.placeholder"
|
||||
class="content-textarea"
|
||||
style="margin-top: 12px; background-color: #f0fdf4"
|
||||
style="background-color: #f0fdf4"
|
||||
/>
|
||||
|
||||
<!-- AI小助手功能 -->
|
||||
<div style="margin-top: 12px">
|
||||
<div class="question-prompt">AI小助手</div>
|
||||
<div class="textarea-with-button" style="width: 600px">
|
||||
<a-textarea
|
||||
v-model:value="child.suggestion"
|
||||
:rows="3"
|
||||
placeholder="请输入优化提示词并回车..."
|
||||
class="suggestion-textarea-inner"
|
||||
@pressEnter="generateContent(index, childIndex)"
|
||||
/>
|
||||
<a-button
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="generateContent(index, childIndex)"
|
||||
:loading="child.generating"
|
||||
class="send-button-inner"
|
||||
>
|
||||
<template #icon>
|
||||
<RobotOutlined/>
|
||||
</template>
|
||||
发送
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</a-card>
|
||||
@@ -1807,24 +1770,68 @@ export default {
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.content-with-ai-button {
|
||||
position: relative;
|
||||
margin-top: 16px;
|
||||
|
||||
.ant-textarea {
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.ai-generate-btn {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 10;
|
||||
background-color: #722ed1 !important;
|
||||
border-color: #722ed1 !important;
|
||||
|
||||
&:hover {
|
||||
background-color: #9254de !important;
|
||||
border-color: #9254de !important;
|
||||
box-shadow: 0 4px 12px rgba(114, 46, 209, 0.4) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.child-section {
|
||||
margin-bottom: 24px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px dashed #e8e8e8;
|
||||
position: relative;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.child-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #1890ff;
|
||||
.child-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
padding: 12px 16px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 6px 6px 0 0;
|
||||
border-left: 3px solid #1890ff;
|
||||
|
||||
.child-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.ai-generate-btn {
|
||||
background-color: #722ed1 !important;
|
||||
border-color: #722ed1 !important;
|
||||
|
||||
&:hover {
|
||||
background-color: #9254de !important;
|
||||
border-color: #9254de !important;
|
||||
box-shadow: 0 4px 12px rgba(114, 46, 209, 0.4) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content-textarea {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user