This commit is contained in:
parent
ddd85bc176
commit
d19de44668
|
|
@ -1667,6 +1667,34 @@ class DeploymentServer:
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}}
|
}}
|
||||||
|
.history-container {{
|
||||||
|
margin-top: 15px;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #fafafa;
|
||||||
|
}}
|
||||||
|
.history-item {{
|
||||||
|
padding: 10px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
}}
|
||||||
|
.history-item:hover {{
|
||||||
|
background-color: #e3f2fd;
|
||||||
|
}}
|
||||||
|
.history-item:last-child {{
|
||||||
|
border-bottom: none;
|
||||||
|
}}
|
||||||
|
.history-empty {{
|
||||||
|
padding: 20px;
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 14px;
|
||||||
|
}}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -1706,6 +1734,17 @@ class DeploymentServer:
|
||||||
<label for="sqlEditor"><strong>SQL 语句:</strong></label>
|
<label for="sqlEditor"><strong>SQL 语句:</strong></label>
|
||||||
<textarea id="sqlEditor" class="sql-editor" placeholder="输入 SQL 查询语句,例如:SELECT * FROM table_name LIMIT 10"></textarea>
|
<textarea id="sqlEditor" class="sql-editor" placeholder="输入 SQL 查询语句,例如:SELECT * FROM table_name LIMIT 10"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- SQL 历史记录 -->
|
||||||
|
<div id="historyPanel" style="display: none;">
|
||||||
|
<div style="margin-top: 10px; margin-bottom: 5px;">
|
||||||
|
<strong>📜 历史查询(最近10条):</strong>
|
||||||
|
</div>
|
||||||
|
<div id="historyContainer" class="history-container">
|
||||||
|
<div class="history-empty">暂无历史记录</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="margin-top: 10px;">
|
<div style="margin-top: 10px;">
|
||||||
<button class="btn btn-success" onclick="executeSQL()">▶ 执行查询</button>
|
<button class="btn btn-success" onclick="executeSQL()">▶ 执行查询</button>
|
||||||
<button class="btn" onclick="clearSQL()">🗑️ 清空</button>
|
<button class="btn" onclick="clearSQL()">🗑️ 清空</button>
|
||||||
|
|
@ -2008,6 +2047,9 @@ class DeploymentServer:
|
||||||
row_dict[col] = values[i] if i < len(values) else None
|
row_dict[col] = values[i] if i < len(values) else None
|
||||||
data_rows.append(row_dict)
|
data_rows.append(row_dict)
|
||||||
|
|
||||||
|
# 保存SQL历史记录
|
||||||
|
save_sql_history(database, sql)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'success': True,
|
'success': True,
|
||||||
'data': data_rows,
|
'data': data_rows,
|
||||||
|
|
@ -2017,6 +2059,19 @@ class DeploymentServer:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'error': str(e)})
|
return jsonify({'success': False, 'error': str(e)})
|
||||||
|
|
||||||
|
@self.app.route('/api/database/history')
|
||||||
|
def get_sql_history():
|
||||||
|
"""获取SQL历史记录API"""
|
||||||
|
try:
|
||||||
|
db_name = request.args.get('db')
|
||||||
|
if not db_name:
|
||||||
|
return jsonify({'success': False, 'error': '缺少数据库名称'})
|
||||||
|
|
||||||
|
history = load_sql_history(db_name)
|
||||||
|
return jsonify({'success': True, 'history': history})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({'success': False, 'error': str(e)})
|
||||||
|
|
||||||
@self.app.route('/<project_name>')
|
@self.app.route('/<project_name>')
|
||||||
def deploy_project(project_name):
|
def deploy_project(project_name):
|
||||||
"""触发项目部署"""
|
"""触发项目部署"""
|
||||||
|
|
@ -2047,6 +2102,47 @@ class DeploymentServer:
|
||||||
self.app.run(host='0.0.0.0', port=self.port, debug=False, use_reloader=False)
|
self.app.run(host='0.0.0.0', port=self.port, debug=False, use_reloader=False)
|
||||||
|
|
||||||
|
|
||||||
|
def save_sql_history(database, sql):
|
||||||
|
"""保存SQL历史记录到文件"""
|
||||||
|
try:
|
||||||
|
history_dir = Path('.devops/sql_history')
|
||||||
|
history_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
history_file = history_dir / f'{database}.json'
|
||||||
|
|
||||||
|
# 读取现有历史记录
|
||||||
|
history = []
|
||||||
|
if history_file.exists():
|
||||||
|
with open(history_file, 'r', encoding='utf-8') as f:
|
||||||
|
history = json.load(f)
|
||||||
|
|
||||||
|
# 添加新记录(去重)
|
||||||
|
if sql not in history:
|
||||||
|
history.insert(0, sql) # 插入到开头
|
||||||
|
# 只保留最近10条
|
||||||
|
history = history[:10]
|
||||||
|
|
||||||
|
# 保存到文件
|
||||||
|
with open(history_file, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(history, f, ensure_ascii=False, indent=2)
|
||||||
|
except Exception as e:
|
||||||
|
Logger.warning(f"保存SQL历史记录失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def load_sql_history(database):
|
||||||
|
"""从文件加载SQL历史记录"""
|
||||||
|
try:
|
||||||
|
history_file = Path('.devops/sql_history') / f'{database}.json'
|
||||||
|
|
||||||
|
if history_file.exists():
|
||||||
|
with open(history_file, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
return []
|
||||||
|
except Exception as e:
|
||||||
|
Logger.warning(f"加载SQL历史记录失败: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
import argparse
|
import argparse
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue