|
@@ -3,6 +3,7 @@ import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { CloudObject, CloudQuery } from '../../../../lib/cloud/ncloud';
|
|
|
+import { HostListener } from '@angular/core';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-page-crm-data',
|
|
@@ -14,6 +15,11 @@ import { CloudObject, CloudQuery } from '../../../../lib/cloud/ncloud';
|
|
|
|
|
|
export class PageCrmData implements AfterViewInit {
|
|
|
// 标签相关数据
|
|
|
+
|
|
|
+ //7.3
|
|
|
+ @ViewChild('messageInput') messageInput!: ElementRef<HTMLTextAreaElement>;
|
|
|
+ @ViewChild('messageContainer') messageContainer!: ElementRef<HTMLDivElement>;
|
|
|
+ //
|
|
|
// 标签相关数据
|
|
|
sourceTags = [
|
|
|
{
|
|
@@ -563,4 +569,185 @@ getTypeIcon(type: string): string {
|
|
|
});
|
|
|
}, 5000);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //7.2
|
|
|
+
|
|
|
+ // AI对话相关属性
|
|
|
+ showAIDialog = false;
|
|
|
+ currentAIModel: any = null;
|
|
|
+ userMessage = '';
|
|
|
+ aiMessages: any[] = [];
|
|
|
+ isAIThinking = false;
|
|
|
+ aiSuggestions = [
|
|
|
+ '这个模型的具体功能是什么?',
|
|
|
+ '模型使用了哪些训练数据?',
|
|
|
+ '模型的准确率和性能指标如何?',
|
|
|
+ '如何在实际业务中使用这个模型?'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 知识库 - 模拟真实AI回答
|
|
|
+ private knowledgeBase: { [key: string]: any } = {
|
|
|
+ '销售预测模型': {
|
|
|
+ description: '该模型基于历史销售数据和市场趋势,能够预测未来3-6个月的销售情况,准确率达到87.5%。',
|
|
|
+ dataUsed: '使用了2019-2023年的销售记录、客户购买行为数据和市场调研报告。',
|
|
|
+ accuracy: '测试集准确率87.5%,召回率82.3%,F1分数84.8%。',
|
|
|
+ usage: '通过API集成到CRM系统,每日自动生成销售预测报告。'
|
|
|
+ },
|
|
|
+ '情感分析模型': {
|
|
|
+ description: '分析客户反馈、评论和社交媒体中的情感倾向,识别正面、负面和中性情绪。',
|
|
|
+ dataUsed: '10万条客户评论、5万条客服对话记录和社交媒体数据。',
|
|
|
+ accuracy: '情感分类准确率92.1%,支持中文、英文和西班牙语。',
|
|
|
+ usage: '实时分析客户反馈,自动触发满意度低的客户跟进流程。'
|
|
|
+ },
|
|
|
+ '趋势预测模型': {
|
|
|
+ description: '识别产品需求变化和市场趋势,帮助调整库存和营销策略。',
|
|
|
+ dataUsed: '行业报告、搜索引擎趋势和产品销售数据。',
|
|
|
+ accuracy: '趋势预测准确率79.3%,提前3个月预警市场变化。',
|
|
|
+ usage: '每周生成趋势报告,指导产品开发和营销活动。'
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开AI对话框
|
|
|
+ openAIDialog(model: any) {
|
|
|
+ if (model.status !== 'completed') return;
|
|
|
+
|
|
|
+ this.currentAIModel = model;
|
|
|
+ this.showAIDialog = true;
|
|
|
+ this.userMessage = '';
|
|
|
+
|
|
|
+ // 初始化AI欢迎消息
|
|
|
+ this.aiMessages = [{
|
|
|
+ role: 'assistant',
|
|
|
+ content: `您好!我是${model.title} AI助手,专为销售团队设计。我可以回答关于这个模型的各种问题,包括:<br>
|
|
|
+ • 模型功能和应用场景<br>
|
|
|
+ • 训练数据和性能指标<br>
|
|
|
+ • 实际使用方法和集成方式<br><br>
|
|
|
+ 请问您想了解什么?`,
|
|
|
+ time: new Date()
|
|
|
+ }];
|
|
|
+
|
|
|
+ // 自动聚焦输入框
|
|
|
+ setTimeout(() => {
|
|
|
+ this.messageInput.nativeElement.focus();
|
|
|
+ this.scrollToBottom();
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭AI对话框
|
|
|
+ closeAIDialog() {
|
|
|
+ this.showAIDialog = false;
|
|
|
+ this.currentAIModel = null;
|
|
|
+ this.userMessage = '';
|
|
|
+ this.aiMessages = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送消息
|
|
|
+ sendMessage(event?: Event) {
|
|
|
+ if (event) event.preventDefault();
|
|
|
+ if (!this.userMessage.trim()) return;
|
|
|
+
|
|
|
+ const question = this.userMessage.trim();
|
|
|
+
|
|
|
+ // 添加用户消息
|
|
|
+ this.aiMessages.push({
|
|
|
+ role: 'user',
|
|
|
+ content: question,
|
|
|
+ time: new Date()
|
|
|
+ });
|
|
|
+
|
|
|
+ this.userMessage = '';
|
|
|
+ this.isAIThinking = true;
|
|
|
+ this.scrollToBottom();
|
|
|
+
|
|
|
+ // 获取AI响应
|
|
|
+ setTimeout(() => {
|
|
|
+ const response = this.generateAIResponse(question);
|
|
|
+ this.aiMessages.push({
|
|
|
+ role: 'assistant',
|
|
|
+ content: response,
|
|
|
+ time: new Date()
|
|
|
+ });
|
|
|
+ this.isAIThinking = false;
|
|
|
+ this.scrollToBottom();
|
|
|
+ }, 800); // 模拟网络延迟
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成AI响应
|
|
|
+ private generateAIResponse(question: string): string {
|
|
|
+ const model = this.currentAIModel.title;
|
|
|
+ const knowledge = this.knowledgeBase[model] || {};
|
|
|
+
|
|
|
+ // 问题分类和回答
|
|
|
+ if (question.includes('功能') || question.includes('做什么') || question.includes('用途')) {
|
|
|
+ return `关于<strong>${model}</strong>的功能:<br><br>${knowledge.description ||
|
|
|
+ '该模型主要用于销售场景的数据分析和决策支持,具体功能包括预测分析、趋势识别和客户行为分析等。'}`;
|
|
|
+ }
|
|
|
+ else if (question.includes('数据') || question.includes('训练') || question.includes('样本')) {
|
|
|
+ return `关于<strong>${model}</strong>的训练数据:<br><br>${knowledge.dataUsed ||
|
|
|
+ '模型使用了公司多年的销售数据、客户互动记录和市场调研数据,经过严格的数据清洗和特征工程处理。'}`;
|
|
|
+ }
|
|
|
+ else if (question.includes('准确') || question.includes('性能') || question.includes('指标')) {
|
|
|
+ return `关于<strong>${model}</strong>的性能指标:<br><br>${knowledge.accuracy ||
|
|
|
+ '模型在测试集上表现良好,准确率和召回率均超过80%,具体指标会根据不同业务场景有所变化。'}`;
|
|
|
+ }
|
|
|
+ else if (question.includes('使用') || question.includes('怎么用') || question.includes('集成')) {
|
|
|
+ return `关于<strong>${model}</strong>的使用方法:<br><br>${knowledge.usage ||
|
|
|
+ '可以通过我们的API接口集成到现有系统中,也支持导出分析报告。详细技术文档请联系技术团队获取。'}`;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return `感谢您的提问。关于"${question}",${model}可以提供专业分析:<br><br>
|
|
|
+ 1. 该问题涉及${model}的${question.includes('客户') ? '客户分析' : '预测'}功能<br>
|
|
|
+ 2. 我们建议${question.includes('销售') ? '结合历史销售数据' : '参考模型输出'}进行决策<br>
|
|
|
+ 3. 如需更详细分析,可以提供具体数据样本<br><br>
|
|
|
+ 您是否需要更具体的信息?`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择建议问题
|
|
|
+ selectSuggestion(suggestion: string) {
|
|
|
+ this.userMessage = suggestion;
|
|
|
+ this.sendMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 修改训练结果项的点击处理
|
|
|
+ onResultClick(result: any) {
|
|
|
+ if (result.status === 'completed') {
|
|
|
+ this.openAIDialog(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 监听滚轮事件
|
|
|
+ @HostListener('wheel', ['$event'])
|
|
|
+ onWheel(event: WheelEvent) {
|
|
|
+ // 防止页面整体滚动
|
|
|
+ if (this.showAIDialog) {
|
|
|
+ const container = this.messageContainer?.nativeElement;
|
|
|
+ if (container && container.contains(event.target as Node)) {
|
|
|
+ event.preventDefault();
|
|
|
+ container.scrollTop += event.deltaY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保每次新消息都滚动到底部
|
|
|
+ ngAfterViewChecked() {
|
|
|
+ this.scrollToBottom();
|
|
|
+ }
|
|
|
+
|
|
|
+ private scrollToBottom(): void {
|
|
|
+ if (this.messageContainer) {
|
|
|
+ try {
|
|
|
+ const container = this.messageContainer.nativeElement;
|
|
|
+ container.scrollTop = container.scrollHeight;
|
|
|
+ } catch (err) {
|
|
|
+ console.error('滚动错误:', err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ //
|