148 lines
5.1 KiB
Python
148 lines
5.1 KiB
Python
import sys
|
|
import requests
|
|
import json
|
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
|
QLabel, QLineEdit, QPushButton, QTextEdit, QMessageBox,
|
|
QComboBox)
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
|
class PartAddWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("新增部件")
|
|
self.setGeometry(100, 100, 500, 500)
|
|
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
# 主窗口部件
|
|
central_widget = QWidget()
|
|
self.setCentralWidget(central_widget)
|
|
layout = QVBoxLayout()
|
|
|
|
# 机组ID
|
|
turbine_id_layout = QHBoxLayout()
|
|
turbine_id_layout.addWidget(QLabel("机组ID*:"))
|
|
self.turbine_id_input = QLineEdit()
|
|
turbine_id_layout.addWidget(self.turbine_id_input)
|
|
layout.addLayout(turbine_id_layout)
|
|
|
|
# 部件名称
|
|
part_name_layout = QHBoxLayout()
|
|
part_name_layout.addWidget(QLabel("部件名称:"))
|
|
self.part_name_input = QLineEdit()
|
|
part_name_layout.addWidget(self.part_name_input)
|
|
layout.addLayout(part_name_layout)
|
|
|
|
# 部件编号
|
|
part_code_layout = QHBoxLayout()
|
|
part_code_layout.addWidget(QLabel("部件编号:"))
|
|
self.part_code_input = QLineEdit()
|
|
part_code_layout.addWidget(self.part_code_input)
|
|
layout.addLayout(part_code_layout)
|
|
|
|
# 部件类型(下拉选择)
|
|
part_type_layout = QHBoxLayout()
|
|
part_type_layout.addWidget(QLabel("部件类型:"))
|
|
self.part_type_combo = QComboBox()
|
|
self.part_type_combo.addItems(["", "VANE-1", "VANE-2", "VANE-3"]) # 已知的部件类型
|
|
part_type_layout.addWidget(self.part_type_combo)
|
|
layout.addLayout(part_type_layout)
|
|
|
|
# 部件描述
|
|
part_desc_layout = QVBoxLayout()
|
|
part_desc_layout.addWidget(QLabel("部件描述:"))
|
|
self.part_desc_input = QTextEdit()
|
|
self.part_desc_input.setMaximumHeight(80)
|
|
part_desc_layout.addWidget(self.part_desc_input)
|
|
layout.addLayout(part_desc_layout)
|
|
|
|
# 部件厂商
|
|
part_manufacturer_layout = QHBoxLayout()
|
|
part_manufacturer_layout.addWidget(QLabel("部件厂商:"))
|
|
self.part_manufacturer_input = QLineEdit()
|
|
part_manufacturer_layout.addWidget(self.part_manufacturer_input)
|
|
layout.addLayout(part_manufacturer_layout)
|
|
|
|
# 部件型号
|
|
part_model_layout = QHBoxLayout()
|
|
part_model_layout.addWidget(QLabel("部件型号:"))
|
|
self.part_model_input = QLineEdit()
|
|
part_model_layout.addWidget(self.part_model_input)
|
|
layout.addLayout(part_model_layout)
|
|
|
|
# 按钮区域
|
|
button_layout = QHBoxLayout()
|
|
button_layout.addStretch()
|
|
|
|
# 提交按钮
|
|
self.submit_btn = QPushButton("提交")
|
|
self.submit_btn.setFixedWidth(100)
|
|
self.submit_btn.clicked.connect(self.submit_data)
|
|
button_layout.addWidget(self.submit_btn)
|
|
|
|
layout.addLayout(button_layout)
|
|
|
|
central_widget.setLayout(layout)
|
|
|
|
def validate_inputs(self):
|
|
if not self.turbine_id_input.text().strip():
|
|
QMessageBox.warning(self, "输入错误", "机组ID不能为空!")
|
|
return False
|
|
return True
|
|
|
|
def submit_data(self):
|
|
if not self.validate_inputs():
|
|
return
|
|
|
|
# 构造请求数据
|
|
part_data = {
|
|
"turbineId": self.turbine_id_input.text().strip(),
|
|
"partName": self.part_name_input.text().strip(),
|
|
"partCode": self.part_code_input.text().strip(),
|
|
"partType": self.part_type_combo.currentText(),
|
|
"partDesc": self.part_desc_input.toPlainText().strip(),
|
|
"partManufacturer": self.part_manufacturer_input.text().strip(),
|
|
"partModel": self.part_model_input.text().strip()
|
|
}
|
|
|
|
# 确认对话框
|
|
reply = QMessageBox.question(
|
|
self, '确认提交',
|
|
'确定要提交这些部件信息吗?',
|
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
|
)
|
|
|
|
if reply == QMessageBox.No:
|
|
return
|
|
|
|
# 提交数据
|
|
url = "http://pms.dtyx.net:9158/part"
|
|
headers = {
|
|
"Authorization": "null",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(url, headers=headers, data=json.dumps(part_data))
|
|
response.raise_for_status()
|
|
|
|
result = response.json()
|
|
QMessageBox.information(
|
|
self, "提交成功",
|
|
f"部件信息提交成功!\n\n响应结果:\n{json.dumps(result, indent=2)}"
|
|
)
|
|
|
|
except Exception as e:
|
|
QMessageBox.critical(
|
|
self, "提交失败",
|
|
f"部件信息提交失败!\n\n错误信息:\n{str(e)}"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
window = PartAddWindow()
|
|
window.show()
|
|
sys.exit(app.exec_()) |