From 4b9ae00452baf7b5a7f1a64ead608e8505ac34c1 Mon Sep 17 00:00:00 2001 From: ArvinLovegood Date: Sun, 23 Feb 2025 21:58:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=E6=B7=BB=E5=8A=A0=E5=BC=B9?= =?UTF-8?q?=E5=B9=95=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E8=82=A1?= =?UTF-8?q?=E7=A5=A8=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 stock.vue 中集成 vue3-danmaku 弹幕组件 - 实现 WebSocket 连接以接收实时弹幕消息 - 添加发送弹幕功能 - 优化股票搜索和显示逻辑 - 更新 App.vue 中的导入信息 - 在 package.json 中添加 vue3-danmaku 依赖 --- backend/data/stock_data_api_test.go | 4 +-- frontend/package-lock.json | 11 +++++- frontend/package.json | 3 +- frontend/package.json.md5 | 2 +- frontend/src/App.vue | 1 - frontend/src/components/stock.vue | 53 +++++++++++++++++++++++++---- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/backend/data/stock_data_api_test.go b/backend/data/stock_data_api_test.go index e5bd5e9..6a8fb39 100644 --- a/backend/data/stock_data_api_test.go +++ b/backend/data/stock_data_api_test.go @@ -24,8 +24,8 @@ func TestGetTelegraph(t *testing.T) { } func TestGetFinancialReports(t *testing.T) { - //GetFinancialReports("sz000802", 30) - GetFinancialReports("hk00927", 30) + GetFinancialReports("sz000802", 30) + //GetFinancialReports("hk00927", 30) } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 69a69ae..f8af9ed 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16,7 +16,8 @@ "html2canvas": "^1.4.1", "md-editor-v3": "^5.2.3", "vue": "^3.2.25", - "vue-router": "^4.5.0" + "vue-router": "^4.5.0", + "vue3-danmaku": "^1.6.1" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", @@ -2268,6 +2269,14 @@ "vue": "^3.2.0" } }, + "node_modules/vue3-danmaku": { + "version": "1.6.1", + "resolved": "https://registry.npmmirror.com/vue3-danmaku/-/vue3-danmaku-1.6.1.tgz", + "integrity": "sha512-v7KqMV5WK3mqRSotSuJfnJldsIpilh72nLKKebWGCO7HM4k330QV1f4oje410GfwSx+SrJ+YLeTG8QLJYuKwYg==", + "peerDependencies": { + "vue": "^3.0.0" + } + }, "node_modules/vueuc": { "version": "0.4.64", "resolved": "https://registry.npmmirror.com/vueuc/-/vueuc-0.4.64.tgz", diff --git a/frontend/package.json b/frontend/package.json index a78e811..fc3f612 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,7 +17,8 @@ "html2canvas": "^1.4.1", "md-editor-v3": "^5.2.3", "vue": "^3.2.25", - "vue-router": "^4.5.0" + "vue-router": "^4.5.0", + "vue3-danmaku": "^1.6.1" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index 5210015..4461a08 100644 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -a8dd30a6289daa9c1986221ddaa93695 \ No newline at end of file +2091cce83d29f564a50e85f1667b2f4c \ No newline at end of file diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 649a397..eafed34 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -18,7 +18,6 @@ import { ExpandOutline, RefreshOutline, PowerOutline, LogoGithub, MoveOutline, WalletOutline, StarOutline, } from '@vicons/ionicons5' - const content = ref('数据来源于网络,仅供参考;投资有风险,入市需谨慎') const isFullscreen = ref(false) const activeKey = ref('stock') diff --git a/frontend/src/components/stock.vue b/frontend/src/components/stock.vue index f990129..3ef7ce4 100644 --- a/frontend/src/components/stock.vue +++ b/frontend/src/components/stock.vue @@ -30,7 +30,7 @@ import { useNotification } from 'naive-ui' import {EventsEmit, EventsOn, WindowFullscreen, WindowReload, WindowUnfullscreen} from '../../wailsjs/runtime' -import {Add} from '@vicons/ionicons5' +import {Add, BalloonOutline} from '@vicons/ionicons5' import {MdPreview,MdEditor } from 'md-editor-v3'; // preview.css相比style.css少了编辑器那部分样式 //import 'md-editor-v3/lib/preview.css'; @@ -39,8 +39,11 @@ import 'md-editor-v3/lib/style.css'; import { ExportPDF } from '@vavt/v3-extension'; import '@vavt/v3-extension/lib/asset/ExportPDF.css'; import html2canvas from "html2canvas"; -import {asBlob} from 'html-docx-js-typescript'; //将html转为word +import {asBlob} from 'html-docx-js-typescript'; +import vueDanmaku from 'vue3-danmaku' +const danmus = ref(['欢迎回来~']) +const ws = ref(null) const toolbars = [0]; const handleProgress = (progress) => { @@ -144,11 +147,32 @@ onMounted(() => { icon.value = res.icon; }); + // 创建 WebSocket 连接 + ws.value = new WebSocket('ws://8.134.249.145:16688/ws'); // 替换为你的 WebSocket 服务器地址 + + ws.value.onopen = () => { + console.log('WebSocket 连接已打开'); + }; + + ws.value.onmessage = (event) => { + const message = event.data; + danmus.value.push(message); + }; + + ws.value.onerror = (error) => { + console.error('WebSocket 错误:', error); + }; + + ws.value.onclose = () => { + console.log('WebSocket 连接已关闭'); + }; }) onBeforeUnmount(() => { // console.log(`the component is now unmounted.`) clearInterval(ticker.value) + ws.value.close() + }) EventsOn("refresh",(data)=>{ @@ -331,7 +355,17 @@ function removeMonitor(code,name,key) { }) } +function SendDanmu(){ + //danmus.value.push(data.name) + console.log("SendDanmu",data.name) + console.log("SendDanmu-readyState", ws.value.readyState) + ws.value.send(data.name) +} + function getStockList(value){ + + + // console.log("getStockList",value) let result; result=stockList.value.filter(item => item.name.includes(value)||item.ts_code.includes(value)) @@ -690,8 +724,9 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警