From da1389bf6605944e7d26d04c8fa1021ed33ba8e2 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 15 May 2025 20:23:13 +0800 Subject: [PATCH] add history --- docker-compose.yml | 2 +- src/views/AStockAnalysisView.vue | 628 ++++++++++++++++++++----------- src/views/CryptoAnalysisView.vue | 293 +++++++++++++- 3 files changed, 694 insertions(+), 229 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fedf983..d228a08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: . dockerfile: Dockerfile - image: tradus-web:1.17 + image: tradus-web:1.18 container_name: tradus-web ports: - '6000:80' diff --git a/src/views/AStockAnalysisView.vue b/src/views/AStockAnalysisView.vue index 01a4a31..cd453ba 100644 --- a/src/views/AStockAnalysisView.vue +++ b/src/views/AStockAnalysisView.vue @@ -2,6 +2,11 @@ import { ref, nextTick } from 'vue' import { useUserStore } from '../stores/user' +interface HistoryItem { + code: string + timestamp: number +} + const userStore = useUserStore() const stockCode = ref('') const isAnalyzing = ref(false) @@ -11,6 +16,10 @@ const currentThought = ref('') const showInitialView = ref(true) const copySuccess = ref(false) +const HISTORY_KEY = 'astock_search_history' +const MAX_HISTORY = 5 +const searchHistory = ref([]) + // 根据环境选择API基础URL const apiBaseUrl = import.meta.env.MODE === 'development' ? 'http://127.0.0.1:8000' : 'https://api.ibtc.work' @@ -22,6 +31,47 @@ const scrollToBottom = async () => { } } +// 加载搜索历史 +const loadSearchHistory = () => { + const history = localStorage.getItem(HISTORY_KEY) + if (history) { + searchHistory.value = JSON.parse(history) + } +} + +// 添加搜索历史 +const addToHistory = (code: string) => { + const newItem = { + code: code.toUpperCase(), + timestamp: Date.now(), + } + const history = searchHistory.value.filter((item) => item.code !== newItem.code) + history.unshift(newItem) + searchHistory.value = history.slice(0, MAX_HISTORY) + localStorage.setItem(HISTORY_KEY, JSON.stringify(searchHistory.value)) +} + +// 从历史中选择 +const selectFromHistory = (item: HistoryItem) => { + stockCode.value = item.code + handleAnalysis() +} + +// 删除历史记录 +const removeFromHistory = (item: HistoryItem) => { + searchHistory.value = searchHistory.value.filter((h) => h.code !== item.code) + localStorage.setItem(HISTORY_KEY, JSON.stringify(searchHistory.value)) +} + +// 清空历史记录 +const clearHistory = () => { + searchHistory.value = [] + localStorage.removeItem(HISTORY_KEY) +} + +// 初始化时加载历史记录 +loadSearchHistory() + const handleAnalysis = async () => { if (!stockCode.value || isAnalyzing.value) return @@ -32,6 +82,9 @@ const handleAnalysis = async () => { return } + // 添加到搜索历史 + addToHistory(code) + showInitialView.value = false isAnalyzing.value = true analysisContent.value = '' @@ -214,6 +267,37 @@ const copyAnalysis = async () => { + + +
+
+
+ 搜索历史 + +
+
+
+ + +
+
+
+
@@ -278,6 +362,7 @@ const copyAnalysis = async () => {