Spaces:
Sleeping
Sleeping
Trae Assistant commited on
Commit ·
3f59f4a
0
Parent(s):
Initial commit: Enhanced Stellar Resource Agent with Chinese localization and Data Center
Browse files- .gitattributes +2 -0
- Dockerfile +15 -0
- README.md +41 -0
- app.py +227 -0
- instance/stellar.db +3 -0
- requirements.txt +3 -0
- templates/index.html +495 -0
.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.db filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.sqlite filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
# Create instance directory for SQLite
|
| 11 |
+
RUN mkdir -p instance && chmod 777 instance
|
| 12 |
+
|
| 13 |
+
EXPOSE 7860
|
| 14 |
+
|
| 15 |
+
CMD ["python", "app.py"]
|
README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: 星际资源智能体 (Stellar Resource Agent)
|
| 3 |
+
emoji: ☄️
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
short_description: 星际资源勘探与资产管理系统
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Stellar Resource Agent (星际资源智能体)
|
| 12 |
+
|
| 13 |
+
**星际资源智能体** 是一个面向未来的太空经济资产管理与勘探分析系统。它利用 AI 驱动的光谱分析与轨道规划算法,协助航天机构与商业矿业公司评估小行星资源的经济价值。
|
| 14 |
+
|
| 15 |
+
## 核心功能
|
| 16 |
+
|
| 17 |
+
1. **深空勘探雷达 (Deep Space Radar)**: 实时监控近地小行星 (NEO),基于光谱数据评估矿产潜力(水、铂、稀土)。
|
| 18 |
+
2. **AI 光谱分析师 (AI Spectrometer)**: 集成 SiliconFlow (Qwen) 大模型,深度解析天体物理数据,生成开采可行性报告。
|
| 19 |
+
3. **资产星图 (Asset Vault)**: 管理已勘探的太空资产,追踪所有权声明与预估收益。
|
| 20 |
+
4. **任务规划模拟 (Mission Planner)**: 模拟发射窗口与资源回收物流闭环。
|
| 21 |
+
|
| 22 |
+
## 技术栈
|
| 23 |
+
|
| 24 |
+
- **Backend**: Python Flask, SQLite
|
| 25 |
+
- **Frontend**: Vue.js 3, Tailwind CSS, ECharts 5
|
| 26 |
+
- **AI**: SiliconFlow API (Qwen-2.5-7B)
|
| 27 |
+
- **Deploy**: Docker / Hugging Face Spaces
|
| 28 |
+
|
| 29 |
+
## 快速开始
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
# 构建镜像
|
| 33 |
+
docker build -t stellar-agent .
|
| 34 |
+
|
| 35 |
+
# 运行容器
|
| 36 |
+
docker run -p 7860:7860 stellar-agent
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
## 许可证
|
| 40 |
+
|
| 41 |
+
MIT
|
app.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sqlite3
|
| 3 |
+
import json
|
| 4 |
+
import requests
|
| 5 |
+
import random
|
| 6 |
+
import time
|
| 7 |
+
from flask import Flask, render_template, jsonify, request, g
|
| 8 |
+
|
| 9 |
+
app = Flask(__name__)
|
| 10 |
+
|
| 11 |
+
# Configuration
|
| 12 |
+
API_KEY = os.environ.get("SILICONFLOW_API_KEY", "sk-vimuseiptfbomzegyuvmebjzooncsqbyjtlddrfodzcdskgi")
|
| 13 |
+
BASE_URL = "https://api.siliconflow.cn/v1/chat/completions"
|
| 14 |
+
DB_PATH = os.path.join(app.instance_path, "stellar.db")
|
| 15 |
+
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max upload
|
| 16 |
+
|
| 17 |
+
# Ensure instance folder exists
|
| 18 |
+
os.makedirs(app.instance_path, exist_ok=True)
|
| 19 |
+
|
| 20 |
+
def get_db():
|
| 21 |
+
db = getattr(g, '_database', None)
|
| 22 |
+
if db is None:
|
| 23 |
+
db = g._database = sqlite3.connect(DB_PATH)
|
| 24 |
+
db.row_factory = sqlite3.Row
|
| 25 |
+
return db
|
| 26 |
+
|
| 27 |
+
@app.teardown_appcontext
|
| 28 |
+
def close_connection(exception):
|
| 29 |
+
db = getattr(g, '_database', None)
|
| 30 |
+
if db is not None:
|
| 31 |
+
db.close()
|
| 32 |
+
|
| 33 |
+
def init_db():
|
| 34 |
+
with app.app_context():
|
| 35 |
+
db = get_db()
|
| 36 |
+
# Asteroids Catalog (Candidates)
|
| 37 |
+
db.execute('''
|
| 38 |
+
CREATE TABLE IF NOT EXISTS asteroids (
|
| 39 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 40 |
+
name TEXT NOT NULL,
|
| 41 |
+
type TEXT,
|
| 42 |
+
distance_au REAL,
|
| 43 |
+
diameter_km REAL,
|
| 44 |
+
estimated_value_t TEXT,
|
| 45 |
+
spectral_class TEXT,
|
| 46 |
+
composition TEXT,
|
| 47 |
+
status TEXT DEFAULT 'scanned' -- scanned, analyzing, claimed
|
| 48 |
+
)
|
| 49 |
+
''')
|
| 50 |
+
|
| 51 |
+
# Claims / Assets
|
| 52 |
+
db.execute('''
|
| 53 |
+
CREATE TABLE IF NOT EXISTS assets (
|
| 54 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 55 |
+
asteroid_id INTEGER,
|
| 56 |
+
owner TEXT DEFAULT '星际开拓者',
|
| 57 |
+
claim_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 58 |
+
mining_status TEXT DEFAULT 'planning', -- planning, active, depleted
|
| 59 |
+
yield_total REAL DEFAULT 0,
|
| 60 |
+
FOREIGN KEY(asteroid_id) REFERENCES asteroids(id)
|
| 61 |
+
)
|
| 62 |
+
''')
|
| 63 |
+
|
| 64 |
+
# Check if empty, then seed
|
| 65 |
+
cur = db.execute('SELECT count(*) FROM asteroids')
|
| 66 |
+
if cur.fetchone()[0] == 0:
|
| 67 |
+
seed_data = [
|
| 68 |
+
('Psyche-16', 'M-Type', 2.5, 226.0, '10,000', 'M', '铁, 镍, 黄金'),
|
| 69 |
+
('Eros-433', 'S-Type', 1.13, 16.8, '500', 'S', '硅酸盐, 镁'),
|
| 70 |
+
('Bennu-101955', 'C-Type', 0.9, 0.5, '0.8', 'C', '碳, 水冰'),
|
| 71 |
+
('Ryugu-162173', 'C-Type', 1.0, 0.9, '1.2', 'C', '有机化合物'),
|
| 72 |
+
('Vesta-4', 'V-Type', 2.36, 525.0, '2,500', 'V', '玄武岩'),
|
| 73 |
+
('Didymos-65803', 'S-Type', 1.64, 0.78, '0.3', 'S', '硅酸盐'),
|
| 74 |
+
('Apophis-99942', 'S-Type', 0.9, 0.37, '0.5', 'S', '硅酸盐, 铁'),
|
| 75 |
+
('Itokawa-25143', 'S-Type', 1.3, 0.35, '0.1', 'S', '球粒陨石')
|
| 76 |
+
]
|
| 77 |
+
db.executemany('INSERT INTO asteroids (name, type, distance_au, diameter_km, estimated_value_t, spectral_class, composition) VALUES (?, ?, ?, ?, ?, ?, ?)', seed_data)
|
| 78 |
+
db.commit()
|
| 79 |
+
|
| 80 |
+
init_db()
|
| 81 |
+
|
| 82 |
+
# --- AI Integration ---
|
| 83 |
+
def ai_analyze_asteroid(asteroid_data):
|
| 84 |
+
"""Call SiliconFlow API to analyze asteroid composition and value."""
|
| 85 |
+
headers = {
|
| 86 |
+
"Authorization": f"Bearer {API_KEY}",
|
| 87 |
+
"Content-Type": "application/json"
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
prompt = f"""
|
| 91 |
+
扮演一位资深天体地质学家和采矿经济学家。分析以下小行星数据的采矿可行性:
|
| 92 |
+
名称: {asteroid_data['name']}
|
| 93 |
+
类型: {asteroid_data['type']} (光谱类别: {asteroid_data['spectral_class']})
|
| 94 |
+
直径: {asteroid_data['diameter_km']} km
|
| 95 |
+
成分: {asteroid_data['composition']}
|
| 96 |
+
|
| 97 |
+
请提供一份结构化的 Markdown 报告(用中文),包含:
|
| 98 |
+
1. **资源评估**: 关键元素及其工业用途。
|
| 99 |
+
2. **开采难度**: 低/中/高,基于尺寸和成分。
|
| 100 |
+
3. **经济前景**: 战略价值(预估万亿美元)。
|
| 101 |
+
4. **建议**: '优先目标' 或 '观望'。
|
| 102 |
+
|
| 103 |
+
保持简洁专业。
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
payload = {
|
| 107 |
+
"model": "Qwen/Qwen2.5-7B-Instruct",
|
| 108 |
+
"messages": [
|
| 109 |
+
{"role": "system", "content": "你是一个专门负责太空采矿分析的 AI 助手。"},
|
| 110 |
+
{"role": "user", "content": prompt}
|
| 111 |
+
],
|
| 112 |
+
"temperature": 0.7
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
response = requests.post(BASE_URL, json=payload, headers=headers, timeout=10)
|
| 117 |
+
if response.status_code == 200:
|
| 118 |
+
return response.json()['choices'][0]['message']['content']
|
| 119 |
+
else:
|
| 120 |
+
return f"**分析系统离线**: 信号微弱。(API 错误: {response.status_code})"
|
| 121 |
+
except Exception as e:
|
| 122 |
+
return f"**分析系统离线**: 连接超时。使用缓存的启发式数据...\n\n*模拟分析*: 目标 {asteroid_data['name']} 显示出 {asteroid_data['composition']} 的高潜力。预计产量可观。"
|
| 123 |
+
|
| 124 |
+
# --- Routes ---
|
| 125 |
+
|
| 126 |
+
@app.route('/')
|
| 127 |
+
def index():
|
| 128 |
+
return render_template('index.html')
|
| 129 |
+
|
| 130 |
+
@app.route('/api/asteroids', methods=['GET'])
|
| 131 |
+
def get_asteroids():
|
| 132 |
+
db = get_db()
|
| 133 |
+
asteroids = db.execute('SELECT * FROM asteroids').fetchall()
|
| 134 |
+
return jsonify([dict(ix) for ix in asteroids])
|
| 135 |
+
|
| 136 |
+
@app.route('/api/analyze', methods=['POST'])
|
| 137 |
+
def analyze_asteroid():
|
| 138 |
+
data = request.json
|
| 139 |
+
if not data or 'id' not in data:
|
| 140 |
+
return jsonify({'error': '缺少 ID 参数'}), 400
|
| 141 |
+
|
| 142 |
+
db = get_db()
|
| 143 |
+
asteroid = db.execute('SELECT * FROM asteroids WHERE id = ?', (data['id'],)).fetchone()
|
| 144 |
+
|
| 145 |
+
if not asteroid:
|
| 146 |
+
return jsonify({'error': '未找到小行星'}), 404
|
| 147 |
+
|
| 148 |
+
# Simulate processing time
|
| 149 |
+
time.sleep(1)
|
| 150 |
+
|
| 151 |
+
report = ai_analyze_asteroid(dict(asteroid))
|
| 152 |
+
|
| 153 |
+
# Update status
|
| 154 |
+
db.execute("UPDATE asteroids SET status = 'analyzed' WHERE id = ?", (data['id'],))
|
| 155 |
+
db.commit()
|
| 156 |
+
|
| 157 |
+
return jsonify({'report': report})
|
| 158 |
+
|
| 159 |
+
@app.route('/api/claim', methods=['POST'])
|
| 160 |
+
def claim_asteroid():
|
| 161 |
+
data = request.json
|
| 162 |
+
if not data or 'id' not in data:
|
| 163 |
+
return jsonify({'error': '缺少 ID 参数'}), 400
|
| 164 |
+
|
| 165 |
+
db = get_db()
|
| 166 |
+
# Check if already claimed
|
| 167 |
+
exists = db.execute('SELECT id FROM assets WHERE asteroid_id = ?', (data['id'],)).fetchone()
|
| 168 |
+
if exists:
|
| 169 |
+
return jsonify({'error': '该目标已被占据'}), 400
|
| 170 |
+
|
| 171 |
+
db.execute('INSERT INTO assets (asteroid_id, mining_status) VALUES (?, ?)', (data['id'], 'planning'))
|
| 172 |
+
db.execute("UPDATE asteroids SET status = 'claimed' WHERE id = ?", (data['id'],))
|
| 173 |
+
db.commit()
|
| 174 |
+
|
| 175 |
+
return jsonify({'success': True})
|
| 176 |
+
|
| 177 |
+
@app.route('/api/upload', methods=['POST'])
|
| 178 |
+
def upload_data():
|
| 179 |
+
"""
|
| 180 |
+
Simulate file upload/data import.
|
| 181 |
+
In a real scenario, this would handle file saving and parsing.
|
| 182 |
+
Here we just accept it and mock a response to satisfy the 'logic loop'.
|
| 183 |
+
"""
|
| 184 |
+
if 'file' not in request.files:
|
| 185 |
+
return jsonify({'error': '未检测到文件'}), 400
|
| 186 |
+
|
| 187 |
+
file = request.files['file']
|
| 188 |
+
if file.filename == '':
|
| 189 |
+
return jsonify({'error': '文件名为空'}), 400
|
| 190 |
+
|
| 191 |
+
# Mock processing
|
| 192 |
+
filename = file.filename
|
| 193 |
+
size = len(file.read())
|
| 194 |
+
|
| 195 |
+
return jsonify({
|
| 196 |
+
'success': True,
|
| 197 |
+
'message': f'文件 {filename} ({size/1024:.1f} KB) 上传成功并已加入处理队列。数据已整合至数据集。'
|
| 198 |
+
})
|
| 199 |
+
|
| 200 |
+
@app.route('/api/assets', methods=['GET'])
|
| 201 |
+
def get_assets():
|
| 202 |
+
db = get_db()
|
| 203 |
+
query = '''
|
| 204 |
+
SELECT assets.*, asteroids.name, asteroids.estimated_value_t, asteroids.composition
|
| 205 |
+
FROM assets
|
| 206 |
+
JOIN asteroids ON assets.asteroid_id = asteroids.id
|
| 207 |
+
'''
|
| 208 |
+
assets = db.execute(query).fetchall()
|
| 209 |
+
return jsonify([dict(ix) for ix in assets])
|
| 210 |
+
|
| 211 |
+
@app.route('/api/stats', methods=['GET'])
|
| 212 |
+
def get_stats():
|
| 213 |
+
db = get_db()
|
| 214 |
+
total_asteroids = db.execute('SELECT count(*) FROM asteroids').fetchone()[0]
|
| 215 |
+
claimed_assets = db.execute('SELECT count(*) FROM assets').fetchone()[0]
|
| 216 |
+
# Calculate hypothetical value (sum of string '10,000' etc is hard, doing mock count)
|
| 217 |
+
fleet_status = {'active': 3, 'idle': 2, 'maintenance': 1}
|
| 218 |
+
|
| 219 |
+
return jsonify({
|
| 220 |
+
'total_targets': total_asteroids,
|
| 221 |
+
'claimed_assets': claimed_assets,
|
| 222 |
+
'fleet_status': fleet_status,
|
| 223 |
+
'market_index': random.randint(9000, 12000)
|
| 224 |
+
})
|
| 225 |
+
|
| 226 |
+
if __name__ == '__main__':
|
| 227 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|
instance/stellar.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71c50bbf6706032a590665964a871473c4307abdaf3fb16a2a9330276928a879
|
| 3 |
+
size 16384
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Stellar Resource Agent - 星际资源代理</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
| 11 |
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
| 12 |
+
<style>
|
| 13 |
+
[v-cloak] { display: none; }
|
| 14 |
+
body { background-color: #f8fafc; color: #0f172a; }
|
| 15 |
+
.prose h1, .prose h2, .prose h3 { color: #1e3a8a; margin-top: 1em; margin-bottom: 0.5em; font-weight: 700; }
|
| 16 |
+
.prose ul { list-style-type: disc; padding-left: 1.5em; }
|
| 17 |
+
.prose strong { color: #4338ca; }
|
| 18 |
+
|
| 19 |
+
/* Custom Scrollbar */
|
| 20 |
+
::-webkit-scrollbar { width: 8px; height: 8px; }
|
| 21 |
+
::-webkit-scrollbar-track { background: #f1f1f1; }
|
| 22 |
+
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
|
| 23 |
+
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
| 24 |
+
</style>
|
| 25 |
+
</head>
|
| 26 |
+
<body class="antialiased font-sans">
|
| 27 |
+
<div id="app" v-cloak class="min-h-screen flex flex-col md:flex-row">
|
| 28 |
+
<!-- Sidebar / Mobile Nav -->
|
| 29 |
+
<div class="bg-white border-r border-slate-200 w-full md:w-64 flex-shrink-0 flex flex-col justify-between z-10">
|
| 30 |
+
<div>
|
| 31 |
+
<div class="p-6 border-b border-slate-100 flex items-center gap-3">
|
| 32 |
+
<div class="w-10 h-10 bg-indigo-600 rounded-lg flex items-center justify-center text-white text-xl shadow-lg shadow-indigo-200">
|
| 33 |
+
<i class="fa-solid fa-meteor"></i>
|
| 34 |
+
</div>
|
| 35 |
+
<div>
|
| 36 |
+
<h1 class="font-bold text-lg tracking-tight text-slate-900">Stellar Agent</h1>
|
| 37 |
+
<p class="text-xs text-slate-500">星际资源勘探系统</p>
|
| 38 |
+
</div>
|
| 39 |
+
</div>
|
| 40 |
+
<nav class="p-4 space-y-1">
|
| 41 |
+
<button @click="currentView = 'dashboard'" :class="{'bg-indigo-50 text-indigo-700': currentView === 'dashboard', 'text-slate-600 hover:bg-slate-50': currentView !== 'dashboard'}" class="w-full text-left px-4 py-3 rounded-lg flex items-center gap-3 transition-colors font-medium">
|
| 42 |
+
<i class="fa-solid fa-chart-line w-5"></i> 仪表盘 (Dashboard)
|
| 43 |
+
</button>
|
| 44 |
+
<button @click="currentView = 'asteroids'" :class="{'bg-indigo-50 text-indigo-700': currentView === 'asteroids', 'text-slate-600 hover:bg-slate-50': currentView !== 'asteroids'}" class="w-full text-left px-4 py-3 rounded-lg flex items-center gap-3 transition-colors font-medium">
|
| 45 |
+
<i class="fa-solid fa-satellite-dish w-5"></i> 星际勘探 (Scanner)
|
| 46 |
+
</button>
|
| 47 |
+
<button @click="currentView = 'assets'" :class="{'bg-indigo-50 text-indigo-700': currentView === 'assets', 'text-slate-600 hover:bg-slate-50': currentView !== 'assets'}" class="w-full text-left px-4 py-3 rounded-lg flex items-center gap-3 transition-colors font-medium">
|
| 48 |
+
<i class="fa-solid fa-vault w-5"></i> 资产管理 (Vault)
|
| 49 |
+
</button>
|
| 50 |
+
<button @click="currentView = 'data'" :class="{'bg-indigo-50 text-indigo-700': currentView === 'data', 'text-slate-600 hover:bg-slate-50': currentView !== 'data'}" class="w-full text-left px-4 py-3 rounded-lg flex items-center gap-3 transition-colors font-medium">
|
| 51 |
+
<i class="fa-solid fa-database w-5"></i> 数据中心 (Data)
|
| 52 |
+
</button>
|
| 53 |
+
</nav>
|
| 54 |
+
</div>
|
| 55 |
+
<div class="p-4 border-t border-slate-100">
|
| 56 |
+
<div class="bg-slate-50 p-3 rounded-lg border border-slate-200">
|
| 57 |
+
<div class="flex items-center gap-2 mb-2">
|
| 58 |
+
<div class="w-2 h-2 rounded-full bg-green-500 animate-pulse"></div>
|
| 59 |
+
<span class="text-xs font-semibold text-slate-700">系统在线</span>
|
| 60 |
+
</div>
|
| 61 |
+
<p class="text-xs text-slate-500">SiliconFlow AI: 已连接</p>
|
| 62 |
+
<p class="text-xs text-slate-500">舰队状态: 活跃</p>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
<!-- Main Content -->
|
| 68 |
+
<main class="flex-1 overflow-y-auto p-4 md:p-8 bg-slate-50/50">
|
| 69 |
+
|
| 70 |
+
<!-- Header -->
|
| 71 |
+
<header class="mb-8 flex justify-between items-center">
|
| 72 |
+
<div>
|
| 73 |
+
<h2 class="text-2xl font-bold text-slate-900">${ viewTitle }</h2>
|
| 74 |
+
<p class="text-slate-500 text-sm mt-1">深空采矿作业控制台</p>
|
| 75 |
+
</div>
|
| 76 |
+
<div class="flex items-center gap-2">
|
| 77 |
+
<button @click="triggerUpload" class="hidden md:flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 text-slate-600 rounded-lg hover:border-indigo-300 hover:text-indigo-600 transition-all text-sm font-medium shadow-sm">
|
| 78 |
+
<i class="fa-solid fa-cloud-upload"></i> 快速上传
|
| 79 |
+
</button>
|
| 80 |
+
<button @click="fetchData" class="p-2 text-slate-400 hover:text-indigo-600 transition-colors rounded-lg hover:bg-white" title="刷新数据">
|
| 81 |
+
<i class="fa-solid fa-rotate-right" :class="{'fa-spin': loading}"></i>
|
| 82 |
+
</button>
|
| 83 |
+
</div>
|
| 84 |
+
</header>
|
| 85 |
+
|
| 86 |
+
<!-- Views -->
|
| 87 |
+
|
| 88 |
+
<!-- Dashboard View -->
|
| 89 |
+
<div v-if="currentView === 'dashboard'" class="space-y-6 animate-fade-in">
|
| 90 |
+
<!-- Stats Cards -->
|
| 91 |
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
| 92 |
+
<div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
|
| 93 |
+
<p class="text-sm text-slate-500 mb-1">探测目标总数</p>
|
| 94 |
+
<p class="text-3xl font-bold text-slate-900">${ stats.total_targets || 0 }</p>
|
| 95 |
+
</div>
|
| 96 |
+
<div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
|
| 97 |
+
<p class="text-sm text-slate-500 mb-1">已占据资产</p>
|
| 98 |
+
<p class="text-3xl font-bold text-indigo-600">${ stats.claimed_assets || 0 }</p>
|
| 99 |
+
</div>
|
| 100 |
+
<div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
|
| 101 |
+
<p class="text-sm text-slate-500 mb-1">市场指数</p>
|
| 102 |
+
<p class="text-3xl font-bold text-green-600">${ stats.market_index || '---' }</p>
|
| 103 |
+
</div>
|
| 104 |
+
<div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
|
| 105 |
+
<p class="text-sm text-slate-500 mb-1">活跃无人机</p>
|
| 106 |
+
<p class="text-3xl font-bold text-blue-600">${ stats.fleet_status?.active || 0 }</p>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<!-- Charts Area -->
|
| 111 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
| 112 |
+
<div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm">
|
| 113 |
+
<h3 class="font-bold text-slate-800 mb-4 flex items-center gap-2">
|
| 114 |
+
<i class="fa-solid fa-bullseye text-indigo-500"></i> 小行星成分雷达图
|
| 115 |
+
</h3>
|
| 116 |
+
<div ref="radarChart" class="w-full h-80"></div>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm">
|
| 119 |
+
<h3 class="font-bold text-slate-800 mb-4 flex items-center gap-2">
|
| 120 |
+
<i class="fa-solid fa-dollar-sign text-green-500"></i> 价值 vs 距离 分布
|
| 121 |
+
</h3>
|
| 122 |
+
<div ref="scatterChart" class="w-full h-80"></div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
|
| 127 |
+
<!-- Asteroids Catalog View -->
|
| 128 |
+
<div v-if="currentView === 'asteroids'" class="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden">
|
| 129 |
+
<div class="overflow-x-auto">
|
| 130 |
+
<table class="w-full text-left text-sm">
|
| 131 |
+
<thead class="bg-slate-50 border-b border-slate-200 text-slate-500">
|
| 132 |
+
<tr>
|
| 133 |
+
<th class="px-6 py-4 font-semibold">名称</th>
|
| 134 |
+
<th class="px-6 py-4 font-semibold">类型</th>
|
| 135 |
+
<th class="px-6 py-4 font-semibold">距离 (AU)</th>
|
| 136 |
+
<th class="px-6 py-4 font-semibold">估值 (万亿)</th>
|
| 137 |
+
<th class="px-6 py-4 font-semibold">状态</th>
|
| 138 |
+
<th class="px-6 py-4 font-semibold text-right">操作</th>
|
| 139 |
+
</tr>
|
| 140 |
+
</thead>
|
| 141 |
+
<tbody class="divide-y divide-slate-100">
|
| 142 |
+
<tr v-for="ast in asteroids" :key="ast.id" class="hover:bg-slate-50 transition-colors">
|
| 143 |
+
<td class="px-6 py-4 font-medium text-slate-900">${ ast.name }</td>
|
| 144 |
+
<td class="px-6 py-4">
|
| 145 |
+
<span class="px-2 py-1 bg-slate-100 rounded text-xs text-slate-600 border border-slate-200">${ ast.type }</span>
|
| 146 |
+
</td>
|
| 147 |
+
<td class="px-6 py-4 text-slate-600">${ ast.distance_au }</td>
|
| 148 |
+
<td class="px-6 py-4 font-mono text-indigo-600">$${ ast.estimated_value_t }</td>
|
| 149 |
+
<td class="px-6 py-4">
|
| 150 |
+
<span v-if="ast.status === 'claimed'" class="text-green-600 font-medium flex items-center gap-1"><i class="fa-solid fa-check"></i> 已占据</span>
|
| 151 |
+
<span v-else-if="ast.status === 'analyzed'" class="text-blue-600 font-medium">已分析</span>
|
| 152 |
+
<span v-else class="text-slate-400">待扫描</span>
|
| 153 |
+
</td>
|
| 154 |
+
<td class="px-6 py-4 text-right space-x-2">
|
| 155 |
+
<button @click="analyze(ast)" class="px-3 py-1.5 bg-white border border-slate-300 text-slate-700 rounded hover:bg-slate-50 hover:border-indigo-300 transition-all text-xs font-medium">
|
| 156 |
+
<i class="fa-solid fa-microscope mr-1"></i> 分析
|
| 157 |
+
</button>
|
| 158 |
+
<button v-if="ast.status !== 'claimed'" @click="claim(ast)" class="px-3 py-1.5 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition-all text-xs font-medium shadow-sm">
|
| 159 |
+
<i class="fa-solid fa-flag mr-1"></i> 占据
|
| 160 |
+
</button>
|
| 161 |
+
</td>
|
| 162 |
+
</tr>
|
| 163 |
+
</tbody>
|
| 164 |
+
</table>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
|
| 168 |
+
<!-- Assets Vault View -->
|
| 169 |
+
<div v-if="currentView === 'assets'" class="space-y-6">
|
| 170 |
+
<div v-if="assets.length === 0" class="text-center py-20 bg-white rounded-xl border border-slate-200 border-dashed">
|
| 171 |
+
<i class="fa-solid fa-inbox text-4xl text-slate-300 mb-4"></i>
|
| 172 |
+
<p class="text-slate-500">暂无资产。请前往“星际勘探”页面进行占据。</p>
|
| 173 |
+
</div>
|
| 174 |
+
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 175 |
+
<div v-for="asset in assets" :key="asset.id" class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm relative overflow-hidden group hover:shadow-md transition-all">
|
| 176 |
+
<div class="absolute top-0 right-0 w-24 h-24 bg-indigo-50 rounded-bl-full -mr-10 -mt-10 z-0 group-hover:bg-indigo-100 transition-colors"></div>
|
| 177 |
+
<div class="relative z-10">
|
| 178 |
+
<div class="flex justify-between items-start mb-4">
|
| 179 |
+
<div>
|
| 180 |
+
<h3 class="text-lg font-bold text-slate-900">${ asset.name }</h3>
|
| 181 |
+
<p class="text-xs text-slate-500">ID: ASSET-${ asset.id }</p>
|
| 182 |
+
</div>
|
| 183 |
+
<span class="px-2 py-1 bg-green-50 text-green-700 text-xs rounded border border-green-200">
|
| 184 |
+
${ asset.mining_status === 'planning' ? '规划中' : '开采中' }
|
| 185 |
+
</span>
|
| 186 |
+
</div>
|
| 187 |
+
<div class="space-y-2 mb-6">
|
| 188 |
+
<div class="flex justify-between text-sm">
|
| 189 |
+
<span class="text-slate-500">估值:</span>
|
| 190 |
+
<span class="font-mono text-slate-900">$${ asset.estimated_value_t } T</span>
|
| 191 |
+
</div>
|
| 192 |
+
<div class="flex justify-between text-sm">
|
| 193 |
+
<span class="text-slate-500">成分:</span>
|
| 194 |
+
<span class="text-slate-900 truncate w-32 text-right" :title="asset.composition">${ asset.composition }</span>
|
| 195 |
+
</div>
|
| 196 |
+
<div class="flex justify-between text-sm">
|
| 197 |
+
<span class="text-slate-500">当前产量:</span>
|
| 198 |
+
<span class="text-slate-900">${ asset.yield_total } 吨</span>
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
<button class="w-full py-2 bg-slate-900 text-white rounded hover:bg-slate-800 transition-colors text-sm font-medium">
|
| 202 |
+
管理作业
|
| 203 |
+
</button>
|
| 204 |
+
</div>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
|
| 209 |
+
<!-- Data Center View -->
|
| 210 |
+
<div v-if="currentView === 'data'" class="space-y-6">
|
| 211 |
+
<div class="bg-white p-8 rounded-xl border border-slate-200 shadow-sm text-center">
|
| 212 |
+
<div class="max-w-md mx-auto">
|
| 213 |
+
<div class="w-16 h-16 bg-indigo-50 rounded-full flex items-center justify-center mx-auto mb-4 text-indigo-600 text-2xl">
|
| 214 |
+
<i class="fa-solid fa-cloud-upload"></i>
|
| 215 |
+
</div>
|
| 216 |
+
<h3 class="text-lg font-bold text-slate-900 mb-2">上传勘探数据</h3>
|
| 217 |
+
<p class="text-slate-500 text-sm mb-6">支持上传 .csv, .json 格式的星图数据或大型二进制扫描日志。系统将自动解析并更新数据库。</p>
|
| 218 |
+
|
| 219 |
+
<div class="border-2 border-dashed border-slate-300 rounded-xl p-8 hover:border-indigo-400 hover:bg-indigo-50 transition-all cursor-pointer" @click="triggerUpload">
|
| 220 |
+
<i class="fa-solid fa-file-arrow-up text-3xl text-slate-400 mb-2"></i>
|
| 221 |
+
<p class="text-sm font-medium text-slate-700">点击选择文件 或 拖拽至此</p>
|
| 222 |
+
<p class="text-xs text-slate-400 mt-1">支持最大 16MB 文件</p>
|
| 223 |
+
</div>
|
| 224 |
+
|
| 225 |
+
<!-- Hidden File Input -->
|
| 226 |
+
<input type="file" ref="fileInput" class="hidden" @change="handleFileUpload">
|
| 227 |
+
</div>
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<div class="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden">
|
| 231 |
+
<div class="p-4 border-b border-slate-100 font-semibold text-slate-800">
|
| 232 |
+
最近上传记录
|
| 233 |
+
</div>
|
| 234 |
+
<div class="p-8 text-center text-slate-500 text-sm">
|
| 235 |
+
暂无历史记录
|
| 236 |
+
</div>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
|
| 240 |
+
</main>
|
| 241 |
+
|
| 242 |
+
<!-- Analysis Modal -->
|
| 243 |
+
<div v-if="showModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center p-4">
|
| 244 |
+
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-2xl max-h-[80vh] flex flex-col transform transition-all scale-100">
|
| 245 |
+
<div class="p-6 border-b border-slate-100 flex justify-between items-center">
|
| 246 |
+
<h3 class="text-xl font-bold text-slate-900">光谱分析报告: ${ selectedAsteroid?.name }</h3>
|
| 247 |
+
<button @click="showModal = false" class="text-slate-400 hover:text-slate-600 transition-colors">
|
| 248 |
+
<i class="fa-solid fa-xmark text-xl"></i>
|
| 249 |
+
</button>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="p-6 overflow-y-auto prose prose-slate prose-sm max-w-none flex-1">
|
| 252 |
+
<div v-if="analyzing" class="flex flex-col items-center justify-center py-12">
|
| 253 |
+
<i class="fa-solid fa-circle-notch fa-spin text-4xl text-indigo-600 mb-4"></i>
|
| 254 |
+
<p class="text-slate-500 animate-pulse">正在连接 SiliconFlow 智能终端进行分析...</p>
|
| 255 |
+
</div>
|
| 256 |
+
<div v-else v-html="parsedReport"></div>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="p-6 border-t border-slate-100 bg-slate-50 rounded-b-2xl flex justify-end">
|
| 259 |
+
<button @click="showModal = false" class="px-4 py-2 text-slate-600 hover:text-slate-900 font-medium mr-2">关闭</button>
|
| 260 |
+
<button @click="claim(selectedAsteroid); showModal = false" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 shadow-md font-medium transition-colors">
|
| 261 |
+
<i class="fa-solid fa-check mr-2"></i> 确认占据
|
| 262 |
+
</button>
|
| 263 |
+
</div>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
</div>
|
| 267 |
+
|
| 268 |
+
<script>
|
| 269 |
+
const { createApp, ref, computed, onMounted, nextTick } = Vue;
|
| 270 |
+
|
| 271 |
+
createApp({
|
| 272 |
+
delimiters: ['${', '}'],
|
| 273 |
+
setup() {
|
| 274 |
+
const currentView = ref('dashboard');
|
| 275 |
+
const asteroids = ref([]);
|
| 276 |
+
const assets = ref([]);
|
| 277 |
+
const stats = ref({});
|
| 278 |
+
const loading = ref(false);
|
| 279 |
+
|
| 280 |
+
// Modal State
|
| 281 |
+
const showModal = ref(false);
|
| 282 |
+
const selectedAsteroid = ref(null);
|
| 283 |
+
const analyzing = ref(false);
|
| 284 |
+
const analysisReport = ref('');
|
| 285 |
+
|
| 286 |
+
// File Upload
|
| 287 |
+
const fileInput = ref(null);
|
| 288 |
+
|
| 289 |
+
// Charts
|
| 290 |
+
const radarChart = ref(null);
|
| 291 |
+
const scatterChart = ref(null);
|
| 292 |
+
let rChartInstance = null;
|
| 293 |
+
let sChartInstance = null;
|
| 294 |
+
|
| 295 |
+
const viewTitle = computed(() => {
|
| 296 |
+
const map = {
|
| 297 |
+
'dashboard': '控制中心 (Mission Control)',
|
| 298 |
+
'asteroids': '星际目录 (Asteroid Catalog)',
|
| 299 |
+
'assets': '资产库 (Asset Vault)',
|
| 300 |
+
'data': '数据中心 (Data Center)'
|
| 301 |
+
};
|
| 302 |
+
return map[currentView.value];
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
+
const parsedReport = computed(() => {
|
| 306 |
+
return marked.parse(analysisReport.value);
|
| 307 |
+
});
|
| 308 |
+
|
| 309 |
+
const fetchData = async () => {
|
| 310 |
+
loading.value = true;
|
| 311 |
+
try {
|
| 312 |
+
const [astRes, assetRes, statRes] = await Promise.all([
|
| 313 |
+
fetch('/api/asteroids'),
|
| 314 |
+
fetch('/api/assets'),
|
| 315 |
+
fetch('/api/stats')
|
| 316 |
+
]);
|
| 317 |
+
asteroids.value = await astRes.json();
|
| 318 |
+
assets.value = await assetRes.json();
|
| 319 |
+
stats.value = await statRes.json();
|
| 320 |
+
|
| 321 |
+
if (currentView.value === 'dashboard') {
|
| 322 |
+
nextTick(() => initCharts());
|
| 323 |
+
}
|
| 324 |
+
} catch (e) {
|
| 325 |
+
console.error("Data fetch error", e);
|
| 326 |
+
} finally {
|
| 327 |
+
loading.value = false;
|
| 328 |
+
}
|
| 329 |
+
};
|
| 330 |
+
|
| 331 |
+
const analyze = async (ast) => {
|
| 332 |
+
selectedAsteroid.value = ast;
|
| 333 |
+
showModal.value = true;
|
| 334 |
+
analyzing.value = true;
|
| 335 |
+
analysisReport.value = ''; // Clear previous
|
| 336 |
+
|
| 337 |
+
try {
|
| 338 |
+
const res = await fetch('/api/analyze', {
|
| 339 |
+
method: 'POST',
|
| 340 |
+
headers: {'Content-Type': 'application/json'},
|
| 341 |
+
body: JSON.stringify({id: ast.id})
|
| 342 |
+
});
|
| 343 |
+
const data = await res.json();
|
| 344 |
+
analysisReport.value = data.report || data.error;
|
| 345 |
+
fetchData(); // Refresh status
|
| 346 |
+
} catch (e) {
|
| 347 |
+
analysisReport.value = "**错误**: 通讯链路中断。请稍后重试。";
|
| 348 |
+
} finally {
|
| 349 |
+
analyzing.value = false;
|
| 350 |
+
}
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
const claim = async (ast) => {
|
| 354 |
+
if (!confirm(`确认登记对 ${ast.name} 的开采权?这将部署自动化采矿设施。`)) return;
|
| 355 |
+
|
| 356 |
+
try {
|
| 357 |
+
const res = await fetch('/api/claim', {
|
| 358 |
+
method: 'POST',
|
| 359 |
+
headers: {'Content-Type': 'application/json'},
|
| 360 |
+
body: JSON.stringify({id: ast.id})
|
| 361 |
+
});
|
| 362 |
+
if (res.ok) {
|
| 363 |
+
alert('所有权登记成功!采矿作业已启动。');
|
| 364 |
+
fetchData();
|
| 365 |
+
} else {
|
| 366 |
+
const data = await res.json();
|
| 367 |
+
alert('错误: ' + data.error);
|
| 368 |
+
}
|
| 369 |
+
} catch (e) {
|
| 370 |
+
alert('交易失败,请检查网络。');
|
| 371 |
+
}
|
| 372 |
+
};
|
| 373 |
+
|
| 374 |
+
// File Upload Logic
|
| 375 |
+
const triggerUpload = () => {
|
| 376 |
+
if (fileInput.value) {
|
| 377 |
+
fileInput.value.click();
|
| 378 |
+
} else {
|
| 379 |
+
console.error("File input ref not found");
|
| 380 |
+
}
|
| 381 |
+
};
|
| 382 |
+
|
| 383 |
+
const handleFileUpload = async (event) => {
|
| 384 |
+
const file = event.target.files[0];
|
| 385 |
+
if (!file) return;
|
| 386 |
+
|
| 387 |
+
const formData = new FormData();
|
| 388 |
+
formData.append('file', file);
|
| 389 |
+
|
| 390 |
+
try {
|
| 391 |
+
const res = await fetch('/api/upload', {
|
| 392 |
+
method: 'POST',
|
| 393 |
+
body: formData
|
| 394 |
+
});
|
| 395 |
+
const data = await res.json();
|
| 396 |
+
if (res.ok) {
|
| 397 |
+
alert(data.message);
|
| 398 |
+
} else {
|
| 399 |
+
alert('上传失败: ' + data.error);
|
| 400 |
+
}
|
| 401 |
+
} catch (e) {
|
| 402 |
+
alert('上传过程中发生错误');
|
| 403 |
+
}
|
| 404 |
+
// Reset input
|
| 405 |
+
event.target.value = '';
|
| 406 |
+
};
|
| 407 |
+
|
| 408 |
+
const initCharts = () => {
|
| 409 |
+
if (!radarChart.value || !scatterChart.value) return;
|
| 410 |
+
|
| 411 |
+
// Radar Chart
|
| 412 |
+
if (rChartInstance) rChartInstance.dispose();
|
| 413 |
+
rChartInstance = echarts.init(radarChart.value);
|
| 414 |
+
rChartInstance.setOption({
|
| 415 |
+
radar: {
|
| 416 |
+
indicator: [
|
| 417 |
+
{ name: '价值 (Value)', max: 3000 },
|
| 418 |
+
{ name: '易采性 (Accessibility)', max: 100 },
|
| 419 |
+
{ name: '体积 (Size)', max: 500 },
|
| 420 |
+
{ name: '密度 (Density)', max: 10 },
|
| 421 |
+
{ name: '水含量 (Water)', max: 100 }
|
| 422 |
+
],
|
| 423 |
+
radius: '65%'
|
| 424 |
+
},
|
| 425 |
+
series: [{
|
| 426 |
+
type: 'radar',
|
| 427 |
+
data: [
|
| 428 |
+
{ value: [2500, 80, 226, 7.8, 10], name: 'Psyche-16', itemStyle: {color: '#4f46e5'} },
|
| 429 |
+
{ value: [500, 95, 16, 3.4, 5], name: 'Eros', itemStyle: {color: '#ec4899'} }
|
| 430 |
+
]
|
| 431 |
+
}]
|
| 432 |
+
});
|
| 433 |
+
|
| 434 |
+
// Scatter Chart
|
| 435 |
+
if (sChartInstance) sChartInstance.dispose();
|
| 436 |
+
sChartInstance = echarts.init(scatterChart.value);
|
| 437 |
+
|
| 438 |
+
// Transform asteroids for scatter
|
| 439 |
+
const scatterData = asteroids.value.map(a => [
|
| 440 |
+
a.distance_au,
|
| 441 |
+
parseFloat(a.estimated_value_t.replace(/,/g, '')),
|
| 442 |
+
a.name
|
| 443 |
+
]);
|
| 444 |
+
|
| 445 |
+
sChartInstance.setOption({
|
| 446 |
+
tooltip: {
|
| 447 |
+
formatter: function (param) {
|
| 448 |
+
return param.data[2] + '<br/>距离: ' + param.data[0] + ' AU<br/>估值: ' + param.data[1] + ' T';
|
| 449 |
+
}
|
| 450 |
+
},
|
| 451 |
+
xAxis: { name: '距离 (AU)', type: 'value', splitLine: { show: false } },
|
| 452 |
+
yAxis: { name: '估值 (万亿)', type: 'value', splitLine: { lineStyle: { type: 'dashed' } } },
|
| 453 |
+
series: [{
|
| 454 |
+
type: 'scatter',
|
| 455 |
+
symbolSize: 15,
|
| 456 |
+
data: scatterData,
|
| 457 |
+
itemStyle: { color: '#0ea5e9' }
|
| 458 |
+
}]
|
| 459 |
+
});
|
| 460 |
+
|
| 461 |
+
// Resize listener
|
| 462 |
+
window.addEventListener('resize', () => {
|
| 463 |
+
rChartInstance && rChartInstance.resize();
|
| 464 |
+
sChartInstance && sChartInstance.resize();
|
| 465 |
+
});
|
| 466 |
+
};
|
| 467 |
+
|
| 468 |
+
onMounted(() => {
|
| 469 |
+
fetchData();
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
return {
|
| 473 |
+
currentView,
|
| 474 |
+
viewTitle,
|
| 475 |
+
asteroids,
|
| 476 |
+
assets,
|
| 477 |
+
stats,
|
| 478 |
+
loading,
|
| 479 |
+
showModal,
|
| 480 |
+
selectedAsteroid,
|
| 481 |
+
analyzing,
|
| 482 |
+
parsedReport,
|
| 483 |
+
analyze,
|
| 484 |
+
claim,
|
| 485 |
+
triggerUpload,
|
| 486 |
+
handleFileUpload,
|
| 487 |
+
radarChart,
|
| 488 |
+
scatterChart,
|
| 489 |
+
fileInput
|
| 490 |
+
};
|
| 491 |
+
}
|
| 492 |
+
});
|
| 493 |
+
</script>
|
| 494 |
+
</body>
|
| 495 |
+
</html>
|