|
@@ -111,12 +111,22 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { ref, reactive, nextTick, computed } from 'vue';
|
|
|
+import { ref, reactive, nextTick, computed, onMounted } from 'vue';
|
|
|
import { marked } from 'marked';
|
|
|
import { ChatLineRound, User, Download } from '@element-plus/icons-vue';
|
|
|
import { Document, Paragraph, TextRun, Packer } from 'docx';
|
|
|
-import { askAIQuestion, uploadFileApi, type AIQuestionParams, type UploadFileResponse } from '../api';
|
|
|
+import {
|
|
|
+ askAIQuestion,
|
|
|
+ uploadFileApi,
|
|
|
+ getLatestQuestionList,
|
|
|
+ type AIQuestionParams,
|
|
|
+ type UploadFileResponse,
|
|
|
+ type ChatContent,
|
|
|
+ type LatestQuestionResponse,
|
|
|
+ type AIQuestionResponse
|
|
|
+} from '../api';
|
|
|
import { ElMessage } from 'element-plus/es'
|
|
|
+import * as internal from 'stream';
|
|
|
const renderMarkdown = (content: string): string => {
|
|
|
// Configure marked with options
|
|
|
marked.setOptions({
|
|
@@ -300,9 +310,45 @@ const dateRange = ref([getFirstDayOfMonth(), new Date()]);
|
|
|
// Chat functionality
|
|
|
const inputMessage = ref('请进行数据分析,给一个总结报告,不超过300字');
|
|
|
const loading = ref(false);
|
|
|
-const messages = reactive<ChatMessage[]>([
|
|
|
- { role: 'assistant', content: '你好,需要分析查询哪些数据,请交给我' },
|
|
|
-]);
|
|
|
+const messages = reactive<ChatMessage[]>([]);
|
|
|
+const questionId = ref<number | null>(null);
|
|
|
+
|
|
|
+const isSameDay = (dateString: string, compareDate: Date) => {
|
|
|
+ // Parse yyyy-MM-dd hh:mm:ss format
|
|
|
+ const [datePart] = dateString.split(' ');
|
|
|
+ const [year, month, day] = datePart.split('-').map(Number);
|
|
|
+
|
|
|
+ return year === compareDate.getFullYear() &&
|
|
|
+ month - 1 === compareDate.getMonth() && // Months are 0-indexed in JS
|
|
|
+ day === compareDate.getDate();
|
|
|
+};
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ try {
|
|
|
+ const result = await getLatestQuestionList();
|
|
|
+ if (result.code === 'ok' && result.data.contents) {
|
|
|
+ result.data.contents.forEach(content => {
|
|
|
+ messages.push({
|
|
|
+ role: content.type === 0 ? 'assistant' : 'user',
|
|
|
+ content: content.content
|
|
|
+ });
|
|
|
+
|
|
|
+ // Check if createTime is today and set questionId
|
|
|
+ if (content.createTime && content.questionId) {
|
|
|
+ if (isSameDay(content.createTime, new Date())) {
|
|
|
+ questionId.value = content.questionId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // Default message if no history
|
|
|
+ messages.push({ role: 'assistant', content: '你好,需要分析查询哪些数据,请交给我' });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Failed to load chat history:', error);
|
|
|
+ messages.push({ role: 'assistant', content: '你好,需要分析查询哪些数据,请交给我' });
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
const sendMessage = async () => {
|
|
|
if (!inputMessage.value.trim() || loading.value) return;
|
|
@@ -322,7 +368,7 @@ const sendMessage = async () => {
|
|
|
'free': 4
|
|
|
};
|
|
|
|
|
|
- const params: AIQuestionParams = {
|
|
|
+ const params: AIQuestionParams & { questionId?: number } = {
|
|
|
questionDataSource: dataSourceMap[dataSource.value],
|
|
|
sourceContent: dataSource.value === 'system' ? systemTable.value : '',
|
|
|
content: inputMessage.value,
|
|
@@ -331,12 +377,18 @@ const sendMessage = async () => {
|
|
|
url: dataSource.value === 'upload' ? uploadedFilePath.value : ''
|
|
|
};
|
|
|
|
|
|
+ // Only include questionId if we have one from today's conversation
|
|
|
+ if (questionId.value) {
|
|
|
+ params.questionId = questionId.value;
|
|
|
+ }
|
|
|
+
|
|
|
const result = await askAIQuestion(params);
|
|
|
messages[thinkingIndex] = {
|
|
|
role: 'assistant',
|
|
|
- content: result.data || '根据您的请求,我已分析了相关数据。分析结果显示...',
|
|
|
+ content: result.data.queryRes || '根据您的请求,我已分析了相关数据。分析结果显示...',
|
|
|
loading: false
|
|
|
};
|
|
|
+ questionId.value = result.data.questionId;
|
|
|
} catch (error) {
|
|
|
console.error('API error:', error);
|
|
|
messages[thinkingIndex] = {
|