-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
217 lines (196 loc) · 10.5 KB
/
index.html
File metadata and controls
217 lines (196 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stock Visualizer - Vue 3</title>
<!-- 使用 CDN 引入 Vue 3, Axios 和 Element Plus -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/element-plus"></script>
<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
<!-- 图表库 -->
<script src="https://unpkg.com/echarts/dist/echarts.min.js"></script>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f5f7fa; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; background: white; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.header { display: flex; align-items: center; gap: 20px; margin-bottom: 30px; border-bottom: 2px solid #ebeef5; padding-bottom: 20px; }
.form-section { display: flex; gap: 15px; margin-bottom: 30px; background: #f9f9f9; padding: 20px; border-radius: 8px; border: 1px solid #dcdfe6; }
/* #chart { width: 100%; height: 500px; margin-top: 20px; } */
.status-msg { margin-top: 15px; }
</style>
</head>
<body>
<div id="app" class="container">
<div class="header">
<h1 style="color: #409EFF; margin: 0;">股票数据可视化工具😋</h1>
<p style="color: #909399;">孟鑫杰2400303409</p>
</div>
<div class="form-section">
<el-select v-model="source" placeholder="选择目标网站" style="width: 200px;">
<el-option label="AkShare (大陆股票)" value="akshare"></el-option>
<el-option label="Sina API (备用)" value="sina" disabled></el-option>
</el-select>
<el-input
v-model="stockCode"
placeholder="请输入股票代码(如 000001)"
style="width: 250px;"
@keyup.enter="startFetch">
<template #prepend>代码</template>
</el-input>
<el-button type="primary" :loading="isFetching" @click="startFetch" icon="el-icon-download">
{{ isFetching ? '正在抓取中...' : '抓取' }}
</el-button>
<el-button @click="loadData(stockCode)" :disabled="!stockCode">加载图表</el-button>
<el-input-number v-model="analysisInterval" :min="1" :max="180" label="分析间隔" @change="fetchAnalysis(stockCode)"></el-input-number>
<span style="font-size: 14px; color: #606266;">采样天数间隔(1~180)</span>
</div>
<el-alert
v-if="statusMsg"
:title="statusMsg"
:type="statusType"
show-icon
class="status-msg">
</el-alert>
<!-- 移除原有ECharts图表容器 -->
<!-- <div id="chart"></div> -->
<div v-if="plotImgUrl" style="text-align: center; margin-top: 20px;">
<img :src="plotImgUrl" alt="Stock Chart" style="max-width: 100%; height: auto; border-radius: 8px;">
</div>
<div style="margin-top: 30px;" v-if="analysisData.length > 0">
<h3>📈 股价趋势分析表 (采样对比)</h3>
<el-table :data="analysisData" border stripe style="width: 100%">
<el-table-column prop="startTime" label="开始日期" width="120"></el-table-column>
<el-table-column prop="endTime" label="结束日期" width="120"></el-table-column>
<el-table-column prop="startPrice" label="开始价格"></el-table-column>
<el-table-column prop="endPrice" label="结束价格"></el-table-column>
<el-table-column prop="change" label="涨跌">
<template #default="scope">
<span :style="{ color: scope.row.change > 0 ? '#F56C6C' : scope.row.change < 0 ? '#67C23A' : '#909399' }">
{{ scope.row.change > 0 ? '+' : '' }}{{ scope.row.change }}
</span>
</template>
</el-table-column>
<el-table-column prop="trend" label="趋势">
<template #default="scope">
<el-tag :type="scope.row.trend === '上升' ? 'danger' : scope.row.trend === '下降' ? 'success' : 'info'">
{{ scope.row.trend }}
</el-tag>
</template>
</el-table-column>
</el-table>
</div>
<!-- <div style="margin-top: 30px;">-->
<!-- <h3>📊 数据预览 (最新10条)</h3>-->
<!-- <el-table :data="tableData" border stripe style="width: 100%" v-if="tableData.length > 0">-->
<!-- <el-table-column prop="日期" label="日期"></el-table-column>-->
<!-- <el-table-column prop="开盘价" label="开盘价"></el-table-column>-->
<!-- <el-table-column prop="最高价" label="最高价"></el-table-column>-->
<!-- <el-table-column prop="最低价" label="最低价"></el-table-column>-->
<!-- <el-table-column prop="收盘价" label="收盘价"></el-table-column>-->
<!-- <el-table-column prop="成交量" label="成交量"></el-table-column>-->
<!-- </el-table>-->
<!-- </div>-->
</div>
<script>
const { createApp, ref, onMounted } = Vue;
const { ElMessage } = ElementPlus;
// 尝试自动探测可用端口
const API_BASE_URL = ref('http://127.0.0.1:11451');
createApp({
setup() {
const stockCode = ref('000001');
const source = ref('akshare');
const isFetching = ref(false);
const isBackendOnline = ref(false);
const statusMsg = ref('');
const statusType = ref('info');
const tableData = ref([]);
const analysisData = ref([]);
const analysisInterval = ref(30);
let myChart = null;
let plotImgUrl = ref("");
const startFetch = async () => {
if (!stockCode.value) {
ElMessage.error('股票代码不能为空!');
return;
}
isFetching.value = true;
statusMsg.value = '正在触发抓取任务,请稍候...';
statusType.value = 'info';
try {
const response = await axios.post(`${API_BASE_URL.value}/fetch`, {
stock_code: stockCode.value,
source: source.value
});
if (response.data.status === 'success') {
ElMessage.success(response.data.message);
statusMsg.value = `抓取成功!获取到数据预览:${response.data.message}`;
statusType.value = 'success';
tableData.value = response.data.data_preview;
loadData(stockCode.value);
fetchAnalysis(stockCode.value);
}
} catch (error) {
const errMsg = error.response?.data?.detail || '服务器通信失败';
ElMessage.error('抓取失败: ' + errMsg);
statusMsg.value = '抓取报错:' + errMsg;
statusType.value = 'error';
} finally {
isFetching.value = false;
}
};
const checkHealth = async () => {
// 添加对 18888 以及其他备用端口的扫描
const ports = [18888, 8000, 8001, 8002];
for (const port of ports) {
try {
const response = await axios.get(`http://127.0.0.1:${port}/health`);
if (response.data.status === 'ok') {
isBackendOnline.value = true;
API_BASE_URL.value = `http://127.0.0.1:${port}`;
return;
}
} catch (error) {
// 继续尝试下一个端口
}
}
isBackendOnline.value = false;
ElMessage.warning('检测到后端服务未启动,请先运行“运行Web可视化界面.bat”!');
};
const fetchAnalysis = async (code) => {
if (!code) return;
try {
const response = await axios.get(`${API_BASE_URL.value}/analysis/${code}?interval=${analysisInterval.value}`);
analysisData.value = response.data;
} catch (error) {
console.error('获取趋势分析失败');
}
};
const loadData = async (code) => {
try {
const response = await axios.get(`${API_BASE_URL.value}/data/${code}`);
const rawData = response.data;
// 不再调用updateChart,直接展示图片
tableData.value = rawData.slice(-10).reverse();
fetchAnalysis(code);
// 设置图片路径,改为后端API地址
plotImgUrl.value = `${API_BASE_URL.value}/stock_plot/stock_${code}_plot.png?${Date.now()}`;
} catch (error) {
ElMessage.warning('暂无该股票的历史数据,请先点击抓取。');
plotImgUrl.value = "";
}
};
onMounted(() => {
checkHealth();
window.addEventListener('resize', () => myChart && myChart.resize());
});
return {
stockCode, source, isFetching, isBackendOnline, statusMsg, statusType, tableData,
analysisData, analysisInterval, startFetch, loadData, fetchAnalysis, plotImgUrl
};
}
}).use(ElementPlus).mount('#app');
</script>
</body>
</html>