diff --git a/src/store/emotionAudio.js b/src/store/emotionAudio.js
new file mode 100644
index 0000000..9c707a5
--- /dev/null
+++ b/src/store/emotionAudio.js
@@ -0,0 +1,89 @@
+import { defineStore } from 'pinia'
+
+export const useEmotionAudioStore = defineStore('emotionAudio', {
+ state: () => ({
+ soundInstance: null, // Howl 实例
+ isPlaying: false, // 播放状态
+ isVoiceEnabled: true, // 新增声音开关状态
+ playbackPosition: 0, // 新增播放位置存储
+ lastVoiceState: null,
+ ttsUrl:'',
+ isNewInstance: false, // 新增是否是新实例的标志
+ nowSound:'',
+ currentAudioUrl: '', // 当前音频URL
+ isPaused: false, // 是否处于暂停状态
+ duration: 0 // 音频总时长
+ }),
+ actions: {
+ // 设置音频实例
+ setAudioInstance(instance) {
+ this.soundInstance = instance
+ },
+ // 播放控制
+ play() {
+ if (this.soundInstance) {
+ if (this.isPaused && this.playbackPosition > 0) {
+ // 从暂停位置继续播放
+ this.soundInstance.seek(this.playbackPosition)
+ }
+ this.soundInstance.play()
+ this.isPlaying = true
+ this.isPaused = false
+ }
+ },
+ // 暂停控制
+ pause() {
+ if (this.soundInstance && this.isPlaying) {
+ // 保存当前播放位置
+ this.playbackPosition = this.soundInstance.seek() || 0
+ this.soundInstance.pause()
+ this.isPlaying = false
+ this.isPaused = true
+ }
+ },
+ // 停止播放
+ stop() {
+ if (this.soundInstance) {
+ this.soundInstance.stop()
+ this.isPlaying = false
+ this.isPaused = false
+ this.playbackPosition = 0
+ }
+ },
+ // 切换播放/暂停
+ togglePlayPause() {
+ if (this.isPlaying) {
+ this.pause()
+ } else {
+ this.play()
+ }
+ },
+ // 设置当前音频URL
+ setCurrentAudioUrl(url) {
+ if (this.currentAudioUrl !== url) {
+ // 如果是新的音频,重置播放状态
+ this.stop()
+ this.currentAudioUrl = url
+ this.playbackPosition = 0
+ this.isPaused = false
+ }
+ },
+ // 语音开关控制
+ toggleVoice() {
+ this.isVoiceEnabled = !this.isVoiceEnabled
+ if (!this.isVoiceEnabled) {
+ // 关闭语音时停止当前播放
+ this.stop()
+ }
+ },
+ // 重置音频状态
+ resetAudioState() {
+ this.stop()
+ this.currentAudioUrl = ''
+ this.ttsUrl = ''
+ this.soundInstance = null
+ this.nowSound = ''
+ }
+ }
+})
+
diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue
index 1aff158..57c85c4 100644
--- a/src/views/AiEmotion.vue
+++ b/src/views/AiEmotion.vue
@@ -182,14 +182,14 @@ import StockTabs from '@/views/components/StockTabs.vue'; // 导入股票标签
import blueBorderImg from '@/assets/img/AiEmotion/blueBorder.png' //导入蓝色背景框图片
import { ElMessage } from 'element-plus';
import { useEmotionStore } from '@/store/emotion'; // 导入Pinia store
-import { useAudioStore } from '@/store/audio.js'; // 导入音频store
+import { useEmotionAudioStore } from '@/store/emotionAudio.js'; // 导入音频store
import { useChatStore } from '@/store/chat.js'; // 导入聊天store
import { Howl, Howler } from 'howler'; // 导入音频播放库
import { reactive } from 'vue';
import { marked } from 'marked'; // 引入marked库
// 使用Pinia store
const emotionStore = useEmotionStore();
-const audioStore = useAudioStore();
+const emotionAudioStore = useEmotionAudioStore();
const chatStore = useChatStore();
// 处理refuse数据的函数
@@ -686,8 +686,8 @@ function playAudio(url) {
}
// 检查是否启用了语音功能
- console.log('语音功能状态:', audioStore.isVoiceEnabled);
- if (!audioStore.isVoiceEnabled) {
+ console.log('语音功能状态:', emotionAudioStore.isVoiceEnabled);
+ if (!emotionAudioStore.isVoiceEnabled) {
console.log('语音功能已关闭,跳过播放');
return;
}
@@ -696,11 +696,11 @@ function playAudio(url) {
try {
// 设置当前音频URL
- audioStore.setCurrentAudioUrl(url);
+ emotionAudioStore.setCurrentAudioUrl(url);
// 停止之前的音频
- if (audioStore.nowSound && audioStore.nowSound.playing()) {
- audioStore.nowSound.stop();
+ if (emotionAudioStore.nowSound && emotionAudioStore.nowSound.playing()) {
+ emotionAudioStore.nowSound.stop();
}
// 创建新的音频实例
@@ -710,41 +710,41 @@ function playAudio(url) {
format: ['mp3', 'wav'],
onplay: () => {
isAudioPlaying.value = true;
- audioStore.isPlaying = true;
+ emotionAudioStore.isPlaying = true;
console.log('开始播放场景应用语音');
},
onend: () => {
isAudioPlaying.value = false;
- audioStore.isPlaying = false;
- audioStore.isPaused = false;
- audioStore.playbackPosition = 0;
+ emotionAudioStore.isPlaying = false;
+ emotionAudioStore.isPaused = false;
+ emotionAudioStore.playbackPosition = 0;
console.log('场景应用语音播放结束');
},
onstop: () => {
isAudioPlaying.value = false;
- audioStore.isPlaying = false;
+ emotionAudioStore.isPlaying = false;
console.log('场景应用语音播放停止');
},
onpause: () => {
isAudioPlaying.value = false;
- audioStore.isPlaying = false;
+ emotionAudioStore.isPlaying = false;
console.log('场景应用语音播放暂停');
},
onerror: (error) => {
isAudioPlaying.value = false;
- audioStore.isPlaying = false;
+ emotionAudioStore.isPlaying = false;
console.error('音频播放错误:', error);
},
onload: () => {
// 音频加载完成,获取时长
- audioStore.duration = newSound.duration();
- console.log('音频加载完成,时长:', audioStore.duration);
+ emotionAudioStore.duration = newSound.duration();
+ console.log('音频加载完成,时长:', emotionAudioStore.duration);
}
});
// 保存音频实例到store
- audioStore.nowSound = newSound;
- audioStore.setAudioInstance(newSound);
+ emotionAudioStore.nowSound = newSound;
+ emotionAudioStore.setAudioInstance(newSound);
// 播放音频
newSound.play();
@@ -757,8 +757,8 @@ function playAudio(url) {
// 停止音频播放
function stopAudio() {
- if (audioStore.nowSound) {
- audioStore.nowSound.stop();
+ if (emotionAudioStore.nowSound) {
+ emotionAudioStore.nowSound.stop();
}
isAudioPlaying.value = false;
}
diff --git a/src/views/components/marketTemperature.vue b/src/views/components/marketTemperature.vue
index bcb98a9..59c1ff8 100644
--- a/src/views/components/marketTemperature.vue
+++ b/src/views/components/marketTemperature.vue
@@ -189,10 +189,10 @@ function initChart(raw, klineDataRawValue, WDRLValue) {
maxPrice = Math.max(maxPrice, high)
})
- // 将最小值向下取整到10的倍数
- const yAxisMin = Math.floor(minPrice / 10) * 10
- // 将最大值向上取整到10的倍数,并增加一些余量
- const yAxisMax = Math.ceil(maxPrice / 10) * 10 + 10
+ // 计算小于最小值的整数作为y轴最小值
+ const yAxisMin = Math.floor(minPrice)
+ // 计算大于最大值的整数作为y轴最大值
+ const yAxisMax = Math.ceil(maxPrice)
// 温度日历
WDRL.value = WDRLValue
diff --git a/src/views/homePage.vue b/src/views/homePage.vue
index 6a61aca..73728e9 100644
--- a/src/views/homePage.vue
+++ b/src/views/homePage.vue
@@ -10,7 +10,7 @@ import Feedback from "./Feedback.vue";
import { useAppBridge } from "../assets/js/useAppBridge.js";
import { useDataStore } from "@/store/dataList.js";
import { useChatStore } from "../store/chat";
-import { useAudioStore } from "../store/audio";
+import { useEmotionAudioStore } from "../store/emotionAudio";
import _ from "lodash";
import logo from "../assets/img/homePage/logo.png";
@@ -43,20 +43,20 @@ const dataStore = useDataStore();
const chatStore = useChatStore();
// 变量
// 音频管理
-const audioStore = useAudioStore();
-const isVoice = computed(() => audioStore.isVoiceEnabled);
+const emotionAudioStore = useEmotionAudioStore();
+const isVoice = computed(() => emotionAudioStore.isVoiceEnabled);
const toggleVoice = () => {
- if (!audioStore.isVoiceEnabled) {
+ if (!emotionAudioStore.isVoiceEnabled) {
// 如果语音功能关闭,先开启语音功能
- audioStore.toggleVoice();
+ emotionAudioStore.toggleVoice();
} else {
// 如果语音功能开启,则切换播放/暂停状态
- if (audioStore.currentAudioUrl || audioStore.ttsUrl) {
+ if (emotionAudioStore.currentAudioUrl || emotionAudioStore.ttsUrl) {
// 有音频时切换播放/暂停
- audioStore.togglePlayPause();
+ emotionAudioStore.togglePlayPause();
} else {
// 没有音频时关闭语音功能
- audioStore.toggleVoice();
+ emotionAudioStore.toggleVoice();
}
}
};
@@ -605,8 +605,8 @@ onMounted(async () => {
-
-
+
+