Browse Source

删除了无效滚动和本地浏览器存储,新建emotion.ts文件

ds_hxl
宋杰 3 weeks ago
parent
commit
5e919701de
  1. 30
      src/store/emotion.ts
  2. 87
      src/views/AiEmotion.vue

30
src/store/emotion.ts

@ -0,0 +1,30 @@
// @/store/emotion.js
import { defineStore } from 'pinia';
export const useEmotionStore = defineStore('emotion', {
state: () => ({
history: [] as HistoryItem[], // 历史记录数组
}),
actions: {
// 添加历史记录
addHistory(item: HistoryItem) {
this.history.unshift(item); // 新记录添加到数组顶部,保持顺序
},
// 清空历史记录
clearHistory() {
this.history = [];
},
},
});
// 定义历史记录项的类型
interface HistoryItem {
queryText: string; // 用户输入的查询文本(如股票名称/代码)
stockInfo: {
name: string; // 股票名称
code: string; // 股票代码
market: string; // 市场(如 usa/cn/hk)
};
apiData: any; // 接口返回的原始数据(包含图表数据)
timestamp: string; // 记录时间
}

87
src/views/AiEmotion.vue

@ -17,15 +17,6 @@
</div>
</div>
</div>
<!-- 输入框和发送按钮 -->
<!-- <footer class="input-container fixed-bottom">
<input type="text" v-model="userInput" placeholder="请输入内容..." class="input-box" />
<button @click="handleSendMessage(userInput)" class="send-button">发送</button>
</footer> -->
<!-- <div class="input-container fixed-bottom">
<input type="text" v-model="userInput" placeholder="请输入内容..." class="input-box" />
<button @click="sendMessage" class="send-button">发送</button>
</div> -->
</div>
@ -132,18 +123,9 @@
<div class="class09">
<img src="@/assets/img/AiEmotion/场景应用.png" alt="场景应用标题">
<div class="bk-image">
<!-- <div class="text-container">
<p>情绪监控-金融宇宙的量子检测网络核心任务:构建全市场情绪引力场雷达</p>
<p>情绪解码-主力思维的神经破译矩阵核心任务:解构资金行为的量子密码</p>
<p>情绪推演-未来战争的时空推演舱核心任务:情绪推演</p>
<p>情绪套利-财富裂变的粒子对撞机核心任务:将情绪差转化为a收益粒子流</p>
</div> -->
</div>
</div>
</div>
<!-- <div v-else class="loading">
<p>数据加载中请稍候...</p>
</div> -->
</template>
<script setup>
@ -163,30 +145,16 @@ const marketTemperatureRef = ref(null); // 引用市场温度计组件
const emoEnergyConverterRef = ref(null)
const emotionDecodRef = ref(null)
const emotionalBottomRadarRef = ref(null)
const userInput = ref('');
const messages = ref([]);
const displayDate = ref(''); //
const isPageLoaded = ref(false); //
const isPageLoaded = ref(true); //
const isRotating = ref(false);//
const userInputDisplayRef = ref(null);//
const data1 = ref(null); //
const data2 = ref(); //
const version1 = ref(2); //
//使
defineExpose({ handleSendMessage })
//
const loadMessagesFromLocalStorage = () => {
const storedMessages = localStorage.getItem('chatMessages');
if (storedMessages) {
messages.value = JSON.parse(storedMessages);
}
};
//
const saveMessagesToLocalStorage = () => {
localStorage.setItem('chatMessages', JSON.stringify(messages.value));
};
//
function startImageRotation() {
isRotating.value = true;
@ -214,13 +182,6 @@ async function handleSendMessage(input) {
if (input.trim()) {
const userMessage = reactive({ sender: 'user', text: input });
messages.value.push(userMessage);
userInput.value = ''; //
//
messages.value.push({
sender: 'ai',
text: '数据加载中,请稍候...'
});
//
isRotating.value = true;
@ -262,32 +223,18 @@ async function handleSendMessage(input) {
updateSpan01();
} else {
console.error('工作流接口返回非股票信息:', parsedData.refuse);
messages.value.push({
sender: 'ai',
text: `工作流接口返回信息: ${parsedData.refuse || '未知错误'}`,
});
}
} catch (error) {
console.error('请求工作流接口失败:', error);
messages.value.push({
sender: 'ai',
text: '工作流接口请求失败,请稍后再试。',
});
} finally {
//
isRotating.value = false;
//
saveMessagesToLocalStorage();
}
} else {
messages.value.push({
sender: 'ai',
text: '请输入内容后再发送。',
});
}
}
const version1 = ref(2); //
//
async function fetchData(code, market) {
try {
@ -319,45 +266,28 @@ async function fetchData(code, market) {
console.log('图表数据接口返回数据:', stockDataResponse.data);
if (stockDataResponse.code === 200 && stockDataResponse.data) {
messages.value.push({
sender: 'ai',
text: `股票数据已成功获取`,
});
// xx
const lastTwoNumbers = stockDataResponse.data.GSWDJ.map(([date, num1, num2]) => [
date,
Math.round(num1),
Math.round(num2)
]).at(-1);
console.log('111111111111111111111111111')
//
displayDate.value = lastTwoNumbers[0];//
data1.value = lastTwoNumbers[1] //
data2.value = lastTwoNumbers[2] //
console.log('1111111111111111111111')
//
const chatStore = useChatStore();
renderCharts(chatStore.kLineData[chatStore.kLineData.length - 1]);
console.log('2222222222222222222222')
//
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
displayDate.value = `${year}/${month}/${day}`;
//
isPageLoaded.value = true;
// isPageLoaded.value = true;
} else {
messages.value.push({
sender: 'ai',
text: '图表数据接口返回数据不完整,请稍后再试。',
});
}
} catch (error) {
messages.value.push({
sender: 'ai',
text: '图表数据接口请求失败,请稍后再试。',
});
}
}
@ -400,7 +330,6 @@ function renderCharts(data) {
//
onMounted(() => {
startImageRotation();
loadMessagesFromLocalStorage();//
});
</script>

Loading…
Cancel
Save