|
@@ -1,4 +1,4 @@
|
|
-import { Component, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
|
|
|
|
|
|
+import { Component, OnInit, ViewChild, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
import * as echarts from 'echarts';
|
|
import * as echarts from 'echarts';
|
|
|
|
|
|
@@ -9,41 +9,43 @@ import * as echarts from 'echarts';
|
|
templateUrl: './page-interview.html',
|
|
templateUrl: './page-interview.html',
|
|
styleUrl: './page-interview.scss'
|
|
styleUrl: './page-interview.scss'
|
|
})
|
|
})
|
|
-export class PageInterview implements OnInit, AfterViewInit {
|
|
|
|
-remainingTime = '04:32';
|
|
|
|
-isAnalyzing = false;
|
|
|
|
-showSubmitButton = false;
|
|
|
|
-userAnswer = '';
|
|
|
|
-// 在组件中定义Base64编码的SVG
|
|
|
|
-avatarImages = {
|
|
|
|
- default: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNiAzNiI+PHBhdGggZmlsbD0iI0ZGQjkwMCIgZD0iTTM2IDE4YzAgOS45NDEtOC4wNTkgMTgtMTggMThTMCAyNy45NDEgMCAxOCA4LjA1OSAwIDE4IDBzMTggOC4wNTkgMTggMTgiLz48cGF0aCBmaWxsPSIjNjYyMjEyIiBkPSJNMTguODQ1IDEzLjE0OGMuMTM0LS4yNDYuMzU2LS4zNjkuNjU3LS4zNjkuMzA5IDAgLjUyOS4xMjMuNjY0LjM2OS4xMzYuMjQ1LjIwNC41NzkuMjA0IDEuMDAzIDAgLjQxNS0uMDY4Ljc0LS4yMDQuOTg1LS4xMzUuMjQ0LS4zNTUuMzY2LS42NjQuMzY2LS4zMDEgMC0uNTIzLS4xMjItLjY1Ny0uMzY2LS4xMzUtLjI0NS0uMjAyLS41Ny0uMjAyLS45ODUgMC0uNDI0LjA2Ny0uNzU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wNTQgNC45NTEtMS4wNTQgMi43NjMgMCA0Ljk1MS40MTkgNC45NTEgMS4wNTQgMCAuNjM1LTIuMTg4IDEuMDU0LTQuOTUxIDEuMDU0em0wLTIuMTA4Yy0zLjAxNyAwLTUuNDUxLS40OTQtNS40NTEtMS4wNTRzMi40MzQtMS4wNTQgNS40NTEtMS4wNTRjMy4wMTggMCA1LjQ1MS40OTQgNS40NTEgMS4wNTRzLTIuNDMzIDEuMDU0LTUuNDUxIDEuMDU0eiIvPjwvc3ZnPg==',
|
|
|
|
- // 其他表情...
|
|
|
|
-};
|
|
|
|
- // 问题相关
|
|
|
|
|
|
+export class PageInterview implements OnInit, AfterViewInit, OnDestroy {
|
|
|
|
+ // 倒计时相关属性
|
|
|
|
+ remainingTime: string = '30:00';
|
|
|
|
+ remainingMinutes: number = 30;
|
|
|
|
+ remainingSeconds: number = 0;
|
|
|
|
+ timerInterval: any;
|
|
|
|
+
|
|
|
|
+ // 其他现有属性保持不变
|
|
|
|
+ isAnalyzing = false;
|
|
|
|
+ showSubmitButton = false;
|
|
|
|
+ userAnswer = '';
|
|
|
|
+
|
|
|
|
+ avatarImages = {
|
|
|
|
+ default: 'data:image/svg+xml;base64,...',
|
|
|
|
+ speaking: 'data:image/svg+xml;base64,...',
|
|
|
|
+ };
|
|
|
|
+
|
|
questions = [
|
|
questions = [
|
|
"欢迎参加本次AI面试,我是您的面试官AI助手。",
|
|
"欢迎参加本次AI面试,我是您的面试官AI助手。",
|
|
"首先,请简单介绍一下您自己。",
|
|
"首先,请简单介绍一下您自己。",
|
|
"您在过去工作中遇到的最大技术挑战是什么?您是如何解决的?",
|
|
"您在过去工作中遇到的最大技术挑战是什么?您是如何解决的?",
|
|
"请描述一个您与团队意见不合时,您是如何处理的案例。"
|
|
"请描述一个您与团队意见不合时,您是如何处理的案例。"
|
|
];
|
|
];
|
|
|
|
+
|
|
currentQuestionIndex = 0;
|
|
currentQuestionIndex = 0;
|
|
currentQuestion = this.questions[0];
|
|
currentQuestion = this.questions[0];
|
|
showQuestionCard = false;
|
|
showQuestionCard = false;
|
|
progress = 30;
|
|
progress = 30;
|
|
|
|
|
|
- // 对话相关
|
|
|
|
messages: {sender: 'ai' | 'user', text: string}[] = [];
|
|
messages: {sender: 'ai' | 'user', text: string}[] = [];
|
|
|
|
|
|
- // 语音相关
|
|
|
|
isListening = false;
|
|
isListening = false;
|
|
isSpeaking = false;
|
|
isSpeaking = false;
|
|
|
|
|
|
- // 头像和表情相关
|
|
|
|
avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f913.svg";
|
|
avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f913.svg";
|
|
expressionText = "正在聆听您的回答...";
|
|
expressionText = "正在聆听您的回答...";
|
|
|
|
|
|
- // 仪表盘相关
|
|
|
|
showRadarChart = false;
|
|
showRadarChart = false;
|
|
metrics = {
|
|
metrics = {
|
|
expressiveness: 82,
|
|
expressiveness: 82,
|
|
@@ -51,7 +53,6 @@ avatarImages = {
|
|
relevance: 73
|
|
relevance: 73
|
|
};
|
|
};
|
|
|
|
|
|
- // 预设回答
|
|
|
|
presetAnswers = [
|
|
presetAnswers = [
|
|
"我是张伟,有5年Java开发经验,擅长分布式系统设计。",
|
|
"我是张伟,有5年Java开发经验,擅长分布式系统设计。",
|
|
"我们曾遇到高并发下的数据库瓶颈,我通过引入Redis缓存和分库分表解决了问题。",
|
|
"我们曾遇到高并发下的数据库瓶颈,我通过引入Redis缓存和分库分表解决了问题。",
|
|
@@ -63,15 +64,51 @@ avatarImages = {
|
|
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
this.initConversation();
|
|
this.initConversation();
|
|
- this.startProgressTimer();
|
|
|
|
|
|
+ this.startCountdown(); // 启动倒计时
|
|
}
|
|
}
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
ngAfterViewInit(): void {
|
|
- // 初始化雷达图
|
|
|
|
this.initRadarChart();
|
|
this.initRadarChart();
|
|
}
|
|
}
|
|
|
|
|
|
- // 初始化对话
|
|
|
|
|
|
+ ngOnDestroy(): void {
|
|
|
|
+ if (this.timerInterval) {
|
|
|
|
+ clearInterval(this.timerInterval);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 倒计时相关方法
|
|
|
|
+ private startCountdown() {
|
|
|
|
+ this.updateTimeDisplay();
|
|
|
|
+
|
|
|
|
+ this.timerInterval = setInterval(() => {
|
|
|
|
+ if (this.remainingSeconds > 0) {
|
|
|
|
+ this.remainingSeconds--;
|
|
|
|
+ } else {
|
|
|
|
+ if (this.remainingMinutes > 0) {
|
|
|
|
+ this.remainingMinutes--;
|
|
|
|
+ this.remainingSeconds = 59;
|
|
|
|
+ } else {
|
|
|
|
+ clearInterval(this.timerInterval);
|
|
|
|
+ this.handleTimeUp();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.updateTimeDisplay();
|
|
|
|
+ }, 1000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private updateTimeDisplay() {
|
|
|
|
+ const mins = this.remainingMinutes.toString().padStart(2, '0');
|
|
|
|
+ const secs = this.remainingSeconds.toString().padStart(2, '0');
|
|
|
|
+ this.remainingTime = `${mins}:${secs}`;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private handleTimeUp() {
|
|
|
|
+ this.addAIMessage("面试时间已结束,系统将自动提交您的回答");
|
|
|
|
+ this.submitAnswer();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 其他现有方法保持不变
|
|
initConversation(): void {
|
|
initConversation(): void {
|
|
this.addAIMessage(this.questions[0]);
|
|
this.addAIMessage(this.questions[0]);
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
@@ -79,51 +116,31 @@ avatarImages = {
|
|
}, 1500);
|
|
}, 1500);
|
|
}
|
|
}
|
|
|
|
|
|
- // 提问问题
|
|
|
|
askQuestion(index: number): void {
|
|
askQuestion(index: number): void {
|
|
if (index >= this.questions.length) return;
|
|
if (index >= this.questions.length) return;
|
|
|
|
|
|
this.currentQuestionIndex = index;
|
|
this.currentQuestionIndex = index;
|
|
this.currentQuestion = this.questions[index];
|
|
this.currentQuestion = this.questions[index];
|
|
-
|
|
|
|
- // 添加到对话框
|
|
|
|
this.addAIMessage(this.currentQuestion);
|
|
this.addAIMessage(this.currentQuestion);
|
|
-
|
|
|
|
- // 更新头像状态
|
|
|
|
this.avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f4ac.svg";
|
|
this.avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f4ac.svg";
|
|
this.expressionText = "等待您的回答...";
|
|
this.expressionText = "等待您的回答...";
|
|
}
|
|
}
|
|
|
|
|
|
- // 添加AI消息
|
|
|
|
addAIMessage(text: string): void {
|
|
addAIMessage(text: string): void {
|
|
- this.messages.push({
|
|
|
|
- sender: 'ai',
|
|
|
|
- text: text
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 滚动到底部
|
|
|
|
|
|
+ this.messages.push({ sender: 'ai', text: text });
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
this.dialogContainer.nativeElement.scrollTop = this.dialogContainer.nativeElement.scrollHeight;
|
|
this.dialogContainer.nativeElement.scrollTop = this.dialogContainer.nativeElement.scrollHeight;
|
|
}, 0);
|
|
}, 0);
|
|
-
|
|
|
|
- // 自动语音播报
|
|
|
|
this.speakText(text);
|
|
this.speakText(text);
|
|
}
|
|
}
|
|
|
|
|
|
- // 添加用户消息
|
|
|
|
addUserMessage(text: string): void {
|
|
addUserMessage(text: string): void {
|
|
- this.messages.push({
|
|
|
|
- sender: 'user',
|
|
|
|
- text: text
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 滚动到底部
|
|
|
|
|
|
+ this.messages.push({ sender: 'user', text: text });
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
this.dialogContainer.nativeElement.scrollTop = this.dialogContainer.nativeElement.scrollHeight;
|
|
this.dialogContainer.nativeElement.scrollTop = this.dialogContainer.nativeElement.scrollHeight;
|
|
}, 0);
|
|
}, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- // 语音播报
|
|
|
|
speakText(text: string): void {
|
|
speakText(text: string): void {
|
|
if (this.isSpeaking) return;
|
|
if (this.isSpeaking) return;
|
|
|
|
|
|
@@ -131,7 +148,6 @@ avatarImages = {
|
|
this.avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f5e3.svg";
|
|
this.avatarImage = "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f5e3.svg";
|
|
this.expressionText = "正在播报问题...";
|
|
this.expressionText = "正在播报问题...";
|
|
|
|
|
|
- // 使用Web Speech API
|
|
|
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
utterance.lang = 'zh-CN';
|
|
utterance.lang = 'zh-CN';
|
|
utterance.rate = 0.9;
|
|
utterance.rate = 0.9;
|
|
@@ -146,39 +162,28 @@ avatarImages = {
|
|
speechSynthesis.speak(utterance);
|
|
speechSynthesis.speak(utterance);
|
|
}
|
|
}
|
|
|
|
|
|
- // 开始语音输入
|
|
|
|
startVoiceInput(): void {
|
|
startVoiceInput(): void {
|
|
this.isListening = true;
|
|
this.isListening = true;
|
|
this.expressionText = "正在聆听您的回答...";
|
|
this.expressionText = "正在聆听您的回答...";
|
|
- console.log('语音输入开始');
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // 停止语音输入
|
|
|
|
stopVoiceInput(): void {
|
|
stopVoiceInput(): void {
|
|
this.isListening = false;
|
|
this.isListening = false;
|
|
-
|
|
|
|
- // 模拟语音识别结果
|
|
|
|
this.userAnswer = this.presetAnswers[this.currentQuestionIndex - 1] || "这是我的回答...";
|
|
this.userAnswer = this.presetAnswers[this.currentQuestionIndex - 1] || "这是我的回答...";
|
|
- this.showSubmitButton = true; // 显示提交按钮
|
|
|
|
-
|
|
|
|
- // 不再自动提交,等待用户点击
|
|
|
|
|
|
+ this.showSubmitButton = true;
|
|
this.avatarImage = this.avatarImages.default;
|
|
this.avatarImage = this.avatarImages.default;
|
|
this.expressionText = "请确认您的回答";
|
|
this.expressionText = "请确认您的回答";
|
|
}
|
|
}
|
|
|
|
+
|
|
submitAnswer(): void {
|
|
submitAnswer(): void {
|
|
this.showSubmitButton = false;
|
|
this.showSubmitButton = false;
|
|
this.addUserMessage(this.userAnswer);
|
|
this.addUserMessage(this.userAnswer);
|
|
-
|
|
|
|
- // 开始分析
|
|
|
|
this.isAnalyzing = true;
|
|
this.isAnalyzing = true;
|
|
this.avatarImage = this.avatarImages.default;
|
|
this.avatarImage = this.avatarImages.default;
|
|
this.expressionText = "正在分析您的回答...";
|
|
this.expressionText = "正在分析您的回答...";
|
|
|
|
|
|
- // 模拟分析过程 (2秒)
|
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
this.isAnalyzing = false;
|
|
this.isAnalyzing = false;
|
|
-
|
|
|
|
- // 问下一题或结束
|
|
|
|
if (this.currentQuestionIndex < this.questions.length - 1) {
|
|
if (this.currentQuestionIndex < this.questions.length - 1) {
|
|
this.askQuestion(this.currentQuestionIndex + 1);
|
|
this.askQuestion(this.currentQuestionIndex + 1);
|
|
} else {
|
|
} else {
|
|
@@ -189,14 +194,12 @@ avatarImages = {
|
|
}, 2000);
|
|
}, 2000);
|
|
}
|
|
}
|
|
|
|
|
|
- // 播放问题
|
|
|
|
playQuestion(): void {
|
|
playQuestion(): void {
|
|
if (!this.isSpeaking) {
|
|
if (!this.isSpeaking) {
|
|
this.speakText(this.questions[this.currentQuestionIndex]);
|
|
this.speakText(this.questions[this.currentQuestionIndex]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 切换雷达图
|
|
|
|
toggleRadarChart(): void {
|
|
toggleRadarChart(): void {
|
|
this.showRadarChart = !this.showRadarChart;
|
|
this.showRadarChart = !this.showRadarChart;
|
|
if (this.showRadarChart) {
|
|
if (this.showRadarChart) {
|
|
@@ -206,7 +209,6 @@ avatarImages = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 初始化雷达图
|
|
|
|
initRadarChart(): void {
|
|
initRadarChart(): void {
|
|
if (!this.showRadarChart) return;
|
|
if (!this.showRadarChart) return;
|
|
|
|
|
|
@@ -289,16 +291,8 @@ avatarImages = {
|
|
|
|
|
|
this.radarChart.setOption(option);
|
|
this.radarChart.setOption(option);
|
|
|
|
|
|
- // 响应式调整
|
|
|
|
window.addEventListener('resize', () => {
|
|
window.addEventListener('resize', () => {
|
|
this.radarChart?.resize();
|
|
this.radarChart?.resize();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 进度条计时器
|
|
|
|
- startProgressTimer(): void {
|
|
|
|
- setInterval(() => {
|
|
|
|
- this.progress = Math.min(this.progress + 10, 100);
|
|
|
|
- }, 5000);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+}
|